splinter: curses TUI on NetBSD curses, CDE palettes as themes
The harness now has the interface it was missing: a chat pane on three quarters of the screen, a sidebar on one quarter, a status bar underneath. - vendor/netbsd-curses: NetBSD's curses and terminfo, ported edition, vendored with PROVENANCE.md. The build of that one directory needs GNU make; splinter's own Makefile stays POSIX make. - tools/genpalettes.py turns CDE's *.dp palette files into a C table. 42 palettes, generated, checked in with the generator, so the source of every colour is a file in the CDE tree and not a guess. - themes: roles are derived, not invented - background is the darkest of the eight colour sets, foreground the lightest, border the second darkest, accent the most saturated of the rest, status the accent darkened by a third. Delphinium is the default. Unknown palette is an error. - colours map to the terminal through xterm's 256-colour cube when available, the 16 basic colours otherwise, so a palette looks the same everywhere within what the terminal can show. - ui.c redraws only on change; the sidebar shows session, transport, theme and last-turn numbers. Widgets are a labelled empty area - the registry lands next. Six test binaries green, including test_theme (42 palettes, ordering invariants, unknown name rejected, colour indices in range).
This commit is contained in:
1 parent
10e59f23ac
commit
d2e06b316d
793 files changed
+95749
-25
No files matched your search
@@ -1,28 +1,43 @@
|
||||
# splinter -- POSIX make, no GNU extensions, no shell helpers.
|
||||
# splinter -- POSIX make for our own code, GNU make only for the vendored curses.
|
||||
#
|
||||
# `make` builds the binary
|
||||
# `make check` builds and runs every test binary
|
||||
# `make clean` removes generated files only
|
||||
# make builds the binary (with the curses TUI)
|
||||
# make check builds and runs every test binary
|
||||
# make curses builds the vendored NetBSD curses explicitly
|
||||
# make clean removes generated files only
|
||||
#
|
||||
# Generated files never mix with handwritten ones, and nothing here needs a
|
||||
# configure step: the dependency set is libc, plus curl(1) at runtime if you
|
||||
# use --endpoint.
|
||||
# configure step: the dependency set is libc, the vendored NetBSD curses, and
|
||||
# curl(1) at runtime if you use --endpoint.
|
||||
|
||||
CC ?= cc
|
||||
CFLAGS ?= -std=c99 -O2 -Wall -Wextra -Werror -D_POSIX_C_SOURCE=200809L -Iinclude
|
||||
CFLAGS ?= -std=c99 -O2 -Wall -Wextra -Werror -D_POSIX_C_SOURCE=200809L \
|
||||
-Iinclude -Isrc -Ivendor/netbsd-curses/libcurses
|
||||
LDFLAGS ?=
|
||||
LIBS ?=
|
||||
PREFIX ?= /usr/local
|
||||
|
||||
CURSES_DIR = vendor/netbsd-curses
|
||||
CURSES_A = $(CURSES_DIR)/libcurses/libcurses.a \
|
||||
$(CURSES_DIR)/libterminfo/libterminfo.a
|
||||
|
||||
BIN = splinter
|
||||
OBJ = src/buf.o src/tool.o src/session.o src/transport.o src/transport_curl.o \
|
||||
src/builtin.o src/agent.o
|
||||
src/builtin.o src/agent.o src/theme.o src/palettes.o src/ui.o
|
||||
TESTS = tests/test_buf tests/test_tool tests/test_session tests/test_transport \
|
||||
tests/test_agent
|
||||
tests/test_agent tests/test_theme
|
||||
|
||||
all: $(BIN)
|
||||
|
||||
$(BIN): $(OBJ) src/main.o
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJ) src/main.o $(LIBS)
|
||||
# The vendored tree ships a GNUmakefile; this is the only place that needs GNU
|
||||
# make, and it is why the comment above says so out loud.
|
||||
$(CURSES_A):
|
||||
cd $(CURSES_DIR) && $(MAKE) -f GNUmakefile libcurses/libcurses.a \
|
||||
libterminfo/libterminfo.a
|
||||
|
||||
curses: $(CURSES_A)
|
||||
|
||||
$(BIN): $(OBJ) src/main.o $(CURSES_A)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJ) src/main.o $(CURSES_A) $(LIBS)
|
||||
|
||||
src/buf.o: src/buf.c include/splinter.h
|
||||
$(CC) $(CFLAGS) -c -o $@ src/buf.c
|
||||
@@ -45,23 +60,35 @@ src/builtin.o: src/builtin.c include/splinter.h
|
||||
src/agent.o: src/agent.c include/splinter.h
|
||||
$(CC) $(CFLAGS) -c -o $@ src/agent.c
|
||||
|
||||
src/main.o: src/main.c include/splinter.h
|
||||
src/theme.o: src/theme.c src/theme.h src/palettes.h include/splinter.h
|
||||
$(CC) $(CFLAGS) -c -o $@ src/theme.c
|
||||
|
||||
src/palettes.o: src/palettes.c src/palettes.h
|
||||
$(CC) $(CFLAGS) -c -o $@ src/palettes.c
|
||||
|
||||
src/ui.o: src/ui.c src/ui.h src/theme.h include/splinter.h
|
||||
$(CC) $(CFLAGS) -c -o $@ src/ui.c
|
||||
|
||||
src/main.o: src/main.c include/splinter.h src/ui.h src/theme.h
|
||||
$(CC) $(CFLAGS) -c -o $@ src/main.c
|
||||
|
||||
tests/test_buf: tests/test_buf.c $(OBJ)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ tests/test_buf.c $(OBJ) $(LIBS)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ tests/test_buf.c $(OBJ) $(CURSES_A) $(LIBS)
|
||||
|
||||
tests/test_tool: tests/test_tool.c $(OBJ)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ tests/test_tool.c $(OBJ) $(LIBS)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ tests/test_tool.c $(OBJ) $(CURSES_A) $(LIBS)
|
||||
|
||||
tests/test_session: tests/test_session.c $(OBJ)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ tests/test_session.c $(OBJ) $(LIBS)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ tests/test_session.c $(OBJ) $(CURSES_A) $(LIBS)
|
||||
|
||||
tests/test_transport: tests/test_transport.c $(OBJ)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ tests/test_transport.c $(OBJ) $(LIBS)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ tests/test_transport.c $(OBJ) $(CURSES_A) $(LIBS)
|
||||
|
||||
tests/test_agent: tests/test_agent.c $(OBJ)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ tests/test_agent.c $(OBJ) $(LIBS)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ tests/test_agent.c $(OBJ) $(CURSES_A) $(LIBS)
|
||||
|
||||
tests/test_theme: tests/test_theme.c $(OBJ)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ tests/test_theme.c $(OBJ) $(CURSES_A) $(LIBS)
|
||||
|
||||
check: $(BIN) $(TESTS)
|
||||
@set -e; for t in $(TESTS); do echo "== $$t"; ./$$t; done; \
|
||||
@@ -71,9 +98,7 @@ install: $(BIN)
|
||||
mkdir -p $(DESTDIR)$(PREFIX)/bin
|
||||
cp $(BIN) $(DESTDIR)$(PREFIX)/bin/
|
||||
|
||||
PREFIX ?= /usr/local
|
||||
|
||||
clean:
|
||||
rm -f $(BIN) $(OBJ) src/main.o $(TESTS)
|
||||
|
||||
.PHONY: all check install clean
|
||||
.PHONY: all check curses install clean
|
||||
+36
-5
@@ -15,6 +15,8 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "splinter.h"
|
||||
#include "theme.h"
|
||||
#include "ui.h"
|
||||
|
||||
static void
|
||||
usage(FILE *f)
|
||||
@@ -82,10 +84,11 @@ main(int argc, char **argv)
|
||||
struct sp_session_info sess;
|
||||
struct sp_buf answer = { 0 }, err = { 0 };
|
||||
const char *prompt = NULL, *endpoint = NULL, *script = NULL;
|
||||
const char *sessdir = NULL, *sessid = NULL;
|
||||
const char *sessdir = NULL, *sessid = NULL, *theme = NULL;
|
||||
int list_themes = 0;
|
||||
char default_id[64];
|
||||
struct script_ctx sctx = { NULL, 0 };
|
||||
int i, rc;
|
||||
int i, rc, chatmode = 0;
|
||||
|
||||
memset(®, 0, sizeof(reg));
|
||||
memset(&ag, 0, sizeof(ag));
|
||||
@@ -113,6 +116,8 @@ main(int argc, char **argv)
|
||||
if (!need_value(argc, i, argv[i]))
|
||||
return 2;
|
||||
script = argv[++i];
|
||||
} else if (!strcmp(argv[i], "--chat")) {
|
||||
chatmode = 1;
|
||||
} else if (!strcmp(argv[i], "--autonomous")) {
|
||||
cfg.autonomous = 1;
|
||||
} else if (!strcmp(argv[i], "--steps")) {
|
||||
@@ -123,6 +128,12 @@ main(int argc, char **argv)
|
||||
if (!need_value(argc, i, argv[i]))
|
||||
return 2;
|
||||
cfg.max_bytes = (size_t)strtoul(argv[++i], NULL, 10);
|
||||
} else if (!strcmp(argv[i], "--theme")) {
|
||||
if (!need_value(argc, i, argv[i]))
|
||||
return 2;
|
||||
theme = argv[++i];
|
||||
} else if (!strcmp(argv[i], "--list-themes")) {
|
||||
list_themes = 1;
|
||||
} else if (!strcmp(argv[i], "--session")) {
|
||||
if (!need_value(argc, i, argv[i]))
|
||||
return 2;
|
||||
@@ -137,6 +148,16 @@ main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (list_themes) {
|
||||
const char **names;
|
||||
size_t count, k;
|
||||
|
||||
sp_theme_list(&names, &count);
|
||||
for (k = 0; k < count; k++)
|
||||
printf("%s\n", names[k]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (endpoint != NULL && script != NULL) {
|
||||
fprintf(stderr, "splinter: choose one transport, not two\n");
|
||||
return 2;
|
||||
@@ -146,9 +167,9 @@ main(int argc, char **argv)
|
||||
"--script)\n");
|
||||
return 2;
|
||||
}
|
||||
if (prompt == NULL) {
|
||||
fprintf(stderr, "splinter: -p/--prompt is required in %s\n",
|
||||
SP_VERSION);
|
||||
if (prompt == NULL && !chatmode) {
|
||||
fprintf(stderr, "splinter: -p/--prompt is required unless you "
|
||||
"pass --chat\n");
|
||||
return 2;
|
||||
}
|
||||
|
||||
@@ -197,6 +218,16 @@ main(int argc, char **argv)
|
||||
ag.reg = ®
|
||||
ag.cfg = &cfg;
|
||||
|
||||
if (chatmode) {
|
||||
rc = sp_ui_run(&ag, endpoint, theme);
|
||||
if (sctx.f != NULL)
|
||||
fclose(sctx.f);
|
||||
sp_buf_free(&answer);
|
||||
sp_buf_free(&err);
|
||||
sp_registry_free(®);
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = sp_agent_run(&ag, prompt, &answer, &err);
|
||||
if (rc == 0) {
|
||||
printf("%s\n", answer.p);
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Generated by tools/genpalettes.py from the CDE palette files.
|
||||
* Do not edit by hand: change the .dp source or the generator.
|
||||
*/
|
||||
#include "palettes.h"
|
||||
|
||||
const struct sp_palette sp_palettes[] = {
|
||||
{ "Alpine", { {0xaf,0xbf,0xfb}, {0x78,0xaa,0xb8}, {0x7a,0xb9,0xd8}, {0xbf,0xc0,0xc5}, {0xbf,0x92,0x79}, {0xbf,0xc0,0xc5}, {0xbd,0xbd,0xeb}, {0xbf,0xc0,0xc5} } },
|
||||
{ "Arizona", { {0xff,0xab,0x78}, {0xa8,0x6b,0x79}, {0xde,0xb3,0x94}, {0x88,0x57,0x70}, {0xc3,0x7d,0x79}, {0xcd,0x78,0x6a}, {0x64,0x60,0x47}, {0x84,0x54,0x5f} } },
|
||||
{ "BeigeRose", { {0x61,0x88,0x88}, {0xd1,0xc0,0xae}, {0xb7,0x89,0x89}, {0xf0,0xec,0xeb}, {0x91,0x91,0x91}, {0xb9,0xb9,0xb9}, {0x87,0x93,0xae}, {0x90,0xb0,0xac} } },
|
||||
{ "Black", { {0x00,0x00,0x00}, {0x00,0x00,0x00}, {0x00,0x00,0x00}, {0x00,0x00,0x00}, {0x00,0x00,0x00}, {0x00,0x00,0x00}, {0x00,0x00,0x00}, {0x00,0x00,0x00} } },
|
||||
{ "BlackWhite", { {0x00,0x00,0x00}, {0xff,0xff,0xff}, {0xff,0xff,0xff}, {0x00,0x00,0x00}, {0x00,0x00,0x00}, {0x00,0x00,0x00}, {0x00,0x00,0x00}, {0x00,0x00,0x00} } },
|
||||
{ "Broica", { {0xed,0xa8,0x70}, {0x99,0x99,0x99}, {0x89,0x98,0xaa}, {0x68,0x6f,0x82}, {0xc6,0xb2,0xa8}, {0x49,0x92,0xa7}, {0xb7,0x87,0x8d}, {0x93,0xab,0xbf} } },
|
||||
{ "Cabernet", { {0xd8,0x87,0x75}, {0x63,0x8a,0x7a}, {0x45,0x62,0x56}, {0x4b,0x5e,0x61}, {0xb6,0x5c,0x71}, {0x83,0x3b,0x47}, {0x79,0x46,0x55}, {0x49,0x5c,0x65} } },
|
||||
{ "Camouflage", { {0xac,0xbe,0xb4}, {0x6e,0x7d,0x76}, {0x90,0x7b,0x7b}, {0x82,0x82,0x9b}, {0x8e,0x8e,0x77}, {0x7f,0x6c,0x6c}, {0x8e,0x8e,0x85}, {0x4e,0x6b,0x65} } },
|
||||
{ "Charcoal", { {0x87,0xb4,0xb0}, {0x76,0x72,0x79}, {0x69,0x63,0x63}, {0x89,0x6d,0x6d}, {0x82,0x85,0x85}, {0x63,0x6f,0x6d}, {0x91,0x91,0x91}, {0xaf,0x96,0x96} } },
|
||||
{ "Chocolate", { {0xa9,0xa9,0xff}, {0x70,0x8c,0x8d}, {0x87,0x87,0xaf}, {0x96,0x78,0x78}, {0xb9,0xa0,0xa0}, {0xa5,0x82,0x82}, {0xbb,0xbb,0xd9}, {0x96,0x96,0xb9} } },
|
||||
{ "Cinnamon", { {0xb1,0x4b,0x50}, {0x92,0x68,0x66}, {0x79,0x6e,0x6d}, {0x83,0x69,0x60}, {0x9b,0x68,0x62}, {0xa2,0x8d,0x8c}, {0x84,0x75,0x74}, {0x78,0x69,0x5d} } },
|
||||
{ "Clay", { {0xff,0xaa,0xaa}, {0x96,0x82,0x82}, {0x5a,0x8b,0x8d}, {0x8c,0x64,0x64}, {0xaf,0x91,0x91}, {0xa5,0x6e,0x6e}, {0xac,0x83,0x83}, {0x2f,0x8b,0x8d} } },
|
||||
{ "Crimson", { {0xb2,0x4d,0x7a}, {0xae,0xb2,0xc3}, {0x71,0x8b,0xa5}, {0xff,0xf7,0xe9}, {0x68,0xa6,0xa0}, {0x8d,0xad,0xc7}, {0xd3,0x97,0x98}, {0x97,0x93,0xb5} } },
|
||||
{ "DarkGold", { {0xb8,0x96,0x63}, {0x7a,0x7c,0x7f}, {0x53,0x55,0x70}, {0xff,0xff,0xe2}, {0xa8,0xa8,0xa8}, {0x79,0x9c,0xa1}, {0x86,0x7f,0xb5}, {0x6b,0x94,0xb2} } },
|
||||
{ "Default", { {0xed,0xa8,0x70}, {0x99,0x99,0x99}, {0x89,0x98,0xaa}, {0x68,0x6f,0x82}, {0xc6,0xb2,0xa8}, {0x49,0x92,0xa7}, {0xb7,0x87,0x8d}, {0x93,0xab,0xbf} } },
|
||||
{ "Delphinium", { {0x85,0xc4,0xed}, {0xc8,0xc8,0xc8}, {0x85,0x8c,0xd9}, {0xff,0xff,0xe6}, {0x78,0xb4,0xbe}, {0x55,0x86,0xc3}, {0xba,0x9d,0x91}, {0x90,0xa0,0xbe} } },
|
||||
{ "Desert", { {0xe5,0xb7,0x93}, {0xc2,0xbb,0xa7}, {0x8c,0x8f,0x98}, {0xfd,0xfd,0xfa}, {0x9f,0xae,0xb5}, {0x6f,0x98,0xa2}, {0x73,0x9e,0xbd}, {0xc4,0x92,0x9b} } },
|
||||
{ "Golden", { {0xfa,0xad,0x49}, {0x4d,0x64,0x8d}, {0xbe,0x82,0x6f}, {0x47,0x63,0x4f}, {0x75,0x7c,0xa6}, {0x3d,0x77,0x77}, {0x2b,0x79,0x85}, {0xb1,0x70,0x5f} } },
|
||||
{ "Grass", { {0xd4,0xc7,0x7d}, {0xbe,0xc6,0xb7}, {0x5e,0x9c,0x7b}, {0xe2,0xf3,0xe2}, {0xa4,0xa9,0xaa}, {0x90,0xa7,0x93}, {0x60,0x87,0x9e}, {0x82,0x96,0x94} } },
|
||||
{ "GrayScale", { {0xc3,0xc3,0xc3}, {0x78,0x77,0x77}, {0xbd,0xbd,0xbd}, {0x94,0x94,0x93}, {0xbc,0xbc,0xbc}, {0x93,0x93,0x93}, {0x7f,0x7f,0x7f}, {0x93,0x93,0x93} } },
|
||||
{ "Lilac", { {0xd3,0xd1,0x78}, {0xa5,0xa5,0xac}, {0xa6,0x92,0xb7}, {0xc3,0xc3,0xc9}, {0xa5,0xa5,0xac}, {0xc6,0xb1,0xb1}, {0xc2,0xc2,0xd2}, {0x91,0x7e,0x9f} } },
|
||||
{ "MakroSlate", { {0x18,0x1f,0x26}, {0x2b,0x3a,0x44}, {0x45,0x5a,0x66}, {0x60,0x78,0x88}, {0x8e,0xa8,0xb8}, {0xb8,0xcc,0xd8}, {0xd8,0xe8,0xf0}, {0xf8,0xfc,0xff} } },
|
||||
{ "Mustard", { {0xd5,0x80,0x2e}, {0xb7,0x5f,0x5f}, {0x4d,0x64,0x8d}, {0x5c,0x6a,0x58}, {0x88,0x7c,0xa3}, {0xbe,0x82,0x6f}, {0x46,0x79,0x76}, {0x2a,0x68,0x89} } },
|
||||
{ "Neptune", { {0xa2,0xe5,0xc6}, {0x3f,0x93,0x8d}, {0x2d,0x4e,0x76}, {0x78,0x89,0xa5}, {0x63,0x7e,0x95}, {0x3e,0x70,0x8a}, {0x3d,0x7d,0x84}, {0x61,0x6d,0x8e} } },
|
||||
{ "NorthernSky", { {0xa4,0x75,0x91}, {0x1b,0x5d,0x6c}, {0x0c,0x5a,0x87}, {0x00,0x57,0x7a}, {0x41,0x52,0x5c}, {0x4b,0x7b,0x82}, {0x27,0x70,0x8b}, {0x3d,0x40,0x7c} } },
|
||||
{ "Nutmeg", { {0xce,0xc2,0xbb}, {0x25,0x65,0x93}, {0x9f,0x88,0x81}, {0xcd,0xb2,0xa6}, {0xb3,0x9c,0x8f}, {0xcf,0xb8,0xaa}, {0x90,0xac,0xdb}, {0x45,0x72,0x93} } },
|
||||
{ "Olive", { {0x83,0x83,0x5a}, {0xc3,0xc3,0xb9}, {0x87,0x79,0x87}, {0xce,0xc2,0xb8}, {0xcd,0xbd,0xaa}, {0xe1,0xa8,0x97}, {0xb5,0xa1,0xb5}, {0x9a,0x91,0x9a} } },
|
||||
{ "Orchid", { {0xb9,0xb9,0xff}, {0x9b,0x9b,0xb9}, {0xa8,0xa8,0xcd}, {0x82,0x82,0xab}, {0x9b,0xbe,0xd7}, {0x98,0x98,0xc8}, {0x8c,0x8c,0xaa}, {0xb0,0xb0,0xbf} } },
|
||||
{ "PBNJ", { {0xb6,0x5c,0x61}, {0xd9,0xc1,0xb2}, {0xde,0xa1,0x7f}, {0xf1,0xe3,0xd2}, {0xc6,0x90,0x76}, {0xcb,0xa0,0x8d}, {0x9e,0x86,0xb5}, {0xeb,0xd7,0xbf} } },
|
||||
{ "Sand", { {0xea,0xbe,0x93}, {0xc7,0xaf,0xaf}, {0x8e,0xa2,0xc1}, {0xd4,0xd4,0xda}, {0xaf,0x81,0x81}, {0xbb,0xb5,0xa8}, {0xbf,0xbe,0xd6}, {0x96,0x96,0x96} } },
|
||||
{ "SantaFe", { {0xef,0x9d,0x9d}, {0x7e,0xab,0xab}, {0xbd,0xa2,0x8d}, {0xce,0xaf,0x9a}, {0x83,0xa5,0xb6}, {0x7f,0x9c,0x8c}, {0x72,0xab,0xc8}, {0x9c,0x99,0x92} } },
|
||||
{ "Savannah", { {0xda,0x9a,0x68}, {0xb4,0xaa,0x94}, {0xa0,0xb2,0xc8}, {0xd2,0xbf,0xa8}, {0xc6,0xb2,0xa8}, {0x97,0xa7,0x92}, {0xb7,0xae,0xaa}, {0x93,0xab,0xbf} } },
|
||||
{ "SeaFoam", { {0xaa,0xcb,0xdb}, {0xa7,0xa8,0xa7}, {0x7d,0xb7,0xbb}, {0x97,0xb0,0xb2}, {0xaf,0xbf,0xba}, {0xc5,0xaf,0xa4}, {0x98,0xaa,0xa5}, {0xc8,0xad,0xa0} } },
|
||||
{ "SkyRed", { {0xcc,0x68,0x6f}, {0xaf,0xc0,0xc2}, {0x6d,0xa7,0xb4}, {0xe1,0xeb,0xe1}, {0x6e,0x91,0xaa}, {0x8b,0x97,0x9f}, {0xb7,0xb5,0x8d}, {0x5e,0x84,0xb9} } },
|
||||
{ "SoftBlue", { {0x7f,0xa9,0xeb}, {0x76,0xa9,0x9c}, {0x5b,0x85,0xd0}, {0x6c,0x6c,0x6c}, {0x94,0xd5,0xdf}, {0xb8,0xce,0xbc}, {0xbd,0xbd,0xeb}, {0x5d,0x7c,0xb8} } },
|
||||
{ "SouthWest", { {0xff,0x7d,0x79}, {0xa9,0x75,0x61}, {0xc0,0x9b,0x80}, {0xb1,0x88,0x85}, {0xb8,0x6f,0x4b}, {0x88,0x72,0x61}, {0xb8,0x8a,0x75}, {0x98,0x9c,0xa8} } },
|
||||
{ "Summer", { {0xff,0x56,0x64}, {0xff,0xd6,0x90}, {0x82,0x9f,0xff}, {0xff,0xff,0xff}, {0x86,0xea,0xe7}, {0xb8,0xc8,0xff}, {0x64,0xc1,0xff}, {0xbc,0xc5,0xdb} } },
|
||||
{ "Tundra", { {0xf1,0xbc,0x7f}, {0xa5,0x96,0x80}, {0x7c,0x92,0xb9}, {0x76,0x7e,0x63}, {0x85,0x96,0x80}, {0x7a,0x93,0x95}, {0x82,0x7a,0x8f}, {0x83,0x7e,0x75} } },
|
||||
{ "Urchin", { {0xd5,0xa5,0x91}, {0x0f,0x7c,0x7a}, {0x70,0x68,0x89}, {0x0c,0x68,0x64}, {0x37,0x92,0xa2}, {0x12,0x8e,0x89}, {0x88,0x9a,0x8e}, {0x32,0x83,0x92} } },
|
||||
{ "Wheat", { {0xd1,0xa5,0x7a}, {0xdb,0xc2,0x91}, {0x48,0x6d,0x7f}, {0xbf,0xc0,0xc5}, {0x94,0xd5,0xdf}, {0xb8,0xce,0xbc}, {0xbd,0xbd,0xeb}, {0x5d,0x7c,0xb8} } },
|
||||
{ "White", { {0xff,0xff,0xff}, {0xff,0xff,0xff}, {0xff,0xff,0xff}, {0xff,0xff,0xff}, {0xff,0xff,0xff}, {0xff,0xff,0xff}, {0xff,0xff,0xff}, {0xff,0xff,0xff} } },
|
||||
{ "WhiteBlack", { {0xff,0xff,0xff}, {0x00,0x00,0x00}, {0x00,0x00,0x00}, {0xff,0xff,0xff}, {0xff,0xff,0xff}, {0xff,0xff,0xff}, {0xff,0xff,0xff}, {0xff,0xff,0xff} } },
|
||||
};
|
||||
|
||||
const size_t sp_palette_count = sizeof(sp_palettes) / sizeof(sp_palettes[0]);
|
||||
@@ -0,0 +1,15 @@
|
||||
/* splinter -- CDE palettes, generated by tools/genpalettes.py. */
|
||||
#ifndef SPLINTER_PALETTES_H
|
||||
#define SPLINTER_PALETTES_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
struct sp_palette {
|
||||
const char *name;
|
||||
unsigned char c[8][3]; /* eight CDE colour sets, RGB 0-255 */
|
||||
};
|
||||
|
||||
extern const struct sp_palette sp_palettes[];
|
||||
extern const size_t sp_palette_count;
|
||||
|
||||
#endif /* SPLINTER_PALETTES_H */
|
||||
+174
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* splinter -- CDE palettes as terminal themes.
|
||||
*
|
||||
* Copyright (c) 2026 Konrad Lother
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "theme.h"
|
||||
#include "palettes.h"
|
||||
|
||||
static int
|
||||
luma(const unsigned char *c)
|
||||
{
|
||||
/* integer Rec.601 luma, so the ordering is deterministic and testable */
|
||||
return 299 * c[0] + 587 * c[1] + 114 * c[2];
|
||||
}
|
||||
|
||||
static int
|
||||
saturation(const unsigned char *c)
|
||||
{
|
||||
int hi = c[0], lo = c[0];
|
||||
|
||||
if (c[1] > hi)
|
||||
hi = c[1];
|
||||
if (c[2] > hi)
|
||||
hi = c[2];
|
||||
if (c[1] < lo)
|
||||
lo = c[1];
|
||||
if (c[2] < lo)
|
||||
lo = c[2];
|
||||
return hi - lo;
|
||||
}
|
||||
|
||||
static const struct sp_palette *
|
||||
find_palette(const char *name)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < sp_palette_count; i++) {
|
||||
if (strcmp(sp_palettes[i].name, name) == 0)
|
||||
return &sp_palettes[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
sp_theme_load(const char *name, struct sp_theme *out, struct sp_buf *err)
|
||||
{
|
||||
const struct sp_palette *p;
|
||||
int order[8], i, j;
|
||||
int darkest, lightest, second, accent;
|
||||
int best;
|
||||
|
||||
if (name == NULL || *name == '\0')
|
||||
name = SP_THEME_DEFAULT;
|
||||
p = find_palette(name);
|
||||
if (p == NULL) {
|
||||
sp_buf_printf(err, "theme: unknown palette '%s' (%zu known)",
|
||||
name, sp_palette_count);
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
order[i] = i;
|
||||
for (i = 1; i < 8; i++) {
|
||||
int v = order[i];
|
||||
|
||||
for (j = i - 1; j >= 0 && luma(p->c[order[j]]) > luma(p->c[v]);
|
||||
j--)
|
||||
order[j + 1] = order[j];
|
||||
order[j + 1] = v;
|
||||
}
|
||||
|
||||
darkest = order[0];
|
||||
lightest = order[7];
|
||||
second = order[1];
|
||||
|
||||
accent = -1;
|
||||
best = -1;
|
||||
for (i = 0; i < 8; i++) {
|
||||
int idx = order[i], s;
|
||||
|
||||
if (idx == darkest || idx == lightest || idx == second)
|
||||
continue;
|
||||
s = saturation(p->c[idx]);
|
||||
if (s > best) {
|
||||
best = s;
|
||||
accent = idx;
|
||||
}
|
||||
}
|
||||
if (accent < 0)
|
||||
accent = lightest; /* a fully grey palette has no accent */
|
||||
|
||||
memset(out, 0, sizeof(*out));
|
||||
out->name = p->name;
|
||||
memcpy(out->bg, p->c[darkest], 3);
|
||||
memcpy(out->fg, p->c[lightest], 3);
|
||||
memcpy(out->border, p->c[second], 3);
|
||||
memcpy(out->accent, p->c[accent], 3);
|
||||
for (i = 0; i < 3; i++)
|
||||
out->status[i] = (unsigned char)(p->c[accent][i] * 2 / 3);
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t
|
||||
sp_theme_list(const char ***names, size_t *count)
|
||||
{
|
||||
static const char *list[256];
|
||||
size_t i, n = 0;
|
||||
|
||||
for (i = 0; i < sp_palette_count && n < 256; i++)
|
||||
list[n++] = sp_palettes[i].name;
|
||||
*names = list;
|
||||
*count = n;
|
||||
return n;
|
||||
}
|
||||
|
||||
short
|
||||
sp_color_rgb(unsigned char r, unsigned char g, unsigned char b, short colors)
|
||||
{
|
||||
static const unsigned char base[16][3] = {
|
||||
{ 0, 0, 0}, {128, 0, 0}, { 0, 128, 0}, {128, 128, 0},
|
||||
{ 0, 0, 128}, {128, 0, 128}, { 0, 128, 128}, {192, 192, 192},
|
||||
{128, 128, 128}, {255, 0, 0}, { 0, 255, 0}, {255, 255, 0},
|
||||
{ 0, 0, 255}, {255, 0, 255}, { 0, 255, 255}, {255, 255, 255}
|
||||
};
|
||||
static const int level[6] = { 0, 95, 135, 175, 215, 255 };
|
||||
int i, best = 0, bestd = 1 << 30;
|
||||
|
||||
if (colors >= 256) {
|
||||
int ri = 0, gi = 0, bi = 0, dr, dg, db;
|
||||
|
||||
for (i = 1; i < 6; i++) {
|
||||
if (r >= level[i])
|
||||
ri = i;
|
||||
}
|
||||
for (i = 1; i < 6; i++) {
|
||||
if (g >= level[i])
|
||||
gi = i;
|
||||
}
|
||||
for (i = 1; i < 6; i++) {
|
||||
if (b >= level[i])
|
||||
bi = i;
|
||||
}
|
||||
dr = r - level[ri];
|
||||
dg = g - level[gi];
|
||||
db = b - level[bi];
|
||||
if (dr * dr + dg * dg + db * db > 3 * 32 * 32) {
|
||||
/* closer to a grey than to a cube corner: use the ramp */
|
||||
int grey = (r + g + b) / 3;
|
||||
int gi2 = (grey - 8) / 10;
|
||||
|
||||
if (gi2 < 0)
|
||||
gi2 = 0;
|
||||
if (gi2 > 23)
|
||||
gi2 = 23;
|
||||
return (short)(232 + gi2);
|
||||
}
|
||||
return (short)(16 + 36 * ri + 6 * gi + bi);
|
||||
}
|
||||
|
||||
for (i = 0; i < (colors >= 16 ? 16 : 8); i++) {
|
||||
int dr = r - base[i][0], dg = g - base[i][1], db = b - base[i][2];
|
||||
int d = dr * dr + dg * dg + db * db;
|
||||
|
||||
if (d < bestd) {
|
||||
bestd = d;
|
||||
best = i;
|
||||
}
|
||||
}
|
||||
return (short)best;
|
||||
}
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* splinter -- CDE palettes as terminal themes.
|
||||
*
|
||||
* Copyright (c) 2026 Konrad Lother
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* A CDE palette is eight colour sets, not a set of named roles. Roles are
|
||||
* therefore derived, not looked up, and the derivation is stated so it can be
|
||||
* checked:
|
||||
*
|
||||
* background darkest of the eight
|
||||
* foreground lightest of the eight
|
||||
* border second darkest
|
||||
* accent the most saturated of the remaining six
|
||||
* status the accent, darkened by a third (a bar has to read as a bar)
|
||||
*
|
||||
* The default palette is Delphinium, the CDE desktop default.
|
||||
*/
|
||||
#ifndef SPLINTER_THEME_H
|
||||
#define SPLINTER_THEME_H
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "splinter.h"
|
||||
|
||||
struct sp_theme {
|
||||
const char *name;
|
||||
unsigned char bg[3];
|
||||
unsigned char fg[3];
|
||||
unsigned char border[3];
|
||||
unsigned char accent[3];
|
||||
unsigned char status[3];
|
||||
};
|
||||
|
||||
#define SP_THEME_DEFAULT "Delphinium"
|
||||
|
||||
/* Load a palette by name; NULL selects the default. Returns 0 or -1. */
|
||||
int sp_theme_load(const char *name, struct sp_theme *out, struct sp_buf *err);
|
||||
|
||||
/* List palette names, alphabetical. Returns the number written. */
|
||||
size_t sp_theme_list(const char ***names, size_t *count);
|
||||
|
||||
/* Nearest xterm colour index for an RGB triple, for `colors` palette entries. */
|
||||
short sp_color_rgb(unsigned char r, unsigned char g, unsigned char b,
|
||||
short colors);
|
||||
|
||||
#endif /* SPLINTER_THEME_H */
|
||||
@@ -0,0 +1,361 @@
|
||||
/*
|
||||
* splinter -- curses chat interface.
|
||||
*
|
||||
* Copyright (c) 2026 Konrad Lother
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*
|
||||
* Layout, fixed and deliberate:
|
||||
*
|
||||
* +---------------------------------+------------+
|
||||
* | history | sidebar |
|
||||
* | three quarters | one quarter|
|
||||
* +---------------------------------+------------+
|
||||
* | status bar |
|
||||
* +----------------------------------------------+
|
||||
*
|
||||
* Only the UI thread ever calls into curses. Anything that wants to appear in
|
||||
* the sidebar hands over finished text and never touches a WINDOW.
|
||||
*
|
||||
* Redraws happen when something changed -- after a turn, after a key -- so an
|
||||
* idle splinter burns no CPU.
|
||||
*
|
||||
* Keys: Enter sends, Ctrl-L redraws, Ctrl-C drops the input line, Ctrl-D quits.
|
||||
*/
|
||||
#include <curses.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#include "splinter.h"
|
||||
#include "theme.h"
|
||||
#include "ui.h"
|
||||
|
||||
#define MAX_ENTRIES 512
|
||||
|
||||
struct entry {
|
||||
char *role;
|
||||
char *text;
|
||||
};
|
||||
|
||||
struct ui_state {
|
||||
struct entry entries[MAX_ENTRIES];
|
||||
size_t n;
|
||||
long last_ms;
|
||||
size_t last_steps;
|
||||
size_t last_calls;
|
||||
const char *endpoint;
|
||||
int quit;
|
||||
struct sp_theme theme;
|
||||
};
|
||||
|
||||
static WINDOW *ui_hist;
|
||||
static WINDOW *ui_side;
|
||||
static WINDOW *ui_input;
|
||||
static WINDOW *ui_status;
|
||||
|
||||
enum {
|
||||
PAIR_MAIN = 1, /* fg on bg */
|
||||
PAIR_ACCENT, /* accent on bg */
|
||||
PAIR_DIM, /* border on bg */
|
||||
PAIR_STATUS /* bg on status */
|
||||
};
|
||||
|
||||
static void
|
||||
init_colors(const struct sp_theme *t)
|
||||
{
|
||||
short n = (short)(COLORS > 0 ? COLORS : 8);
|
||||
|
||||
if (!has_colors())
|
||||
return;
|
||||
start_color();
|
||||
use_default_colors();
|
||||
init_pair(PAIR_MAIN, sp_color_rgb(t->fg[0], t->fg[1], t->fg[2], n),
|
||||
sp_color_rgb(t->bg[0], t->bg[1], t->bg[2], n));
|
||||
init_pair(PAIR_ACCENT, sp_color_rgb(t->accent[0], t->accent[1],
|
||||
t->accent[2], n), sp_color_rgb(t->bg[0], t->bg[1], t->bg[2], n));
|
||||
init_pair(PAIR_DIM, sp_color_rgb(t->border[0], t->border[1],
|
||||
t->border[2], n), sp_color_rgb(t->bg[0], t->bg[1], t->bg[2], n));
|
||||
init_pair(PAIR_STATUS, sp_color_rgb(t->bg[0], t->bg[1], t->bg[2], n),
|
||||
sp_color_rgb(t->status[0], t->status[1], t->status[2], n));
|
||||
}
|
||||
|
||||
static int
|
||||
entry_height(int width, size_t len)
|
||||
{
|
||||
if (width < 2)
|
||||
return 1;
|
||||
return (int)((len + (size_t)width - 1) / (size_t)width);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_history(struct ui_state *s)
|
||||
{
|
||||
int rows, cols, y = 0;
|
||||
size_t idx, start, used = 0;
|
||||
|
||||
getmaxyx(ui_hist, rows, cols);
|
||||
werase(ui_hist);
|
||||
|
||||
/* the newest entries that fit, then painted top-down */
|
||||
start = s->n;
|
||||
for (idx = s->n; idx > 0; idx--) {
|
||||
const struct entry *e = &s->entries[idx - 1];
|
||||
size_t need = (size_t)entry_height(cols,
|
||||
strlen(e->role) + strlen(e->text) + 2);
|
||||
|
||||
if (used + need > (size_t)rows)
|
||||
break;
|
||||
used += need;
|
||||
start = idx - 1;
|
||||
}
|
||||
|
||||
for (idx = start; idx < s->n && y >= 0 && y < rows; idx++) {
|
||||
const struct entry *e = &s->entries[idx];
|
||||
int ny, nx;
|
||||
|
||||
wmove(ui_hist, y, 0);
|
||||
if (strcmp(e->role, "you") == 0)
|
||||
wattron(ui_hist, COLOR_PAIR(PAIR_ACCENT) | A_BOLD);
|
||||
else if (strcmp(e->role, "agent") == 0)
|
||||
wattron(ui_hist, COLOR_PAIR(PAIR_MAIN));
|
||||
else if (strcmp(e->role, "error") == 0)
|
||||
wattron(ui_hist, COLOR_PAIR(PAIR_ACCENT) | A_BOLD);
|
||||
else
|
||||
wattron(ui_hist, COLOR_PAIR(PAIR_DIM));
|
||||
waddstr(ui_hist, e->role);
|
||||
wattroff(ui_hist, A_BOLD);
|
||||
waddstr(ui_hist, ": ");
|
||||
waddnstr(ui_hist, e->text, rows * cols);
|
||||
wattrset(ui_hist, A_NORMAL);
|
||||
getyx(ui_hist, ny, nx);
|
||||
y = nx == 0 ? ny : ny + 1;
|
||||
}
|
||||
wnoutrefresh(ui_hist);
|
||||
}
|
||||
|
||||
static void
|
||||
sidebar_heading(int *y, int cols, const char *text)
|
||||
{
|
||||
wattron(ui_side, COLOR_PAIR(PAIR_DIM) | A_BOLD);
|
||||
mvwaddnstr(ui_side, *y, 0, text, cols - 1);
|
||||
wattroff(ui_side, A_BOLD);
|
||||
(*y)++;
|
||||
wattron(ui_side, COLOR_PAIR(PAIR_MAIN));
|
||||
}
|
||||
|
||||
static void
|
||||
draw_sidebar(struct ui_state *s, const char *id, const char *dir)
|
||||
{
|
||||
int cols, y = 0;
|
||||
|
||||
cols = getmaxx(ui_side);
|
||||
werase(ui_side);
|
||||
|
||||
sidebar_heading(&y, cols, "session");
|
||||
mvwaddnstr(ui_side, y++, 0, id != NULL ? id : "-", cols - 1);
|
||||
if (dir != NULL)
|
||||
mvwaddnstr(ui_side, y++, 0, dir, cols - 1);
|
||||
y++;
|
||||
|
||||
sidebar_heading(&y, cols, "transport");
|
||||
mvwaddnstr(ui_side, y++, 0, s->endpoint != NULL ? s->endpoint : "script",
|
||||
cols - 1);
|
||||
y++;
|
||||
|
||||
sidebar_heading(&y, cols, "theme");
|
||||
wattron(ui_side, COLOR_PAIR(PAIR_ACCENT));
|
||||
mvwaddnstr(ui_side, y++, 0, s->theme.name, cols - 1);
|
||||
wattron(ui_side, COLOR_PAIR(PAIR_MAIN));
|
||||
y++;
|
||||
|
||||
sidebar_heading(&y, cols, "last turn");
|
||||
mvwprintw(ui_side, y++, 0, "%ld ms", s->last_ms);
|
||||
mvwprintw(ui_side, y++, 0, "%zu steps", s->last_steps);
|
||||
mvwprintw(ui_side, y++, 0, "%zu tool calls", s->last_calls);
|
||||
y++;
|
||||
|
||||
sidebar_heading(&y, cols, "widgets");
|
||||
wattron(ui_side, COLOR_PAIR(PAIR_DIM));
|
||||
mvwaddnstr(ui_side, y, 0, "none loaded", cols - 1);
|
||||
wattrset(ui_side, A_NORMAL);
|
||||
wnoutrefresh(ui_side);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_status(struct ui_state *s)
|
||||
{
|
||||
int cols = getmaxx(ui_status);
|
||||
|
||||
werase(ui_status);
|
||||
wattron(ui_status, COLOR_PAIR(PAIR_STATUS));
|
||||
mvwhline(ui_status, 0, 0, ' ', cols);
|
||||
mvwaddnstr(ui_status, 0, 1, "splinter " SP_VERSION, cols - 2);
|
||||
{
|
||||
char right[96];
|
||||
|
||||
snprintf(right, sizeof(right), "%s %ldms ", s->theme.name,
|
||||
s->last_ms);
|
||||
if ((int)strlen(right) + 1 < cols)
|
||||
mvwaddnstr(ui_status, 0, cols - (int)strlen(right) - 1,
|
||||
right, cols - 1);
|
||||
}
|
||||
wattroff(ui_status, COLOR_PAIR(PAIR_STATUS));
|
||||
wnoutrefresh(ui_status);
|
||||
}
|
||||
|
||||
static void
|
||||
add_entry(struct ui_state *s, const char *role, const char *text)
|
||||
{
|
||||
struct entry *e;
|
||||
|
||||
if (s->n == MAX_ENTRIES) {
|
||||
free(s->entries[0].role);
|
||||
free(s->entries[0].text);
|
||||
memmove(&s->entries[0], &s->entries[1],
|
||||
sizeof(s->entries[0]) * (MAX_ENTRIES - 1));
|
||||
s->n--;
|
||||
}
|
||||
e = &s->entries[s->n++];
|
||||
e->role = strdup(role);
|
||||
e->text = strdup(text != NULL ? text : "");
|
||||
}
|
||||
|
||||
static void
|
||||
layout(void)
|
||||
{
|
||||
int rows, cols, chat_w, side_w;
|
||||
|
||||
getmaxyx(stdscr, rows, cols);
|
||||
chat_w = cols * 3 / 4;
|
||||
if (cols - chat_w < 12)
|
||||
chat_w = cols > 24 ? cols - 16 : cols;
|
||||
side_w = cols - chat_w;
|
||||
ui_hist = newwin(rows - 2, chat_w, 0, 0);
|
||||
ui_side = newwin(rows - 2, side_w, 0, chat_w);
|
||||
ui_input = newwin(1, cols, rows - 2, 0);
|
||||
ui_status = newwin(1, cols, rows - 1, 0);
|
||||
keypad(ui_input, TRUE);
|
||||
}
|
||||
|
||||
int
|
||||
sp_ui_run(struct sp_agent *ag, const char *endpoint, const char *theme_name)
|
||||
{
|
||||
struct ui_state s;
|
||||
struct sp_buf answer = { 0 }, err = { 0 };
|
||||
char input[1024];
|
||||
int rc = 0;
|
||||
|
||||
memset(&s, 0, sizeof(s));
|
||||
s.endpoint = endpoint;
|
||||
if (sp_buf_init(&answer) != 0 || sp_buf_init(&err) != 0)
|
||||
return 1;
|
||||
if (sp_theme_load(theme_name, &s.theme, &err) != 0) {
|
||||
fprintf(stderr, "splinter: %s\n",
|
||||
err.p != NULL ? err.p : "theme");
|
||||
return 1;
|
||||
}
|
||||
|
||||
initscr();
|
||||
cbreak();
|
||||
noecho();
|
||||
keypad(stdscr, TRUE);
|
||||
curs_set(1);
|
||||
init_colors(&s.theme);
|
||||
layout();
|
||||
|
||||
add_entry(&s, "splinter", "ready. Enter sends, Ctrl-D quits.");
|
||||
|
||||
for (;;) {
|
||||
struct timespec t0, t1;
|
||||
int ch;
|
||||
|
||||
draw_history(&s);
|
||||
draw_sidebar(&s, ag->sess != NULL ? ag->sess->id : NULL,
|
||||
ag->sess != NULL ? ag->sess->dir : NULL);
|
||||
draw_status(&s);
|
||||
werase(ui_input);
|
||||
mvwaddstr(ui_input, 0, 0, "> ");
|
||||
wnoutrefresh(ui_input);
|
||||
doupdate();
|
||||
|
||||
{
|
||||
size_t len = 0;
|
||||
|
||||
wmove(ui_input, 0, 2);
|
||||
wrefresh(ui_input);
|
||||
for (;;) {
|
||||
ch = wgetch(ui_input);
|
||||
if (ch == '\n' || ch == '\r' || ch == KEY_ENTER)
|
||||
break;
|
||||
if (ch == 4) {
|
||||
s.quit = 1;
|
||||
break;
|
||||
}
|
||||
if (ch == 12)
|
||||
break;
|
||||
if (ch == 3) {
|
||||
len = 0;
|
||||
werase(ui_input);
|
||||
mvwaddstr(ui_input, 0, 0, "> ");
|
||||
wrefresh(ui_input);
|
||||
continue;
|
||||
}
|
||||
if (ch == KEY_BACKSPACE || ch == 127 || ch == 8) {
|
||||
if (len > 0) {
|
||||
len--;
|
||||
mvwaddch(ui_input, 0,
|
||||
(int)len + 2, ' ');
|
||||
wmove(ui_input, 0,
|
||||
(int)len + 2);
|
||||
wrefresh(ui_input);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (ch >= 32 && ch < 127 &&
|
||||
len < sizeof(input) - 1) {
|
||||
input[len++] = (char)ch;
|
||||
waddch(ui_input, (chtype)ch);
|
||||
wrefresh(ui_input);
|
||||
}
|
||||
}
|
||||
input[len] = '\0';
|
||||
}
|
||||
|
||||
if (s.quit)
|
||||
break;
|
||||
if (input[0] == '\0')
|
||||
continue;
|
||||
|
||||
add_entry(&s, "you", input);
|
||||
draw_history(&s);
|
||||
draw_sidebar(&s, ag->sess != NULL ? ag->sess->id : NULL,
|
||||
ag->sess != NULL ? ag->sess->dir : NULL);
|
||||
draw_status(&s);
|
||||
werase(ui_input);
|
||||
mvwaddstr(ui_input, 0, 0, " working...");
|
||||
wrefresh(ui_input);
|
||||
doupdate();
|
||||
|
||||
sp_buf_clear(&answer);
|
||||
sp_buf_clear(&err);
|
||||
clock_gettime(CLOCK_MONOTONIC, &t0);
|
||||
rc = sp_agent_run(ag, input, &answer, &err);
|
||||
clock_gettime(CLOCK_MONOTONIC, &t1);
|
||||
|
||||
s.last_ms = (long)((t1.tv_sec - t0.tv_sec) * 1000 +
|
||||
(t1.tv_nsec - t0.tv_nsec) / 1000000);
|
||||
s.last_steps = ag->stats.steps;
|
||||
s.last_calls = ag->stats.tool_calls;
|
||||
|
||||
if (rc == 0)
|
||||
add_entry(&s, "agent", answer.p);
|
||||
else
|
||||
add_entry(&s, "error", err.p != NULL ? err.p :
|
||||
"turn failed");
|
||||
}
|
||||
|
||||
endwin();
|
||||
sp_buf_free(&answer);
|
||||
sp_buf_free(&err);
|
||||
return rc;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/* splinter -- curses chat interface entry point. */
|
||||
#ifndef SPLINTER_UI_H
|
||||
#define SPLINTER_UI_H
|
||||
|
||||
#include "splinter.h"
|
||||
|
||||
/*
|
||||
* Run the interactive chat loop until the user quits. `theme_name` is a CDE
|
||||
* palette name; NULL selects the default. Returns 0 on a clean quit.
|
||||
*/
|
||||
int sp_ui_run(struct sp_agent *ag, const char *endpoint,
|
||||
const char *theme_name);
|
||||
|
||||
#endif /* SPLINTER_UI_H */
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,76 @@
|
||||
/* splinter -- CDE theme derivation tests. */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "theme.h"
|
||||
#include "palettes.h"
|
||||
|
||||
static int failures;
|
||||
|
||||
#define CHECK(cond) do { \
|
||||
if (!(cond)) { \
|
||||
fprintf(stderr, "FAIL %s:%d: %s\n", __FILE__, __LINE__, #cond); \
|
||||
failures++; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static int
|
||||
luma(const unsigned char *c)
|
||||
{
|
||||
return 299 * c[0] + 587 * c[1] + 114 * c[2];
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
struct sp_theme t, t2;
|
||||
struct sp_buf err;
|
||||
const char **names;
|
||||
size_t count, i;
|
||||
int seen_delphinium = 0;
|
||||
|
||||
if (sp_buf_init(&err) != 0)
|
||||
return 1;
|
||||
|
||||
/* every palette in the CDE tree is present, and sorted by name */
|
||||
CHECK(sp_theme_list(&names, &count) == count);
|
||||
CHECK(count == sp_palette_count);
|
||||
CHECK(count >= 40);
|
||||
for (i = 1; i < count; i++)
|
||||
CHECK(strcmp(names[i - 1], names[i]) < 0);
|
||||
|
||||
/* the default is Delphinium, and NULL means the default */
|
||||
CHECK(sp_theme_load(NULL, &t, &err) == 0);
|
||||
CHECK(strcmp(t.name, SP_THEME_DEFAULT) == 0);
|
||||
CHECK(strcmp(t.name, "Delphinium") == 0);
|
||||
CHECK(sp_theme_load("Delphinium", &t2, &err) == 0);
|
||||
CHECK(memcmp(&t, &t2, sizeof(t)) == 0);
|
||||
|
||||
/* roles are derived by luminance, so bg is darker than fg in every one */
|
||||
for (i = 0; i < count; i++) {
|
||||
CHECK(sp_theme_load(names[i], &t, &err) == 0);
|
||||
CHECK(luma(t.bg) <= luma(t.fg));
|
||||
CHECK(luma(t.border) >= luma(t.bg));
|
||||
CHECK(luma(t.status) <= luma(t.accent));
|
||||
}
|
||||
(void)seen_delphinium;
|
||||
|
||||
/* an unknown palette is an error, never a silent fallback */
|
||||
sp_buf_clear(&err);
|
||||
CHECK(sp_theme_load("NoSuchPalette", &t, &err) == -1);
|
||||
CHECK(strstr(err.p, "unknown palette") != NULL);
|
||||
|
||||
/* colour mapping stays inside the terminal's palette */
|
||||
CHECK(sp_color_rgb(0, 0, 0, 256) >= 16);
|
||||
CHECK(sp_color_rgb(0, 0, 0, 256) <= 255);
|
||||
CHECK(sp_color_rgb(255, 255, 255, 256) >= 16);
|
||||
CHECK(sp_color_rgb(255, 255, 255, 256) <= 255);
|
||||
CHECK(sp_color_rgb(0, 0, 0, 8) >= 0 && sp_color_rgb(0, 0, 0, 8) < 8);
|
||||
CHECK(sp_color_rgb(255, 255, 255, 16) >= 0);
|
||||
CHECK(sp_color_rgb(255, 255, 255, 16) < 16);
|
||||
|
||||
sp_buf_free(&err);
|
||||
if (failures == 0)
|
||||
printf("test_theme: ok (%zu palettes)\n", count);
|
||||
return failures == 0 ? 0 : 1;
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Turn CDE palette files (*.dp) into a C table for splinter.
|
||||
|
||||
A CDE palette file holds eight colours, one per line, in the order the desktop
|
||||
numbers its colour sets. Two encodings occur in the CDE tree:
|
||||
|
||||
#RRRRGGGGBBBB 16 bits per channel, 48 bits total
|
||||
Black / White a colour name (only four files use this)
|
||||
|
||||
Both are handled. Anything that is neither is a hard error: a palette that
|
||||
silently turns grey hides a broken file, and the palette is what the user sees
|
||||
first.
|
||||
|
||||
Usage: genpalettes.py <palette-dir> > palettes.c
|
||||
"""
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
|
||||
NAMED = {
|
||||
"black": (0, 0, 0),
|
||||
"white": (255, 255, 255),
|
||||
}
|
||||
|
||||
HEX48 = re.compile(r"^#([0-9a-fA-F]{12})$")
|
||||
|
||||
|
||||
def parse_line(text: str, path: str, lineno: int):
|
||||
tok = text.strip()
|
||||
if not tok:
|
||||
return None
|
||||
m = HEX48.match(tok)
|
||||
if m:
|
||||
v = m.group(1)
|
||||
return tuple(int(v[i:i + 4], 16) >> 8 for i in (0, 4, 8))
|
||||
low = tok.lower()
|
||||
if low in NAMED:
|
||||
return NAMED[low]
|
||||
raise SystemExit("%s:%d: neither #RRRRGGGGBBBB nor a known name: %r"
|
||||
% (path, lineno, tok))
|
||||
|
||||
|
||||
def load(path: str):
|
||||
out = []
|
||||
with open(path, "r", encoding="utf-8") as fh:
|
||||
for lineno, line in enumerate(fh, 1):
|
||||
rgb = parse_line(line, path, lineno)
|
||||
if rgb is not None:
|
||||
out.append(rgb)
|
||||
if len(out) != 8:
|
||||
raise SystemExit("%s: %d colours, expected 8" % (path, len(out)))
|
||||
return out
|
||||
|
||||
|
||||
def main() -> int:
|
||||
if len(sys.argv) != 2:
|
||||
raise SystemExit(__doc__)
|
||||
src = sys.argv[1]
|
||||
names = sorted(f[:-3] for f in os.listdir(src) if f.endswith(".dp"))
|
||||
if not names:
|
||||
raise SystemExit("%s: no .dp files" % src)
|
||||
|
||||
w = sys.stdout.write
|
||||
w("/*\n"
|
||||
" * Generated by tools/genpalettes.py from the CDE palette files.\n"
|
||||
" * Do not edit by hand: change the .dp source or the generator.\n"
|
||||
" */\n"
|
||||
"#include \"palettes.h\"\n\n"
|
||||
"const struct sp_palette sp_palettes[] = {\n")
|
||||
for name in names:
|
||||
cols = load(os.path.join(src, name + ".dp"))
|
||||
body = ", ".join("{0x%02x,0x%02x,0x%02x}" % c for c in cols)
|
||||
w("\t{ \"%s\", { %s } },\n" % (name, body))
|
||||
w("};\n\n"
|
||||
"const size_t sp_palette_count = "
|
||||
"sizeof(sp_palettes) / sizeof(sp_palettes[0]);\n")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -0,0 +1,19 @@
|
||||
*.o
|
||||
*.lo
|
||||
*.ho
|
||||
*.so
|
||||
*.a
|
||||
*.xz
|
||||
infocmp/infocmp
|
||||
tabs/tabs
|
||||
nbperf/nbperf
|
||||
tic/tic
|
||||
tic/host_tic
|
||||
tic/hash.c
|
||||
tput/tput
|
||||
tset/tset
|
||||
config.mak
|
||||
terminfo/terminfo.cdb
|
||||
libterminfo/compiled_terms.c
|
||||
libterminfo/termcap_hash.c
|
||||
libterminfo/hash.c
|
||||
Vendored
+54
@@ -0,0 +1,54 @@
|
||||
Copyright (c) 1980-1994
|
||||
The Regents of the University of California. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the University nor the names of its contributors
|
||||
may be used to endorse or promote products derived from this software
|
||||
without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGE.
|
||||
|
||||
Copyright (c) 1999-2016 The NetBSD Foundation, Inc.
|
||||
Copyright (c) 2016 other Contributors.
|
||||
All rights reserved.
|
||||
|
||||
This code is derived from software contributed to The NetBSD Foundation
|
||||
by Roy Marples.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
Vendored
+569
@@ -0,0 +1,569 @@
|
||||
HOSTCC ?= $(CC)
|
||||
AWK ?= awk
|
||||
AR ?= ar
|
||||
RANLIB ?= ranlib
|
||||
HOST_SH ?= /bin/sh
|
||||
LN ?= ln
|
||||
INSTALL ?= ./install.sh
|
||||
MKDIR ?= mkdir
|
||||
|
||||
SO_SUFFIX ?= .so
|
||||
|
||||
PIC = -fPIC
|
||||
|
||||
PREFIX=/usr/local
|
||||
BINDIR=$(PREFIX)/bin
|
||||
LIBDIR=$(PREFIX)/lib
|
||||
INCDIR=$(PREFIX)/include
|
||||
MANDIR=$(PREFIX)/share/man
|
||||
MAN1DIR=$(MANDIR)/man1
|
||||
MAN3DIR=$(MANDIR)/man3
|
||||
|
||||
-include config.mak
|
||||
|
||||
ifneq ($(HOSTCC),$(CC))
|
||||
CROSSCOMPILING=1
|
||||
else
|
||||
CROSSCOMPILING=0
|
||||
CFLAGS_HOST=$(CFLAGS)
|
||||
endif
|
||||
|
||||
ifneq (,$(findstring $(PIC),$(CFLAGS)))
|
||||
#CFLAGS contains -fPIC, so we can use the same obj files for dyn/static lib
|
||||
ALLPIC=1
|
||||
else
|
||||
ALLPIC=0
|
||||
endif
|
||||
|
||||
ifneq (,$(findstring -static,$(LDFLAGS)))
|
||||
#LDFLAGS contains -static, so the user wants to build static binaries
|
||||
STATIC_BINS=1
|
||||
else
|
||||
STATIC_BINS=0
|
||||
endif
|
||||
|
||||
CFLAGS+=-Werror-implicit-function-declaration
|
||||
CPPFLAGS+= -I. -I./libterminfo
|
||||
|
||||
TOOL_NBPERF= nbperf/nbperf
|
||||
NBPERF_SRCS= nbperf/nbperf.c
|
||||
NBPERF_SRCS+= nbperf/nbperf-bdz.c nbperf/nbperf-chm.c nbperf/nbperf-chm3.c
|
||||
NBPERF_SRCS+= nbperf/graph2.c nbperf/graph3.c
|
||||
NBPERF_SRCS+= nbperf/mi_vector_hash.c
|
||||
NBPERF_OBJS= $(NBPERF_SRCS:.c=.o)
|
||||
|
||||
TOOL_HOSTTIC=tic/host_tic
|
||||
TOOL_TTIC=tic/tic
|
||||
TIC_SRCS=tic/tic.c
|
||||
TIC_SRCS+=tic/cdbw.c tic/mi_vector_hash.c tic/compile.c tic/hash.c
|
||||
CLEANFILES+=tic/hash.c
|
||||
TIC_OBJS=$(TIC_SRCS:.c=.o)
|
||||
TIC_HOBJS=$(TIC_SRCS:.c=.ho)
|
||||
TOOL_TIC=$(TOOL_HOSTTIC)
|
||||
TIC_MAN=$(sort $(wildcard tic/*.1))
|
||||
|
||||
tic/compile.o: CPPFLAGS+= -DTERMINFO_COMPILE -DTERMINFO_DB -DTERMINFO_COMPAT
|
||||
|
||||
TI_SRCS= libterminfo/term.c libterminfo/ti.c libterminfo/setupterm.c \
|
||||
libterminfo/curterm.c libterminfo/tparm.c libterminfo/tputs.c
|
||||
TI_SRCS+=libterminfo/compile.c libterminfo/hash.c
|
||||
TI_SRCS+=libterminfo/cdbr.c
|
||||
TI_SRCS+=libterminfo/mi_vector_hash.c
|
||||
# Build in termcap emulation
|
||||
TI_SRCS+=libterminfo/termcap.c
|
||||
TI_LIBA=libterminfo/libterminfo.a
|
||||
TI_LIBSO=libterminfo/libterminfo$(SO_SUFFIX)
|
||||
TI_OBJS=$(TI_SRCS:.c=.o)
|
||||
TI_LOBJS=$(TI_SRCS:.c=.lo)
|
||||
TI_MAN =$(sort $(wildcard libterminfo/*.3))
|
||||
|
||||
libterminfo/term.o: CPPFLAGS+=-DINSTALL_PREFIX=\"$(PREFIX)\" -DTERMINFO_COMPILE -DTERMINFO_DB -DTERMINFO_COMPAT
|
||||
libterminfo/term.lo: CPPFLAGS+=-DINSTALL_PREFIX=\"$(PREFIX)\" -DTERMINFO_COMPILE -DTERMINFO_DB -DTERMINFO_COMPAT
|
||||
libterminfo/compile.o: CPPFLAGS+= -DTERMINFO_COMPILE -DTERMINFO_DB -DTERMINFO_COMPAT
|
||||
libterminfo/compile.lo: CPPFLAGS+= -DTERMINFO_COMPILE -DTERMINFO_DB -DTERMINFO_COMPAT
|
||||
libterminfo/termcap.o: CPPFLAGS+= -DTERMINFO_COMPILE -DTERMINFO_DB -DTERMINFO_COMPAT
|
||||
libterminfo/termcap.lo: CPPFLAGS+= -DTERMINFO_COMPILE -DTERMINFO_DB -DTERMINFO_COMPAT
|
||||
|
||||
CU_SRCS_=acs.c addbytes.c addch.c addchnstr.c addnstr.c attributes.c \
|
||||
background.c bell.c border.c box.c chgat.c clear.c clearok.c \
|
||||
clrtobot.c clrtoeol.c color.c copywin.c cr_put.c \
|
||||
ctrace.c cur_hash.c curs_set.c \
|
||||
curses.c delch.c deleteln.c delwin.c echochar.c erase.c fileio.c \
|
||||
flushok.c fullname.c getch.c getstr.c getyx.c id_subwins.c idlok.c \
|
||||
idcok.c inch.c inchstr.c initscr.c insch.c insdelln.c insertln.c \
|
||||
instr.c keypad.c keyname.c leaveok.c line.c meta.c move.c \
|
||||
mvwin.c newwin.c nodelay.c notimeout.c overlay.c overwrite.c pause.c \
|
||||
printw.c putchar.c refresh.c resize.c scanw.c screen.c scroll.c \
|
||||
scrollok.c setterm.c standout.c timeout.c toucholap.c touchwin.c \
|
||||
tstp.c tty.c unctrl.c underscore.c immedok.c syncok.c ripoffline.c \
|
||||
slk.c version.c mouse.c
|
||||
|
||||
|
||||
ifndef DISABLE_WCHAR
|
||||
CPPFLAGS+=-DHAVE_WCHAR
|
||||
CU_SRCS_+= cchar.c add_wch.c add_wchstr.c addwstr.c echo_wchar.c ins_wch.c \
|
||||
insstr.c ins_wstr.c get_wch.c get_wstr.c in_wch.c in_wchstr.c \
|
||||
inwstr.c
|
||||
else
|
||||
CPPFLAGS+=-DDISABLE_WCHAR
|
||||
endif
|
||||
|
||||
CU_SRCS=$(patsubst %,libcurses/%,$(CU_SRCS_))
|
||||
CU_INCS=libcurses/curses.h libcurses/unctrl.h
|
||||
CU_OBJS=$(CU_SRCS:.c=.o)
|
||||
CU_LIBA=libcurses/libcurses.a
|
||||
CU_LIBSO=libcurses/libcurses$(SO_SUFFIX)
|
||||
CU_LOBJS=$(CU_SRCS:.c=.lo)
|
||||
CU_MAN =$(sort $(wildcard libcurses/*.3))
|
||||
|
||||
PA_SRCS_ = _deck.c above.c below.c bottom.c del.c getuser.c hidden.c
|
||||
PA_SRCS_+= hide.c move.c new.c replace.c setuser.c show.c top.c
|
||||
PA_SRCS_+= update.c window.c
|
||||
PA_SRCS=$(patsubst %,libpanel/%,$(PA_SRCS_))
|
||||
PA_INCS=libpanel/panel.h
|
||||
PA_OBJS=$(PA_SRCS:.c=.o)
|
||||
PA_LIBA=libpanel/libpanel.a
|
||||
PA_LIBSO=libpanel/libpanel$(SO_SUFFIX)
|
||||
PA_LOBJS=$(PA_SRCS:.c=.lo)
|
||||
PA_MAN =$(sort $(wildcard libpanel/*.3))
|
||||
|
||||
ME_SRCS_=menu.c item.c userptr.c internals.c driver.c post.c attributes.c
|
||||
ME_MAN = $(sort $(wildcard libmenu/*.3))
|
||||
ME_SRCS=$(patsubst %,libmenu/%,$(ME_SRCS_))
|
||||
ME_INCS=libmenu/menu.h libmenu/eti.h
|
||||
ME_OBJS=$(ME_SRCS:.c=.o)
|
||||
ME_LIBA=libmenu/libmenu.a
|
||||
ME_LIBSO=libmenu/libmenu$(SO_SUFFIX)
|
||||
ME_LOBJS=$(ME_SRCS:.c=.lo)
|
||||
|
||||
FO_SRCS_=driver.c field_types.c internals.c field.c form.c post.c type_alnum.c \
|
||||
type_alpha.c type_integer.c type_numeric.c type_enum.c type_regex.c \
|
||||
type_ipv4.c type_ipv6.c
|
||||
FO_MAN= $(sort $(wildcard libform/*.3))
|
||||
FO_SRCS=$(patsubst %,libform/%,$(FO_SRCS_))
|
||||
FO_INCS=libform/form.h
|
||||
FO_OBJS=$(FO_SRCS:.c=.o)
|
||||
FO_LIBA=libform/libform.a
|
||||
FO_LIBSO=libform/libform$(SO_SUFFIX)
|
||||
FO_LOBJS=$(FO_SRCS:.c=.lo)
|
||||
|
||||
TS_SRCS_=map.c misc.c set.c term.c tset.c
|
||||
TS_SRCS=$(patsubst %,tset/%,$(TS_SRCS_))
|
||||
TS_OBJS=$(TS_SRCS:.c=.o)
|
||||
TS_MAN= $(sort $(wildcard tset/*.1))
|
||||
|
||||
TP_SRCS=tput/tput.c
|
||||
TP_OBJS=tput/tput.o
|
||||
TP_MAN =$(sort $(wildcard tput/*.1))
|
||||
|
||||
IC_SRCS=infocmp/infocmp.c
|
||||
IC_OBJS=infocmp/infocmp.o
|
||||
IC_MAN =$(sort $(wildcard infocmp/*.1))
|
||||
|
||||
TA_SRCS=tabs/tabs.c
|
||||
TA_OBJS=tabs/tabs.o
|
||||
TA_MAN =$(sort $(wildcard tabs/*.1))
|
||||
|
||||
STALIBS=$(TI_LIBA) $(CU_LIBA) $(PA_LIBA) $(ME_LIBA) $(FO_LIBA)
|
||||
DYNLIBS=$(TI_LIBSO) $(CU_LIBSO) $(PA_LIBSO) $(ME_LIBSO) $(FO_LIBSO)
|
||||
PROGS=$(TOOL_TTIC) tset/tset tput/tput infocmp/infocmp tabs/tabs
|
||||
|
||||
ifeq ($(STATIC_BINS),0)
|
||||
TI_LINKLIB=$(TI_LIBSO)
|
||||
else
|
||||
TI_LINKLIB=$(TI_LIBA)
|
||||
endif
|
||||
|
||||
all: $(STALIBS) $(DYNLIBS) $(PROGS)
|
||||
|
||||
all-static: $(STALIBS) $(PROGS)
|
||||
|
||||
all-dynamic: $(DYNLIBS) $(PROGS)
|
||||
|
||||
install-tic: $(TOOL_TTIC)
|
||||
$(INSTALL) -Dm 755 $(TOOL_TTIC) $(DESTDIR)$(BINDIR)/tic
|
||||
|
||||
install-tset: tset/tset
|
||||
$(INSTALL) -Dm 755 tset/tset $(DESTDIR)$(BINDIR)/tset
|
||||
$(LN) -sf $(notdir $<) $(DESTDIR)$(BINDIR)/reset
|
||||
|
||||
install-tput: tput/tput tput/clear.sh
|
||||
$(INSTALL) -Dm 755 tput/tput $(DESTDIR)$(BINDIR)/tput
|
||||
$(INSTALL) -Dm 755 tput/clear.sh $(DESTDIR)$(BINDIR)/clear
|
||||
|
||||
install-infocmp: infocmp/infocmp
|
||||
$(INSTALL) -Dm 755 infocmp/infocmp $(DESTDIR)$(BINDIR)/infocmp
|
||||
|
||||
install-tabs: tabs/tabs
|
||||
$(INSTALL) -Dm 755 tabs/tabs $(DESTDIR)$(BINDIR)/tabs
|
||||
|
||||
install-progs: install-tic install-tset install-tput install-infocmp install-tabs
|
||||
|
||||
install-headers-curses: libcurses/curses.h libcurses/unctrl.h
|
||||
$(INSTALL) -Dm 644 libcurses/curses.h $(DESTDIR)$(INCDIR)/curses.h
|
||||
$(INSTALL) -Dm 644 libcurses/unctrl.h $(DESTDIR)$(INCDIR)/unctrl.h
|
||||
$(LN) -sf curses.h $(DESTDIR)$(INCDIR)/ncurses.h
|
||||
|
||||
install-headers-terminfo: libterminfo/term.h libterminfo/termcap.h
|
||||
$(INSTALL) -Dm 644 libterminfo/term.h $(DESTDIR)$(INCDIR)/term.h
|
||||
$(INSTALL) -Dm 644 libterminfo/termcap.h $(DESTDIR)$(INCDIR)/termcap.h
|
||||
|
||||
install-headers-panel: libpanel/panel.h
|
||||
$(INSTALL) -Dm 644 libpanel/panel.h $(DESTDIR)$(INCDIR)/panel.h
|
||||
|
||||
install-headers-menu: libmenu/menu.h libmenu/eti.h
|
||||
$(INSTALL) -Dm 644 libmenu/menu.h $(DESTDIR)$(INCDIR)/menu.h
|
||||
$(INSTALL) -Dm 644 libmenu/eti.h $(DESTDIR)$(INCDIR)/eti.h
|
||||
|
||||
install-headers-form: libform/form.h
|
||||
$(INSTALL) -Dm 644 libform/form.h $(DESTDIR)$(INCDIR)/form.h
|
||||
|
||||
install-headers: install-headers-terminfo install-headers-curses install-headers-panel install-headers-menu install-headers-form
|
||||
|
||||
install-stalib-curses: $(CU_LIBA)
|
||||
$(INSTALL) -Dm 644 $< $(DESTDIR)$(LIBDIR)/$(notdir $<)
|
||||
$(LN) -sf $(notdir $<) $(DESTDIR)$(LIBDIR)/libncurses.a
|
||||
$(LN) -sf $(notdir $<) $(DESTDIR)$(LIBDIR)/libncursesw.a
|
||||
|
||||
install-stalib-terminfo: $(TI_LIBA)
|
||||
$(INSTALL) -Dm 644 $< $(DESTDIR)$(LIBDIR)/$(notdir $<)
|
||||
$(LN) -sf $(notdir $<) $(DESTDIR)$(LIBDIR)/libtermcap.a
|
||||
|
||||
install-stalib-panel: $(PA_LIBA)
|
||||
$(INSTALL) -Dm 644 $< $(DESTDIR)$(LIBDIR)/$(notdir $<)
|
||||
$(LN) -sf $(notdir $<) $(DESTDIR)$(LIBDIR)/$(basename $(notdir $<))w.a
|
||||
|
||||
install-stalib-menu: $(ME_LIBA)
|
||||
$(INSTALL) -Dm 644 $< $(DESTDIR)$(LIBDIR)/$(notdir $<)
|
||||
$(LN) -sf $(notdir $<) $(DESTDIR)$(LIBDIR)/$(basename $(notdir $<))w.a
|
||||
|
||||
install-stalib-form: $(FO_LIBA)
|
||||
$(INSTALL) -Dm 644 $< $(DESTDIR)$(LIBDIR)/$(notdir $<)
|
||||
$(LN) -sf $(notdir $<) $(DESTDIR)$(LIBDIR)/$(basename $(notdir $<))w.a
|
||||
|
||||
install-stalibs: install-stalib-terminfo install-stalib-curses install-stalib-panel install-stalib-menu install-stalib-form
|
||||
|
||||
install-dynlib-curses: $(CU_LIBSO)
|
||||
$(INSTALL) -Dm 644 $< $(DESTDIR)$(LIBDIR)/$(notdir $<)
|
||||
$(LN) -sf $(notdir $<) $(DESTDIR)$(LIBDIR)/libncurses$(SO_SUFFIX)
|
||||
$(LN) -sf $(notdir $<) $(DESTDIR)$(LIBDIR)/libncursesw$(SO_SUFFIX)
|
||||
|
||||
install-dynlib-terminfo: $(TI_LIBSO)
|
||||
$(INSTALL) -Dm 644 $< $(DESTDIR)$(LIBDIR)/$(notdir $<)
|
||||
$(LN) -sf $(notdir $<) $(DESTDIR)$(LIBDIR)/libtermcap$(SO_SUFFIX)
|
||||
|
||||
install-dynlib-panel: $(PA_LIBSO)
|
||||
$(INSTALL) -Dm 644 $< $(DESTDIR)$(LIBDIR)/$(notdir $<)
|
||||
$(LN) -sf $(notdir $<) $(DESTDIR)$(LIBDIR)/$(basename $(notdir $<))w$(SO_SUFFIX)
|
||||
|
||||
install-dynlib-menu: $(ME_LIBSO)
|
||||
$(INSTALL) -Dm 644 $< $(DESTDIR)$(LIBDIR)/$(notdir $<)
|
||||
$(LN) -sf $(notdir $<) $(DESTDIR)$(LIBDIR)/$(basename $(notdir $<))w$(SO_SUFFIX)
|
||||
|
||||
install-dynlib-form: $(FO_LIBSO)
|
||||
$(INSTALL) -Dm 644 $< $(DESTDIR)$(LIBDIR)/$(notdir $<)
|
||||
$(LN) -sf $(notdir $<) $(DESTDIR)$(LIBDIR)/$(basename $(notdir $<))w$(SO_SUFFIX)
|
||||
|
||||
install-dynlibs: install-dynlib-terminfo install-dynlib-curses install-dynlib-panel install-dynlib-menu install-dynlib-form
|
||||
install-libs: install-stalibs install-dynlibs
|
||||
|
||||
install-pc-dir:
|
||||
$(MKDIR) -p $(DESTDIR)$(LIBDIR)/pkgconfig
|
||||
|
||||
install-pc-curses: install-pc-dir
|
||||
./genpc curses "curses terminal library" "-lcurses -lterminfo" > $(DESTDIR)$(LIBDIR)/pkgconfig/curses.pc
|
||||
./genpc ncurses "ncurses terminal library" "-lncurses -lterminfo" > $(DESTDIR)$(LIBDIR)/pkgconfig/ncurses.pc
|
||||
./genpc ncursesw "ncurses terminal library" "-lncurses -lterminfo" > $(DESTDIR)$(LIBDIR)/pkgconfig/ncursesw.pc
|
||||
|
||||
install-pc-terminfo: install-pc-dir
|
||||
./genpc terminfo "terminfo library" "-lterminfo" > $(DESTDIR)$(LIBDIR)/pkgconfig/terminfo.pc
|
||||
./genpc termcap "termcap library" "-lterminfo" > $(DESTDIR)$(LIBDIR)/pkgconfig/termcap.pc
|
||||
|
||||
install-pc-panel: install-pc-dir
|
||||
./genpc panel "curses panel library" "-lpanel -lcurses -lterminfo" > $(DESTDIR)$(LIBDIR)/pkgconfig/panel.pc
|
||||
./genpc panelw "curses panel library" "-lpanel -lncurses -lterminfo" > $(DESTDIR)$(LIBDIR)/pkgconfig/panelw.pc
|
||||
|
||||
install-pc-menu: install-pc-dir
|
||||
./genpc menu "curses menu library" "-lmenu -lcurses -lterminfo" > $(DESTDIR)$(LIBDIR)/pkgconfig/menu.pc
|
||||
./genpc menuw "curses menu library" "-lmenu -lcurses -lterminfo" > $(DESTDIR)$(LIBDIR)/pkgconfig/menuw.pc
|
||||
|
||||
install-pc-form: install-pc-dir
|
||||
./genpc form "curses form library" "-lform -lcurses -lterminfo" > $(DESTDIR)$(LIBDIR)/pkgconfig/form.pc
|
||||
./genpc formw "curses form library" "-lform -lcurses -lterminfo" > $(DESTDIR)$(LIBDIR)/pkgconfig/formw.pc
|
||||
|
||||
install-pcs: install-pc-form install-pc-menu install-pc-panel install-pc-terminfo install-pc-curses
|
||||
|
||||
INSTALL_MANPAGES_COMMAND=test -L $< && $(INSTALL) -Dl `readlink $<` $@ || $(INSTALL) -Dm 644 $< $@
|
||||
|
||||
$(DESTDIR)$(MAN1DIR)/%: tic/%
|
||||
$(INSTALL_MANPAGES_COMMAND)
|
||||
$(DESTDIR)$(MAN1DIR)/%: tset/%
|
||||
$(INSTALL_MANPAGES_COMMAND)
|
||||
$(DESTDIR)$(MAN1DIR)/%: tput/%
|
||||
$(INSTALL_MANPAGES_COMMAND)
|
||||
$(DESTDIR)$(MAN1DIR)/%: infocmp/%
|
||||
$(INSTALL_MANPAGES_COMMAND)
|
||||
$(DESTDIR)$(MAN1DIR)/%: tabs/%
|
||||
$(INSTALL_MANPAGES_COMMAND)
|
||||
|
||||
$(DESTDIR)$(MAN3DIR)/%: libterminfo/%
|
||||
$(INSTALL_MANPAGES_COMMAND)
|
||||
$(DESTDIR)$(MAN3DIR)/%: libcurses/%
|
||||
$(INSTALL_MANPAGES_COMMAND)
|
||||
$(DESTDIR)$(MAN3DIR)/%: libpanel/%
|
||||
$(INSTALL_MANPAGES_COMMAND)
|
||||
$(DESTDIR)$(MAN3DIR)/%: libmenu/%
|
||||
$(INSTALL_MANPAGES_COMMAND)
|
||||
$(DESTDIR)$(MAN3DIR)/%: libform/%
|
||||
$(INSTALL_MANPAGES_COMMAND)
|
||||
|
||||
install-man-tic: $(TIC_MAN:tic/%=$(DESTDIR)$(MAN1DIR)/%)
|
||||
install-man-tset: $(TS_MAN:tset/%=$(DESTDIR)$(MAN1DIR)/%)
|
||||
install-man-tput: $(TP_MAN:tput/%=$(DESTDIR)$(MAN1DIR)/%)
|
||||
install-man-infocmp: $(IC_MAN:infocmp/%=$(DESTDIR)$(MAN1DIR)/%)
|
||||
install-man-tabs: $(TA_MAN:tabs/%=$(DESTDIR)$(MAN1DIR)/%)
|
||||
|
||||
install-prog-manpages: install-man-tic install-man-tset install-man-tput \
|
||||
install-man-infocmp install-man-tabs
|
||||
|
||||
install-man-terminfo: $(TI_MAN:libterminfo/%=$(DESTDIR)$(MAN3DIR)/%)
|
||||
install-man-curses: $(CU_MAN:libcurses/%=$(DESTDIR)$(MAN3DIR)/%)
|
||||
install-man-panel: $(PA_MAN:libpanel/%=$(DESTDIR)$(MAN3DIR)/%)
|
||||
install-man-menu: $(ME_MAN:libmenu/%=$(DESTDIR)$(MAN3DIR)/%)
|
||||
install-man-form: $(FO_MAN:libform/%=$(DESTDIR)$(MAN3DIR)/%)
|
||||
|
||||
install-lib-manpages: install-man-terminfo install-man-curses \
|
||||
install-man-panel install-man-menu install-man-form
|
||||
|
||||
install-manpages: install-prog-manpages install-lib-manpages
|
||||
|
||||
install: install-headers install-libs install-progs install-pcs install-manpages
|
||||
|
||||
install-static: install-headers install-progs install-pcs install-stalibs
|
||||
install-dynamic: TI_LINKLIB=$(TI_LIBSO)
|
||||
install-dynamic: install-headers install-progs install-pcs install-dynlibs
|
||||
|
||||
# TODO: gen (if necessary) and install manpages
|
||||
|
||||
clean:
|
||||
rm -f $(NBPERF_OBJS) $(TOOL_NBPERF) $(TIC_OBJS) $(TIC_HOBJS) \
|
||||
$(TOOL_TTIC) $(TOOL_TIC) $(CLEANFILES) $(TI_LIBA) \
|
||||
$(CU_LIBA) $(TI_OBJS) $(CU_OBJS) $(CU_LOBJS) $(TI_LOBJS) \
|
||||
$(CU_LIBSO) $(TI_LIBSO) \
|
||||
$(PA_LIBA) $(PA_LIBSO) $(PA_OBJS) $(PA_LOBJS) \
|
||||
$(ME_LIBA) $(ME_LIBSO) $(ME_OBJS) $(ME_LOBJS) \
|
||||
$(FO_LIBA) $(FO_LIBSO) $(FO_OBJS) $(FO_LOBJS) \
|
||||
$(TS_OBJS) tset/tset $(TP_OBJS) tput/tput \
|
||||
$(IC_OBJS) infocmp/infocmp $(TA_OBJS) tabs/tabs
|
||||
|
||||
$(TOOL_NBPERF): $(NBPERF_OBJS)
|
||||
$(HOSTCC) $(LDFLAGS_HOST) $^ -o $@
|
||||
|
||||
tset/tset: $(TI_LINKLIB)
|
||||
tset/tset: $(TS_OBJS)
|
||||
$(CC) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
tput/tput: $(TI_LINKLIB)
|
||||
tput/tput: $(TP_OBJS)
|
||||
$(CC) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
infocmp/infocmp: $(TI_LINKLIB)
|
||||
infocmp/infocmp: $(IC_OBJS)
|
||||
$(CC) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
tabs/tabs: $(TI_LINKLIB)
|
||||
tabs/tabs: $(TA_OBJS)
|
||||
$(CC) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
tset/%.o: tset/%.c
|
||||
$(CC) $(CPPFLAGS) -I./tset -I. -I./libterminfo $(CFLAGS) -c -o $@ $<
|
||||
tput/%.o: tput/%.c
|
||||
$(CC) $(CPPFLAGS) -I./tset -I. -I./libterminfo $(CFLAGS) -c -o $@ $<
|
||||
infocmp/%.o: infocmp/%.c
|
||||
$(CC) $(CPPFLAGS) -I. -I./libterminfo $(CFLAGS) -c -o $@ $<
|
||||
tabs/%.o: tabs/%.c
|
||||
$(CC) $(CPPFLAGS) -I. -I./libterminfo $(CFLAGS) -c -o $@ $<
|
||||
nbperf/%.o: nbperf/%.c
|
||||
$(HOSTCC) $(CPPFLAGS) -O0 -g0 $(CFLAGS_HOST) -c -o $@ $<
|
||||
|
||||
ifeq ($(CROSSCOMPILING),0)
|
||||
tic/%.ho: tic/%.o
|
||||
$(LN) -sf $(notdir $<) $@
|
||||
|
||||
$(TOOL_HOSTTIC): $(TOOL_TTIC)
|
||||
$(LN) -sf $(notdir $<) $@
|
||||
else
|
||||
tic/%.ho: tic/%.c
|
||||
$(HOSTCC) $(CPPFLAGS) -I./tic -O0 -g0 $(CFLAGS_HOST) -c -o $@ $<
|
||||
|
||||
$(TOOL_HOSTTIC): $(TIC_HOBJS)
|
||||
$(HOSTCC) $(LDFLAGS_HOST) $^ -o $@
|
||||
endif
|
||||
|
||||
tic/%.o: tic/%.c
|
||||
$(CC) $(CPPFLAGS) -I./tic $(CFLAGS) -c -o $@ $<
|
||||
|
||||
libcurses/%.o: libcurses/%.c
|
||||
$(CC) $(CPPFLAGS) -I./libcurses $(CFLAGS) -c -o $@ $<
|
||||
|
||||
libterminfo/%.o: libterminfo/%.c
|
||||
$(CC) $(CPPFLAGS) -I./libcurses $(CFLAGS) -c -o $@ $<
|
||||
|
||||
libmenu/%.o: libmenu/%.c
|
||||
$(CC) $(CPPFLAGS) -I./libcurses -I./libmenu $(CFLAGS) -c -o $@ $<
|
||||
|
||||
libpanel/%.o: libpanel/%.c
|
||||
$(CC) $(CPPFLAGS) -I./libcurses -I./libpanel $(CFLAGS) -c -o $@ $<
|
||||
|
||||
libform/%.o: libform/%.c
|
||||
$(CC) $(CPPFLAGS) -I./libcurses -I./libmenu -I./libform $(CFLAGS) -c -o $@ $<
|
||||
|
||||
ifeq ($(ALLPIC),1)
|
||||
|
||||
$(CU_LOBJS): $(CU_OBJS)
|
||||
libcurses/%.lo: libcurses/%.o
|
||||
$(LN) -sf $(notdir $<) $@
|
||||
|
||||
$(TI_LOBJS): $(TI_OBJS)
|
||||
libterminfo/%.lo: libterminfo/%.o
|
||||
$(LN) -sf $(notdir $<) $@
|
||||
|
||||
$(PA_LOBJS): $(PA_OBJS)
|
||||
libpanel/%.lo: libpanel/%.o
|
||||
$(LN) -sf $(notdir $<) $@
|
||||
|
||||
$(ME_LOBJS): $(ME_OBJS)
|
||||
libmenu/%.lo: libmenu/%.o
|
||||
$(LN) -sf $(notdir $<) $@
|
||||
|
||||
$(FO_LOBJS): $(FO_OBJS)
|
||||
libform/%.lo: libform/%.o
|
||||
$(LN) -sf $(notdir $<) $@
|
||||
else
|
||||
libcurses/%.lo: libcurses/%.c
|
||||
$(CC) $(CPPFLAGS) -I./libcurses $(CFLAGS) $(PIC) -c -o $@ $<
|
||||
|
||||
libterminfo/%.lo: libterminfo/%.c
|
||||
$(CC) $(CPPFLAGS) -I./libcurses $(CFLAGS) $(PIC) -c -o $@ $<
|
||||
|
||||
libpanel/%.lo: libpanel/%.c
|
||||
$(CC) $(CPPFLAGS) -I./libcurses -I./libpanel $(CFLAGS) $(PIC) -c -o $@ $<
|
||||
|
||||
libmenu/%.lo: libmenu/%.c
|
||||
$(CC) $(CPPFLAGS) -I./libcurses -I./libmenu $(CFLAGS) $(PIC) -c -o $@ $<
|
||||
|
||||
libform/%.lo: libform/%.c
|
||||
$(CC) $(CPPFLAGS) -I./libcurses -I./libmenu -I./libform $(CFLAGS) $(PIC) -c -o $@ $<
|
||||
endif
|
||||
|
||||
tic/hash.c: libterminfo/hash.c
|
||||
cp libterminfo/hash.c tic/hash.c
|
||||
|
||||
$(TOOL_TTIC): $(TIC_OBJS)
|
||||
$(CC) $(LDFLAGS) $^ -o $@
|
||||
|
||||
TERMINFODIR=./terminfo
|
||||
SCRIPT_ENV= \
|
||||
TERMINFODIR=$(TERMINFODIR) \
|
||||
TOOL_AWK=awk \
|
||||
TOOL_NBPERF=$(TOOL_NBPERF) \
|
||||
TOOL_SED=sed \
|
||||
TOOL_SORT=sort \
|
||||
TOOL_TIC=$(TOOL_TIC)
|
||||
|
||||
$(TI_LIBA): $(TI_OBJS)
|
||||
rm -f $@
|
||||
$(AR) crs $@ $^
|
||||
$(RANLIB) $@
|
||||
|
||||
$(TI_LIBSO): $(TI_LOBJS)
|
||||
$(CC) -shared -o $@ $^ -Wl,-soname=$(notdir $@)
|
||||
|
||||
libterminfo/hash.c: libterminfo/genhash libterminfo/term.h
|
||||
@echo "Generating terminfo hash"
|
||||
$(SCRIPT_ENV) $(HOST_SH) $^ > $@
|
||||
|
||||
libterminfo/termcap_hash.c: libterminfo/genthash libterminfo/termcap_map.c
|
||||
@echo "Generating termcap hash"
|
||||
${SCRIPT_ENV} ${HOST_SH} $^ > $@
|
||||
|
||||
# Allow terminfo descriptions to be compiled into libterminfo
|
||||
libterminfo/compiled_terms.c: libterminfo/genterms libterminfo/term.h ${TERMINFODIR}/terminfo
|
||||
@echo "Generating compiled terminfo descriptions"
|
||||
${SCRIPT_ENV} ${HOST_SH} $^ > $@
|
||||
|
||||
libterminfo/hash.c: $(TOOL_NBPERF)
|
||||
libterminfo/termcap_hash.c: $(TOOL_NBPERF)
|
||||
libterminfo/compiled_terms.c: $(TOOL_TIC)
|
||||
libterminfo/term.c: libterminfo/compiled_terms.c
|
||||
libterminfo/term.o: libterminfo/compiled_terms.c
|
||||
libterminfo/termcap.c: libterminfo/termcap_hash.c
|
||||
|
||||
CLEANFILES+=libterminfo/hash.c libterminfo/termcap_hash.c \
|
||||
libterminfo/compiled_terms.c
|
||||
|
||||
# Generate our man pages
|
||||
#terminfo.5: genman terminfo.5.in term.h termcap_map.c
|
||||
# @echo "Generating terminfo man pages"
|
||||
# ${SCRIPT_ENV} ${HOST_SH} $^ > $@
|
||||
|
||||
$(CU_LIBA): $(CU_OBJS)
|
||||
rm -f $@
|
||||
$(AR) crs $@ $^
|
||||
$(RANLIB) $@
|
||||
|
||||
$(CU_LIBSO): $(TI_LIBSO)
|
||||
$(CU_LIBSO): $(CU_LOBJS)
|
||||
$(CC) -shared -o $@ $^ -Wl,-soname=$(notdir $@)
|
||||
|
||||
libcurses/fileio.h: libcurses/shlib_version libcurses/genfileioh.awk
|
||||
$(AWK) -f ./genfileioh.awk < ./shlib_version > ./fileio.h
|
||||
|
||||
$(PA_LIBA): $(PA_OBJS)
|
||||
rm -f $@
|
||||
$(AR) crs $@ $^
|
||||
$(RANLIB) $@
|
||||
|
||||
$(PA_LIBSO): $(CU_LIBSO)
|
||||
$(PA_LIBSO): $(PA_LOBJS)
|
||||
$(CC) -shared -o $@ $^ -Wl,-soname=$(notdir $@)
|
||||
|
||||
$(ME_LIBA): $(ME_OBJS)
|
||||
rm -f $@
|
||||
$(AR) crs $@ $^
|
||||
$(RANLIB) $@
|
||||
|
||||
$(ME_LIBSO): $(CU_LIBSO)
|
||||
$(ME_LIBSO): $(ME_LOBJS)
|
||||
$(CC) -shared -o $@ $^ -Wl,-soname=$(notdir $@)
|
||||
|
||||
$(FO_LIBA): $(FO_OBJS)
|
||||
rm -f $@
|
||||
$(AR) crs $@ $^
|
||||
$(RANLIB) $@
|
||||
|
||||
$(FO_LIBSO): $(CU_LIBSO)
|
||||
$(FO_LIBSO): $(FO_LOBJS)
|
||||
$(CC) -shared -o $@ $^ -Wl,-soname=$(notdir $@)
|
||||
|
||||
# Allow terminfo descriptions to be compiled into libterminfo
|
||||
${TERMINFODIR}/terminfo.cdb: $(TOOL_TIC) ${TERMINFODIR}/terminfo
|
||||
@echo "Generating compiled terminfo database"
|
||||
$^
|
||||
|
||||
.PHONY: all all-static all-dynamic install install-tic install-tset \
|
||||
install-tput install-infocmp install-tabs install-progs \
|
||||
install-headers-curses install-headers-terminfo \
|
||||
install-headers-panel install-headers-menu install-headers-form \
|
||||
install-headers install-stalib-curses install-stalib-terminfo \
|
||||
install-stalib-panel install-stalib-menu install-stalib-form \
|
||||
install-stalibs install-dynlib-curses install-dynlib-terminfo \
|
||||
install-dynlib-panel install-dynlib-menu install-dynlib-form \
|
||||
install-dynlibs install-libs install-pc-dir install-pc-curses \
|
||||
install-pc-terminfo install-pc-panel install-pc-menu \
|
||||
install-pc-form install-pcs install-static install-dynamic clean \
|
||||
install-man-tic install-man-tset install-man-tput \
|
||||
install-man-infocmp install-man-tabs install-prog-manpages \
|
||||
install-man-terminfo install-man-curses install-man-panel \
|
||||
install-man-menu install-man-form install-lib-manpages \
|
||||
install-manpages
|
||||
Vendored
+27
@@ -0,0 +1,27 @@
|
||||
# vendor/netbsd-curses — provenance
|
||||
|
||||
**What this is.** NetBSD's curses and terminfo implementation, ported to Linux
|
||||
and other POSIX systems ("netbsd-libcurses portable edition"). Wide-character
|
||||
capable, close to a drop-in replacement for ncurses.
|
||||
|
||||
**Where it came from.** `https://github.com/sabotage-linux/netbsd-curses`,
|
||||
vendored on 2026-11-07 from the copy already in use at
|
||||
`~/src/matriks/src/curses/netbsd-curses` (the same tree OpenITT planned to use
|
||||
for its client layer).
|
||||
|
||||
**What was removed and why.** Compiled objects (`*.o`, `*.lo`), shared objects
|
||||
(`*.so`) and static archives (`*.a`) were left out: they are build output, they
|
||||
carry the build machine's paths, and a checked-in binary is a binary nobody can
|
||||
audit. `make` in `splinter/` rebuilds them.
|
||||
|
||||
**How it is built.** The vendored tree ships a `GNUmakefile`, so this one
|
||||
directory needs GNU make; `splinter`'s own `Makefile` stays POSIX make. The
|
||||
target `$(CURSES_A)` in `splinter/Makefile` is the only place that crosses over.
|
||||
|
||||
**License.** NetBSD's BSD-2-Clause-style COPYING is kept verbatim at
|
||||
`vendor/netbsd-curses/COPYING`. Nothing here was modified.
|
||||
|
||||
**Why it is vendored at all.** The alternative is ncurses, which is a different
|
||||
implementation with different behaviour on redraw and wide characters. Using
|
||||
NetBSD's curses keeps the terminal behaviour identical to the NetBSD tools this
|
||||
machine already runs, and removes a system dependency from the build.
|
||||
Vendored
+218
@@ -0,0 +1,218 @@
|
||||
netbsd-libcurses portable edition
|
||||
=================================
|
||||
|
||||
this is a port of netbsd's curses library for usage on Linux systems
|
||||
(tested and developed on sabotage linux, based on musl libc).
|
||||
It should be possible to use on other POSIX platforms as well with minor
|
||||
changes.
|
||||
|
||||
it supports widechar (like the ncursesw build variant) and is close to being
|
||||
a 100% feature-complete drop-in replacement for ncurses.
|
||||
|
||||
to this date, there are only 3 implementations of the curses API:
|
||||
|
||||
- the ubiquitous ncurses library, which is used on almost every UNIX system
|
||||
(Linux, Mac OS X, FreeBSD, OpenBSD and others).
|
||||
- netbsd curses, previously used on netbsd only.
|
||||
- pdcurses, targetting the windows terminal, SDL and X11 (unusable on UNIX
|
||||
terminals).
|
||||
|
||||
Why do we need an ncurses replacement ?
|
||||
---------------------------------------
|
||||
- Competition is good.
|
||||
- Ncurses is one of the most used libraries in the linux ecosystem and
|
||||
therefore it's usually one of the first libraries built in a source-based
|
||||
distro.
|
||||
There's basically no way around it, unless you're building a single-purpose
|
||||
appliance.
|
||||
- Readability/Hacking.
|
||||
even though ncurses is free software, it is very hard to change its source
|
||||
code:
|
||||
- extremely complicated build process with several layers of preprocessing
|
||||
using tools like awk, sed and the output of the C preprocessor with reliance
|
||||
on implementation details, [as shown by the recent breakage when distros
|
||||
updated to GCC 5][0].
|
||||
- heavy use of macros, making the code hard to read.
|
||||
- very much code (bloat).
|
||||
- Usability.
|
||||
the default configuration of ncurses is usually not what one wants, and it
|
||||
features several dozens of configure options to customize the build,
|
||||
for example making it split up in several smaller libraries, with or without
|
||||
widechar support, etc.
|
||||
|
||||
this makes it hard to guess which files to link against and which headers to
|
||||
use when building a package against ncurses.
|
||||
`-lncurses`? `-lncursesw -lterminfo -ltic`? `curses.h`? `ncurses/ncursesw.h`?
|
||||
this filename chaos [is often fixed in a distro-specific manner][1].
|
||||
|
||||
to accomodate for this, ncurses ships its own config tool ncurses(w)5-config
|
||||
instead of a standardized pkg-config description file (disabled by default)
|
||||
to query the necessary CFLAGS and LDFLAGS.
|
||||
unfortunately like every other homebrewed pkg-config replacement, this config
|
||||
utility was designed without cross-compilation in mind, so many packages
|
||||
using ncurses and autoconf fail to cross-compile when unpatched.
|
||||
- Size and build time.
|
||||
|
||||
Table 1: Comparison between ncurses and netbsd curses
|
||||
-----------------------------------------------------
|
||||
| | NCURSES | NETBSD CURSES |
|
||||
|:----------------------------|:------------:|:-------------:|
|
||||
| Size of extracted source | 15.8 MB | 3.3 MB |
|
||||
| Installed size | 15.9 MB | 1.3 MB |
|
||||
| Installed size w/debuginfo | 128.3 MB | 19.9 MB |
|
||||
| Build time (make -j2) | 59 sec | 9 sec |
|
||||
| size of libncursesw.so | 346 KB | 150 KB |
|
||||
| size of static linked nano | 334 KB | 288 KB |
|
||||
|
||||
|
||||
when scaling up to more build jobs, it is expected that netbsd curses fares a
|
||||
lot better since its Makefile is fully parallelizable, while ncurses spends a
|
||||
lot of time in a single process executing the configure script.
|
||||
|
||||
Differences from ncurses
|
||||
------------------------
|
||||
- the structures used differ. some programs access ncurses structure members directly,
|
||||
they must be patched to use a portable approach.
|
||||
- mouse handling is lacking. ncurses mouse handling routines are provided as no-op
|
||||
macros, so software using it builds without having to patch it.
|
||||
- some rarely used functions like vidputs() are missing. users must be patched.
|
||||
- the terminfo database is compiled (via tic) into a binary database in CDB format.
|
||||
- "only" 510 color pairs are supported.
|
||||
- some functionality like tgetent() lives in libterminfo rather than in libcurses.
|
||||
it may be necessary to add -lterminfo to LDFLAGS for packages using those functions.
|
||||
|
||||
TODO
|
||||
----
|
||||
- installation of global terminfo db
|
||||
(rather than just a small built-in, handpicked set)
|
||||
|
||||
Compilation
|
||||
-----------
|
||||
netbsd-curses ships without a configure script, and requires GNU make.
|
||||
variables for compilation can be passed directly to make, or be saved into config.mak.
|
||||
recognized variables are:
|
||||
|
||||
- CC - the C compiler
|
||||
- HOSTCC - the C compiler used for host programs when crosscompiling.
|
||||
if set, and different from CC, cross-compilation is assumed.
|
||||
- CFLAGS - flags for the compiler
|
||||
- CPPFLAGS - flags for the preprocessor
|
||||
- LDFLAGS - flags for the linker
|
||||
- PREFIX - filesystem prefix used for hardcoded paths and installation
|
||||
- DESTDIR - staging directory for installation
|
||||
|
||||
examples:
|
||||
|
||||
make CFLAGS="-Os -Wall -fPIC" PREFIX=/usr/local -j4 all install
|
||||
make CFLAGS=-O2 LDFLAGS=-static PREFIX=/usr all-static install-static
|
||||
|
||||
example config.mak:
|
||||
|
||||
CFLAGS = -O3 -Wall
|
||||
PREFIX = /usr
|
||||
DESTDIR = foo
|
||||
|
||||
if you're using config.mak, you can just run `make && make install` and the
|
||||
variables will be picked up automatically.
|
||||
|
||||
the `all` and `install` Makefile targets will build/install all programs,
|
||||
shared and static libs, and headers.
|
||||
the `all-static` and `install-static` targets will build/install all programs,
|
||||
static libs, and headers.
|
||||
the `all-dynamic` and `install-dynamic` targets will build/install all programs
|
||||
shared libs, and headers.
|
||||
|
||||
the `all` build can be sped up by putting `-fPIC` in CFLAGS.
|
||||
this has the effect that the same object files will be used for the dynamic and
|
||||
static libs; otherwise they will be compiled twice with different CFLAGS.
|
||||
|
||||
Compiled-in terminal database
|
||||
-----------------------------
|
||||
support for about a dozen common TERMs is built-in already. if you need one
|
||||
that's not included, you can either add yours to `libterminfo/genterms` or
|
||||
`make terminfo/terminfo.cdb` and install the result to either
|
||||
`$PREFIX/share/terminfo.cdb` or `$HOME/.terminfo.cdb`.
|
||||
|
||||
Compiling software against netbsd-curses
|
||||
----------------------------------------
|
||||
the functionality that ncurses offers is usually (if not configured to split
|
||||
into several separate libs) available in a single `libncurses` library.
|
||||
netbsd-curses on the other hand has it always split into `libcurses` and
|
||||
`libterminfo`.
|
||||
this difference requires to give the build system a hint that it needs to
|
||||
link to both libcurses and libterminfo.
|
||||
|
||||
- programs using pkg-config(1) automatically get the right options
|
||||
due to the supplied .pc files.
|
||||
|
||||
- for autoconf based software (using a configure script) it is usually
|
||||
sufficient to invoke configure like this:
|
||||
|
||||
LIBS="-lcurses -lterminfo" ./configure ...
|
||||
|
||||
- for Makefile-only based build systems, it should be sufficient to add
|
||||
the libs to LDFLAGS:
|
||||
|
||||
make LDFLAGS="-lcurses -lterminfo" ...
|
||||
|
||||
with these instructions it is easy to compile the majority of ncurses apps
|
||||
without problems against netbsd-curses.
|
||||
|
||||
a small percentage of apps written for ncurses poke at internals and need
|
||||
light patching:
|
||||
|
||||
- [patch for midnight commander][2] - merged upstream as rev 38d4c655d
|
||||
- [patch for python 2.7.x and 3.6][3]
|
||||
|
||||
if you have trouble compiling a specific package, first look at the
|
||||
[sabotage linux build recipes][4].
|
||||
if you still can't get the package to compile, feel free to open an issue
|
||||
[at the netbsd-curses issue tracker][5].
|
||||
|
||||
License
|
||||
-------
|
||||
libcurses, tset and tput are (C) 1980-1994
|
||||
"The Regents of the University of California" licensed under the 3-clause BSD
|
||||
license.
|
||||
Everything else is (C) 1999-2016 The NetBSD Foundation, Inc. and Contributors,
|
||||
licensed under the 2-clause BSD license.
|
||||
see COPYING for the full text, and in doubt, consult the copyright clauses in
|
||||
the respective .c files. Files without copyright clauses in the file header
|
||||
are explicitly released under the terms of the 2-clause BSD license as well.
|
||||
|
||||
|
||||
APPENDIX A: Test Setup used for comparison in Table 1
|
||||
-----------------------------------------------------
|
||||
All tests were done on a dual core x86_64 sabotage linux system, with the following
|
||||
features:
|
||||
installation of shared and static libs, headers, etc,
|
||||
i.e. make -j2 all install.
|
||||
ncurses and netbsd curses were both configured with support for widechars, and
|
||||
built-in terminfo database for a handful of terminals.
|
||||
|
||||
CFLAGS (optimized for size):
|
||||
-g0 -fdata-sections -ffunction-sections -Os -fno-unwind-tables
|
||||
-fno-asynchronous-unwind-tables -Wa,--noexecstack
|
||||
|
||||
LDFLAGS:
|
||||
-s -Wl,--gc-sections -Wl,-z,relro,-z,now
|
||||
|
||||
netbsd curses was installed without manpages (ncurses: 1.1 MB) and terminfo
|
||||
database (ncurses: 6.4MB).
|
||||
the debug info build was created with -g3 and debuginfo stripped into external
|
||||
files via objcopy.
|
||||
|
||||
APPENDIX B: History of NetBSD curses
|
||||
------------------------------------
|
||||
|
||||
Thomas Dickey did a [thorough investigation][6] on the history of NetBSD curses.
|
||||
|
||||
|
||||
[0]:http://trac.sagemath.org/ticket/18301
|
||||
[1]:https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/log/scripts/kconfig/lxdialog/check-lxdialog.sh
|
||||
[2]:https://github.com/MidnightCommander/mc/commit/38d4c655d322837574e957b4a824f4a0d1bb3b86
|
||||
[3]:https://github.com/sabotage-linux/sabotage/blob/06a4a815/KEEP/python2710-curses.patch
|
||||
[4]:https://github.com/sabotage-linux/sabotage/tree/master/pkg
|
||||
[5]:https://github.com/sabotage-linux/netbsd-curses/issues
|
||||
[6]:http://invisible-island.net/ncurses/ncurses-netbsd.html
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
cat << EOF
|
||||
Name: $1
|
||||
Description: $2
|
||||
Version: 5.9
|
||||
Requires:
|
||||
Conflicts:
|
||||
Libs: $3
|
||||
Cflags:
|
||||
EOF
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
# $NetBSD: Makefile,v 1.2 2013/08/11 06:48:46 dholland Exp $
|
||||
|
||||
PROG= infocmp
|
||||
|
||||
CPPFLAGS+= -I${.CURDIR}/../../lib/libterminfo
|
||||
LDADD+= -lterminfo
|
||||
DPADD+= ${LIBTERMINFO}
|
||||
|
||||
.include <bsd.prog.mk>
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
.\" $NetBSD: infocmp.1,v 1.7 2014/03/18 18:20:45 riastradh Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2009 The NetBSD Foundation, Inc.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to The NetBSD Foundation
|
||||
.\" by Roy Marples.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
.\" POSSIBILITY OF SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd February 5, 2010
|
||||
.Dt INFOCMP 1
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm infocmp
|
||||
.Nd compare or print compiled terminfo descriptions
|
||||
.Sh SYNOPSIS
|
||||
.Nm infocmp
|
||||
.Op Fl 1acnqux
|
||||
.Op Fl A Ar database
|
||||
.Op Fl B Ar database
|
||||
.Op Fl w Ar cols
|
||||
.Op Ar term ...
|
||||
.Sh DESCRIPTION
|
||||
The
|
||||
.Nm
|
||||
reconstructs the first available
|
||||
.Xr terminfo 5
|
||||
definition found for
|
||||
.Ar term
|
||||
and prints the result in a
|
||||
.Xr terminfo 5
|
||||
format.
|
||||
Capability types are grouped together and new types start new lines,
|
||||
first flags, then numbers, then strings.
|
||||
Capabilities are sorted by their name.
|
||||
If a second
|
||||
.Ar term
|
||||
is given then the capabilities are compared against each other.
|
||||
.Pp
|
||||
The following options are available:
|
||||
.Bl -tag -width Ev
|
||||
.It Fl 1
|
||||
Print one capability per line.
|
||||
.It Fl A Ar database
|
||||
Use this database to load the first terminal definition.
|
||||
.It Fl B Ar database
|
||||
Use this database to load subsequent terminal definitions.
|
||||
.It Fl a
|
||||
Include commented out capabilities.
|
||||
This only works if the database was compiled with the
|
||||
.Fl a
|
||||
flag passed to
|
||||
.Xr tic 1 .
|
||||
This also sets the
|
||||
.Fl x
|
||||
flag as
|
||||
.Nm
|
||||
retains commented out capabilities as non standard.
|
||||
.It Fl c
|
||||
Print capabilities common to each definition.
|
||||
.It Fl n
|
||||
Print capabilities that do not exist in either definition.
|
||||
.It Fl q
|
||||
Make the comparison listing shorter by omitting subheadings and using
|
||||
- for absent capabilities, @ for canceled capabilities rather than
|
||||
.Dv NULL .
|
||||
.It Fl u
|
||||
Build a new terminal description for the first terminal description,
|
||||
using subsequent terminal descriptions.
|
||||
This also sets the
|
||||
.Fl a
|
||||
flag.
|
||||
.It Fl w Ar cols
|
||||
Limit the width to
|
||||
.Ar cols .
|
||||
.It Fl x
|
||||
Include non-standard capabilities.
|
||||
More
|
||||
.Fl x
|
||||
only handles non-standard capabilities.
|
||||
This only works if the database was compiled with the
|
||||
.Fl x
|
||||
flag passed to
|
||||
.Xr tic 1 .
|
||||
.El
|
||||
.Sh ENVIRONMENT
|
||||
.Bl -tag -width Ev
|
||||
.It Ev COLUMNS
|
||||
Override columns returned by the output terminal.
|
||||
.Fl w
|
||||
.Ar cols
|
||||
supersedes this.
|
||||
.It Ev TERM
|
||||
.Nm
|
||||
uses the contents of the
|
||||
.Ev TERM
|
||||
environment variable if no terminal name is given on the command line.
|
||||
.El
|
||||
.Sh EXIT STATUS
|
||||
.Ex -std infocmp
|
||||
.Sh SEE ALSO
|
||||
.Xr tic 1 ,
|
||||
.Xr terminfo 5
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Nm
|
||||
utility outputs information that conforms to the
|
||||
.St -xcurses4.2
|
||||
standard.
|
||||
.Sh AUTHORS
|
||||
.An Roy Marples Aq Mt roy@NetBSD.org
|
||||
+809
@@ -0,0 +1,809 @@
|
||||
/* $NetBSD: infocmp.c,v 1.17 2020/03/31 12:44:15 roy Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009, 2010, 2020 The NetBSD Foundation, Inc.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Roy Marples.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <netbsd_sys/emalloc.h>
|
||||
#include <netbsd_sys/cdefs.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <term_private.h>
|
||||
#include <term.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define SW 8
|
||||
|
||||
typedef struct tient {
|
||||
char type;
|
||||
const char *id;
|
||||
signed char flag;
|
||||
int num;
|
||||
const char *str;
|
||||
} TIENT;
|
||||
|
||||
static size_t cols;
|
||||
static int aflag, cflag, nflag, qflag, xflag;
|
||||
|
||||
static size_t
|
||||
outstr(FILE *f, const char *str)
|
||||
{
|
||||
unsigned char ch;
|
||||
size_t r, l;
|
||||
|
||||
r = 0;
|
||||
l = strlen(str);
|
||||
while ((ch = (unsigned char)(*str++)) != '\0') {
|
||||
switch (ch) {
|
||||
case 128:
|
||||
ch = '0';
|
||||
break;
|
||||
case '\033':
|
||||
ch = 'E';
|
||||
break;
|
||||
case '\014':
|
||||
ch = 'f';
|
||||
break;
|
||||
case '^': /* FALLTHROUGH */
|
||||
case ',': /* escape these */
|
||||
break;
|
||||
case ' ':
|
||||
ch = 's';
|
||||
break;
|
||||
default:
|
||||
if (ch == '\177') {
|
||||
if (f != NULL)
|
||||
fputc('^', f);
|
||||
ch = '?';
|
||||
r++;
|
||||
} else if (iscntrl(ch) &&
|
||||
ch < 128 &&
|
||||
ch != '\\' &&
|
||||
(l < 4 || isdigit((unsigned char)*str)))
|
||||
{
|
||||
if (f != NULL)
|
||||
fputc('^', f);
|
||||
ch += '@';
|
||||
r++;
|
||||
} else if (!isprint(ch)) {
|
||||
if (f != NULL)
|
||||
fprintf(f, "\\%03o", ch);
|
||||
r += 4;
|
||||
continue;
|
||||
}
|
||||
goto prnt;
|
||||
}
|
||||
|
||||
if (f != NULL)
|
||||
fputc('\\', f);
|
||||
r++;
|
||||
prnt:
|
||||
if (f != NULL)
|
||||
fputc(ch, f);
|
||||
r++;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
static int
|
||||
ent_compare(const void *a, const void *b)
|
||||
{
|
||||
const TIENT *ta, *tb;
|
||||
|
||||
ta = (const TIENT *)a;
|
||||
tb = (const TIENT *)b;
|
||||
return strcmp(ta->id, tb->id);
|
||||
}
|
||||
|
||||
static void
|
||||
setdb(char *db)
|
||||
{
|
||||
static const char *ext[] = { ".cdb", ".db" };
|
||||
|
||||
for (size_t i = 0; i < __arraycount(ext); i++) {
|
||||
char *ptr = strstr(db, ext[i]);
|
||||
if (ptr == NULL || ptr[strlen(ext[i])] != '\0')
|
||||
continue;
|
||||
*ptr = '\0';
|
||||
break;
|
||||
}
|
||||
setenv("TERMINFO", db, 1);
|
||||
}
|
||||
|
||||
static void
|
||||
print_ent(const TIENT *ents, size_t nents)
|
||||
{
|
||||
size_t col, i, l;
|
||||
char nbuf[64];
|
||||
|
||||
if (nents == 0)
|
||||
return;
|
||||
|
||||
col = SW;
|
||||
printf("\t");
|
||||
for (i = 0; i < nents; i++) {
|
||||
if (*ents[i].id == '.' && aflag == 0)
|
||||
continue;
|
||||
switch (ents[i].type) {
|
||||
case 'f':
|
||||
if (ents[i].flag == ABSENT_BOOLEAN)
|
||||
continue;
|
||||
l = strlen(ents[i].id) + 2;
|
||||
if (ents[i].flag == CANCELLED_BOOLEAN)
|
||||
l++;
|
||||
break;
|
||||
case 'n':
|
||||
if (ents[i].num == ABSENT_NUMERIC)
|
||||
continue;
|
||||
if (VALID_NUMERIC(ents[i].num))
|
||||
l = snprintf(nbuf, sizeof(nbuf), "%s#%d,",
|
||||
ents[i].id, ents[i].num);
|
||||
else
|
||||
l = snprintf(nbuf, sizeof(nbuf), "%s@,",
|
||||
ents[i].id);
|
||||
break;
|
||||
case 's':
|
||||
if (ents[i].str == ABSENT_STRING)
|
||||
continue;
|
||||
if (VALID_STRING(ents[i].str))
|
||||
l = strlen(ents[i].id) +
|
||||
outstr(NULL, ents[i].str) + 7;
|
||||
else
|
||||
l = strlen(ents[i].id) + 3;
|
||||
break;
|
||||
default:
|
||||
errx(EXIT_FAILURE, "invalid type");
|
||||
}
|
||||
if (col != SW) {
|
||||
if (col + l > cols) {
|
||||
printf("\n\t");
|
||||
col = SW;
|
||||
} else
|
||||
col += printf(" ");
|
||||
}
|
||||
switch (ents[i].type) {
|
||||
case 'f':
|
||||
col += printf("%s", ents[i].id);
|
||||
if (ents[i].flag == ABSENT_BOOLEAN ||
|
||||
ents[i].flag == CANCELLED_BOOLEAN)
|
||||
col += printf("@");
|
||||
col += printf(",");
|
||||
break;
|
||||
case 'n':
|
||||
col += printf("%s", nbuf);
|
||||
break;
|
||||
case 's':
|
||||
col += printf("%s", ents[i].id);
|
||||
if (VALID_STRING(ents[i].str)) {
|
||||
col += printf("=");
|
||||
col += outstr(stdout, ents[i].str);
|
||||
} else
|
||||
col += printf("@");
|
||||
col += printf(",");
|
||||
break;
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static size_t
|
||||
load_ents(TIENT *ents, TERMINAL *t, char type)
|
||||
{
|
||||
size_t i, n, max;
|
||||
TERMUSERDEF *ud;
|
||||
|
||||
switch (type) {
|
||||
case 'f':
|
||||
max = TIFLAGMAX;
|
||||
break;
|
||||
case 'n':
|
||||
max = TINUMMAX;
|
||||
break;
|
||||
default:
|
||||
max = TISTRMAX;
|
||||
}
|
||||
|
||||
n = 0;
|
||||
for (i = 0; i <= max; i++) {
|
||||
switch (type) {
|
||||
case 'f':
|
||||
if (t->flags[i] == 1 ||
|
||||
(aflag && t->flags[i] == CANCELLED_BOOLEAN))
|
||||
{
|
||||
ents[n].id = _ti_flagid(i);
|
||||
ents[n].type = 'f';
|
||||
ents[n++].flag = t->flags[i];
|
||||
}
|
||||
break;
|
||||
case 'n':
|
||||
if (VALID_NUMERIC(t->nums[i]) ||
|
||||
(aflag && t->nums[i] == CANCELLED_NUMERIC))
|
||||
{
|
||||
ents[n].id = _ti_numid(i);
|
||||
ents[n].type = 'n';
|
||||
ents[n++].num = t->nums[i];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (VALID_STRING(t->strs[i]) ||
|
||||
(aflag && t->strs[i] == CANCELLED_STRING))
|
||||
{
|
||||
ents[n].id = _ti_strid(i);
|
||||
ents[n].type = 's';
|
||||
ents[n++].str = t->strs[i];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (xflag != 0 && t->_nuserdefs != 0) {
|
||||
for (i = 0; i < t->_nuserdefs; i++) {
|
||||
ud = &t->_userdefs[i];
|
||||
if (ud->type == type) {
|
||||
switch (type) {
|
||||
case 'f':
|
||||
if (!aflag &&
|
||||
!VALID_BOOLEAN(ud->flag))
|
||||
continue;
|
||||
break;
|
||||
case 'n':
|
||||
if (!aflag &&
|
||||
!VALID_NUMERIC(ud->num))
|
||||
continue;
|
||||
break;
|
||||
case 's':
|
||||
if (!aflag &&
|
||||
!VALID_STRING(ud->str))
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
ents[n].id = ud->id;
|
||||
ents[n].type = ud->type;
|
||||
ents[n].flag = ud->flag;
|
||||
ents[n].num = ud->num;
|
||||
ents[n++].str = ud->str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
qsort(ents, n, sizeof(TIENT), ent_compare);
|
||||
return n;
|
||||
}
|
||||
|
||||
static void
|
||||
cprint_ent(TIENT *ent)
|
||||
{
|
||||
|
||||
if (ent == NULL) {
|
||||
if (qflag == 0)
|
||||
printf("NULL");
|
||||
else
|
||||
printf("-");
|
||||
}
|
||||
|
||||
switch (ent->type) {
|
||||
case 'f':
|
||||
if (VALID_BOOLEAN(ent->flag))
|
||||
printf(ent->flag == 1 ? "T" : "F");
|
||||
else if (qflag == 0)
|
||||
printf("F");
|
||||
else if (ent->flag == CANCELLED_BOOLEAN)
|
||||
printf("@");
|
||||
else
|
||||
printf("-");
|
||||
break;
|
||||
case 'n':
|
||||
if (VALID_NUMERIC(ent->num))
|
||||
printf("%d", ent->num);
|
||||
else if (qflag == 0)
|
||||
printf("NULL");
|
||||
else if (ent->num == CANCELLED_NUMERIC)
|
||||
printf("@");
|
||||
else
|
||||
printf("-");
|
||||
break;
|
||||
case 's':
|
||||
if (VALID_STRING(ent->str)) {
|
||||
printf("'");
|
||||
outstr(stdout, ent->str);
|
||||
printf("'");
|
||||
} else if (qflag == 0)
|
||||
printf("NULL");
|
||||
else if (ent->str == CANCELLED_STRING)
|
||||
printf("@");
|
||||
else
|
||||
printf("-");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
compare_ents(TIENT *ents1, size_t n1, TIENT *ents2, size_t n2)
|
||||
{
|
||||
size_t i1, i2;
|
||||
TIENT *e1, *e2, ee;
|
||||
int c;
|
||||
|
||||
i1 = i2 = 0;
|
||||
ee.type = 'f';
|
||||
ee.flag = ABSENT_BOOLEAN;
|
||||
ee.num = ABSENT_NUMERIC;
|
||||
ee.str = ABSENT_STRING;
|
||||
while (i1 != n1 || i2 != n2) {
|
||||
if (i1 == n1)
|
||||
c = 1;
|
||||
else if (i2 == n2)
|
||||
c = -1;
|
||||
else
|
||||
c = strcmp(ents1[i1].id, ents2[i2].id);
|
||||
if (c == 0) {
|
||||
e1 = &ents1[i1++];
|
||||
e2 = &ents2[i2++];
|
||||
} else if (c < 0) {
|
||||
e1 = &ents1[i1++];
|
||||
e2 = ⅇ
|
||||
ee.id = e1->id;
|
||||
ee.type = e1->type;
|
||||
} else {
|
||||
e1 = ⅇ
|
||||
e2 = &ents2[i2++];
|
||||
ee.id = e2->id;
|
||||
ee.type = e2->type;
|
||||
}
|
||||
switch (e1->type) {
|
||||
case 'f':
|
||||
if (cflag != 0) {
|
||||
if (e1->flag == e2->flag)
|
||||
printf("\t%s\n", ents1[i1].id);
|
||||
continue;
|
||||
}
|
||||
if (e1->flag == e2->flag)
|
||||
continue;
|
||||
break;
|
||||
case 'n':
|
||||
if (cflag != 0) {
|
||||
if (e1->num == e2->num)
|
||||
printf("\t%s#%d\n",
|
||||
ents1[i1].id, ents1[i1].num);
|
||||
continue;
|
||||
}
|
||||
if (e1->num == e2->num)
|
||||
continue;
|
||||
break;
|
||||
case 's':
|
||||
if (cflag != 0) {
|
||||
if (VALID_STRING(e1->str) &&
|
||||
VALID_STRING(e2->str) &&
|
||||
strcmp(e1->str, e2->str) == 0) {
|
||||
printf("\t%s=", ents1[i1].id);
|
||||
outstr(stdout, ents1[i1].str);
|
||||
printf("\n");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (VALID_STRING(e1->str) &&
|
||||
VALID_STRING(e2->str) &&
|
||||
strcmp(e1->str, e2->str) == 0)
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
printf("\t%s: ", e1->id);
|
||||
cprint_ent(e1);
|
||||
if (e1->type == 'f')
|
||||
printf(":");
|
||||
else
|
||||
printf(", ");
|
||||
cprint_ent(e2);
|
||||
printf(".\n");
|
||||
}
|
||||
}
|
||||
|
||||
static TERMINAL *
|
||||
load_term(const char *name)
|
||||
{
|
||||
TERMINAL *t;
|
||||
|
||||
t = ecalloc(1, sizeof(*t));
|
||||
if (name == NULL)
|
||||
name = getenv("TERM");
|
||||
if (name == NULL)
|
||||
name = "dumb";
|
||||
if (_ti_getterm(t, name, 1) == 1)
|
||||
return t;
|
||||
|
||||
if (_ti_database == NULL)
|
||||
errx(EXIT_FAILURE,
|
||||
"no terminal definition found in internal database");
|
||||
else
|
||||
errx(EXIT_FAILURE,
|
||||
"no terminal definition found in %s.db", _ti_database);
|
||||
}
|
||||
|
||||
static void
|
||||
show_missing(TERMINAL *t1, TERMINAL *t2, char type)
|
||||
{
|
||||
ssize_t i, max;
|
||||
const char *id;
|
||||
|
||||
switch (type) {
|
||||
case 'f':
|
||||
max = TIFLAGMAX;
|
||||
break;
|
||||
case 'n':
|
||||
max = TINUMMAX;
|
||||
break;
|
||||
default:
|
||||
max = TISTRMAX;
|
||||
}
|
||||
|
||||
for (i = 0; i <= max; i++) {
|
||||
switch (type) {
|
||||
case 'f':
|
||||
if (t1->flags[i] != ABSENT_BOOLEAN ||
|
||||
t2->flags[i] != ABSENT_BOOLEAN)
|
||||
continue;
|
||||
id = _ti_flagid(i);
|
||||
break;
|
||||
case 'n':
|
||||
if (t1->nums[i] != ABSENT_NUMERIC ||
|
||||
t2->nums[i] != ABSENT_NUMERIC)
|
||||
continue;
|
||||
id = _ti_numid(i);
|
||||
break;
|
||||
default:
|
||||
if (t1->strs[i] != ABSENT_STRING ||
|
||||
t2->strs[i] != ABSENT_STRING)
|
||||
continue;
|
||||
id = _ti_strid(i);
|
||||
break;
|
||||
}
|
||||
printf("\t!%s.\n", id);
|
||||
}
|
||||
}
|
||||
|
||||
static TERMUSERDEF *
|
||||
find_userdef(TERMINAL *term, const char *id)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < term->_nuserdefs; i++)
|
||||
if (strcmp(term->_userdefs[i].id, id) == 0)
|
||||
return &term->_userdefs[i];
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
use_terms(TERMINAL *term, size_t nuse, char **uterms)
|
||||
{
|
||||
TERMINAL **terms;
|
||||
TERMUSERDEF *ud, *tud;
|
||||
size_t i, j, agree, absent, data;
|
||||
|
||||
terms = ecalloc(nuse, sizeof(*terms));
|
||||
for (i = 0; i < nuse; i++) {
|
||||
if (strcmp(term->name, *uterms) == 0)
|
||||
errx(EXIT_FAILURE, "cannot use same terminal");
|
||||
for (j = 0; j < i; j++)
|
||||
if (strcmp(terms[j]->name, *uterms) == 0)
|
||||
errx(EXIT_FAILURE, "cannot use same terminal");
|
||||
terms[i] = load_term(*uterms++);
|
||||
}
|
||||
|
||||
for (i = 0; i < TIFLAGMAX + 1; i++) {
|
||||
agree = absent = data = 0;
|
||||
for (j = 0; j < nuse; j++) {
|
||||
if (terms[j]->flags[i] == ABSENT_BOOLEAN ||
|
||||
terms[j]->flags[i] == CANCELLED_BOOLEAN)
|
||||
absent++;
|
||||
else {
|
||||
data++;
|
||||
if (term->flags[i] == terms[j]->flags[i])
|
||||
agree++;
|
||||
}
|
||||
}
|
||||
if (data == 0)
|
||||
continue;
|
||||
if (agree > 0 && agree + absent == nuse)
|
||||
term->flags[i] = ABSENT_BOOLEAN;
|
||||
else if (term->flags[i] == ABSENT_BOOLEAN)
|
||||
term->flags[i] = CANCELLED_BOOLEAN;
|
||||
}
|
||||
|
||||
for (i = 0; i < TINUMMAX + 1; i++) {
|
||||
agree = absent = data = 0;
|
||||
for (j = 0; j < nuse; j++) {
|
||||
if (terms[j]->nums[i] == ABSENT_NUMERIC ||
|
||||
terms[j]->nums[i] == CANCELLED_NUMERIC)
|
||||
absent++;
|
||||
else {
|
||||
data++;
|
||||
if (term->nums[i] == terms[j]->nums[i])
|
||||
agree++;
|
||||
}
|
||||
}
|
||||
if (data == 0)
|
||||
continue;
|
||||
if (agree > 0 && agree + absent == nuse)
|
||||
term->nums[i] = ABSENT_NUMERIC;
|
||||
else if (term->nums[i] == ABSENT_NUMERIC)
|
||||
term->nums[i] = CANCELLED_NUMERIC;
|
||||
}
|
||||
|
||||
for (i = 0; i < TISTRMAX + 1; i++) {
|
||||
agree = absent = data = 0;
|
||||
for (j = 0; j < nuse; j++) {
|
||||
if (terms[j]->strs[i] == ABSENT_STRING ||
|
||||
terms[j]->strs[i] == CANCELLED_STRING)
|
||||
absent++;
|
||||
else {
|
||||
data++;
|
||||
if (VALID_STRING(term->strs[i]) &&
|
||||
strcmp(term->strs[i],
|
||||
terms[j]->strs[i]) == 0)
|
||||
agree++;
|
||||
}
|
||||
}
|
||||
if (data == 0)
|
||||
continue;
|
||||
if (agree > 0 && agree + absent == nuse)
|
||||
term->strs[i] = ABSENT_STRING;
|
||||
else if (term->strs[i] == ABSENT_STRING)
|
||||
term->strs[i] = CANCELLED_STRING;
|
||||
}
|
||||
|
||||
/* User defined caps are more tricky.
|
||||
First we set any to absent that agree. */
|
||||
for (i = 0; i < term->_nuserdefs; i++) {
|
||||
agree = absent = data = 0;
|
||||
ud = &term->_userdefs[i];
|
||||
for (j = 0; j < nuse; j++) {
|
||||
tud = find_userdef(terms[j], ud->id);
|
||||
if (tud == NULL)
|
||||
absent++;
|
||||
else {
|
||||
data++;
|
||||
switch (ud->type) {
|
||||
case 'f':
|
||||
if (tud->type == 'f' &&
|
||||
tud->flag == ud->flag)
|
||||
agree++;
|
||||
break;
|
||||
case 'n':
|
||||
if (tud->type == 'n' &&
|
||||
tud->num == ud->num)
|
||||
agree++;
|
||||
break;
|
||||
case 's':
|
||||
if (tud->type == 's' &&
|
||||
VALID_STRING(tud->str) &&
|
||||
VALID_STRING(ud->str) &&
|
||||
strcmp(ud->str, tud->str) == 0)
|
||||
agree++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (data == 0)
|
||||
continue;
|
||||
if (agree > 0 && agree + absent == nuse) {
|
||||
ud->flag = ABSENT_BOOLEAN;
|
||||
ud->num = ABSENT_NUMERIC;
|
||||
ud->str = ABSENT_STRING;
|
||||
}
|
||||
}
|
||||
|
||||
/* Now add any that we don't have as cancelled */
|
||||
for (i = 0; i < nuse; i++) {
|
||||
for (j = 0; j < terms[i]->_nuserdefs; j++) {
|
||||
ud = find_userdef(term, terms[i]->_userdefs[j].id);
|
||||
if (ud != NULL)
|
||||
continue; /* We have handled this */
|
||||
term->_userdefs = erealloc(term->_userdefs,
|
||||
sizeof(*term->_userdefs) * (term->_nuserdefs + 1));
|
||||
tud = &term->_userdefs[term->_nuserdefs++];
|
||||
tud->id = terms[i]->_userdefs[j].id;
|
||||
tud->type = terms[i]->_userdefs[j].flag;
|
||||
tud->flag = CANCELLED_BOOLEAN;
|
||||
tud->num = CANCELLED_NUMERIC;
|
||||
tud->str = CANCELLED_STRING;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
char *term, *Barg;
|
||||
int ch, uflag;
|
||||
TERMINAL *t, *t2;
|
||||
size_t n, n2;
|
||||
struct winsize ws;
|
||||
TIENT ents[TISTRMAX + 1], ents2[TISTRMAX + 1];
|
||||
|
||||
cols = 80; /* default */
|
||||
term = getenv("COLUMNS");
|
||||
if (term != NULL)
|
||||
cols = strtoul(term, NULL, 10);
|
||||
else if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) == 0)
|
||||
cols = ws.ws_col;
|
||||
|
||||
uflag = xflag = 0;
|
||||
Barg = NULL;
|
||||
while ((ch = getopt(argc, argv, "1A:B:acnquw:x")) != -1)
|
||||
switch (ch) {
|
||||
case '1':
|
||||
cols = 1;
|
||||
break;
|
||||
case 'A':
|
||||
setdb(optarg);
|
||||
break;
|
||||
case 'B':
|
||||
Barg = optarg;
|
||||
break;
|
||||
case 'a':
|
||||
aflag = 1;
|
||||
break;
|
||||
case 'c':
|
||||
cflag = 1;
|
||||
break;
|
||||
case 'n':
|
||||
nflag = 1;
|
||||
break;
|
||||
case 'q':
|
||||
qflag = 1;
|
||||
break;
|
||||
case 'u':
|
||||
uflag = 1;
|
||||
aflag = 1;
|
||||
break;
|
||||
case 'w':
|
||||
cols = strtoul(optarg, NULL, 10);
|
||||
break;
|
||||
case 'x':
|
||||
xflag = 1;
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
fprintf(stderr,
|
||||
"usage: %s [-1acnqux] [-A database] [-B database] "
|
||||
"[-w cols] [term]\n",
|
||||
argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
cols--;
|
||||
|
||||
if (optind + 1 < argc)
|
||||
aflag = 1;
|
||||
|
||||
if (optind < argc)
|
||||
term = argv[optind++];
|
||||
else
|
||||
term = NULL;
|
||||
t = load_term(term);
|
||||
|
||||
if (uflag != 0)
|
||||
use_terms(t, argc - optind, argv + optind);
|
||||
|
||||
if ((optind + 1 != argc && nflag == 0) || uflag != 0) {
|
||||
if (uflag == 0)
|
||||
printf("# Reconstructed from %s\n",
|
||||
_ti_database == NULL ?
|
||||
"internal database" : _ti_database);
|
||||
/* Strip internal versioning */
|
||||
term = strchr(t->name, TERMINFO_VDELIM);
|
||||
if (term != NULL)
|
||||
*term = '\0';
|
||||
printf("%s", t->name);
|
||||
if (t->_alias != NULL) {
|
||||
char *alias, *aliascpy, *delim;
|
||||
|
||||
alias = aliascpy = estrdup(t->_alias);
|
||||
while (alias != NULL && *alias != '\0') {
|
||||
putchar('|');
|
||||
delim = strchr(alias, TERMINFO_VDELIM);
|
||||
if (delim != NULL)
|
||||
*delim++ = '\0';
|
||||
printf("%s", alias);
|
||||
if (delim != NULL) {
|
||||
while (*delim != '\0' && *delim != '|')
|
||||
delim++;
|
||||
if (*delim == '\0')
|
||||
alias = NULL;
|
||||
else
|
||||
alias = delim + 1;
|
||||
} else
|
||||
alias = NULL;
|
||||
}
|
||||
free(aliascpy);
|
||||
}
|
||||
if (t->desc != NULL && *t->desc != '\0')
|
||||
printf("|%s", t->desc);
|
||||
printf(",\n");
|
||||
|
||||
n = load_ents(ents, t, 'f');
|
||||
print_ent(ents, n);
|
||||
n = load_ents(ents, t, 'n');
|
||||
print_ent(ents, n);
|
||||
n = load_ents(ents, t, 's');
|
||||
print_ent(ents, n);
|
||||
|
||||
if (uflag != 0) {
|
||||
printf("\t");
|
||||
n = SW;
|
||||
for (; optind < argc; optind++) {
|
||||
n2 = 5 + strlen(argv[optind]);
|
||||
if (n != SW) {
|
||||
if (n + n2 > cols) {
|
||||
printf("\n\t");
|
||||
n = SW;
|
||||
} else
|
||||
n += printf(" ");
|
||||
}
|
||||
n += printf("use=%s,", argv[optind]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
if (Barg == NULL)
|
||||
unsetenv("TERMINFO");
|
||||
else
|
||||
setdb(Barg);
|
||||
t2 = load_term(argv[optind++]);
|
||||
printf("comparing %s to %s.\n", t->name, t2->name);
|
||||
if (qflag == 0)
|
||||
printf(" comparing booleans.\n");
|
||||
if (nflag == 0) {
|
||||
n = load_ents(ents, t, 'f');
|
||||
n2 = load_ents(ents2, t2, 'f');
|
||||
compare_ents(ents, n, ents2, n2);
|
||||
} else
|
||||
show_missing(t, t2, 'f');
|
||||
if (qflag == 0)
|
||||
printf(" comparing numbers.\n");
|
||||
if (nflag == 0) {
|
||||
n = load_ents(ents, t, 'n');
|
||||
n2 = load_ents(ents2, t2, 'n');
|
||||
compare_ents(ents, n, ents2, n2);
|
||||
} else
|
||||
show_missing(t, t2, 'n');
|
||||
if (qflag == 0)
|
||||
printf(" comparing strings.\n");
|
||||
if (nflag == 0) {
|
||||
n = load_ents(ents, t, 's');
|
||||
n2 = load_ents(ents2, t2, 's');
|
||||
compare_ents(ents, n, ents2, n2);
|
||||
} else
|
||||
show_missing(t, t2, 's');
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# This is an actually-safe install command which installs the new
|
||||
# file atomically in the new location, rather than overwriting
|
||||
# existing files.
|
||||
#
|
||||
|
||||
usage() {
|
||||
printf "usage: %s [-D] [-l] [-m mode] src dest\n" "$0" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
mkdirp=
|
||||
symlink=
|
||||
mode=755
|
||||
|
||||
while getopts Dlm: name ; do
|
||||
case "$name" in
|
||||
D) mkdirp=yes ;;
|
||||
l) symlink=yes ;;
|
||||
m) mode=$OPTARG ;;
|
||||
?) usage ;;
|
||||
esac
|
||||
done
|
||||
shift $(($OPTIND - 1))
|
||||
|
||||
test "$#" -eq 2 || usage
|
||||
src=$1
|
||||
dst=$2
|
||||
tmp="$dst.tmp.$$"
|
||||
|
||||
case "$dst" in
|
||||
*/) printf "%s: %s ends in /\n", "$0" "$dst" 1>&2 ; exit 1 ;;
|
||||
esac
|
||||
|
||||
set -C
|
||||
set -e
|
||||
|
||||
if test "$mkdirp" ; then
|
||||
umask 022
|
||||
case "$2" in
|
||||
*/*) mkdir -p "${dst%/*}" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
trap 'rm -f "$tmp"' EXIT INT QUIT TERM HUP
|
||||
|
||||
umask 077
|
||||
|
||||
if test "$symlink" ; then
|
||||
ln -s "$1" "$tmp"
|
||||
else
|
||||
cat < "$1" > "$tmp"
|
||||
chmod "$mode" "$tmp"
|
||||
fi
|
||||
|
||||
mv -f "$tmp" "$2"
|
||||
test -d "$2" && {
|
||||
rm -f "$2/$tmp"
|
||||
printf "%s: %s is a directory\n" "$0" "$dst" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
exit 0
|
||||
@@ -0,0 +1,54 @@
|
||||
#$Id: Makefile,v 1.2 2007/05/28 15:01:58 blymn Exp $
|
||||
#$Log: Makefile,v $
|
||||
#Revision 1.2 2007/05/28 15:01:58 blymn
|
||||
#Merge in wide curses code done as a Summer of Code project by
|
||||
#Ruibiao Qiu.
|
||||
#
|
||||
#Revision 1.1.2.2 2007/01/31 10:08:47 blymn
|
||||
#Fix up build errors.
|
||||
#
|
||||
#Revision 1.1.2.1 2007/01/21 12:05:54 blymn
|
||||
#Merge wide curses.
|
||||
#
|
||||
#Revision 1.1 2007/01/21 11:38:59 blymn
|
||||
#Wide curses merge
|
||||
#
|
||||
#Revision 1.1 2005/08/31 14:52:08 ruibiao
|
||||
#
|
||||
#A patach for the current source
|
||||
#
|
||||
#Revision 1.2 2005/08/23 21:29:08 ruibiao
|
||||
#
|
||||
#Changed to the right libraries
|
||||
#
|
||||
#Revision 1.1 2005/08/23 16:38:22 ruibiao
|
||||
#
|
||||
#Initial version, to build all versions of file views and the unit tester
|
||||
#
|
||||
|
||||
RM = /bin/rm -f
|
||||
CFLAGS =
|
||||
|
||||
.if defined(DEBUG)
|
||||
CFLAGS+= -g
|
||||
.endif
|
||||
|
||||
all: wcview nwview ccview tcview ncview ex1
|
||||
|
||||
wcview: view.c
|
||||
gcc -DHAVE_WCHAR -o wcview view.c -I.. $(CFLAGS) -lcurses -Wl,-rpath,.. -L..
|
||||
|
||||
nwview: view.c
|
||||
gcc -DHAVE_WCHAR -o nwview view.c -DNCURSES -I/usr/pkg/include $(CFLAGS) -lcurses -Wl,-rpath,/usr/pkg/lib -L/usr/pkg/lib
|
||||
|
||||
ccview: view.c
|
||||
gcc -o ccview view.c -I.. $(CFLAGS) -lcurses -Wl,-rpath,.. -L..
|
||||
|
||||
tcview: view.c
|
||||
gcc -o tcview view.c -L/usr/lib -Wl,-rpath,/usr/lib $(CFLAGS) -lcurses
|
||||
|
||||
ncview: view.c
|
||||
gcc -o ncview view.c -I/usr/pkg/include -DNCURSES -L/usr/pkg/lib -Wl,-rpath,/usr/pkg/lib $(CFLAGS) -lncurses
|
||||
|
||||
ex1: ex1.c
|
||||
gcc -DHAVE_WCHAR -o ex1 ex1.c -I.. $(CFLAGS) -lcurses -Wl,-rpath,.. -L..
|
||||
+333
@@ -0,0 +1,333 @@
|
||||
/* $NetBSD: ex1.c,v 1.5 2007/05/28 15:01:58 blymn Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <curses.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <locale.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define YSIZE 4
|
||||
#define XSIZE 30
|
||||
|
||||
void quit( int );
|
||||
|
||||
main()
|
||||
{
|
||||
int i, j, c, n = 0, ac = 0;
|
||||
size_t len;
|
||||
char id[100];
|
||||
FILE *fp;
|
||||
char *s;
|
||||
cchar_t cc, ncc, cstr[ 128 ], icc, icstr[ 128 ], bcc;
|
||||
int wc_on = 0, wgc_on = 0;
|
||||
char mbs[] = "大";
|
||||
char mbstr[] = "大学之道,在明明德,在亲民,在止于至善。 (Liji)";
|
||||
wchar_t wstr[ 128 ], owstr[ 4 ], gwstr[ 128 ], iwstr[ 128 ];
|
||||
int wslen = 0;
|
||||
wint_t wc;
|
||||
char nostr[ 128 ];
|
||||
attr_t al[ 15 ] = { WA_BLINK,
|
||||
WA_BOLD,
|
||||
WA_DIM,
|
||||
WA_LOW,
|
||||
WA_TOP,
|
||||
WA_INVIS,
|
||||
WA_HORIZONTAL,
|
||||
WA_VERTICAL,
|
||||
WA_LEFT,
|
||||
WA_RIGHT,
|
||||
WA_PROTECT,
|
||||
WA_REVERSE,
|
||||
WA_STANDOUT,
|
||||
WA_UNDERLINE };
|
||||
|
||||
fprintf( stderr, "Current locale: %s\n", setlocale(LC_ALL, ""));
|
||||
if (( wslen = mbstowcs( &cc.vals[ 0 ], mbs, strlen( mbs ))) < 0 ) {
|
||||
fprintf( stderr, "mbstowcs() failed\n" );
|
||||
return -1;
|
||||
}
|
||||
fprintf( stderr, "WC string length: %d\n", wslen );
|
||||
fprintf( stderr, "WC width: %d\n", wcwidth( cc.vals[ 0 ]));
|
||||
cc.elements = ncc.elements = 8;
|
||||
cc.attributes = ncc.attributes = 0;
|
||||
ncc.vals[ 0 ] = 0xda00;
|
||||
cc.vals[ 1 ] = ncc.vals[ 1 ] = 0xda01;
|
||||
cc.vals[ 2 ] = ncc.vals[ 2 ] = 0xda02;
|
||||
cc.vals[ 3 ] = ncc.vals[ 3 ] = 0xda03;
|
||||
cc.vals[ 4 ] = ncc.vals[ 4 ] = 0xda04;
|
||||
cc.vals[ 5 ] = ncc.vals[ 5 ] = 0xda05;
|
||||
cc.vals[ 6 ] = ncc.vals[ 6 ] = 0xda06;
|
||||
cc.vals[ 7 ] = ncc.vals[ 7 ] = 0xda07;
|
||||
|
||||
if (( wslen = mbstowcs( wstr, mbstr, strlen( mbstr ))) < 0 ) {
|
||||
fprintf( stderr, "mbstowcs() failed\n" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
for ( i = 0; i < wslen; i++ ) {
|
||||
cstr[ i ].vals[ 0 ] = wstr[ i ];
|
||||
}
|
||||
cstr[ wslen ].vals[ 0 ] = 0;
|
||||
|
||||
bcc.elements = 8;
|
||||
bcc.attributes = 0;
|
||||
bcc.vals[ 0 ] = L'_';
|
||||
bcc.vals[ 1 ] = 0xda01;
|
||||
bcc.vals[ 2 ] = 0xda02;
|
||||
bcc.vals[ 3 ] = 0xda03;
|
||||
bcc.vals[ 4 ] = 0xda04;
|
||||
bcc.vals[ 5 ] = 0xda05;
|
||||
bcc.vals[ 6 ] = 0xda06;
|
||||
bcc.vals[ 7 ] = 0xda07;
|
||||
|
||||
initscr(); /* Always call initscr() first */
|
||||
signal(SIGINT, quit); /* Make sure wou have a 'cleanup' fn */
|
||||
crmode(); /* We want cbreak mode */
|
||||
noecho(); /* We want to have control of chars */
|
||||
delwin(stdscr); /* Create our own stdscr */
|
||||
stdscr = newwin(YSIZE, XSIZE, 1, 1);
|
||||
flushok(stdscr, TRUE); /* Enable flushing of stdout */
|
||||
scrollok(stdscr, TRUE); /* Enable scrolling */
|
||||
erase(); /* Initially, clear the screen */
|
||||
|
||||
standout();
|
||||
move(0,0);
|
||||
while (1) {
|
||||
if ( !wgc_on ) {
|
||||
c = getchar();
|
||||
switch(c) {
|
||||
case 'q': /* Quit on 'q' */
|
||||
quit( 0 );
|
||||
break;
|
||||
case 'p':
|
||||
keypad( stdscr, TRUE );
|
||||
break;
|
||||
case 'P':
|
||||
keypad( stdscr, FALSE );
|
||||
break;
|
||||
case 'g':
|
||||
wgc_on = 1;
|
||||
echo();
|
||||
break;
|
||||
case 'b':
|
||||
get_wstr( gwstr );
|
||||
move( 1, 0 );
|
||||
addstr( "Input:" );
|
||||
addwstr( gwstr );
|
||||
refresh();
|
||||
break;
|
||||
case 'h':
|
||||
move( 0, 0 );
|
||||
in_wch( &icc );
|
||||
move( 1, 0 );
|
||||
add_wch( &icc );
|
||||
refresh();
|
||||
break;
|
||||
case 'y':
|
||||
move( 0, 0 );
|
||||
in_wchstr( icstr );
|
||||
move( 1, 0 );
|
||||
add_wchstr( icstr );
|
||||
refresh();
|
||||
break;
|
||||
case 'u':
|
||||
move( 0, 0 );
|
||||
inwstr( iwstr );
|
||||
move( 1, 0 );
|
||||
addwstr( iwstr );
|
||||
refresh();
|
||||
break;
|
||||
case 'i':
|
||||
move( 0, 0 );
|
||||
hline_set( &cc, 20 );
|
||||
move( 0, 0 );
|
||||
vline_set( &cc, 20 );
|
||||
refresh();
|
||||
break;
|
||||
case 'o':
|
||||
clrtobot();
|
||||
refresh();
|
||||
break;
|
||||
case 's': /* Go into standout mode on 's' */
|
||||
standout();
|
||||
break;
|
||||
case 'e': /* Exit standout mode on 'e' */
|
||||
standend();
|
||||
break;
|
||||
case 'r': /* Force a refresh on 'r' */
|
||||
wrefresh(curscr);
|
||||
break;
|
||||
case 'w': /* Turn on/off add_wch() tests */
|
||||
wc_on = 1 - wc_on;
|
||||
break;
|
||||
case 'd':
|
||||
add_wchstr(( const cchar_t *)&cstr );
|
||||
refresh();
|
||||
break;
|
||||
case 'c':
|
||||
addwstr(( const wchar_t *)&wstr );
|
||||
refresh();
|
||||
break;
|
||||
case 'z':
|
||||
move( 0, 1 );
|
||||
if ( wc_on )
|
||||
add_wch( &cc );
|
||||
else
|
||||
addch( c );
|
||||
refresh();
|
||||
break;
|
||||
case 'x':
|
||||
move( 0, 3 );
|
||||
if ( wc_on )
|
||||
add_wch( &cc );
|
||||
else
|
||||
addch( c );
|
||||
refresh();
|
||||
break;
|
||||
case 'n':
|
||||
add_wch( &ncc );
|
||||
refresh();
|
||||
break;
|
||||
case 'm':
|
||||
//border( 0, 0, 0, 0, 0, 0, 0, 0 );
|
||||
border_set( NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL );
|
||||
refresh();
|
||||
break;
|
||||
case 'j':
|
||||
box_set( stdscr, &cc, &cc );
|
||||
refresh();
|
||||
break;
|
||||
case 'k':
|
||||
erase();
|
||||
refresh();
|
||||
break;
|
||||
case '1':
|
||||
move( 0, 0 );
|
||||
clrtoeol();
|
||||
refresh();
|
||||
break;
|
||||
case '2':
|
||||
move( 0, 0 );
|
||||
sprintf( nostr, "Orig:%x", al[ ac ]);
|
||||
addstr( nostr );
|
||||
ac = ( ac + 1 ) % 16;
|
||||
bcc.attributes = al[ ac ];
|
||||
bkgrnd( &bcc );
|
||||
move( 1, 0 );
|
||||
sprintf( nostr, "New:%x", al[ ac ]);
|
||||
//addstr( nostr );
|
||||
insstr( nostr );
|
||||
refresh();
|
||||
break;
|
||||
case 'v':
|
||||
if ( wc_on )
|
||||
ins_wch( &cc );
|
||||
else
|
||||
insch( c );
|
||||
refresh();
|
||||
break;
|
||||
case 'f':
|
||||
ins_wstr(( const wchar_t *)&wstr );
|
||||
refresh();
|
||||
break;
|
||||
case 't':
|
||||
for ( i = 0; i < 4; i++ ) {
|
||||
owstr[ i ] = wstr[ i + 5 ];
|
||||
wstr[ i + 5 ] = i + 0xda05;
|
||||
}
|
||||
ins_wstr(( const wchar_t *)&wstr );
|
||||
refresh();
|
||||
for ( i = 0; i < 4; i++ )
|
||||
wstr[ i + 5 ] = owstr[ i ];
|
||||
break;
|
||||
default: /* By default output the character */
|
||||
if ( wc_on )
|
||||
add_wch( &cc );
|
||||
else {
|
||||
if ( c < 0x7F )
|
||||
addch( c );
|
||||
else {
|
||||
addstr( keyname( c ));
|
||||
}
|
||||
}
|
||||
refresh();
|
||||
}
|
||||
} else {
|
||||
get_wch( &wc );
|
||||
switch ( wc ) {
|
||||
case L'w':
|
||||
wgc_on = 0;
|
||||
noecho();
|
||||
break;
|
||||
case L'q':
|
||||
quit( 0 );
|
||||
break;
|
||||
case L't':
|
||||
notimeout( stdscr, TRUE );
|
||||
break;
|
||||
case L'T':
|
||||
notimeout( stdscr, FALSE );
|
||||
break;
|
||||
case L'd':
|
||||
nodelay( stdscr, TRUE );
|
||||
break;
|
||||
case L'D':
|
||||
nodelay( stdscr, FALSE );
|
||||
break;
|
||||
case L'p':
|
||||
keypad( stdscr, TRUE );
|
||||
break;
|
||||
case L'P':
|
||||
keypad( stdscr, FALSE );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void quit( int sig )
|
||||
{
|
||||
erase(); /* Terminate by erasing the screen */
|
||||
refresh();
|
||||
endwin(); /* Always end with endwin() */
|
||||
delwin(curscr); /* Return storage */
|
||||
delwin(stdscr);
|
||||
putchar('\n');
|
||||
exit( sig );
|
||||
}
|
||||
|
||||
+527
@@ -0,0 +1,527 @@
|
||||
/*
|
||||
* view.c -- a silly little viewer program
|
||||
*
|
||||
* written by Eric S. Raymond <esr@snark.thyrsus.com> December 1994
|
||||
* to test the scrolling code in ncurses.
|
||||
*
|
||||
* modified by Thomas Dickey <dickey@clark.net> July 1995 to demonstrate
|
||||
* the use of 'resizeterm()', and May 2000 to illustrate wide-character
|
||||
* handling.
|
||||
*
|
||||
* Takes a filename argument. It's a simple file-viewer with various
|
||||
* scroll-up and scroll-down commands.
|
||||
*
|
||||
* n -- scroll one line forward
|
||||
* p -- scroll one line back
|
||||
*
|
||||
* Either command accepts a numeric prefix interpreted as a repeat count.
|
||||
* Thus, typing `5n' should scroll forward 5 lines in the file.
|
||||
*
|
||||
* The way you can tell this is working OK is that, in the trace file,
|
||||
* there should be one scroll operation plus a small number of line
|
||||
* updates, as opposed to a whole-page update. This means the physical
|
||||
* scroll operation worked, and the refresh() code only had to do a
|
||||
* partial repaint.
|
||||
*
|
||||
* $Id: view.c,v 1.2 2007/05/28 15:01:58 blymn Exp $
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <signal.h>
|
||||
#ifdef NCURSES
|
||||
#define _XOPEN_SOURCE_EXTENDED
|
||||
#include <ncurses.h>
|
||||
#include <term.h>
|
||||
#else
|
||||
#include <curses.h>
|
||||
#endif /* NCURSES */
|
||||
#include <locale.h>
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <termios.h>
|
||||
#include <util.h>
|
||||
#include <unistd.h>
|
||||
#ifdef HAVE_WCHAR
|
||||
#include <wchar.h>
|
||||
#endif /* HAVE_WCHAR */
|
||||
#ifdef DEBUG
|
||||
#include <syslog.h>
|
||||
#endif /* DEBUG */
|
||||
|
||||
#define UChar(c) ((unsigned char)(c))
|
||||
#define SIZEOF(table) (sizeof(table)/sizeof(table[0]))
|
||||
#define typeMalloc(type,n) (type *) malloc((n) * sizeof(type))
|
||||
|
||||
#define my_pair 1
|
||||
|
||||
#undef CURSES_CH_T
|
||||
#ifdef HAVE_WCHAR
|
||||
#define CURSES_CH_T cchar_t
|
||||
#else
|
||||
#define CURSES_CH_T chtype
|
||||
#endif /* HAVE_WCHAR */
|
||||
|
||||
static void finish(int sig);
|
||||
static void show_all(const char *tag);
|
||||
|
||||
static int shift = 0;
|
||||
static bool try_color = FALSE;
|
||||
|
||||
static char *fname;
|
||||
static CURSES_CH_T **my_lines;
|
||||
static CURSES_CH_T **lptr;
|
||||
static unsigned num_lines;
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
static const char *msg[] = {
|
||||
"Usage: view [options] file"
|
||||
,""
|
||||
,"Options:"
|
||||
," -c use color if terminal supports it"
|
||||
," -i ignore INT, QUIT, TERM signals"
|
||||
," -n NUM specify maximum number of lines (default 1000)"
|
||||
#if defined(KEY_RESIZE)
|
||||
," -r use old-style sigwinch handler rather than KEY_RESIZE"
|
||||
#endif
|
||||
#ifdef TRACE
|
||||
," -t trace screen updates"
|
||||
," -T NUM specify trace mask"
|
||||
#endif
|
||||
};
|
||||
size_t n;
|
||||
for (n = 0; n < SIZEOF(msg); n++)
|
||||
fprintf(stderr, "%s\n", msg[n]);
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
static int ch_len(CURSES_CH_T * src)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
#ifdef HAVE_WCHAR
|
||||
while (getcchar(src++, NULL, NULL, NULL, NULL) > 0)
|
||||
result++;
|
||||
#else
|
||||
while (*src++)
|
||||
result++;
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate a string into an array of chtype's. If UTF-8 mode is
|
||||
* active, translate the string accordingly.
|
||||
*/
|
||||
static CURSES_CH_T * ch_dup(char *src)
|
||||
{
|
||||
unsigned len = strlen(src);
|
||||
CURSES_CH_T *dst = typeMalloc(CURSES_CH_T, len + 1);
|
||||
unsigned j, k;
|
||||
#ifdef HAVE_WCHAR
|
||||
wchar_t wstr[CCHARW_MAX + 1];
|
||||
wchar_t wch;
|
||||
int l = 0;
|
||||
mbstate_t state;
|
||||
size_t rc;
|
||||
int width;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WCHAR
|
||||
mbrtowc( NULL, NULL, 1, &state );
|
||||
#endif
|
||||
for (j = k = 0; j < len; j++) {
|
||||
#ifdef HAVE_WCHAR
|
||||
rc = mbrtowc(&wch, src + j, len - j, &state);
|
||||
#ifdef DEBUG
|
||||
syslog( LOG_INFO, "[ch_dup]mbrtowc() returns %d", rc );
|
||||
#endif /* DEBUG */
|
||||
if (rc == (size_t) -1 || rc == (size_t) -2)
|
||||
break;
|
||||
j += rc - 1;
|
||||
if ((width = wcwidth(wch)) < 0)
|
||||
break;
|
||||
if ((width > 0 && l > 0) || l == CCHARW_MAX) {
|
||||
wstr[l] = L'\0';
|
||||
l = 0;
|
||||
if (setcchar(dst + k, wstr, 0, 0, NULL) != OK)
|
||||
break;
|
||||
++k;
|
||||
}
|
||||
if (width == 0 && l == 0)
|
||||
wstr[l++] = L' ';
|
||||
wstr[l++] = wch;
|
||||
#ifdef DEBUG
|
||||
syslog( LOG_INFO, "[ch_dup]wch=%x", wch );
|
||||
#endif /* DEBUG */
|
||||
#else
|
||||
dst[k++] = src[j];
|
||||
#endif
|
||||
}
|
||||
#ifdef HAVE_WCHAR
|
||||
if (l > 0) {
|
||||
wstr[l] = L'\0';
|
||||
if (setcchar(dst + k, wstr, 0, 0, NULL) == OK)
|
||||
++k;
|
||||
}
|
||||
setcchar(dst + k, L"", 0, 0, NULL);
|
||||
#else
|
||||
dst[k] = 0;
|
||||
#endif
|
||||
return dst;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int MAXLINES = 1000;
|
||||
FILE *fp;
|
||||
char buf[BUFSIZ];
|
||||
int i;
|
||||
int my_delay = 0;
|
||||
CURSES_CH_T **olptr;
|
||||
int length = 0;
|
||||
int value = 0;
|
||||
bool done = FALSE;
|
||||
bool got_number = FALSE;
|
||||
const char *my_label = "Input";
|
||||
#ifdef HAVE_WCHAR
|
||||
cchar_t icc;
|
||||
#endif /* HAVE_WCHAR */
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
|
||||
(void) signal(SIGINT, finish); /* arrange interrupts to terminate */
|
||||
|
||||
while ((i = getopt(argc, argv, "cin:rtT:")) != EOF) {
|
||||
switch (i) {
|
||||
case 'c':
|
||||
try_color = TRUE;
|
||||
break;
|
||||
case 'i':
|
||||
signal(SIGINT, SIG_IGN);
|
||||
signal(SIGQUIT, SIG_IGN);
|
||||
signal(SIGTERM, SIG_IGN);
|
||||
break;
|
||||
case 'n':
|
||||
if ((MAXLINES = atoi(optarg)) < 1)
|
||||
usage();
|
||||
break;
|
||||
#ifdef TRACE
|
||||
case 'T':
|
||||
trace(atoi(optarg));
|
||||
break;
|
||||
case 't':
|
||||
trace(TRACE_CALLS);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
}
|
||||
if (optind + 1 != argc)
|
||||
usage();
|
||||
|
||||
if ((my_lines = typeMalloc(CURSES_CH_T *, MAXLINES + 2)) == 0)
|
||||
usage();
|
||||
|
||||
fname = argv[optind];
|
||||
if ((fp = fopen(fname, "r")) == 0) {
|
||||
perror(fname);
|
||||
exit( 1 );
|
||||
}
|
||||
|
||||
/* slurp the file */
|
||||
num_lines = 0;
|
||||
for (lptr = &my_lines[0]; (lptr - my_lines) < MAXLINES; lptr++) {
|
||||
char temp[BUFSIZ], *s, *d;
|
||||
int col;
|
||||
|
||||
if (fgets(buf, sizeof(buf), fp) == 0)
|
||||
break;
|
||||
|
||||
/* convert tabs so that shift will work properly */
|
||||
for (s = buf, d = temp, col = 0; (*d = *s) != '\0'; s++) {
|
||||
if (*d == '\n') {
|
||||
*d = '\0';
|
||||
break;
|
||||
} else if (*d == '\t') {
|
||||
col = (col | 7) + 1;
|
||||
while ((d - temp) != col)
|
||||
*d++ = ' ';
|
||||
} else
|
||||
#ifdef HAVE_WCHAR
|
||||
col++, d++;
|
||||
#else
|
||||
if (isprint(UChar(*d))) {
|
||||
col++;
|
||||
d++;
|
||||
} else {
|
||||
sprintf(d, "\\%03o", UChar(*s));
|
||||
d += strlen(d);
|
||||
col = (d - temp);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
*lptr = ch_dup(temp);
|
||||
num_lines++;
|
||||
}
|
||||
(void) fclose(fp);
|
||||
length = lptr - my_lines;
|
||||
|
||||
(void) initscr(); /* initialize the curses library */
|
||||
keypad(stdscr, TRUE); /* enable keyboard mapping */
|
||||
(void) nonl(); /* tell curses not to do NL->CR/NL on output */
|
||||
(void) cbreak(); /* take input chars one at a time, no wait for \n */
|
||||
(void) noecho(); /* don't echo input */
|
||||
nodelay(stdscr, TRUE);
|
||||
idlok(stdscr, TRUE); /* allow use of insert/delete line */
|
||||
|
||||
if (try_color) {
|
||||
if (has_colors()) {
|
||||
start_color();
|
||||
init_pair(my_pair, COLOR_WHITE, COLOR_BLUE);
|
||||
bkgd(COLOR_PAIR(my_pair));
|
||||
} else {
|
||||
try_color = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
lptr = my_lines;
|
||||
while (!done) {
|
||||
int n;
|
||||
#ifdef HAVE_WCHAR
|
||||
wint_t c = 0;
|
||||
int ret;
|
||||
#else
|
||||
int c = 0;
|
||||
#endif /* HAVE_WCHAR */
|
||||
|
||||
if (!got_number)
|
||||
show_all(my_label);
|
||||
|
||||
n = 0;
|
||||
for (;;) {
|
||||
c = 0;
|
||||
#ifdef HAVE_WCHAR
|
||||
ret = get_wch( &c );
|
||||
if ( ret == ERR ) {
|
||||
if (!my_delay)
|
||||
napms(50);
|
||||
continue;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
else if ( ret == KEY_CODE_YES )
|
||||
syslog( LOG_INFO, "[main]Func key(%x)", c );
|
||||
else
|
||||
syslog( LOG_INFO, "[main]c=%x", c );
|
||||
#endif /* DEBUG */
|
||||
#else
|
||||
c = getch();
|
||||
#ifdef DEBUG
|
||||
syslog( LOG_INFO, "[main]c='%c'", c );
|
||||
#endif /* DEBUG */
|
||||
#endif /* HAVE_WCHAR */
|
||||
if ((c < 127) && isdigit(c)) {
|
||||
if (!got_number) {
|
||||
mvprintw(0, 0, "Count: ");
|
||||
clrtoeol();
|
||||
}
|
||||
addch(c);
|
||||
value = 10 * value + (c - '0');
|
||||
got_number = TRUE;
|
||||
} else
|
||||
break;
|
||||
}
|
||||
if (got_number && value) {
|
||||
n = value;
|
||||
} else {
|
||||
n = 1;
|
||||
}
|
||||
|
||||
#ifdef HAVE_WCHAR
|
||||
if (ret != ERR)
|
||||
my_label = key_name( c );
|
||||
else
|
||||
if (!my_delay)
|
||||
napms(50);
|
||||
#else
|
||||
if (c != ERR)
|
||||
my_label = keyname(c);
|
||||
#endif /* HAVE_WCHAR */
|
||||
switch (c) {
|
||||
case KEY_DOWN:
|
||||
#ifdef HAVE_WCHAR
|
||||
case L'n':
|
||||
#else
|
||||
case 'n':
|
||||
#endif /* HAVE_WCHAR */
|
||||
olptr = lptr;
|
||||
for (i = 0; i < n; i++)
|
||||
if ((lptr - my_lines) < (length - LINES + 1))
|
||||
lptr++;
|
||||
else
|
||||
break;
|
||||
wscrl(stdscr, lptr - olptr);
|
||||
break;
|
||||
|
||||
case KEY_UP:
|
||||
#ifdef HAVE_WCHAR
|
||||
case L'p':
|
||||
#else
|
||||
case 'p':
|
||||
#endif /* HAVE_WCHAR */
|
||||
olptr = lptr;
|
||||
for (i = 0; i < n; i++)
|
||||
if (lptr > my_lines)
|
||||
lptr--;
|
||||
else
|
||||
break;
|
||||
wscrl(stdscr, lptr - olptr);
|
||||
break;
|
||||
|
||||
#ifdef HAVE_WCHAR
|
||||
case L'h':
|
||||
#else
|
||||
case 'h':
|
||||
#endif /* HAVE_WCHAR */
|
||||
case KEY_HOME:
|
||||
lptr = my_lines;
|
||||
break;
|
||||
|
||||
#ifdef HAVE_WCHAR
|
||||
case L'e':
|
||||
#else
|
||||
case 'e':
|
||||
#endif /* HAVE_WCHAR */
|
||||
case KEY_END:
|
||||
if (length > LINES)
|
||||
lptr = my_lines + length - LINES + 1;
|
||||
else
|
||||
lptr = my_lines;
|
||||
break;
|
||||
|
||||
#ifdef HAVE_WCHAR
|
||||
case L'r':
|
||||
#else
|
||||
case 'r':
|
||||
#endif /* HAVE_WCHAR */
|
||||
case KEY_RIGHT:
|
||||
shift += n;
|
||||
break;
|
||||
|
||||
#ifdef HAVE_WCHAR
|
||||
case L'l':
|
||||
#else
|
||||
case 'l':
|
||||
#endif /* HAVE_WCHAR */
|
||||
case KEY_LEFT:
|
||||
shift -= n;
|
||||
if (shift < 0) {
|
||||
shift = 0;
|
||||
beep();
|
||||
}
|
||||
break;
|
||||
|
||||
#ifdef HAVE_WCHAR
|
||||
case L'q':
|
||||
#else
|
||||
case 'q':
|
||||
#endif /* HAVE_WCHAR */
|
||||
done = TRUE;
|
||||
break;
|
||||
|
||||
#ifdef KEY_RESIZE
|
||||
case KEY_RESIZE:
|
||||
//refresh();
|
||||
break;
|
||||
#endif
|
||||
#ifdef HAVE_WCHAR
|
||||
case L's':
|
||||
#else
|
||||
case 's':
|
||||
#endif /* HAVE_WCHAR */
|
||||
if (got_number) {
|
||||
halfdelay(my_delay = n);
|
||||
} else {
|
||||
nodelay(stdscr, FALSE);
|
||||
my_delay = -1;
|
||||
}
|
||||
break;
|
||||
#ifdef HAVE_WCHAR
|
||||
case L' ':
|
||||
#else
|
||||
case ' ':
|
||||
#endif /* HAVE_WCHAR */
|
||||
nodelay(stdscr, TRUE);
|
||||
my_delay = 0;
|
||||
break;
|
||||
#ifndef HAVE_WCHAR
|
||||
case ERR:
|
||||
if (!my_delay)
|
||||
napms(50);
|
||||
break;
|
||||
#endif /* HAVE_WCHAR */
|
||||
default:
|
||||
beep();
|
||||
break;
|
||||
}
|
||||
if (c >= KEY_MIN || (c > 0 && !isdigit(c))) {
|
||||
got_number = FALSE;
|
||||
value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
finish(0); /* we're done */
|
||||
}
|
||||
|
||||
static void finish(int sig)
|
||||
{
|
||||
endwin();
|
||||
exit(sig != 0 ? 1 : 0 );
|
||||
}
|
||||
|
||||
static void show_all(const char *tag)
|
||||
{
|
||||
int i;
|
||||
char temp[BUFSIZ];
|
||||
CURSES_CH_T *s;
|
||||
time_t this_time;
|
||||
|
||||
sprintf(temp, "%s (%3dx%3d) col %d ", tag, LINES, COLS, shift);
|
||||
i = strlen(temp);
|
||||
sprintf(temp + i, "view %.*s", (int) (sizeof(temp) - 7 - i), fname);
|
||||
move(0, 0);
|
||||
printw("%.*s", COLS, temp);
|
||||
clrtoeol();
|
||||
this_time = time((time_t *) 0);
|
||||
strcpy(temp, ctime(&this_time));
|
||||
if ((i = strlen(temp)) != 0) {
|
||||
temp[--i] = 0;
|
||||
if (move(0, COLS - i - 2) != ERR)
|
||||
printw(" %s", temp);
|
||||
}
|
||||
|
||||
scrollok(stdscr, FALSE); /* prevent screen from moving */
|
||||
for (i = 1; i < LINES; i++) {
|
||||
move(i, 0);
|
||||
printw("%3ld:", (long) (lptr + i - my_lines));
|
||||
clrtoeol();
|
||||
if ((s = lptr[i - 1]) != 0) {
|
||||
if (i < num_lines) {
|
||||
int len = ch_len(s);
|
||||
if (len > shift) {
|
||||
#ifdef HAVE_WCHAR
|
||||
add_wchstr(s + shift);
|
||||
#else
|
||||
addchstr(s + shift);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
setscrreg(1, LINES - 1);
|
||||
scrollok(stdscr, TRUE);
|
||||
refresh();
|
||||
}
|
||||
+195
@@ -0,0 +1,195 @@
|
||||
# $NetBSD: Makefile,v 1.71 2014/07/05 22:31:32 dholland Exp $
|
||||
# @(#)Makefile 8.2 (Berkeley) 1/2/94
|
||||
|
||||
|
||||
WARNS= 2
|
||||
AWK ?= awk
|
||||
AR ?= ar
|
||||
CPPFLAGS+=-I. -I.. -I../libterminfo
|
||||
CFLAGS+=-Werror-implicit-function-declaration
|
||||
ifdef DEBUG_CURSES
|
||||
CPPFLAGS+=-g -DDEBUG
|
||||
endif
|
||||
ifdef SMALL
|
||||
CPPFLAGS+=-DSMALL
|
||||
endif
|
||||
LIB= curses
|
||||
SRCS= acs.c addbytes.c addch.c addchnstr.c addnstr.c attributes.c \
|
||||
background.c bell.c border.c box.c chgat.c clear.c clearok.c \
|
||||
clrtobot.c clrtoeol.c color.c copywin.c cr_put.c \
|
||||
ctrace.c cur_hash.c curs_set.c \
|
||||
curses.c delch.c deleteln.c delwin.c echochar.c erase.c fileio.c \
|
||||
flushok.c fullname.c getch.c getstr.c getyx.c id_subwins.c idlok.c \
|
||||
idcok.c inch.c inchstr.c initscr.c insch.c insdelln.c insertln.c \
|
||||
instr.c keypad.c keyname.c leaveok.c line.c meta.c move.c \
|
||||
mvwin.c newwin.c nodelay.c notimeout.c overlay.c overwrite.c pause.c \
|
||||
printw.c putchar.c refresh.c resize.c scanw.c screen.c scroll.c \
|
||||
scrollok.c setterm.c standout.c timeout.c toucholap.c touchwin.c \
|
||||
tstp.c tty.c unctrl.c underscore.c
|
||||
|
||||
MAN= curses.3 curses_addch.3 curses_addchstr.3 curses_addstr.3 \
|
||||
curses_attributes.3 curses_background.3 curses_border.3 \
|
||||
curses_chgat.3 curses_clear.3 curses_color.3 \
|
||||
curses_cursor.3 curses_default_colors.3 \
|
||||
curses_delch.3 curses_deleteln.3 curses_echochar.3 curses_fileio.3 \
|
||||
curses_inch.3 curses_input.3 curses_insertch.3 curses_insertln.3 \
|
||||
curses_insdelln.3 curses_keyname.3 curses_line.3 curses_pad.3 \
|
||||
curses_print.3 curses_refresh.3 curses_scanw.3 curses_screen.3 \
|
||||
curses_scroll.3 curses_standout.3 curses_termcap.3 curses_touch.3 \
|
||||
curses_tty.3 curses_underscore.3 curses_window.3
|
||||
INCS= curses.h unctrl.h
|
||||
INCSDIR=/usr/include
|
||||
|
||||
LIBDPLIBS+= terminfo ${.CURDIR}/../libterminfo
|
||||
|
||||
ifndef DISABLE_WCHAR
|
||||
CPPFLAGS+=-DHAVE_WCHAR
|
||||
SRCS+= cchar.c add_wch.c add_wchstr.c addwstr.c echo_wchar.c ins_wch.c \
|
||||
insstr.c ins_wstr.c get_wch.c get_wstr.c in_wch.c in_wchstr.c \
|
||||
inwstr.c
|
||||
else
|
||||
CPPFLAGS+=-DDISABLE_WCHAR
|
||||
endif
|
||||
|
||||
MLINKS+= curses_addch.3 addch.3 curses_addchstr.3 addchnstr.3 \
|
||||
curses_addchstr.3 addchstr.3 curses_addstr.3 addnstr.3 \
|
||||
curses_addstr.3 addstr.3 \
|
||||
curses_default_colors.3 assume_default_colors.3 \
|
||||
curses_attributes.3 attr_get.3 curses_attributes.3 attr_off.3 \
|
||||
curses_attributes.3 attr_on.3 curses_attributes.3 attr_set.3 \
|
||||
curses_attributes.3 attron.3 curses_attributes.3 attroff.3 \
|
||||
curses_attributes.3 attrset.3 curses_tty.3 beep.3 \
|
||||
curses_background.3 bkgd.3 curses_background.3 bkgdset.3 \
|
||||
curses_border.3 border.3 curses_border.3 box.3 \
|
||||
curses_chgat.3 chgat.3 curses_chgat.3 mvchgat.3 \
|
||||
curses_chgat.3 mvwchgat.3 curses_chgat.3 wchgat.3 \
|
||||
curses_color.3 can_change_color.3 curses_tty.3 cbreak.3 \
|
||||
curses_clear.3 clear.3 curses_clear.3 clearok.3 \
|
||||
curses_clear.3 clrtobot.3 curses_clear.3 clrtoeol.3 \
|
||||
curses_color.3 color_content.3 curses_attributes.3 color_set.3 \
|
||||
curses_window.3 copywin.3 curses_tty.3 curs_set.3 \
|
||||
curses_input.3 define_key.3 \
|
||||
curses_tty.3 delay_output.3 curses_tty.3 def_prog_mode.3 \
|
||||
curses_tty.3 def_shell_mode.3 curses_delch.3 delch.3 \
|
||||
curses_deleteln.3 deleteln.3 curses_screen.3 delscreen.3 \
|
||||
curses_window.3 delwin.3 curses_window.3 derwin.3 \
|
||||
curses_refresh.3 doupdate.3 curses_window.3 dupwin.3 \
|
||||
curses_tty.3 echo.3 curses_echochar.3 echochar.3 \
|
||||
curses_screen.3 endwin.3 curses_clear.3 erase.3 \
|
||||
curses_tty.3 erasechar.3 \
|
||||
curses_tty.3 flash.3 curses_tty.3 flushinp.3 \
|
||||
curses_refresh.3 flushok.3 \
|
||||
curses_termcap.3 fullname.3 curses_attributes.3 getattrs.3 \
|
||||
curses_background.3 getbkgd.3 \
|
||||
curses_input.3 getch.3 curses_cursor.3 getcury.3 \
|
||||
curses_cursor.3 getcurx.3 curses_cursor.3 getbegy.3 \
|
||||
curses_cursor.3 getbegx.3 curses_cursor.3 getmaxx.3 \
|
||||
curses_cursor.3 getmaxy.3 curses_cursor.3 getmaxyx.3 \
|
||||
curses_input.3 getnstr.3 \
|
||||
curses_cursor.3 getpary.3 curses_cursor.3 getparx.3 \
|
||||
curses_cursor.3 getparyx.3 curses_fileio.3 getwin.3 \
|
||||
curses_input.3 getstr.3 \
|
||||
curses_tty.3 gettmode.3 curses_cursor.3 getyx.3 \
|
||||
curses_color.3 has_colors.3 curses_tty.3 has_ic.3 \
|
||||
curses_tty.3 halfdelay.3 curses_tty.3 has_il.3 \
|
||||
curses_line.3 hline.3 curses_tty.3 idcok.3 \
|
||||
curses_tty.3 idlok.3 curses_inch.3 inch.3 \
|
||||
curses_inch.3 inchnstr.3 curses_inch.3 inchstr.3 \
|
||||
curses_inch.3 innstr.3 curses_color.3 init_color.3 \
|
||||
curses_color.3 init_pair.3 curses_screen.3 initscr.3 \
|
||||
curses_insertch.3 insch.3 curses_insdelln.3 insdelln.3 \
|
||||
curses_insertln.3 insertln.3 curses_inch.3 instr.3 \
|
||||
curses_tty.3 intrflush.3 curses_touch.3 is_linetouched.3 \
|
||||
curses_touch.3 is_wintouched.3 curses_screen.3 isendwin.3 \
|
||||
curses_keyname.3 keyname.3 \
|
||||
curses_input.3 keypad.3 curses_tty.3 killchar.3 \
|
||||
curses_refresh.3 leaveok.3 \
|
||||
curses_tty.3 meta.3 curses_cursor.3 move.3 \
|
||||
curses_addch.3 mvaddch.3 curses_addchstr.3 mvaddchnstr.3 \
|
||||
curses_addchstr.3 mvaddchstr.3 curses_addstr.3 mvaddnstr.3 \
|
||||
curses_addstr.3 mvaddstr.3 \
|
||||
curses_cursor.3 mvcur.3 curses_window.3 mvderwin.3 \
|
||||
curses_input.3 mvgetch.3 \
|
||||
curses_input.3 mvgetnstr.3 curses_input.3 mvgetstr.3 \
|
||||
curses_line.3 mvhline.3 curses_print.3 mvprintw.3 \
|
||||
curses_line.3 mvvline.3 curses_addch.3 mvwaddch.3 \
|
||||
curses_addchstr.3 mvwaddchnstr.3 curses_addchstr.3 mvwaddchstr.3 \
|
||||
curses_addstr.3 mvwaddnstr.3 curses_addstr.3 mvwaddstr.3 \
|
||||
curses_input.3 mvwgetch.3 \
|
||||
curses_input.3 mvwgetnstr.3 curses_input.3 mvwgetstr.3 \
|
||||
curses_line.3 mvwhline.3 curses_window.3 mvwin.3 \
|
||||
curses_inch.3 mvinchnstr.3 \
|
||||
curses_inch.3 mvinchstr.3 curses_inch.3 mvinnstr.3 \
|
||||
curses_inch.3 mvinstr.3 curses_inch.3 mvwinchnstr.3 \
|
||||
curses_inch.3 mvwinchstr.3 curses_inch.3 mvwinnstr.3 \
|
||||
curses_inch.3 mvwinstr.3 curses_print.3 mvwprintw.3 \
|
||||
curses_line.3 mvwvline.3 curses_tty.3 napms.3 \
|
||||
curses_pad.3 newpad.3 curses_screen.3 newterm.3 \
|
||||
curses_window.3 newwin.3 curses_tty.3 nl.3 \
|
||||
curses_tty.3 nocbreak.3 curses_input.3 nodelay.3 \
|
||||
curses_tty.3 noecho.3 curses_tty.3 nonl.3 \
|
||||
curses_tty.3 noqiflush.3 \
|
||||
curses_tty.3 noraw.3 curses_input.3 notimeout.3 \
|
||||
curses_window.3 overlay.3 curses_window.3 overwrite.3 \
|
||||
curses_color.3 pair_content.3 curses_echochar.3 pechochar.3 \
|
||||
curses_pad.3 pnoutrefresh.3 \
|
||||
curses_pad.3 prefresh.3 curses_print.3 printw.3 \
|
||||
curses_fileio.3 putwin.3 curses_tty.3 qiflush.3 \
|
||||
curses_tty.3 raw.3 curses_refresh.3 refresh.3 \
|
||||
curses_tty.3 reset_prog_mode.3 curses_tty.3 reset_shell_mode.3 \
|
||||
curses_tty.3 resetty.3 curses_screen.3 resizeterm.3 \
|
||||
curses_tty.3 savetty.3 curses_scanw.3 scanw.3 \
|
||||
curses_scroll.3 scrl.3 curses_scroll.3 scroll.3 \
|
||||
curses_scroll.3 scrollok.3 curses_scroll.3 setscrreg.3 \
|
||||
curses_screen.3 set_term.3 curses_screen.3 setterm.3 \
|
||||
curses_standout.3 standend.3 curses_standout.3 standout.3 \
|
||||
curses_color.3 start_color.3 curses_pad.3 subpad.3 \
|
||||
curses_window.3 subwin.3 curses_input.3 timeout.3 \
|
||||
curses_touch.3 touchline.3 curses_touch.3 touchoverlap.3 \
|
||||
curses_touch.3 touchwin.3 curses_print.3 unctrl.3 \
|
||||
curses_underscore.3 underend.3 curses_underscore.3 underscore.3 \
|
||||
curses_input.3 ungetch.3 curses_touch.3 untouchwin.3 \
|
||||
curses_default_colors.3 use_default_colors.3 curses_line.3 vline.3 \
|
||||
curses_addch.3 waddch.3 curses_addchstr.3 waddchnstr.3 \
|
||||
curses_addchstr.3 waddchstr.3 curses_addstr.3 waddnstr.3 \
|
||||
curses_addstr.3 waddstr.3 \
|
||||
curses_attributes.3 wattr_get.3 curses_attributes.3 wattr_off.3 \
|
||||
curses_attributes.3 wattr_on.3 curses_attributes.3 wattr_set.3 \
|
||||
curses_attributes.3 wattron.3 curses_attributes.3 wattroff.3 \
|
||||
curses_attributes.3 wattrset.3 curses_background.3 wbkgd.3 \
|
||||
curses_background.3 wbkgdset.3 curses_border.3 wborder.3 \
|
||||
curses_clear.3 wclear.3 curses_clear.3 wclrtobot.3 \
|
||||
curses_clear.3 wclrtoeol.3 curses_attributes.3 wcolor_set.3 \
|
||||
curses_delch.3 wdelch.3 curses_deleteln.3 wdeleteln.3 \
|
||||
curses_echochar.3 wechochar.3 \
|
||||
curses_clear.3 werase.3 curses_input.3 wgetch.3 \
|
||||
curses_input.3 wgetnstr.3 curses_input.3 wgetstr.3 \
|
||||
curses_line.3 whline.3 curses_inch.3 winch.3 \
|
||||
curses_inch.3 winchnstr.3 curses_inch.3 winchstr.3 \
|
||||
curses_inch.3 winnstr.3 curses_insertch.3 winsch.3 \
|
||||
curses_insdelln.3 winsdelln.3 curses_insertln.3 winsertln.3 \
|
||||
curses_inch.3 winstr.3 curses_cursor.3 wmove.3 \
|
||||
curses_refresh.3 wnoutrefresh.3 curses_print.3 wprintw.3 \
|
||||
curses_refresh.3 wrefresh.3 curses_window.3 wresize.3 \
|
||||
curses_scanw.3 wscanw.3 curses_scroll.3 wscrl.3 \
|
||||
curses_scroll.3 wsetscrreg.3 curses_standout.3 wstandend.3 \
|
||||
curses_standout.3 wstandout.3 curses_input.3 wtimeout.3 \
|
||||
curses_touch.3 wtouchln.3 curses_underscore.3 wunderend.3 \
|
||||
curses_underscore.3 wunderscore.3 curses_line.3 wvline.3
|
||||
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
|
||||
all: libcurses.a
|
||||
|
||||
clean:
|
||||
rm -f $(OBJS) libcurses.a
|
||||
|
||||
fileio.h: shlib_version genfileioh.awk
|
||||
$(AWK) -f ./genfileioh.awk < ./shlib_version > ./fileio.h
|
||||
|
||||
libcurses.a: $(OBJS)
|
||||
$(AR) cru $@ $^
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CPPFLAGS) $(CFLAGS) $(CFLAGS_MAIN) $(INC) $(PIC) -c -o $@ $<
|
||||
|
||||
+219
@@ -0,0 +1,219 @@
|
||||
# $NetBSD: Makefile,v 1.94 2020/03/23 13:37:36 roy Exp $
|
||||
# @(#)Makefile 8.2 (Berkeley) 1/2/94
|
||||
|
||||
.include <bsd.own.mk>
|
||||
|
||||
WARNS= 2
|
||||
|
||||
CPPFLAGS+=-I${.CURDIR} -I${NETBSDSRCDIR}/lib/libterminfo
|
||||
.if defined(DEBUG_CURSES)
|
||||
CPPFLAGS+=-g -DDEBUG
|
||||
.endif
|
||||
.if defined(SMALL)
|
||||
CPPFLAGS+=-DSMALL
|
||||
.endif
|
||||
LIB= curses
|
||||
SRCS= acs.c addbytes.c addch.c addchnstr.c addnstr.c attributes.c \
|
||||
background.c bell.c border.c box.c chgat.c clear.c clearok.c \
|
||||
clrtobot.c clrtoeol.c color.c copywin.c cr_put.c \
|
||||
ctrace.c cur_hash.c curs_set.c \
|
||||
curses.c delch.c deleteln.c delwin.c echochar.c erase.c fileio.c \
|
||||
flushok.c fullname.c getch.c getstr.c getyx.c id_subwins.c idlok.c \
|
||||
idcok.c immedok.c inch.c inchstr.c initscr.c insch.c insdelln.c \
|
||||
insertln.c insstr.c instr.c keypad.c keyname.c leaveok.c line.c \
|
||||
meta.c mouse.c move.c \
|
||||
mvwin.c newwin.c nodelay.c notimeout.c overlay.c overwrite.c pause.c \
|
||||
printw.c putchar.c refresh.c resize.c ripoffline.c scanw.c screen.c \
|
||||
scroll.c scrollok.c setterm.c slk.c standout.c syncok.c timeout.c \
|
||||
toucholap.c touchwin.c tstp.c tty.c unctrl.c underscore.c version.c
|
||||
|
||||
MAN= curses.3 curses_addch.3 curses_addchstr.3 curses_addstr.3 \
|
||||
curses_attributes.3 curses_background.3 curses_border.3 \
|
||||
curses_cchar.3 \
|
||||
curses_chgat.3 curses_clear.3 curses_color.3 \
|
||||
curses_cursor.3 curses_default_colors.3 \
|
||||
curses_delch.3 curses_deleteln.3 curses_echochar.3 curses_fileio.3 \
|
||||
curses_inch.3 curses_input.3 curses_insch.3 curses_insertln.3 \
|
||||
curses_insdelln.3 curses_keyname.3 curses_line.3 \
|
||||
curses_mouse.3 curses_pad.3 \
|
||||
curses_print.3 curses_refresh.3 curses_scanw.3 curses_screen.3 \
|
||||
curses_scroll.3 curses_slk.3 curses_standout.3 curses_termcap.3 \
|
||||
curses_touch.3 curses_tty.3 curses_underscore.3 curses_version.3 \
|
||||
curses_window.3
|
||||
INCS= curses.h unctrl.h
|
||||
INCSDIR=/usr/include
|
||||
|
||||
LIBDPLIBS+= terminfo ${.CURDIR}/../libterminfo
|
||||
|
||||
.if !defined(DISABLE_WCHAR)
|
||||
CPPFLAGS+=-DHAVE_WCHAR
|
||||
SRCS+= cchar.c add_wch.c add_wchstr.c addwstr.c echo_wchar.c ins_wch.c \
|
||||
ins_wstr.c get_wch.c get_wstr.c in_wch.c in_wchstr.c \
|
||||
inwstr.c
|
||||
.else
|
||||
CPPFLAGS+=-DDISABLE_WCHAR
|
||||
.endif
|
||||
|
||||
MLINKS+= curses_addch.3 addch.3 curses_addchstr.3 addchnstr.3 \
|
||||
curses_addchstr.3 addchstr.3 curses_addstr.3 addnstr.3 \
|
||||
curses_addstr.3 addstr.3 \
|
||||
curses_default_colors.3 assume_default_colors.3 \
|
||||
curses_attributes.3 attr_get.3 curses_attributes.3 attr_off.3 \
|
||||
curses_attributes.3 attr_on.3 curses_attributes.3 attr_set.3 \
|
||||
curses_attributes.3 attron.3 curses_attributes.3 attroff.3 \
|
||||
curses_attributes.3 attrset.3 curses_tty.3 beep.3 \
|
||||
curses_background.3 bkgd.3 curses_background.3 bkgdset.3 \
|
||||
curses_border.3 border.3 curses_border.3 box.3 \
|
||||
curses_cchar.3 getcchar.3 \
|
||||
curses_cchar.3 setcchar.3 \
|
||||
curses_chgat.3 chgat.3 curses_chgat.3 mvchgat.3 \
|
||||
curses_chgat.3 mvwchgat.3 curses_chgat.3 wchgat.3 \
|
||||
curses_color.3 can_change_color.3 curses_tty.3 cbreak.3 \
|
||||
curses_clear.3 clear.3 curses_clear.3 clearok.3 \
|
||||
curses_clear.3 clrtobot.3 curses_clear.3 clrtoeol.3 \
|
||||
curses_color.3 color_content.3 curses_attributes.3 color_set.3 \
|
||||
curses_window.3 copywin.3 curses_tty.3 curs_set.3 \
|
||||
curses_input.3 define_key.3 \
|
||||
curses_tty.3 delay_output.3 curses_tty.3 def_prog_mode.3 \
|
||||
curses_tty.3 def_shell_mode.3 curses_delch.3 delch.3 \
|
||||
curses_deleteln.3 deleteln.3 curses_screen.3 delscreen.3 \
|
||||
curses_window.3 delwin.3 curses_window.3 derwin.3 \
|
||||
curses_refresh.3 doupdate.3 curses_window.3 dupwin.3 \
|
||||
curses_tty.3 echo.3 curses_echochar.3 echochar.3 \
|
||||
curses_screen.3 endwin.3 curses_clear.3 erase.3 \
|
||||
curses_tty.3 erasechar.3 curses_screen.3 filter.3 \
|
||||
curses_tty.3 flash.3 curses_tty.3 flushinp.3 \
|
||||
curses_refresh.3 flushok.3 \
|
||||
curses_termcap.3 fullname.3 curses_attributes.3 getattrs.3 \
|
||||
curses_background.3 getbkgd.3 \
|
||||
curses_input.3 getch.3 curses_cursor.3 getcury.3 \
|
||||
curses_cursor.3 getcurx.3 curses_cursor.3 getbegy.3 \
|
||||
curses_cursor.3 getbegx.3 curses_cursor.3 getmaxx.3 \
|
||||
curses_cursor.3 getmaxy.3 curses_cursor.3 getmaxyx.3 \
|
||||
curses_input.3 getnstr.3 \
|
||||
curses_cursor.3 getpary.3 curses_cursor.3 getparx.3 \
|
||||
curses_cursor.3 getparyx.3 curses_fileio.3 getwin.3 \
|
||||
curses_input.3 getstr.3 \
|
||||
curses_tty.3 gettmode.3 \
|
||||
curses_cursor.3 getyx.3 curses_cursor.3 getsyx.3 \
|
||||
curses_color.3 has_colors.3 curses_tty.3 has_ic.3 \
|
||||
curses_tty.3 halfdelay.3 curses_input.3 has_key.3 \
|
||||
curses_tty.3 has_il.3 \
|
||||
curses_line.3 hline.3 curses_tty.3 idcok.3 \
|
||||
curses_tty.3 idlok.3 curses_refresh.3 immedok.3 curses_inch.3 inch.3 \
|
||||
curses_inch.3 inchnstr.3 curses_inch.3 inchstr.3 \
|
||||
curses_inch.3 innstr.3 curses_color.3 init_color.3 \
|
||||
curses_color.3 init_pair.3 curses_screen.3 initscr.3 \
|
||||
curses_insch.3 insch.3 curses_insdelln.3 insdelln.3 \
|
||||
curses_insertln.3 insertln.3 curses_inch.3 instr.3 \
|
||||
curses_tty.3 intrflush.3 \
|
||||
curses_input.3 is_keypad.3 \
|
||||
curses_refresh.3 is_leaveok.3 curses_touch.3 is_linetouched.3 \
|
||||
curses_pad.3 is_pad.3 curses_screen.3 is_term_resized.3 \
|
||||
curses_touch.3 is_wintouched.3 curses_screen.3 isendwin.3 \
|
||||
curses_keyname.3 keyname.3 \
|
||||
curses_input.3 keypad.3 curses_tty.3 killchar.3 \
|
||||
curses_refresh.3 leaveok.3 \
|
||||
curses_tty.3 meta.3 curses_cursor.3 move.3 \
|
||||
curses_addch.3 mvaddch.3 curses_addchstr.3 mvaddchnstr.3 \
|
||||
curses_addchstr.3 mvaddchstr.3 curses_addstr.3 mvaddnstr.3 \
|
||||
curses_addstr.3 mvaddstr.3 \
|
||||
curses_cursor.3 mvcur.3 curses_window.3 mvderwin.3 \
|
||||
curses_input.3 mvgetch.3 \
|
||||
curses_input.3 mvgetnstr.3 curses_input.3 mvgetstr.3 \
|
||||
curses_line.3 mvhline.3 curses_print.3 mvprintw.3 \
|
||||
curses_line.3 mvvline.3 curses_addch.3 mvwaddch.3 \
|
||||
curses_addchstr.3 mvwaddchnstr.3 curses_addchstr.3 mvwaddchstr.3 \
|
||||
curses_addstr.3 mvwaddnstr.3 curses_addstr.3 mvwaddstr.3 \
|
||||
curses_input.3 mvwgetch.3 \
|
||||
curses_input.3 mvwgetnstr.3 curses_input.3 mvwgetstr.3 \
|
||||
curses_line.3 mvwhline.3 curses_window.3 mvwin.3 \
|
||||
curses_inch.3 mvinchnstr.3 \
|
||||
curses_inch.3 mvinchstr.3 curses_inch.3 mvinnstr.3 \
|
||||
curses_insch.3 mvinsch.3 \
|
||||
curses_inch.3 mvinstr.3 curses_inch.3 mvwinchnstr.3 \
|
||||
curses_inch.3 mvwinchstr.3 curses_inch.3 mvwinnstr.3 \
|
||||
curses_insch.3 mvwinsch.3 \
|
||||
curses_inch.3 mvwinstr.3 curses_print.3 mvwprintw.3 \
|
||||
curses_line.3 mvwvline.3 curses_tty.3 napms.3 \
|
||||
curses_pad.3 newpad.3 curses_screen.3 newterm.3 \
|
||||
curses_window.3 newwin.3 curses_tty.3 nl.3 \
|
||||
curses_tty.3 nocbreak.3 curses_input.3 nodelay.3 \
|
||||
curses_tty.3 noecho.3 curses_tty.3 nonl.3 \
|
||||
curses_tty.3 noqiflush.3 \
|
||||
curses_tty.3 noraw.3 curses_input.3 notimeout.3 \
|
||||
curses_window.3 overlay.3 curses_window.3 overwrite.3 \
|
||||
curses_color.3 pair_content.3 curses_echochar.3 pechochar.3 \
|
||||
curses_pad.3 pnoutrefresh.3 \
|
||||
curses_pad.3 prefresh.3 curses_print.3 printw.3 \
|
||||
curses_fileio.3 putwin.3 curses_tty.3 qiflush.3 \
|
||||
curses_tty.3 raw.3 curses_refresh.3 refresh.3 \
|
||||
curses_tty.3 reset_prog_mode.3 curses_tty.3 reset_shell_mode.3 \
|
||||
curses_tty.3 resetty.3 \
|
||||
curses_screen.3 resizeterm.3 curses_screen.3 resize_term.3 \
|
||||
curses_screen.3 ripoffline.3 \
|
||||
curses_tty.3 savetty.3 curses_scanw.3 scanw.3 \
|
||||
curses_scroll.3 scrl.3 curses_scroll.3 scroll.3 \
|
||||
curses_scroll.3 scrollok.3 curses_scroll.3 setscrreg.3 \
|
||||
curses_cursor.3 setsyx.3 \
|
||||
curses_input.3 set_escdelay.3 curses_screen.3 set_tabsize.3 \
|
||||
curses_screen.3 set_term.3 curses_screen.3 setterm.3 \
|
||||
curses_slk.3 slk_attroff.3 curses_slk.3 slk_attr_off.3 \
|
||||
curses_slk.3 slk_attron.3 curses_slk.3 slk_attr_on.3 \
|
||||
curses_slk.3 slk_attrset.3 curses_slk.3 slk_attr_set.3 \
|
||||
curses_slk.3 slk_clear.3 curses_slk.3 slk_color.3 \
|
||||
curses_slk.3 slk_init.3 curses_slk.3 slk_label.3 \
|
||||
curses_slk.3 slk_noutrefresh.3 curses_slk.3 slk_refresh.3 \
|
||||
curses_slk.3 slk_restore.3 curses_slk.3 slk_set.3 \
|
||||
curses_slk.3 slk_touch.3 curses_slk.3 slk_wset.3 \
|
||||
curses_standout.3 standend.3 curses_standout.3 standout.3 \
|
||||
curses_color.3 start_color.3 curses_pad.3 subpad.3 \
|
||||
curses_window.3 subwin.3 curses_touch.3 syncok.3 \
|
||||
curses_input.3 timeout.3 \
|
||||
curses_touch.3 touchline.3 curses_touch.3 touchoverlap.3 \
|
||||
curses_touch.3 touchwin.3 curses_tty.3 typeahead.3 \
|
||||
curses_print.3 unctrl.3 \
|
||||
curses_underscore.3 underend.3 curses_underscore.3 underscore.3 \
|
||||
curses_input.3 ungetch.3 curses_touch.3 untouchwin.3 \
|
||||
curses_default_colors.3 use_default_colors.3 \
|
||||
curses_screen.3 use_env.3 curses_line.3 vline.3 \
|
||||
curses_addch.3 waddch.3 curses_addchstr.3 waddchnstr.3 \
|
||||
curses_addchstr.3 waddchstr.3 curses_addstr.3 waddnstr.3 \
|
||||
curses_addstr.3 waddstr.3 \
|
||||
curses_attributes.3 wattr_get.3 curses_attributes.3 wattr_off.3 \
|
||||
curses_attributes.3 wattr_on.3 curses_attributes.3 wattr_set.3 \
|
||||
curses_attributes.3 wattron.3 curses_attributes.3 wattroff.3 \
|
||||
curses_attributes.3 wattrset.3 curses_background.3 wbkgd.3 \
|
||||
curses_background.3 wbkgdset.3 curses_border.3 wborder.3 \
|
||||
curses_clear.3 wclear.3 curses_clear.3 wclrtobot.3 \
|
||||
curses_clear.3 wclrtoeol.3 curses_attributes.3 wcolor_set.3 \
|
||||
curses_cursor.3 wcursyncup.3 \
|
||||
curses_delch.3 wdelch.3 curses_deleteln.3 wdeleteln.3 \
|
||||
curses_echochar.3 wechochar.3 \
|
||||
curses_clear.3 werase.3 curses_input.3 wgetch.3 \
|
||||
curses_input.3 wgetnstr.3 curses_input.3 wgetstr.3 \
|
||||
curses_line.3 whline.3 curses_inch.3 winch.3 \
|
||||
curses_inch.3 winchnstr.3 curses_inch.3 winchstr.3 \
|
||||
curses_inch.3 winnstr.3 curses_insch.3 winsch.3 \
|
||||
curses_insdelln.3 winsdelln.3 curses_insertln.3 winsertln.3 \
|
||||
curses_inch.3 winstr.3 curses_cursor.3 wmove.3 \
|
||||
curses_refresh.3 wnoutrefresh.3 curses_print.3 wprintw.3 \
|
||||
curses_refresh.3 wrefresh.3 curses_window.3 wresize.3 \
|
||||
curses_scanw.3 wscanw.3 curses_scroll.3 wscrl.3 \
|
||||
curses_scroll.3 wsetscrreg.3 curses_standout.3 wstandend.3 \
|
||||
curses_standout.3 wstandout.3 curses_touch.3 wsyncup.3 \
|
||||
curses_input.3 wtimeout.3 \
|
||||
curses_touch.3 wtouchln.3 curses_underscore.3 wunderend.3 \
|
||||
curses_underscore.3 wunderscore.3 curses_line.3 wvline.3 \
|
||||
curses_mouse.3 has_mouse.3 \
|
||||
curses_mouse.3 getmouse.3 curses_mouse.3 ungetmouse.3 \
|
||||
curses_mouse.3 mouse_trafo.3 curses_mouse.3 wmouse_trafo.3 \
|
||||
curses_mouse.3 wenclose.3 curses_mouse.3 mouseinterval.3
|
||||
|
||||
SUBDIR.roff+= PSD.doc
|
||||
|
||||
fileio.h: shlib_version genfileioh.awk
|
||||
${TOOL_AWK} -f ${.CURDIR}/genfileioh.awk < ${.CURDIR}/shlib_version > ${.CURDIR}/fileio.h
|
||||
|
||||
.include <bsd.lib.mk>
|
||||
.include <bsd.subdir.mk>
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
# $NetBSD: Makefile,v 1.14 2014/07/15 13:27:58 christos Exp $
|
||||
# from: @(#)Makefile 8.2 (Berkeley) 5/23/94
|
||||
|
||||
SECTION=reference/ref3
|
||||
ARTICLE=curses
|
||||
SRCS= Master
|
||||
CEXAMPLES= ex1.gr ex2.gr life.gr twinkle1.gr twinkle2.gr win_st.gr
|
||||
DEPSRCS=appen.A appen.B appen.C doc.I doc.II doc.III doc.IV fns.doc \
|
||||
intro.0 intro.1 intro.2.tbl intro.3 intro.4 intro.5 intro.6 \
|
||||
macros c_macros $(CEXAMPLES)
|
||||
MACROS= -me
|
||||
CLEANFILES+= ${CEXAMPLES} intro.2.tbl
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: .c .gr
|
||||
|
||||
#
|
||||
# this section formats C input source into nice troffable (or nroffable)
|
||||
# versions. It uses the capabilites of "vgrind", which sets keywords in
|
||||
# bold font, and comments in italics.
|
||||
#
|
||||
|
||||
# Don't re-run vgrind unless you want to patch the output files.
|
||||
|
||||
.c.gr:
|
||||
${TOOL_VFONTEDPR} ${.IMPSRC} | grep -v "^'wh" > ${.TARGET}
|
||||
|
||||
# Unfortunately our make doesn't handle single-suffix rules.
|
||||
intro.2.tbl: intro.2
|
||||
${TOOL_TBL} ${.ALLSRC} > ${.TARGET}
|
||||
|
||||
.include <bsd.doc.mk>
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
.\" $NetBSD: Master,v 1.5 2003/08/07 16:44:26 agc Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)Master 8.2 (Berkeley) 5/24/94
|
||||
.\"
|
||||
.ds Ln Screen Package
|
||||
.so macros
|
||||
.so c_macros
|
||||
.so intro.0
|
||||
.pn 3
|
||||
.bp
|
||||
.so intro.1
|
||||
.so intro.2.tbl
|
||||
.so intro.3
|
||||
.so intro.4
|
||||
.so intro.5
|
||||
.so intro.6
|
||||
.bp
|
||||
.so appen.A
|
||||
.pn 2
|
||||
.oh '\*(Ln''PSD:19-%'
|
||||
.eh 'PSD:19-%''\*(Ln'
|
||||
.bp
|
||||
.bi Contents
|
||||
.sp
|
||||
.xp
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
.\" $NetBSD: appen.A,v 1.7 2003/08/07 16:44:26 agc Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)appen.A 8.1 (Berkeley) 6/8/93
|
||||
.\"
|
||||
.ie t .oh '\*(Ln Appendix A''PS1:19-%'
|
||||
.eh 'PS1:19-%''\*(Ln Appendix A'
|
||||
.el .he ''\fIAppendix A\fR''
|
||||
.bp
|
||||
.(x
|
||||
.ti 0
|
||||
.b "Appendix A"
|
||||
.)x
|
||||
.sh 1 "Examples" 1
|
||||
.pp
|
||||
Here we present a few examples
|
||||
of how to use the package.
|
||||
They attempt to be representative,
|
||||
though not comprehensive.
|
||||
Further examples can be found in the games section
|
||||
of the source tree and in various utilities that use the screen such as
|
||||
.i systat(1) .
|
||||
.pp
|
||||
The following examples are intended to demonstrate
|
||||
the basic structure of a program
|
||||
using the package.
|
||||
An additional, more comprehensive, program can be found in
|
||||
the source code in the
|
||||
\fIexamples\fP subdirectory.
|
||||
.sh 2 "Simple Character Output"
|
||||
.pp
|
||||
This program demonstrates how to set up a window and output characters to it.
|
||||
Also, it demonstrates how one might control the output to the window.
|
||||
If you run this program, you will get a demonstration of the character output
|
||||
chracteristics discussed in the above Character Output section.
|
||||
.(l I
|
||||
.so ex1.gr
|
||||
.)l
|
||||
.sh 2 "Twinkle"
|
||||
.pp
|
||||
This is a moderately simple program which prints
|
||||
patterns on the screen.
|
||||
It switches between patterns of asterisks,
|
||||
putting them on one by one in random order,
|
||||
and then taking them off in the same fashion.
|
||||
It is more efficient to write this
|
||||
using only the motion optimization,
|
||||
as is demonstrated below.
|
||||
.(l I
|
||||
.so twinkle1.gr
|
||||
.)l
|
||||
+199
@@ -0,0 +1,199 @@
|
||||
.\" $NetBSD: appen.B,v 1.5 2003/08/07 16:44:26 agc Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)appen.B 8.1 (Berkeley) 6/8/93
|
||||
.\"
|
||||
.ie t .oh '\*(Ln Appendix B''PS1:19-%'
|
||||
.eh 'PS1:19-%''\*(Ln Appendix B'
|
||||
.el .he ''\fIAppendix B\fR''
|
||||
.bp
|
||||
.(x
|
||||
.ti 0
|
||||
.b "Appendix B"
|
||||
.)x
|
||||
.nr $1 0
|
||||
.sh 1 "The WINDOW structure"
|
||||
.pp
|
||||
The WINDOW structure is defined as follows:
|
||||
.(l I
|
||||
.so win_st.gr
|
||||
.)l
|
||||
.pp
|
||||
.Vn \*_cury \\*
|
||||
.(f
|
||||
\**
|
||||
All variables not normally accessed directly by the user
|
||||
are named with an initial
|
||||
.Bq \*_
|
||||
to avoid conflicts with the user's variables.
|
||||
.)f
|
||||
and
|
||||
.Vn \*_curx
|
||||
are the current \*y for the window.
|
||||
New characters added to the screen
|
||||
are added at this point.
|
||||
.Vn \*_maxy
|
||||
and
|
||||
.Vn \*_maxx
|
||||
are the maximum values allowed for
|
||||
.Vn \*_cury\*,\*_curx ). (
|
||||
.Vn \*_begy
|
||||
and
|
||||
.Vn \*_begx
|
||||
are the starting \*y on the terminal for the window,
|
||||
.i i.e. ,
|
||||
the window's home.
|
||||
.Vn \*_cury ,
|
||||
.Vn \*_curx ,
|
||||
.Vn \*_maxy ,
|
||||
and
|
||||
.Vn \*_maxx
|
||||
are measured relative to
|
||||
.Vn \*_begy\*,\*_begx ), (
|
||||
not the terminal's home.
|
||||
.pp
|
||||
.Vn \*_clear
|
||||
tells if a clear-screen sequence is to be generated
|
||||
on the next
|
||||
.Fn refresh
|
||||
call.
|
||||
This is only meaningful for screens.
|
||||
The initial clear-screen for the first
|
||||
.Fn refresh
|
||||
call is generated by initially setting clear to be TRUE for
|
||||
.Vn curscr ,
|
||||
which always generates a clear-screen if set,
|
||||
irrelevant of the dimensions of the window involved.
|
||||
.Vn \*_leave
|
||||
is TRUE if the current \*y and the cursor
|
||||
are to be left after the last character changed on the terminal,
|
||||
or not moved if there is no change.
|
||||
.Vn \*_scroll
|
||||
is TRUE
|
||||
if scrolling is allowed.
|
||||
.pp
|
||||
.Vn \*_y
|
||||
is a pointer to an array of lines which describe the terminal.
|
||||
Thus:
|
||||
.(l
|
||||
\*_y[i]
|
||||
.)l
|
||||
.lp
|
||||
is a pointer to the
|
||||
.Vn i th
|
||||
line, and
|
||||
.(l
|
||||
\*_y[i][j]
|
||||
.)l
|
||||
.lp
|
||||
is the
|
||||
.Vn j th
|
||||
character on the
|
||||
.Vn i th
|
||||
line.
|
||||
.Vn \*_flags
|
||||
can have one or more values
|
||||
or'd into it.
|
||||
.pp
|
||||
For windows that are not subwindows,
|
||||
.Vn \*_orig
|
||||
is
|
||||
NULL .
|
||||
For subwindows,
|
||||
it points to the main window
|
||||
to which the window is subsidiary.
|
||||
.Vn \*_nextp
|
||||
is a pointer in a circularly linked list
|
||||
of all the windows which are subwindows of the same main window,
|
||||
plus the main window itself.
|
||||
.pp
|
||||
.Vn \*_firstch
|
||||
and
|
||||
.Vn \*_lastch
|
||||
are
|
||||
.Fn malloc ed
|
||||
arrays which contain the index of the
|
||||
first and last changed characters
|
||||
on the line.
|
||||
.Vn \*_ch\*_off
|
||||
is the x offset for the window
|
||||
in the
|
||||
.Vn \*_firstch
|
||||
and
|
||||
.Vn \*_lastch
|
||||
arrays for this window.
|
||||
For main windows,
|
||||
this is always 0;
|
||||
for subwindows
|
||||
it is the difference between the starting point of the main window
|
||||
and that of the subindow,
|
||||
so that change markers can be set relative to the main window.
|
||||
This makes these markers global in scope.
|
||||
.pp
|
||||
All subwindows share the appropriate portions of
|
||||
.Vn _y ,
|
||||
.Vn _firstch ,
|
||||
.Vn _lastch ,
|
||||
and
|
||||
.Vn _insdel
|
||||
with their main window.
|
||||
.pp
|
||||
.b \*_ENDLINE
|
||||
says that the end of the line for this window
|
||||
is also the end of a screen.
|
||||
.b \*_FULLWIN
|
||||
says that this window is a screen.
|
||||
.b \*_SCROLLWIN
|
||||
indicates that the last character of this screen
|
||||
is at the lower right-hand corner of the terminal;
|
||||
.i i.e. ,
|
||||
if a character was put there,
|
||||
the terminal would scroll.
|
||||
.b \*_FULLLINE
|
||||
says that the width of a line is the same as the width of the terminal.
|
||||
If
|
||||
.b \*_FLUSH
|
||||
is set,
|
||||
it says that
|
||||
.Fn fflush "" "" stdout
|
||||
should be called at the end of each
|
||||
.Fn refresh
|
||||
.b \*_STANDOUT
|
||||
says that all characters added to the screen
|
||||
are in standout mode.
|
||||
.b \*_INSDEL
|
||||
is reserved for future use,
|
||||
and is set by
|
||||
.Fn idlok .
|
||||
.Vn \*_firstch
|
||||
is set to
|
||||
.b \*_NOCHANGE
|
||||
for lines on which there has been no change
|
||||
since the last
|
||||
.Fn refresh .
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
.\" $NetBSD: appen.C,v 1.7 2003/08/07 16:44:26 agc Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)appen.C 8.1 (Berkeley) 6/8/93
|
||||
.\"
|
||||
.ie t .oh '\*(Ln Appendix A''PS1:19-%'
|
||||
.eh 'PS1:19-%''\*(Ln Appendix A'
|
||||
.el .he ''\fIAppendix A\fR''
|
||||
.bp
|
||||
.(x
|
||||
.ti 0
|
||||
.b "Appendix A"
|
||||
.)x
|
||||
.sh 1 "Examples" 1
|
||||
.pp
|
||||
Here we present a few examples
|
||||
of how to use the package.
|
||||
They attempt to be representative,
|
||||
though not comprehensive.
|
||||
Further examples can be found in the games section
|
||||
of the source tree and in various utilities that use the screen such as
|
||||
.i systat(1) .
|
||||
.sh 2 "Screen Updating"
|
||||
.pp
|
||||
The following examples are intended to demonstrate
|
||||
the basic structure of a program
|
||||
using the screen updating sections of the package.
|
||||
Several of the programs require calculational sections
|
||||
which are irrelevant of to the example,
|
||||
and are therefore usually not included.
|
||||
It is hoped that the data structure definitions
|
||||
give enough of an idea to allow understanding
|
||||
of what the relevant portions do.
|
||||
.sh 3 "Simple Character Output"
|
||||
.pp
|
||||
This program demonstrates how to set up a window and output characters to it.
|
||||
Also, it demonstrates how one might control the output to the window.
|
||||
If you run this program, you will get a demonstration of the character output
|
||||
chracteristics discussed in the above Character Output section.
|
||||
.(l I
|
||||
.so t2.gr
|
||||
.)l
|
||||
.sh 3 "A Small Screen Manipulator"
|
||||
.pp
|
||||
The next example follows the lines of the previous one but extends then to
|
||||
demonstrate the various othe uses of the package.
|
||||
Make sure you understand how this program works as it encompasses most of
|
||||
anything you will need to do with the package.
|
||||
.(l I
|
||||
.so t3.gr
|
||||
.)l
|
||||
.sh 3 "Twinkle"
|
||||
.pp
|
||||
This is a moderately simple program which prints
|
||||
patterns on the screen.
|
||||
It switches between patterns of asterisks,
|
||||
putting them on one by one in random order,
|
||||
and then taking them off in the same fashion.
|
||||
It is more efficient to write this
|
||||
using only the motion optimization,
|
||||
as is demonstrated below.
|
||||
.(l I
|
||||
.so twinkle1.gr
|
||||
.)l
|
||||
.sh 3 "Life"
|
||||
.pp
|
||||
This program fragment models the famous computer pattern game of life
|
||||
(Scientific American, May, 1974).
|
||||
The calculational routines create a linked list of structures
|
||||
defining where each piece is.
|
||||
Nothing here claims to be optimal,
|
||||
merely demonstrative.
|
||||
This code, however,
|
||||
is a very good place to use the screen updating routines,
|
||||
as it allows them to worry about what the last position looked like,
|
||||
so you don't have to.
|
||||
It also demonstrates some of the input routines.
|
||||
.(l I
|
||||
.so life.gr
|
||||
.)l
|
||||
.sh 2 "Motion optimization"
|
||||
.pp
|
||||
The following example shows how motion optimization
|
||||
is written on its own.
|
||||
Programs which flit from one place to another without
|
||||
regard for what is already there
|
||||
usually do not need the overhead of both space and time
|
||||
associated with screen updating.
|
||||
They should instead use motion optimization.
|
||||
.sh 3 "Twinkle"
|
||||
.pp
|
||||
The
|
||||
.b twinkle
|
||||
program
|
||||
is a good candidate for simple motion optimization.
|
||||
Here is how it could be written
|
||||
(only the routines that have been changed are shown):
|
||||
.(l
|
||||
.so twinkle2.gr
|
||||
.)l
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
.\" $NetBSD: c_macros,v 1.5 2003/08/07 16:44:26 agc Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)c_macros 8.1 (Berkeley) 6/4/93
|
||||
.\"
|
||||
'ie t 'ds _ \d\(mi\u
|
||||
'el 'ds _ _
|
||||
'tr *\(**
|
||||
'ps 9p
|
||||
'vs 10p
|
||||
'ds - \(mi
|
||||
'ds /* \\h'\\w' 'u-\\w'/'u'/*
|
||||
'bd B 3
|
||||
'bd S B 3
|
||||
'nr cm 0
|
||||
'nf
|
||||
'de ()
|
||||
'pn 1
|
||||
..
|
||||
'de +C
|
||||
'nr cm 1
|
||||
'ft 2
|
||||
'ds +K
|
||||
'ds -K
|
||||
..
|
||||
'de -C
|
||||
'nr cm 0
|
||||
'ft 1
|
||||
.ie t 'ds +K \f3
|
||||
.el 'ds +K \fI
|
||||
'ds -K \fP
|
||||
..
|
||||
'+C
|
||||
'-C
|
||||
'am +C
|
||||
'ne 3
|
||||
..
|
||||
'de -F
|
||||
'rm =f
|
||||
..
|
||||
'ft 1
|
||||
'lg 0
|
||||
+347
@@ -0,0 +1,347 @@
|
||||
.\" $NetBSD: doc.I,v 1.5 2003/08/07 16:44:27 agc Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)doc.I 8.1 (Berkeley) 6/4/93
|
||||
.\"
|
||||
.Ds
|
||||
.Fd addch ch \*m
|
||||
char ch;
|
||||
.Fd waddch win\*,ch
|
||||
WINDOW *win;
|
||||
char ch;
|
||||
.De
|
||||
Add the character
|
||||
.Vn ch
|
||||
on the window
|
||||
at the current \*y.
|
||||
If the character is a newline
|
||||
(\'\en\')
|
||||
the line will be cleared to the end,
|
||||
and the current \*y will be changed to the
|
||||
beginning off the next line
|
||||
if newline mapping is on,
|
||||
or to the next line at the same x co-ordinate
|
||||
if it is off.
|
||||
A return
|
||||
(\'\er\')
|
||||
will move to the beginning of the line on the window.
|
||||
Tabs
|
||||
(\'\et\')
|
||||
will be expanded into spaces
|
||||
in the normal tabstop positions of
|
||||
every eight characters.
|
||||
\*(Es
|
||||
.Ds
|
||||
.Fd addstr str \*m
|
||||
char *str;
|
||||
.Fd waddstr win\*,str
|
||||
WINDOW *win;
|
||||
char *str;
|
||||
.De
|
||||
Add the string pointed to by
|
||||
.Vn str
|
||||
on the window at the current \*y.
|
||||
\*(Es
|
||||
In this case, it will put on as much as it can.
|
||||
.Ds
|
||||
.Fd box win\*,vert\*,hor
|
||||
WINDOW *win;
|
||||
char vert\*,hor;
|
||||
.De
|
||||
.Pp
|
||||
Draws a box around the window using
|
||||
.Vn vert
|
||||
as the character for drawing the vertical sides, and
|
||||
.Vn hor
|
||||
for drawing the horizontal lines.
|
||||
If scrolling is not allowed,
|
||||
and the window encompasses the lower right-hand corner of the terminal,
|
||||
the corners are left blank to avoid a scroll.
|
||||
.Ds
|
||||
.Fd clear "" \*m
|
||||
.Fd wclear win
|
||||
WINDOW *win;
|
||||
.De
|
||||
Resets the entire window to blanks.
|
||||
If
|
||||
.Vn win
|
||||
is a screen,
|
||||
this sets the clear flag,
|
||||
which will cause a clear-screen sequence to be sent
|
||||
on the next
|
||||
.Fn refresh
|
||||
call.
|
||||
This also moves the current \*y
|
||||
to (0\*,0).
|
||||
.Ds
|
||||
.Fd clearok scr\*,boolf \*m
|
||||
WINDOW *scr;
|
||||
bool boolf;
|
||||
.De
|
||||
Sets the clear flag for the screen
|
||||
.Vn scr .
|
||||
If
|
||||
.Vn boolf
|
||||
is TRUE,
|
||||
this will force a clear-screen to be printed on the next
|
||||
.Fn refresh ,
|
||||
or stop it from doing so if
|
||||
.Vn boolf
|
||||
is FALSE.
|
||||
This only works on screens,
|
||||
and,
|
||||
unlike
|
||||
.Fn clear ,
|
||||
does not alter the contents of the screen.
|
||||
If
|
||||
.Vn scr
|
||||
is
|
||||
.Vn curscr ,
|
||||
the next
|
||||
.Fn refresh
|
||||
call will cause a clear-screen,
|
||||
even if the window passed to
|
||||
.Fn refresh
|
||||
is not a screen.
|
||||
.Ds
|
||||
.Fd clrtobot "" \*m
|
||||
.Fd wclrtobot win
|
||||
WINDOW *win;
|
||||
.De
|
||||
Wipes the window clear from the current \*y to the bottom.
|
||||
This does not force a clear-screen sequence on the next refresh
|
||||
under any circumstances.
|
||||
\*(Nm
|
||||
.Ds
|
||||
.Fd clrtoeol "" \*m
|
||||
.Fd wclrtoeol win
|
||||
WINDOW *win;
|
||||
.De
|
||||
Wipes the window clear from the current \*y to the end of the line.
|
||||
\*(Nm
|
||||
.Ds
|
||||
.Fd delch
|
||||
.Fd wdelch win
|
||||
WINDOW *win;
|
||||
.De
|
||||
Delete the character at the current \*y.
|
||||
Each character after it on the line shifts to the left,
|
||||
and the last character becomes blank.
|
||||
.Ds
|
||||
.Fd deleteln
|
||||
.Fd wdeleteln win
|
||||
WINDOW *win;
|
||||
.De
|
||||
Delete the current line.
|
||||
Every line below the current one will move up,
|
||||
and the bottom line will become blank.
|
||||
The current \*y will remain unchanged.
|
||||
.Ds
|
||||
.Fd erase "" \*m
|
||||
.Fd werase win
|
||||
WINDOW *win;
|
||||
.De
|
||||
Erases the window to blanks without setting the clear flag.
|
||||
This is analagous to
|
||||
.Fn clear ,
|
||||
except that it never causes a clear-screen sequence to be generated
|
||||
on a
|
||||
.Fn refresh .
|
||||
\*(Nm
|
||||
.Ds
|
||||
.Fd flushok win\*,boolf \*m
|
||||
WINDOW *win;
|
||||
bool boolf;
|
||||
.De
|
||||
Normally,
|
||||
.Fn refresh
|
||||
.Fn fflush 's
|
||||
.Vn stdout
|
||||
when it is finished.
|
||||
.Fn flushok
|
||||
allows you to control this.
|
||||
if
|
||||
.Vn boolf
|
||||
is TRUE
|
||||
(\c
|
||||
.i i.e. ,
|
||||
non-zero)
|
||||
it will do the
|
||||
.Fn fflush ;
|
||||
if it is FALSE.
|
||||
it will not.
|
||||
.Ds
|
||||
.Fd idlok win\*,boolf
|
||||
WINDOW *win;
|
||||
bool boolf;
|
||||
.De
|
||||
Reserved for future use.
|
||||
This will eventually signal to
|
||||
.Fn refresh
|
||||
that it is all right to use the insert and delete line sequences
|
||||
when updating the window.
|
||||
.Ds
|
||||
.Fd insch c
|
||||
char c;
|
||||
.Fd winsch win\*,c
|
||||
WINDOW *win;
|
||||
char c;
|
||||
.De
|
||||
Insert
|
||||
.Vn c
|
||||
at the current \*y
|
||||
Each character after it shifts to the right,
|
||||
and the last character disappears.
|
||||
\*(Es
|
||||
.Ds
|
||||
.Fd insertln
|
||||
.Fd winsertln win
|
||||
WINDOW *win;
|
||||
.De
|
||||
Insert a line above the current one.
|
||||
Every line below the current line
|
||||
will be shifted down,
|
||||
and the bottom line will disappear.
|
||||
The current line will become blank,
|
||||
and the current \*y will remain unchanged.
|
||||
.Ds
|
||||
.Fd move y\*,x \*m
|
||||
int y\*,x;
|
||||
.Fd wmove win\*,y\*,x
|
||||
WINDOW *win;
|
||||
int y\*,x;
|
||||
.De
|
||||
Change the current \*y of the window to
|
||||
.Vn y\*,x ). (
|
||||
\*(Es
|
||||
.Ds
|
||||
.Fd overlay win1\*,win2
|
||||
WINDOW *win1\*,*win2;
|
||||
.De
|
||||
Overlay
|
||||
.Vn win1
|
||||
on
|
||||
.Vn win2 .
|
||||
The contents of
|
||||
.Vn win1 ,
|
||||
insofar as they fit,
|
||||
are placed on
|
||||
.Vn win2
|
||||
at their starting \*y.
|
||||
This is done non-destructively,
|
||||
i.e., blanks on
|
||||
.Vn win1
|
||||
leave the contents of the space on
|
||||
.Vn win2
|
||||
untouched.
|
||||
.Ds
|
||||
.Fd overwrite win1\*,win2
|
||||
WINDOW *win1\*,*win2;
|
||||
.De
|
||||
Overwrite
|
||||
.Vn win1
|
||||
on
|
||||
.Vn win2 .
|
||||
The contents of
|
||||
.Vn win1 ,
|
||||
insofar as they fit,
|
||||
are placed on
|
||||
.Vn win2
|
||||
at their starting \*y.
|
||||
This is done destructively,
|
||||
.i i.e. ,
|
||||
blanks on
|
||||
.Vn win1
|
||||
become blank on
|
||||
.Vn win2 .
|
||||
.Ds
|
||||
.Fd printw fmt\*,arg1\*,arg2\*,...
|
||||
char *fmt;
|
||||
.Fd wprintw win\*,fmt\*,arg1\*,arg2\*,...
|
||||
WINDOW *win;
|
||||
char *fmt;
|
||||
.De
|
||||
Performs a
|
||||
.Fn printf
|
||||
on the window starting at the current \*y.
|
||||
It uses
|
||||
.Fn addstr
|
||||
to add the string on the window.
|
||||
It is often advisable to use the field width options of
|
||||
.Fn printf
|
||||
to avoid leaving things on the window from earlier calls.
|
||||
\*(Es
|
||||
.Ds
|
||||
.Fd refresh "" \*m
|
||||
.Fd wrefresh win
|
||||
WINDOW *win;
|
||||
.De
|
||||
Synchronize the terminal screen with the desired window.
|
||||
If the window is not a screen,
|
||||
only that part covered by it is updated.
|
||||
\*(Es
|
||||
In this case, it will update whatever it can
|
||||
without causing the scroll.
|
||||
.sp
|
||||
As a special case,
|
||||
if
|
||||
.Fn wrefresh
|
||||
is called with the window
|
||||
.Vn curscr
|
||||
the screen is cleared
|
||||
and repainted as it is currently.
|
||||
This is very useful for allowing the redrawing of the screen
|
||||
when the user has garbage dumped on his terminal.
|
||||
.Ds
|
||||
.Fd standout "" \*m
|
||||
.Fd wstandout win
|
||||
WINDOW *win;
|
||||
.Fd standend "" \*m
|
||||
.Fd wstandend win
|
||||
WINDOW *win;
|
||||
.De
|
||||
Start and stop putting characters onto
|
||||
.i win
|
||||
in standout mode.
|
||||
.Fn standout
|
||||
causes any characters added to the window
|
||||
to be put in standout mode on the terminal
|
||||
(if it has that capability).
|
||||
.Fn standend
|
||||
stops this.
|
||||
The sequences
|
||||
.Vn SO
|
||||
and
|
||||
.Vn SE
|
||||
(or
|
||||
.Vn US
|
||||
and
|
||||
.Vn UE
|
||||
if they are not defined)
|
||||
are used (see Appendix A).
|
||||
+140
@@ -0,0 +1,140 @@
|
||||
.\" $NetBSD: doc.II,v 1.5 2003/08/07 16:44:27 agc Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)doc.II 8.1 (Berkeley) 6/4/93
|
||||
.\"
|
||||
.Ds
|
||||
.Fd cbreak "" \*m
|
||||
.Fd nocbreak "" \*m
|
||||
.Fd crmode "" \*m
|
||||
.Fd nocrmode "" \*m
|
||||
.De
|
||||
Set or unset the terminal to/from cbreak mode.
|
||||
The misnamed macros
|
||||
.Fn crmode
|
||||
and
|
||||
.Fn nocrmode
|
||||
are retained for backwards compatibility
|
||||
with ealier versions of the library.
|
||||
.Ds
|
||||
.Fd echo "" \*m
|
||||
.Fd noecho "" \*m
|
||||
.De
|
||||
Sets the terminal to echo or not echo characters.
|
||||
.Ds
|
||||
.Fd getch "" \*m
|
||||
.Fd wgetch win
|
||||
WINDOW *win;
|
||||
.De
|
||||
Gets a character from the terminal and (if necessary)
|
||||
echos it on the window.
|
||||
\*(Es
|
||||
Otherwise, the character gotten is returned.
|
||||
If
|
||||
.i noecho
|
||||
has been set, then the window is left unaltered.
|
||||
In order to retain control of the terminal,
|
||||
it is necessary to have one of
|
||||
.i noecho ,
|
||||
.i cbreak ,
|
||||
or
|
||||
.i rawmode
|
||||
set.
|
||||
If you do not set one,
|
||||
whatever routine you call to read characters will set
|
||||
.i cbreak
|
||||
for you,
|
||||
and then reset to the original mode when finished.
|
||||
.Ds
|
||||
.Fd getstr str \*m
|
||||
char *str;
|
||||
.Fd wgetstr win\*,str
|
||||
WINDOW *win;
|
||||
char *str;
|
||||
.De
|
||||
Get a string through the window
|
||||
and put it in the location pointed to by
|
||||
.Vn str ,
|
||||
which is assumed to be large enough to handle it.
|
||||
It sets tty modes if necessary,
|
||||
and then calls
|
||||
.Fn getch
|
||||
(or
|
||||
.Fn wgetch ) "" win
|
||||
to get the characters needed to fill in the string
|
||||
until a newline or EOF is encountered.
|
||||
The newline stripped off the string.
|
||||
\*(Es
|
||||
.Ds
|
||||
.Fd \*_putchar c
|
||||
char c;
|
||||
.De
|
||||
Put out a character using the
|
||||
.Fn putchar
|
||||
macro.
|
||||
This function is used to output every character
|
||||
that
|
||||
.b curses
|
||||
generates.
|
||||
Thus,
|
||||
it can be redefined by the user who wants to do non-standard things
|
||||
with the output.
|
||||
It is named with an initial \*(lq\*_\*(rq
|
||||
because it usually should be invisible to the programmer.
|
||||
.Ds
|
||||
.Fd raw "" \*m
|
||||
.Fd noraw "" \*m
|
||||
.De
|
||||
Set or unset the terminal to/from raw mode.
|
||||
On version 7
|
||||
.Un \**
|
||||
.(f
|
||||
\**
|
||||
.Un
|
||||
is a trademark of Bell Laboratories.
|
||||
.)f
|
||||
this also turns of newline mapping
|
||||
(see
|
||||
.Fn nl ).
|
||||
.Ds
|
||||
.Fd scanw fmt\*,arg1\*,arg2\*,...
|
||||
char *fmt;
|
||||
.Fd wscanw win\*,fmt\*,arg1\*,arg2\*,...
|
||||
WINDOW *win;
|
||||
char *fmt;
|
||||
.De
|
||||
Perform a
|
||||
.Fn scanf
|
||||
through the window using
|
||||
.Vn fmt .
|
||||
It does this using consecutive
|
||||
.Fn getch 's
|
||||
(or
|
||||
.Fn wgetch 's). "" win
|
||||
\*(Es
|
||||
+341
@@ -0,0 +1,341 @@
|
||||
.\" $NetBSD: doc.III,v 1.5 2003/08/07 16:44:27 agc Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)doc.III 8.1 (Berkeley) 6/4/93
|
||||
.\"
|
||||
.Ds
|
||||
.Fd baudrate "" \*m
|
||||
.De
|
||||
Returns the output baud rate of the terminal.
|
||||
This is a system dependent constant
|
||||
(defined in
|
||||
.b <sys/tty.h>
|
||||
on BSD systems,
|
||||
which is included by
|
||||
.b <curses.h> ).
|
||||
.Ds
|
||||
.Fd delwin win
|
||||
WINDOW *win;
|
||||
.De
|
||||
Deletes the window from existence.
|
||||
All resources are freed for future use by
|
||||
.b calloc (3).
|
||||
If a window has a
|
||||
.Fn subwin
|
||||
allocated window inside of it,
|
||||
deleting the outer window
|
||||
the subwindow is not affected,
|
||||
even though this does invalidate it.
|
||||
Therefore,
|
||||
subwindows should be deleted before their
|
||||
outer windows are.
|
||||
.Ds
|
||||
.Fd endwin
|
||||
.De
|
||||
Finish up window routines before exit.
|
||||
This restores the terminal to the state it was before
|
||||
.Fn initscr
|
||||
(or
|
||||
.Fn gettmode
|
||||
and
|
||||
.Fn setterm )
|
||||
was called.
|
||||
It should always be called before exiting.
|
||||
It does not exit.
|
||||
This is especially useful for resetting tty stats
|
||||
when trapping rubouts via
|
||||
.b signal (2).
|
||||
.Ds
|
||||
.Fd erasechar "" \*m
|
||||
.De
|
||||
Returns the erase character
|
||||
for the terminal,
|
||||
.i i.e. ,
|
||||
the character used by the user to erase a single character from the input.
|
||||
.Ds
|
||||
.Fd getcap str "" "char *"
|
||||
char *str;
|
||||
.De
|
||||
Return a pointer to the
|
||||
.b termcap
|
||||
capability described by
|
||||
.Vn str
|
||||
(see
|
||||
.b termcap (5)
|
||||
for details).
|
||||
.Ds
|
||||
.Fd getyx win\*,y\*,x \*m
|
||||
WINDOW *win;
|
||||
int y\*,x;
|
||||
.De
|
||||
Puts the current \*y of
|
||||
.Vn win
|
||||
in the variables
|
||||
.Vn y
|
||||
and
|
||||
.Vn x .
|
||||
Since it is a macro,
|
||||
not a function,
|
||||
you do not pass the address
|
||||
of
|
||||
.Vn y
|
||||
and
|
||||
.Vn x .
|
||||
.Ds
|
||||
.Fd inch "" \*m
|
||||
.Fd winch win \*m
|
||||
WINDOW *win;
|
||||
.De
|
||||
Returns the character at the current \*(y
|
||||
on the given window.
|
||||
This does not make any changes to the window.
|
||||
.Ds
|
||||
.Fd initscr
|
||||
.De
|
||||
Initialize the screen routines.
|
||||
This must be called before any of the screen routines are used.
|
||||
It initializes the terminal-type data and such,
|
||||
and without it none of the routines can operate.
|
||||
If standard input is not a tty,
|
||||
it sets the specifications to the terminal
|
||||
whose name is pointed to by
|
||||
.Vn Def\*_term
|
||||
(initialy "dumb").
|
||||
If the boolean
|
||||
.Vn My\*_term
|
||||
is true,
|
||||
.Vn Def\*_term
|
||||
is always used.
|
||||
If the system supports the
|
||||
.b TIOCGWINSZ
|
||||
.Fn ioctl "" "" 2
|
||||
call,
|
||||
it is used to get the number of lines and columns for the terminal,
|
||||
otherwise it is taken from the
|
||||
.b termcap
|
||||
description.
|
||||
.Ds
|
||||
.Fd killchar "" \*m
|
||||
.De
|
||||
Returns the line kill character
|
||||
for the terminal,
|
||||
.i i.e. ,
|
||||
the character used by the user to erase an entire line from the input.
|
||||
.Ds
|
||||
.Fd leaveok win\*,boolf \*m
|
||||
WINDOW *win;
|
||||
bool boolf;
|
||||
.De
|
||||
Sets the boolean flag for leaving the cursor after the last change.
|
||||
If
|
||||
.Vn boolf
|
||||
is TRUE,
|
||||
the cursor will be left after the last update on the terminal,
|
||||
and the current \*y for
|
||||
.Vn win
|
||||
will be changed accordingly.
|
||||
If it is FALSE,
|
||||
it will be moved to the current \*y.
|
||||
This flag
|
||||
(initialy FALSE)
|
||||
retains its value until changed by the user.
|
||||
.Ds
|
||||
.Fd longname termbuf\*,name
|
||||
char *termbuf\*,*name;
|
||||
.Fd fullname termbuf\*,name
|
||||
char *termbuf\*,*name;
|
||||
.De
|
||||
.Fn longname
|
||||
fills in
|
||||
.Vn name
|
||||
with the long name of the terminal described by the
|
||||
.b termcap
|
||||
entry in
|
||||
.Vn termbuf .
|
||||
It is generally of little use,
|
||||
but is nice for telling the user in a readable format what terminal
|
||||
we think he has.
|
||||
This is available in the global variable
|
||||
.Vn ttytype .
|
||||
.Vn termbuf
|
||||
is usually set via the termlib routine
|
||||
.Fn tgetent .
|
||||
.Fn fullname
|
||||
is the same as
|
||||
.Fn longname ,
|
||||
except that it gives the fullest name given in the entry,
|
||||
which can be quite verbose.
|
||||
.Ds
|
||||
.Fd mvwin win\*,y\*,x
|
||||
WINDOW *win;
|
||||
int y, x;
|
||||
.De
|
||||
Move the home position of the window
|
||||
.Vn win
|
||||
from its current starting coordinates
|
||||
to
|
||||
.Vn y\*,x ). (
|
||||
If that would put part or all of the window
|
||||
off the edge of the terminal screen,
|
||||
.Fn mvwin
|
||||
returns ERR and does not change anything.
|
||||
For subwindows,
|
||||
.Fn mvwin
|
||||
also returns ERR if you attempt to move it off its main window.
|
||||
If you move a main window,
|
||||
all subwindows are moved along with it.
|
||||
.Ds
|
||||
.Fd newwin lines\*,cols\*,begin\*_y\*,begin\*_x "" "WINDOW *"
|
||||
int lines\*,cols\*,begin\*_y\*,begin\*_x;
|
||||
.De
|
||||
Create a new window with
|
||||
.Vn lines
|
||||
lines and
|
||||
.Vn cols
|
||||
columns starting at position
|
||||
.Vn begin\*_y\*,begin\*_x ). (
|
||||
If either
|
||||
.Vn lines
|
||||
or
|
||||
.Vn cols
|
||||
is 0 (zero),
|
||||
that dimension will be set to
|
||||
.Vn "LINES \- begin\*_y" ) (
|
||||
or
|
||||
.Vn "COLS \- begin\*_x" ) (
|
||||
respectively.
|
||||
Thus, to get a new window of dimensions
|
||||
.Vn LINES
|
||||
\(mu
|
||||
.Vn COLS ,
|
||||
use
|
||||
.Fn newwin . "" 0\*,0\*,0\*,0
|
||||
.Ds
|
||||
.Fd nl "" \*m
|
||||
.Fd nonl "" \*m
|
||||
.De
|
||||
Set or unset the terminal to/from nl mode,
|
||||
.i i.e. ,
|
||||
start/stop the system from mapping
|
||||
.b <RETURN>
|
||||
to
|
||||
.b <LINE-FEED> .
|
||||
If the mapping is not done,
|
||||
.Fn refresh
|
||||
can do more optimization,
|
||||
so it is recommended, but not required, to turn it off.
|
||||
.Ds
|
||||
.Fd scrollok win\*,boolf \*m
|
||||
WINDOW *win;
|
||||
bool boolf;
|
||||
.De
|
||||
Set the scroll flag for the given window.
|
||||
If
|
||||
.Vn boolf
|
||||
is FALSE, scrolling is not allowed.
|
||||
This is its default setting.
|
||||
.Ds
|
||||
.Fd touchline win\*,y\*,startx\*,endx
|
||||
WINDOW *win;
|
||||
int y\*,startx\*,endx;
|
||||
.De
|
||||
This function performs a function similar to
|
||||
.Fn touchwin
|
||||
on a single line.
|
||||
It marks the first change for the given line
|
||||
to be
|
||||
.Vn startx ,
|
||||
if it is before the current first change mark,
|
||||
and
|
||||
the last change mark is set to be
|
||||
.Vn endx
|
||||
if it is currently less than
|
||||
.Vn endx .
|
||||
.Ds
|
||||
.Fd touchoverlap win1\*,win2
|
||||
WINDOW *win1, *win2;
|
||||
.De
|
||||
Touch the window
|
||||
.Vn win2
|
||||
in the area which overlaps with
|
||||
.Vn win1 .
|
||||
If they do not overlap,
|
||||
no changes are made.
|
||||
.Ds
|
||||
.Fd touchwin win
|
||||
WINDOW *win;
|
||||
.De
|
||||
Make it appear that the every location on the window
|
||||
has been changed.
|
||||
This is usually only needed for refreshes with overlapping windows.
|
||||
.Ds
|
||||
.Fd subwin win\*,lines\*,cols\*,begin\*_y\*,begin\*_x "" "WINDOW *"
|
||||
WINDOW *win;
|
||||
int lines\*,cols\*,begin\*_y\*,begin\*_x;
|
||||
.De
|
||||
Create a new window with
|
||||
.Vn lines
|
||||
lines and
|
||||
.Vn cols
|
||||
columns starting at position
|
||||
.Vn begin\*_y\*,begin\*_x ) (
|
||||
inside the window
|
||||
.i win .
|
||||
This means that any change made to either window
|
||||
in the area covered
|
||||
by the subwindow will be made on both windows.
|
||||
.Vn begin\*_y\*,begin\*_x
|
||||
are specified relative to the overall screen,
|
||||
not the relative (0\*,0) of
|
||||
.Vn win .
|
||||
If either
|
||||
.Vn lines
|
||||
or
|
||||
.Vn cols
|
||||
is 0 (zero),
|
||||
that dimension will be set to
|
||||
.Vn "LINES \- begin\*_y" ) (
|
||||
or
|
||||
.Vn "COLS \- begin\*_x" ) (
|
||||
respectively.
|
||||
.Ds
|
||||
.Fd unctrl ch \*m
|
||||
char ch;
|
||||
.De
|
||||
This is actually a debug function for the library,
|
||||
but it is of general usefulness.
|
||||
It returns a string which is a representation of
|
||||
.Vn ch .
|
||||
Control characters become their upper-case equivalents preceded by a "^".
|
||||
Other letters stay just as they are.
|
||||
To use
|
||||
.Fn unctrl ,
|
||||
you may have to have
|
||||
.b #include\ <unctrl.h>
|
||||
in your file.
|
||||
+108
@@ -0,0 +1,108 @@
|
||||
.\" $NetBSD: doc.IV,v 1.5 2003/08/07 16:44:27 agc Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)doc.IV 8.1 (Berkeley) 6/4/93
|
||||
.\"
|
||||
.Ds
|
||||
.Fd gettmode
|
||||
.De
|
||||
Get the tty stats.
|
||||
This is normally called by
|
||||
.Fn initscr .
|
||||
.Ds
|
||||
.Fd mvcur lasty\*,lastx\*,newy\*,newx
|
||||
int lasty\*,lastx\*,newy\*,newx;
|
||||
.De
|
||||
Moves the terminal's cursor from
|
||||
.Vn lasty\*,lastx ) (
|
||||
to
|
||||
.Vn newy\*,newx ) (
|
||||
in an approximation of optimal fashion.
|
||||
This routine uses the functions borrowed from
|
||||
.i ex
|
||||
version 2.6.
|
||||
It is possible to use this optimization
|
||||
without the benefit of the screen routines.
|
||||
With the screen routines, this should not be called by the user.
|
||||
.Fn move
|
||||
and
|
||||
.Fn refresh
|
||||
should be used to move the cursor position,
|
||||
so that the routines know what's going on.
|
||||
.Ds
|
||||
.Fd scroll win
|
||||
WINDOW *win;
|
||||
.De
|
||||
Scroll the window upward one line.
|
||||
This is normally not used by the user.
|
||||
.Ds
|
||||
.Fd savetty "" \*m
|
||||
.Fd resetty "" \*m
|
||||
.De
|
||||
.Fn savetty
|
||||
saves the current tty characteristic flags.
|
||||
.Fn resetty
|
||||
restores them to what
|
||||
.Fn savetty
|
||||
stored.
|
||||
These functions are performed automatically by
|
||||
.Fn initscr
|
||||
and
|
||||
.Fn endwin .
|
||||
.Ds
|
||||
.Fd setterm name
|
||||
char *name;
|
||||
.De
|
||||
Set the terminal characteristics to be those of the terminal named
|
||||
.Vn name ,
|
||||
getting the terminal size from the
|
||||
.b TIOCGWINSZ
|
||||
.Fn ioctl "" "" 2
|
||||
if it exists,
|
||||
otherwise from the environment.
|
||||
This is normally called by
|
||||
.Fn initscr .
|
||||
.Ds
|
||||
.Fd tstp
|
||||
.De
|
||||
If the new
|
||||
.b tty (4)
|
||||
driver is in use,
|
||||
this function
|
||||
will save the current tty state
|
||||
and then put the process to sleep.
|
||||
When the process gets restarted,
|
||||
it restores the tty state
|
||||
and then calls
|
||||
.Fn wrefresh "" "" curscr
|
||||
to redraw the screen.
|
||||
.Fn initscr
|
||||
sets the signal
|
||||
SIGTSTP
|
||||
to trap to this routine.
|
||||
+100
@@ -0,0 +1,100 @@
|
||||
.\" $NetBSD: ex1.c,v 1.6 2003/08/07 16:44:27 agc Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1992, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)ex1.c 8.1 (Berkeley) 6/8/93
|
||||
.\"
|
||||
#include <sys/types.h>
|
||||
#include <curses.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
|
||||
#define YSIZE 10
|
||||
#define XSIZE 20
|
||||
|
||||
int quit();
|
||||
|
||||
main()
|
||||
{
|
||||
int i, j, c;
|
||||
size_t len;
|
||||
char id[100];
|
||||
FILE *fp;
|
||||
char *s;
|
||||
|
||||
initscr(); /* Always call initscr() first */
|
||||
signal(SIGINT, quit); /* Make sure wou have a 'cleanup' fn */
|
||||
crmode(); /* We want cbreak mode */
|
||||
noecho(); /* We want to have control of chars */
|
||||
delwin(stdscr); /* Create our own stdscr */
|
||||
stdscr = newwin(YSIZE, XSIZE, 10, 35);
|
||||
flushok(stdscr, TRUE); /* Enable flushing of stdout */
|
||||
scrollok(stdscr, TRUE); /* Enable scrolling */
|
||||
erase(); /* Initially, clear the screen */
|
||||
|
||||
standout();
|
||||
move(0,0);
|
||||
while (1) {
|
||||
c = getchar();
|
||||
switch(c) {
|
||||
case 'q': /* Quit on 'q' */
|
||||
quit();
|
||||
break;
|
||||
case 's': /* Go into standout mode on 's' */
|
||||
standout();
|
||||
break;
|
||||
case 'e': /* Exit standout mode on 'e' */
|
||||
standend();
|
||||
break;
|
||||
case 'r': /* Force a refresh on 'r' */
|
||||
wrefresh(curscr);
|
||||
break;
|
||||
default: /* By default output the character */
|
||||
addch(c);
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
quit()
|
||||
{
|
||||
erase(); /* Terminate by erasing the screen */
|
||||
refresh();
|
||||
endwin(); /* Always end with endwin() */
|
||||
delwin(curscr); /* Return storage */
|
||||
delwin(stdscr);
|
||||
putchar('\n');
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+208
@@ -0,0 +1,208 @@
|
||||
.\" $NetBSD: ex2.c,v 1.7 2003/08/07 16:44:27 agc Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1992, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)ex2.c 8.1 (Berkeley) 6/8/93
|
||||
.\"
|
||||
#include <curses.h>
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
|
||||
#define YSIZE LINES
|
||||
#define XSIZE COLS
|
||||
|
||||
static int quit();
|
||||
|
||||
/*
|
||||
* This program fills the screen up with characters and the allows the user to
|
||||
* manipulate the text on the screen using some basic commands.
|
||||
* Nothing fancy, just a demonstration of the elementary features of the
|
||||
* curses(3) package.
|
||||
*/
|
||||
main()
|
||||
{
|
||||
int i, j, c, n, d = 0;
|
||||
char id[100];
|
||||
int hh = 0;
|
||||
int curx, cury, base, arg;
|
||||
|
||||
initscr();
|
||||
signal(SIGINT, quit);
|
||||
crmode();
|
||||
noecho();
|
||||
nonl();
|
||||
delwin(stdscr);
|
||||
stdscr = newwin(YSIZE, XSIZE, 0, 0);
|
||||
flushok(stdscr, TRUE);
|
||||
scrollok(stdscr, TRUE);
|
||||
erase();
|
||||
refresh();
|
||||
|
||||
move(0,0);
|
||||
refresh();
|
||||
for (i = 0; i < YSIZE + 2; i++) {
|
||||
(void)snprintf(id, sizeof id, "%d: ", i);
|
||||
addstr(id);
|
||||
for (j = 0; j < XSIZE - strlen(id); j++)
|
||||
addch('0' + (i % 10));
|
||||
}
|
||||
c = getchar();
|
||||
base = 2;
|
||||
curx = cury = 0;
|
||||
move(0, 0);
|
||||
refresh();
|
||||
|
||||
/*
|
||||
* The screen manipulator has the following commands:
|
||||
* 'D' - clear to the end of the current line.
|
||||
* 'B' - clear to the bottom of the screen.
|
||||
* 'E' - erase the screen.
|
||||
* 's' - enter standout mode.
|
||||
* 'e' - exit standout mode.
|
||||
* 'd' n - delete n lines below cursor line.
|
||||
* 'i' n - insert n lines below cursor line.
|
||||
* 'q' - quit.
|
||||
* 'f' - move cursor one position to the right.
|
||||
* 'b' - move cursor one position to the left.
|
||||
* 'n' - move cursor one line down.
|
||||
* 'p' - move cursor one line up.
|
||||
* 'h' - home cusor.
|
||||
* 'l' - force refresh.
|
||||
* 'r' - simulate a carriage return.
|
||||
*
|
||||
* All other characters are ignored.
|
||||
*/
|
||||
for(;;) {
|
||||
switch(c = getchar()) {
|
||||
case 'D':
|
||||
clrtoeol();
|
||||
refresh();
|
||||
continue;
|
||||
case 'B':
|
||||
clrtobot();
|
||||
refresh();
|
||||
continue;
|
||||
case 'E':
|
||||
erase();
|
||||
refresh();
|
||||
continue;
|
||||
case 's':
|
||||
standout();
|
||||
continue;
|
||||
case 'e':
|
||||
standend();
|
||||
continue;
|
||||
case 'd':
|
||||
arg = getchar() - '0';
|
||||
for (i = 0; i < arg; i++)
|
||||
deleteln();
|
||||
refresh();
|
||||
continue;
|
||||
case 'i':
|
||||
arg = getchar() - '0';
|
||||
for (i = 0; i < arg; i++)
|
||||
insertln();
|
||||
refresh();
|
||||
continue;
|
||||
case 'q':
|
||||
quit();
|
||||
case 'f':
|
||||
if (curx < XSIZE - 1)
|
||||
curx++;
|
||||
else {
|
||||
cury++;
|
||||
curx = 0;
|
||||
}
|
||||
break;
|
||||
case 'b':
|
||||
if (curx == 0) {
|
||||
cury--;
|
||||
curx = XSIZE - 1;
|
||||
} else
|
||||
curx--;
|
||||
break;
|
||||
case 'n':
|
||||
cury++;
|
||||
break;
|
||||
case 'p':
|
||||
cury--;
|
||||
break;
|
||||
case 'h':
|
||||
curx = cury = 0;
|
||||
break;
|
||||
case 'l':
|
||||
wrefresh(curscr);
|
||||
continue;
|
||||
case 'r': /* return */
|
||||
{
|
||||
int x, y;
|
||||
getyx(stdscr, y, x);
|
||||
move(y+1, 0);
|
||||
insertln();
|
||||
move(y, x);
|
||||
clrtoeol();
|
||||
refresh();
|
||||
continue;
|
||||
}
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cury < 0) {
|
||||
base--;
|
||||
move(0, 0);
|
||||
insertln();
|
||||
(void)snprintf(id, sizeof id, "%d: ", base);
|
||||
addstr(id);
|
||||
for (j = 0; j < XSIZE - strlen(id) - 2; j++)
|
||||
addch('0' + (base % 10));
|
||||
cury++;
|
||||
} else if (cury >= YSIZE) {
|
||||
move(0, 0);
|
||||
deleteln();
|
||||
move(YSIZE - 1, 0);
|
||||
(void)snprintf(id, sizeof id, "%d: ", base + YSIZE);
|
||||
addstr(id);
|
||||
for (j = 0; j < XSIZE - strlen(id) - 2; j++)
|
||||
addch('0' + ((base + YSIZE) % 10));
|
||||
cury--;
|
||||
base++;
|
||||
}
|
||||
move(cury, curx);
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
quit()
|
||||
{
|
||||
erase();
|
||||
refresh();
|
||||
endwin();
|
||||
exit(0);
|
||||
}
|
||||
+1757
File diff suppressed because it is too large.
Load diff
+104
@@ -0,0 +1,104 @@
|
||||
.\" $NetBSD: intro.0,v 1.6 2003/08/07 16:44:27 agc Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)intro.0 8.1 (Berkeley) 6/4/93
|
||||
.\"
|
||||
.tp
|
||||
.(l C
|
||||
.ps 12
|
||||
.ft B
|
||||
Screen Updating and Cursor Movement Optimization:
|
||||
.fl
|
||||
A Library Package
|
||||
.ft
|
||||
.ps
|
||||
.sp
|
||||
.i "Kenneth C. R. C. Arnold"
|
||||
.i "Elan Amir"
|
||||
.sp
|
||||
Computer Science Division
|
||||
Department of Electrical Engineering and Computer Science
|
||||
University of California, Berkeley
|
||||
Berkeley, California 94720
|
||||
.sp 3
|
||||
.bi ABSTRACT
|
||||
.sp 2
|
||||
.)l
|
||||
.(q
|
||||
.pp
|
||||
This document describes a package of C library functions
|
||||
which allow the user to:
|
||||
.ie t .ip \ \ \ \(bu
|
||||
.el .ip 1)
|
||||
update a screen with reasonable optimization,
|
||||
.ie t .ip \ \ \ \(bu
|
||||
.el .ip 2)
|
||||
get input from the terminal
|
||||
in a screen-oriented fashion,
|
||||
and
|
||||
.ie t .ip \ \ \ \(bu
|
||||
.el .ip 3)
|
||||
independent from the above, move the cursor optimally
|
||||
from one point to another.
|
||||
.pp
|
||||
These routines all use the
|
||||
\*(tc \*(db to describe the capabilities of the terminal.
|
||||
.)q
|
||||
.b Acknowledgements
|
||||
.pp
|
||||
This package would not exist
|
||||
without the work of Bill Joy,
|
||||
who,
|
||||
in writing his editor,
|
||||
created the capability to generally describe terminals,
|
||||
wrote the routines which read this \*(db,
|
||||
and, most importantly,
|
||||
those which implement optimal cursor movement,
|
||||
which routines I have simply lifted nearly intact.
|
||||
Doug Merritt and Kurt Shoens also were extremely important,
|
||||
as were both willing to waste time listening to me rant and rave.
|
||||
The help and/or support of
|
||||
Ken Abrams,
|
||||
Alan Char,
|
||||
Mark Horton,
|
||||
and
|
||||
Joe Kalash,
|
||||
was, and is,
|
||||
also greatly appreciated.
|
||||
.i "Ken Arnold 16 April 1986"
|
||||
.pp
|
||||
The help and/or support of Kirk McKusick and Keith Bostic (public vi!)
|
||||
was invaluable in bringing the package ``into the 90's'', which now
|
||||
includes completely new data structures and screen refresh optimization
|
||||
routines.
|
||||
.i "Elan Amir 29 December 1992"
|
||||
|
||||
|
||||
|
||||
|
||||
+247
@@ -0,0 +1,247 @@
|
||||
.\" $NetBSD: intro.1,v 1.7 2003/08/07 16:44:27 agc Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)intro.1 8.1 (Berkeley) 6/4/93
|
||||
.\"
|
||||
.bp
|
||||
.sh 1 Overview
|
||||
.pp
|
||||
In making available the generalized terminal descriptions in \*(tc,
|
||||
much information was made available to the programmer,
|
||||
but little work was taken out of one's hands.
|
||||
The purpose of this package is to allow the C programmer
|
||||
to do the most common type of terminal dependent functions,
|
||||
those of movement optimization and optimal screen updating,
|
||||
without doing any of the dirty work,
|
||||
and with nearly as much ease as is necessary to simply print
|
||||
or read things.
|
||||
.sh 2 "Terminology"
|
||||
.pp
|
||||
In this document, the following terminology is used:
|
||||
.de Ip
|
||||
.sp
|
||||
.in 5n
|
||||
.ti 0n
|
||||
.b "\\$1" :
|
||||
..
|
||||
.Ip window
|
||||
An internal representation
|
||||
containing an image of what a section of the terminal screen may look like
|
||||
at some point in time.
|
||||
This subsection can either encompass the entire terminal screen,
|
||||
or any smaller portion down to a single character within that screen.
|
||||
.Ip terminal
|
||||
Sometimes called
|
||||
.b terminal
|
||||
.b screen .
|
||||
The package's idea of what the terminal's screen currently looks like,
|
||||
.i i.e. ,
|
||||
what the user sees now.
|
||||
This is a special
|
||||
.i screen :
|
||||
.Ip screen
|
||||
This is a subset of windows which are as large as the terminal screen,
|
||||
.i i.e. ,
|
||||
they start at the upper left hand corner
|
||||
and encompass the lower right hand corner.
|
||||
One of these,
|
||||
.Vn stdscr ,
|
||||
is automatically provided for the programmer.
|
||||
.rm Ip
|
||||
.sh 2 "Compiling Applications"
|
||||
.pp
|
||||
In order to use the library,
|
||||
it is necessary to have certain types and variables defined.
|
||||
Therefore, the programmer must have a line:
|
||||
.(l
|
||||
.b "#include <curses.h>"
|
||||
.)l
|
||||
at the top of the program source.
|
||||
Compilations should have the following form:
|
||||
.(l
|
||||
.ie t \fBcc\fR [ \fIflags\fR ] file ... \fB\-lcurses \-ltermcap\fR
|
||||
.el \fIcc\fR [ flags ] file ... \fI\-lcurses \-ltermcap\fR
|
||||
.)l
|
||||
.sh 2 "Screen Updating"
|
||||
.pp
|
||||
In order to update the screen optimally,
|
||||
it is necessary for the routines to know what the screen currently looks like
|
||||
and what the programmer wants it to look like next.
|
||||
For this purpose,
|
||||
a data type
|
||||
(structure)
|
||||
named
|
||||
.Vn WINDOW
|
||||
is defined
|
||||
which describes a window image to the routines,
|
||||
including its starting position on the screen
|
||||
(the \*y of the upper left hand corner)
|
||||
and its size.
|
||||
One of these
|
||||
(called
|
||||
.Vn curscr
|
||||
for
|
||||
.i "current screen" )
|
||||
is a screen image of what the terminal currently looks like.
|
||||
Another screen
|
||||
(called
|
||||
.Vn stdscr ,
|
||||
for
|
||||
.i "standard screen" )
|
||||
is provided
|
||||
by default
|
||||
to make changes on.
|
||||
.pp
|
||||
A window is a purely internal representation.
|
||||
It is used to build and store
|
||||
a potential image of a portion of the terminal.
|
||||
It doesn't bear any necessary relation
|
||||
to what is really on the terminal screen.
|
||||
It is more like an array of characters on which to make changes.
|
||||
.pp
|
||||
When one has a window which describes
|
||||
what some part the terminal should look like,
|
||||
the routine
|
||||
.Fn refresh
|
||||
(or
|
||||
.Fn wrefresh
|
||||
if the window is not
|
||||
.Vn stdscr )
|
||||
is called.
|
||||
.Fn refresh
|
||||
makes the terminal,
|
||||
in the area covered by the window,
|
||||
look like that window.
|
||||
Note, therefore, that changing something on a window
|
||||
.i does
|
||||
.bi not
|
||||
.i "change the terminal" .
|
||||
Actual updates to the terminal screen
|
||||
are made only by calling
|
||||
.Fn refresh
|
||||
or
|
||||
.Fn wrefresh .
|
||||
This allows the programmer to maintain several different ideas
|
||||
of what a portion of the terminal screen should look like.
|
||||
Also, changes can be made to windows in any order,
|
||||
without regard to motion efficiency.
|
||||
Then, at will,
|
||||
the programmer can effectively say
|
||||
.q "make it look like this" ,
|
||||
and the package will execute the changes in an optimal way.
|
||||
.sh 2 "Naming Conventions"
|
||||
.pp
|
||||
As hinted above,
|
||||
the routines can use several windows,
|
||||
but two are always available:
|
||||
.Vn curscr ,
|
||||
which is the image of what the terminal looks like at present,
|
||||
and
|
||||
.Vn stdscr ,
|
||||
which is the image of what the programmer wants the terminal to look like next.
|
||||
The user should not access
|
||||
.Vn curscr
|
||||
directly.
|
||||
Changes should be made to
|
||||
the appropriate screen,
|
||||
and then the routine
|
||||
.Fn refresh
|
||||
(or
|
||||
.Fn wrefresh )
|
||||
should be called.
|
||||
.pp
|
||||
Many functions are set up to deal with
|
||||
.Vn stdscr
|
||||
as a default screen.
|
||||
For example, to add a character to
|
||||
.Vn stdscr ,
|
||||
one calls
|
||||
.Fn addch
|
||||
with the desired character.
|
||||
If a different window is to be used,
|
||||
the routine
|
||||
.Fn waddch
|
||||
(for
|
||||
.b w indow-specific
|
||||
.Fn addch )
|
||||
is provided\**.
|
||||
.(f
|
||||
\**
|
||||
Actually,
|
||||
.Fn addch
|
||||
is really a
|
||||
.q #define
|
||||
macro with arguments,
|
||||
as are most of the "functions" which act upon
|
||||
.Vn stdscr .
|
||||
.)f
|
||||
This convention of prepending function names with a
|
||||
.Bq w
|
||||
when they are to be applied to specific windows
|
||||
is consistent.
|
||||
The only routines which do
|
||||
.i not
|
||||
do this are those
|
||||
to which a window must always be specified.
|
||||
.pp
|
||||
In order to move the current \*y from one point to another,
|
||||
the routines
|
||||
.Fn move
|
||||
and
|
||||
.Fn wmove
|
||||
are provided.
|
||||
However,
|
||||
it is often desirable to first move and then perform some I/O operation.
|
||||
In order to avoid clumsiness,
|
||||
most I/O routines can be preceded by the prefix
|
||||
.Bq mv
|
||||
and the desired \*y can then be added to the arguments to the function.
|
||||
For example,
|
||||
the calls
|
||||
.(l
|
||||
move(y\*,x);
|
||||
addch(ch);
|
||||
.)l
|
||||
can be replaced by
|
||||
.(l
|
||||
mvaddch(y\*,x\*,ch);
|
||||
.)l
|
||||
and
|
||||
.(l
|
||||
wmove(win\*,y\*,x);
|
||||
waddch(win\*,ch);
|
||||
.)l
|
||||
can be replaced by
|
||||
.(l
|
||||
mvwaddch(win\*,y\*,x\*,ch);
|
||||
.)l
|
||||
Note that the window description pointer
|
||||
.Vn win ) (
|
||||
comes before the added \*y.
|
||||
If a window pointer is needed, it is always the first parameter passed.
|
||||
+82
@@ -0,0 +1,82 @@
|
||||
.\" $NetBSD: intro.2,v 1.8 2003/08/07 16:44:28 agc Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)intro.2 8.1 (Berkeley) 6/4/93
|
||||
.\"
|
||||
.sh 1 Variables
|
||||
.pp
|
||||
Many variables which are used to describe the terminal environment
|
||||
are available to the programmer.
|
||||
They are:
|
||||
.(b
|
||||
.TS
|
||||
expand;
|
||||
lw(6m) lw(8n) lw(50n).
|
||||
type name description
|
||||
_
|
||||
WINDOW * curscr T{
|
||||
.fi
|
||||
current version of the screen (terminal screen).
|
||||
T}
|
||||
WINDOW * stdscr T{
|
||||
standard screen.
|
||||
Most updates are usually done here.
|
||||
T}
|
||||
char * Def\*_term T{
|
||||
default terminal type if type cannot be determined
|
||||
T}
|
||||
bool My\*_term T{
|
||||
use the terminal specification in \fIDef\*_term\fR as terminal,
|
||||
irrelevant of real terminal type
|
||||
T}
|
||||
char * ttytype T{
|
||||
full name of the current terminal.
|
||||
T}
|
||||
int LINES T{
|
||||
number of lines on the terminal
|
||||
T}
|
||||
int COLS T{
|
||||
number of columns on the terminal
|
||||
T}
|
||||
int COLORS T{
|
||||
number of colors on the terminal
|
||||
T}
|
||||
int COLOR_PAIRS T{
|
||||
number of color pairs on the terminal
|
||||
T}
|
||||
int ERR T{
|
||||
error flag returned by routines on a fail.
|
||||
T}
|
||||
int OK T{
|
||||
flag returned by routines upon success.
|
||||
T}
|
||||
.TE
|
||||
.fi
|
||||
.)b
|
||||
.lp
|
||||
+228
@@ -0,0 +1,228 @@
|
||||
.\" $NetBSD: intro.3,v 1.9 2003/11/02 11:16:03 wiz Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)intro.3 8.1 (Berkeley) 6/4/93
|
||||
.\"
|
||||
.sh 1 Usage
|
||||
.pp
|
||||
This is a description of how to actually use the screen package.
|
||||
For simplicity, we assume all updating, reading, etc.
|
||||
is applied to
|
||||
.Vn stdscr ,
|
||||
although a different window can of course be specified.
|
||||
.sh 2 "Initialization"
|
||||
.pp
|
||||
In order to use the screen package,
|
||||
the routines must know about terminal characteristics,
|
||||
and the space for
|
||||
.Vn curscr
|
||||
and
|
||||
.Vn stdscr
|
||||
must be allocated.
|
||||
These functions are performed by
|
||||
.Fn initscr .
|
||||
Since it must allocate space for the windows,
|
||||
it can overflow core when attempting to do so.
|
||||
On this rather rare occasion,
|
||||
.Fn initscr
|
||||
returns ERR.
|
||||
.Fn initscr
|
||||
must
|
||||
.bi always
|
||||
be called before any of the routines which affect windows are used.
|
||||
If it is not,
|
||||
the program will core dump as soon as either
|
||||
.Vn curscr
|
||||
or
|
||||
.Vn stdscr
|
||||
are referenced.
|
||||
However, it is usually best to wait to call it
|
||||
until after you are sure you will need it,
|
||||
like after checking for startup errors.
|
||||
Terminal status changing routines
|
||||
like
|
||||
.Fn nl
|
||||
and
|
||||
.Fn cbreak
|
||||
should be called after
|
||||
.Fn initscr .
|
||||
.pp
|
||||
After the initial window allocation done by
|
||||
.Fn initscr ,
|
||||
specific window characteristics can be set.
|
||||
Scrolling can be enabled by calling
|
||||
.Fn scrollok .
|
||||
If you want the cursor to be left after the last change, use
|
||||
.Fn leaveok .
|
||||
If this isn't done,
|
||||
.Fn refresh
|
||||
will move the cursor to the window's current \*y after updating it.
|
||||
Additional windows can be created by using the functions
|
||||
.Fn newwin
|
||||
and
|
||||
.Fn subwin .
|
||||
.Fn delwin
|
||||
allows you to delete an existing window.
|
||||
The variables
|
||||
.Vn LINES
|
||||
and
|
||||
.Vn COLS
|
||||
control the size of the terminal.
|
||||
They are initially implicitly set by
|
||||
.Fn initscr ,
|
||||
but can be altered explicitly by the user followed by a call to
|
||||
.Fn initscr .
|
||||
Note that any call to
|
||||
.Fn initscr ,
|
||||
will always delete any existing
|
||||
.Vn stdscr
|
||||
and/or
|
||||
.Vn curscr
|
||||
before creating new ones so this change is best done before the initial call to
|
||||
.Fn initscr .
|
||||
.pp
|
||||
.sh 2 "Output"
|
||||
.pp
|
||||
The basic functions
|
||||
used to change what will go on a window are
|
||||
.Fn addch
|
||||
and
|
||||
.Fn move .
|
||||
.Fn addch
|
||||
adds a character at the current \*y,
|
||||
returning ERR if it would cause the window to illegally scroll,
|
||||
.i i.e. ,
|
||||
printing a character in the lower right-hand corner
|
||||
of a terminal which automatically scrolls
|
||||
if scrolling is not allowed.
|
||||
.Fn move
|
||||
changes the current \*y to whatever you want them to be.
|
||||
It returns ERR if you try to move off the window.
|
||||
As mentioned above, you can combine the two into
|
||||
.Fn mvaddch
|
||||
to do both things in one call.
|
||||
.pp
|
||||
The other output functions
|
||||
(such as
|
||||
.Fn addstr
|
||||
and
|
||||
.Fn printw )
|
||||
all call
|
||||
.Fn addch
|
||||
to add characters to the window.
|
||||
.pp
|
||||
After a change has been made to the window,
|
||||
you must call
|
||||
.Fn refresh .
|
||||
when you want the portion of the terminal covered by the window
|
||||
to reflect the change.
|
||||
In order to optimize finding changes,
|
||||
.Fn refresh
|
||||
assumes that any part of the window not changed
|
||||
since the last
|
||||
.Fn refresh
|
||||
of that window has not been changed on the terminal,
|
||||
.i i.e. ,
|
||||
that you have not refreshed a portion of the terminal
|
||||
with an overlapping window.
|
||||
If this is not the case,
|
||||
the routines
|
||||
.Fn touchwin ,
|
||||
.Fn touchline ,
|
||||
and
|
||||
.Fn touchoverlap
|
||||
are provided to make it look like a desired part of window has been changed,
|
||||
thus forcing
|
||||
.Fn refresh
|
||||
to check that whole subsection of the terminal for changes.
|
||||
.pp
|
||||
If you call
|
||||
.Fn wrefresh
|
||||
with
|
||||
.Vn curscr ,
|
||||
it will make the screen look like the image of
|
||||
.Vn curscr .
|
||||
This is useful for implementing a command
|
||||
which would redraw the screen in case it got messed up.
|
||||
.sh 2 Input
|
||||
.pp
|
||||
Input is essentially a mirror image of output.
|
||||
The complementary function to
|
||||
.Fn addch
|
||||
is
|
||||
.Fn getch
|
||||
which,
|
||||
if echo is set,
|
||||
will call
|
||||
.Fn addch
|
||||
to echo the character.
|
||||
Since the screen package needs to know what is on the terminal at all times,
|
||||
if characters are to be echoed,
|
||||
the tty must be in raw or cbreak mode.
|
||||
If it is not,
|
||||
.Fn getch
|
||||
sets it to be cbreak,
|
||||
and then reads in the character.
|
||||
.sh 2 "Termination"
|
||||
.pp
|
||||
In order to perform certain optimizations,
|
||||
and,
|
||||
on some terminals,
|
||||
to work at all,
|
||||
some things must be done
|
||||
before the screen routines start up.
|
||||
These functions are performed in
|
||||
.Fn getttmode
|
||||
and
|
||||
.Fn setterm ,
|
||||
which are called by
|
||||
.Fn initscr .
|
||||
In order to clean up after the routines,
|
||||
the routine
|
||||
.Fn endwin
|
||||
is provided.
|
||||
It restores tty modes to what they were
|
||||
when
|
||||
.Fn initscr
|
||||
was first called.
|
||||
The terminal state module uses the variable
|
||||
.Vn curses_termios
|
||||
to save the original terminal state which is then restored upon a call to
|
||||
.Fn endwin .
|
||||
Thus,
|
||||
anytime after the call to initscr,
|
||||
.Fn endwin
|
||||
should be called before exiting.
|
||||
Note however, that
|
||||
.Fn endwin
|
||||
should always be called
|
||||
.b before
|
||||
the final calls to
|
||||
.Fn delwin ,
|
||||
which free the storage of the windows.
|
||||
+67
@@ -0,0 +1,67 @@
|
||||
.\" $NetBSD: intro.4,v 1.5 2003/08/07 16:44:28 agc Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)intro.4 8.1 (Berkeley) 6/4/93
|
||||
.\"
|
||||
.sh 1 "Cursor Movement Optimizations"
|
||||
.pp
|
||||
One of the most difficult things to do properly is motion optimization.
|
||||
After using
|
||||
.Fn gettmode
|
||||
and
|
||||
.Fn setterm
|
||||
to get the terminal descriptions,
|
||||
the function
|
||||
.Fn mvcur
|
||||
deals with this task.
|
||||
It usage is simple:
|
||||
simply tell it where you are now and where you want to go.
|
||||
For example
|
||||
.(l
|
||||
mvcur(0\*,0\*,LINES/2\*,COLS/2);
|
||||
.)l
|
||||
.lp
|
||||
would move the cursor from the home position (0\*,0)
|
||||
to the middle of the screen.
|
||||
If you wish to force absolute addressing,
|
||||
you can use the function
|
||||
.Fn tgoto
|
||||
from the
|
||||
.b termlib (7)
|
||||
routines,
|
||||
or you can tell
|
||||
.Fn mvcur
|
||||
that you are impossibly far away,
|
||||
For example,
|
||||
to absolutely address the lower left hand corner of the screen
|
||||
from anywhere
|
||||
just claim that you are in the upper right hand corner:
|
||||
.(l
|
||||
mvcur(0\*,COLS\-1\*,LINES\-1\*,0);
|
||||
.)l
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
.\" $NetBSD: intro.5,v 1.8 2003/11/02 11:16:03 wiz Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)intro.5 8.1 (Berkeley) 6/4/93
|
||||
.\"
|
||||
.sh 1 "Character Output and Scrolling"
|
||||
.pp
|
||||
The character output policy deals with the following problems.
|
||||
First, where is the location of the cursor after a character is printed, and
|
||||
secondly, when does the screen scroll if scrolling is enabled.
|
||||
.pp
|
||||
In the normal case the characters are output as expected, with the cursor
|
||||
occupying the position of the next character to be output.
|
||||
However, when the
|
||||
cursor is on the last column of the line, the cursor will remain on that
|
||||
position after the last character on the line is output and will only assume
|
||||
the position on the next line when the next character (the first on the next
|
||||
line) is output.
|
||||
.pp
|
||||
Likewise, if scrolling is enabled, a scroll will be invoked only when the
|
||||
first character on he first line past the bottom line of the window is
|
||||
output.
|
||||
If scrolling is not enabled the chracters will to be output to the
|
||||
bottom right corner of the window which is the cursor location.
|
||||
.pp
|
||||
This policy allows consistent behavior of the cursor at the boundary
|
||||
conditions.
|
||||
Furthermore, it prevents a scroll from happening before it is
|
||||
actually needed (the old package used to scroll when the bottom right position
|
||||
was output a character).
|
||||
As a precedent, it models the
|
||||
.i xterm
|
||||
character output conventions.
|
||||
.sh 1 "Terminal State Handling"
|
||||
.pp
|
||||
The variable
|
||||
.Vn curses_termios
|
||||
contains the terminal state of the terminal.
|
||||
Certain historical routines return information:
|
||||
.Fn baudrate ,
|
||||
.Fn erasechar ,
|
||||
.Fn killchar ,
|
||||
and
|
||||
.Fn ospeed .
|
||||
These routines are obsolete and exist only for backward compatibility.
|
||||
If you wish to use the information in the
|
||||
.Vn curses_termios
|
||||
structure, you should use the
|
||||
\fItsetattr\fP(3)
|
||||
routines.
|
||||
.sh 1 "Subwindows"
|
||||
.pp
|
||||
Subwindows are windows which do not have an independent text structure,
|
||||
.i i.e. ,
|
||||
they are windows whose text is a subset of the text of a larger window: the
|
||||
.i parent
|
||||
window.
|
||||
One consequence of this is that changes to either the parent or the
|
||||
child window are destructive to the other,
|
||||
.i i.e. ,
|
||||
a change to the subwindow is also a change to the parent window and a change
|
||||
to the parent window in the region defined by the subwindow is implicitly a
|
||||
change to the subwindow as well.
|
||||
Apart from this detail, subwindows function like any other window.
|
||||
+44
@@ -0,0 +1,44 @@
|
||||
.\" $NetBSD: intro.6,v 1.6 2003/08/07 16:44:28 agc Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)intro.6 8.1 (Berkeley) 6/4/93
|
||||
.\"
|
||||
.sh 1 "The Functions"
|
||||
.pp
|
||||
In the following definitions,
|
||||
.q \*m
|
||||
means that if
|
||||
.Vn _CURSES_USE_MACROS
|
||||
is defined, the
|
||||
.q function
|
||||
is really a
|
||||
.q #define
|
||||
macro with arguments.
|
||||
.ta 11m 17m 25m 33m 41m 49m 57m 65m 73m
|
||||
.so fns.doc
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
.\" $NetBSD: life.c,v 1.6 2003/08/07 16:44:28 agc Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)life.c 8.1 (Berkeley) 6/8/93
|
||||
.\"
|
||||
# include <curses.h>
|
||||
# include <signal.h>
|
||||
|
||||
/*
|
||||
* Run a life game. This is a demonstration program for
|
||||
* the Screen Updating section of the -lcurses cursor package.
|
||||
*/
|
||||
|
||||
typedef struct lst_st { /* linked list element */
|
||||
int y, x; /* (y, x) position of piece */
|
||||
struct lst_st *next, *last; /* doubly linked */
|
||||
} LIST;
|
||||
|
||||
LIST *Head; /* head of linked list */
|
||||
|
||||
int die();
|
||||
|
||||
main(ac, av)
|
||||
int ac;
|
||||
char *av[];
|
||||
{
|
||||
evalargs(ac, av); /* evaluate arguments */
|
||||
|
||||
initscr(); /* initialize screen package */
|
||||
signal(SIGINT, die); /* set to restore tty stats */
|
||||
cbreak(); /* set for char-by-char */
|
||||
noecho(); /* input */
|
||||
nonl(); /* for optimization */
|
||||
|
||||
getstart(); /* get starting position */
|
||||
for (;;) {
|
||||
prboard(); /* print out current board */
|
||||
update(); /* update board position */
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This is the routine which is called when rubout is hit.
|
||||
* It resets the tty stats to their original values. This
|
||||
* is the normal way of leaving the program.
|
||||
*/
|
||||
die()
|
||||
{
|
||||
signal(SIGINT, SIG_IGN); /* ignore rubouts */
|
||||
mvcur(0, COLS - 1, LINES - 1, 0); /* go to bottom of screen */
|
||||
endwin(); /* set terminal to good state */
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the starting position from the user. They keys u, i, o, j, l,
|
||||
* m, ,, and . are used for moving their relative directions from the
|
||||
* k key. Thus, u move diagonally up to the left, , moves directly down,
|
||||
* etc. x places a piece at the current position, " " takes it away.
|
||||
* The input can also be from a file. The list is built after the
|
||||
* board setup is ready.
|
||||
*/
|
||||
getstart()
|
||||
{
|
||||
reg char c;
|
||||
reg int x, y;
|
||||
auto char buf[100];
|
||||
|
||||
box(stdscr, '|', '_'); /* box in the screen */
|
||||
move(1, 1); /* move to upper left corner */
|
||||
|
||||
for (;;) {
|
||||
refresh(); /* print current position */
|
||||
if ((c = getch()) == 'q')
|
||||
break;
|
||||
switch (c) {
|
||||
case 'u':
|
||||
case 'i':
|
||||
case 'o':
|
||||
case 'j':
|
||||
case 'l':
|
||||
case 'm':
|
||||
case ',':
|
||||
case '.':
|
||||
adjustyx(c);
|
||||
break;
|
||||
case 'f':
|
||||
mvaddstr(0, 0, "File name: ");
|
||||
getstr(buf);
|
||||
readfile(buf);
|
||||
break;
|
||||
case 'x':
|
||||
addch('X');
|
||||
break;
|
||||
case ' ':
|
||||
addch(' ');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (Head != NULL) /* start new list */
|
||||
dellist(Head);
|
||||
Head = malloc(sizeof (LIST));
|
||||
|
||||
/*
|
||||
* loop through the screen looking for 'x's, and add a list
|
||||
* element for each one
|
||||
*/
|
||||
for (y = 1; y < LINES - 1; y++)
|
||||
for (x = 1; x < COLS - 1; x++) {
|
||||
move(y, x);
|
||||
if (inch() == 'x')
|
||||
addlist(y, x);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Print out the current board position from the linked list
|
||||
*/
|
||||
prboard() {
|
||||
|
||||
reg LIST *hp;
|
||||
|
||||
erase(); /* clear out last position */
|
||||
box(stdscr, '|', '_'); /* box in the screen */
|
||||
|
||||
/*
|
||||
* go through the list adding each piece to the newly
|
||||
* blank board
|
||||
*/
|
||||
for (hp = Head; hp; hp = hp->next)
|
||||
mvaddch(hp->y, hp->x, 'X');
|
||||
|
||||
refresh();
|
||||
}
|
||||
+143
@@ -0,0 +1,143 @@
|
||||
.\" $NetBSD: macros,v 1.8 2004/04/27 02:15:04 uwe Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)macros 8.1 (Berkeley) 8/14/93
|
||||
.\"
|
||||
.\" this is the uncommented version. The commented one is in "macros.coms"
|
||||
.ie t .ds _ \d\(mi\u
|
||||
.el .ds _ _
|
||||
.ds , ,\ \" attention: trailing space
|
||||
.ds y (y\*,x) co-ordinates
|
||||
.ds db database
|
||||
.ie n .ds f \fI
|
||||
.el .ds f \fB
|
||||
.ds tc \*ftermcap\fP(5)
|
||||
.ds Es This returns ERR if it would cause the screen to scroll illegally.
|
||||
.ds Nm This has no associated \*(lq\fBmv\fP\*(rq command.
|
||||
.ie t .ds m \fB\s-2\(dg\s+2\fP
|
||||
.el .ds m [*]
|
||||
.\" .hy WINDOW
|
||||
.\".he ''\*(Ln''
|
||||
.\".fo ''\- % \-''
|
||||
.oh '\*(Ln''PS1:19-%'
|
||||
.eh 'PS1:19-%''\*(Ln'
|
||||
.de Un
|
||||
.b
|
||||
\s-2\\$2UNIX\\$1\s+2
|
||||
.ft
|
||||
..
|
||||
.de Ds
|
||||
.sp
|
||||
.lp
|
||||
.ev 1
|
||||
.nf
|
||||
.ft I
|
||||
.in 0
|
||||
.di
|
||||
.Df
|
||||
..
|
||||
.de De
|
||||
.di
|
||||
.Df
|
||||
.ne \n(dn+2
|
||||
.ev
|
||||
.ip
|
||||
..
|
||||
.de Dg
|
||||
.di
|
||||
.Df
|
||||
.ne \n(dn+2
|
||||
.ev
|
||||
..
|
||||
.de Fd
|
||||
.br
|
||||
\&\\$4
|
||||
.fi
|
||||
.b
|
||||
\&\\$1(\\$2)
|
||||
.ft
|
||||
\&\\$3
|
||||
.br
|
||||
.nf
|
||||
..
|
||||
.de Vn
|
||||
\&\\$3\c
|
||||
.i "\\$1" \\$2
|
||||
..
|
||||
.de Bq
|
||||
.ie t \&\*(lq\fB\\$1\fP\*(rq
|
||||
.el \&\*(lq\fI\\$1\fP\*(rq
|
||||
..
|
||||
.de $0
|
||||
.(x
|
||||
.in \\n(Xs
|
||||
\\*($n \\$1
|
||||
.)x
|
||||
..
|
||||
.de $1
|
||||
.nr Xs 0
|
||||
..
|
||||
.de $2
|
||||
.nr Xs 3
|
||||
..
|
||||
.de $3
|
||||
.nr Xs 6
|
||||
..
|
||||
.de Fn
|
||||
.if \\n(.$==0 .tm error
|
||||
.nr ll 0
|
||||
.nr dg 0
|
||||
.ft R
|
||||
.if '\\$\\n(.$'.' .nr ll 1
|
||||
.if '\\$\\n(.$',' .nr ll 1
|
||||
.if '\\$\\n(.$')' .nr ll 1
|
||||
.if '\\$\\n(.$').' .nr ll 1
|
||||
.if '\\$\\n(.$';' .nr ll 1
|
||||
.if '\\$\\n(.$':' .nr ll 1
|
||||
.if '\\$\\n(.$'\'s' .nr ll 1
|
||||
.if '\\$\\n(.$'\(dg' .nr ll 1
|
||||
.\" .if '\\$\\n(.$'' .nr ll 1
|
||||
.nr al \\n(.$-\\n(ll
|
||||
.ds ot \f(CB\\$1\fP(
|
||||
.if \\n(al>1 .as ot \fI\\$2\fP
|
||||
.if \\n(al>2 .as ot ", \fI\\$3\fP
|
||||
.if \\n(al>3 .as ot ", \fI\\$4\fP
|
||||
.if \\n(al>4 .as ot ", \fI\\$5\fP
|
||||
.if \\n(al>5 .as ot ", \fI\\$6\fP
|
||||
.if \\n(al>6 .as ot ", \fI\\$7\fP
|
||||
.if \\n(al>7 .as ot ", \fI\\$8\fP
|
||||
.if \\n(al>8 .as ot ", \fI\\$9\fP
|
||||
.as ot )
|
||||
.if \\n(.$>1 \{\
|
||||
. if \\n(ll==0 .as ot ;
|
||||
. if '\\$\\n(.$'\(dg' .as ot ;
|
||||
.\}
|
||||
.if \\n(ll==1 .as ot \\$\\n(.$
|
||||
\\*(ot
|
||||
..
|
||||
+161
@@ -0,0 +1,161 @@
|
||||
/* $NetBSD: twinkle1.c,v 1.6 2005/05/23 04:04:49 christos Exp $ */
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1980, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)twinkle1.c 8.1 (Berkeley) 6/8/93
|
||||
*/
|
||||
#include <curses.h>
|
||||
#include <signal.h>
|
||||
|
||||
/*
|
||||
* the idea for this program was a product of the imagination of
|
||||
* Kurt Schoens. Not responsible for minds lost or stolen.
|
||||
*/
|
||||
|
||||
#define NCOLS 80
|
||||
#define NLINES 24
|
||||
#define MAXPATTERNS 4
|
||||
|
||||
typedef struct {
|
||||
int y, x;
|
||||
} LOCS;
|
||||
|
||||
static LOCS Layout[NCOLS * NLINES]; /* current board layout */
|
||||
|
||||
static int Pattern, /* current pattern number */
|
||||
Numstars; /* number of stars in pattern */
|
||||
|
||||
static void puton(char);
|
||||
static void makeboard(void);
|
||||
static int ison(int, int);
|
||||
static void die(int);
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
srand(getpid()); /* initialize random sequence */
|
||||
|
||||
initscr();
|
||||
signal(SIGINT, die);
|
||||
noecho();
|
||||
nonl();
|
||||
leaveok(stdscr, TRUE);
|
||||
scrollok(stdscr, FALSE);
|
||||
|
||||
for (;;) {
|
||||
makeboard(); /* make the board setup */
|
||||
puton('*'); /* put on '*'s */
|
||||
puton(' '); /* cover up with ' 's */
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* On program exit, move the cursor to the lower left corner by
|
||||
* direct addressing, since current location is not guaranteed.
|
||||
* We lie and say we used to be at the upper right corner to guarantee
|
||||
* absolute addressing.
|
||||
*/
|
||||
static void
|
||||
die(int n)
|
||||
{
|
||||
signal(SIGINT, SIG_IGN);
|
||||
mvcur(0, COLS - 1, LINES - 1, 0);
|
||||
endwin();
|
||||
exit(n);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Make the current board setup. It picks a random pattern and
|
||||
* calls ison() to determine if the character is on that pattern
|
||||
* or not.
|
||||
*/
|
||||
static void
|
||||
makeboard(void)
|
||||
{
|
||||
int y, x;
|
||||
LOCS *lp;
|
||||
|
||||
Pattern = rand() % MAXPATTERNS;
|
||||
lp = Layout;
|
||||
for (y = 0; y < NLINES; y++)
|
||||
for (x = 0; x < NCOLS; x++)
|
||||
if (ison(y, x)) {
|
||||
lp->y = y;
|
||||
lp->x = x;
|
||||
lp++;
|
||||
}
|
||||
Numstars = lp - Layout;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return TRUE if (y, x) is on the current pattern.
|
||||
*/
|
||||
static int
|
||||
ison(int y, int x)
|
||||
{
|
||||
switch (Pattern) {
|
||||
case 0: /* alternating lines */
|
||||
return !(y & 01);
|
||||
case 1: /* box */
|
||||
if (x >= LINES && y >= NCOLS)
|
||||
return FALSE;
|
||||
if (y < 3 || y >= NLINES - 3)
|
||||
return TRUE;
|
||||
return (x < 3 || x >= NCOLS - 3);
|
||||
case 2: /* holy pattern! */
|
||||
return ((x + y) & 01);
|
||||
case 3: /* bar across center */
|
||||
return (y >= 9 && y <= 15);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
||||
static void
|
||||
puton(char ch)
|
||||
{
|
||||
LOCS *lp;
|
||||
int r;
|
||||
LOCS *end;
|
||||
LOCS temp;
|
||||
|
||||
end = &Layout[Numstars];
|
||||
for (lp = Layout; lp < end; lp++) {
|
||||
r = rand() % Numstars;
|
||||
temp = *lp;
|
||||
*lp = Layout[r];
|
||||
Layout[r] = temp;
|
||||
}
|
||||
|
||||
for (lp = Layout; lp < end; lp++) {
|
||||
mvaddch(lp->y, lp->x, ch);
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
+207
@@ -0,0 +1,207 @@
|
||||
/* $NetBSD: twinkle2.c,v 1.6 2005/05/23 04:04:49 christos Exp $ */
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (c) 1980, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#)twinkle2.c 8.1 (Berkeley) 6/8/93
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <curses.h>
|
||||
#include <signal.h>
|
||||
|
||||
#define NCOLS 80
|
||||
#define NLINES 24
|
||||
#define MAXPATTERNS 4
|
||||
|
||||
typedef struct {
|
||||
int y, x;
|
||||
} LOCS;
|
||||
|
||||
static LOCS Layout[NCOLS * NLINES]; /* current board layout */
|
||||
|
||||
static int Pattern, /* current pattern number */
|
||||
Numstars; /* number of stars in pattern */
|
||||
|
||||
static void puton(char);
|
||||
static void die(int);
|
||||
static void makeboard(void);
|
||||
static int ison(int, int);
|
||||
|
||||
static int AM;
|
||||
static char *VS;
|
||||
static char *TI;
|
||||
static char *CL;
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
char *sp;
|
||||
char buf[1024];
|
||||
char *ptr = buf;
|
||||
|
||||
srand(getpid()); /* initialize random sequence */
|
||||
|
||||
if (isatty(0)) {
|
||||
initscr();
|
||||
gettmode();
|
||||
if ((sp = getenv("TERM")) != NULL)
|
||||
setterm(sp);
|
||||
signal(SIGINT, die);
|
||||
}
|
||||
else {
|
||||
printf("Need a terminal on fd=%d\n", 0);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
tgetent(buf, sp);
|
||||
|
||||
AM = tgetflag("am");
|
||||
TI = tgetstr("ti", &ptr);
|
||||
if (TI == NULL) {
|
||||
printf("terminal does not have the ti capability\n");
|
||||
exit(1);
|
||||
}
|
||||
VS = tgetstr("vs", &ptr);
|
||||
if (VS == NULL) {
|
||||
printf("terminal does not have the vs capability\n");
|
||||
exit(1);
|
||||
}
|
||||
CL = tgetstr("cl", &ptr);
|
||||
if (CL == NULL) {
|
||||
printf("terminal does not have the cl capability\n");
|
||||
exit(1);
|
||||
}
|
||||
puts(TI);
|
||||
puts(VS);
|
||||
|
||||
noecho();
|
||||
nonl();
|
||||
tputs(CL, NLINES, putchar);
|
||||
for (;;) {
|
||||
makeboard(); /* make the board setup */
|
||||
puton('*'); /* put on '*'s */
|
||||
puton(' '); /* cover up with ' 's */
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* On program exit, move the cursor to the lower left corner by
|
||||
* direct addressing, since current location is not guaranteed.
|
||||
* We lie and say we used to be at the upper right corner to guarantee
|
||||
* absolute addressing.
|
||||
*/
|
||||
static void
|
||||
die(int n)
|
||||
{
|
||||
signal(SIGINT, SIG_IGN);
|
||||
mvcur(0, COLS - 1, LINES - 1, 0);
|
||||
endwin();
|
||||
exit(n);
|
||||
}
|
||||
|
||||
static void
|
||||
puton(char ch)
|
||||
{
|
||||
LOCS *lp;
|
||||
int r;
|
||||
LOCS *end;
|
||||
LOCS temp;
|
||||
static int lasty, lastx;
|
||||
|
||||
end = &Layout[Numstars];
|
||||
for (lp = Layout; lp < end; lp++) {
|
||||
r = rand() % Numstars;
|
||||
temp = *lp;
|
||||
*lp = Layout[r];
|
||||
Layout[r] = temp;
|
||||
}
|
||||
|
||||
for (lp = Layout; lp < end; lp++)
|
||||
/* prevent scrolling */
|
||||
if (!AM || (lp->y < NLINES - 1 || lp->x < NCOLS - 1)) {
|
||||
mvcur(lasty, lastx, lp->y, lp->x);
|
||||
putchar(ch);
|
||||
lasty = lp->y;
|
||||
if ((lastx = lp->x + 1) >= NCOLS)
|
||||
if (AM) {
|
||||
lastx = 0;
|
||||
lasty++;
|
||||
}
|
||||
else
|
||||
lastx = NCOLS - 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Make the current board setup. It picks a random pattern and
|
||||
* calls ison() to determine if the character is on that pattern
|
||||
* or not.
|
||||
*/
|
||||
static void
|
||||
makeboard(void)
|
||||
{
|
||||
int y, x;
|
||||
LOCS *lp;
|
||||
|
||||
Pattern = rand() % MAXPATTERNS;
|
||||
lp = Layout;
|
||||
for (y = 0; y < NLINES; y++)
|
||||
for (x = 0; x < NCOLS; x++)
|
||||
if (ison(y, x)) {
|
||||
lp->y = y;
|
||||
lp->x = x;
|
||||
lp++;
|
||||
}
|
||||
Numstars = lp - Layout;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return TRUE if (y, x) is on the current pattern.
|
||||
*/
|
||||
static int
|
||||
ison(int y, int x)
|
||||
{
|
||||
switch (Pattern) {
|
||||
case 0: /* alternating lines */
|
||||
return !(y & 01);
|
||||
case 1: /* box */
|
||||
if (x >= LINES && y >= NCOLS)
|
||||
return FALSE;
|
||||
if (y < 3 || y >= NLINES - 3)
|
||||
return TRUE;
|
||||
return (x < 3 || x >= NCOLS - 3);
|
||||
case 2: /* holy pattern! */
|
||||
return ((x + y) & 01);
|
||||
case 3: /* bar across center */
|
||||
return (y >= 9 && y <= 15);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
.\" $NetBSD: win_st.c,v 1.5 2003/08/07 16:44:29 agc Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1980, 1993
|
||||
.\" The Regents of the University of California. All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\" 3. Neither the name of the University nor the names of its contributors
|
||||
.\" may be used to endorse or promote products derived from this software
|
||||
.\" without specific prior written permission.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" @(#)win_st.c 8.1 (Berkeley) 6/8/93
|
||||
.\"
|
||||
# define WINDOW struct _win_st
|
||||
|
||||
struct _win_st {
|
||||
short _cury, _curx;
|
||||
short _maxy, _maxx;
|
||||
short _begy, _begx;
|
||||
short _flags;
|
||||
short _ch_off;
|
||||
bool _clear;
|
||||
bool _leave;
|
||||
bool _scroll;
|
||||
char **_y;
|
||||
short *_firstch;
|
||||
short *_lastch;
|
||||
struct _win_st *_nextp, *_orig;
|
||||
};
|
||||
|
||||
# define _ENDLINE 001
|
||||
# define _FULLWIN 002
|
||||
# define _SCROLLWIN 004
|
||||
# define _FLUSH 010
|
||||
# define _FULLLINE 020
|
||||
# define _IDLINE 040
|
||||
# define _STANDOUT 0200
|
||||
# define _NOCHANGE -1
|
||||
Vendored
+306
@@ -0,0 +1,306 @@
|
||||
/* $NetBSD: acs.c,v 1.21 2017/01/06 13:53:18 roy Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Julian Coleman.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "curses.h"
|
||||
#include "curses_private.h"
|
||||
#include <netbsd_sys/cdefs.h>
|
||||
#include "term.h"
|
||||
#include <string.h>
|
||||
chtype _acs_char[NUM_ACS];
|
||||
#ifdef HAVE_WCHAR
|
||||
#include <assert.h>
|
||||
#include <locale.h>
|
||||
#include <langinfo.h>
|
||||
#include <strings.h>
|
||||
|
||||
cchar_t _wacs_char[ NUM_ACS ];
|
||||
#endif /* HAVE_WCHAR */
|
||||
|
||||
/*
|
||||
* __init_acs --
|
||||
* Fill in the ACS characters. The 'acs_chars' terminfo entry is a list of
|
||||
* character pairs - ACS definition then terminal representation.
|
||||
*/
|
||||
void
|
||||
__init_acs(SCREEN *screen)
|
||||
{
|
||||
int count;
|
||||
const char *aofac; /* Address of 'ac' */
|
||||
unsigned char acs, term;
|
||||
|
||||
/* Default value '+' for all ACS characters */
|
||||
for (count=0; count < NUM_ACS; count++)
|
||||
_acs_char[count]= '+';
|
||||
|
||||
/* Add the SUSv2 defaults (those that are not '+') */
|
||||
ACS_RARROW = '>';
|
||||
ACS_LARROW = '<';
|
||||
ACS_UARROW = '^';
|
||||
ACS_DARROW = 'v';
|
||||
ACS_BLOCK = '#';
|
||||
/* ACS_DIAMOND = '+'; */
|
||||
ACS_CKBOARD = ':';
|
||||
ACS_DEGREE = 39; /* ' */
|
||||
ACS_PLMINUS = '#';
|
||||
ACS_BOARD = '#';
|
||||
ACS_LANTERN = '#';
|
||||
/* ACS_LRCORNER = '+'; */
|
||||
/* ACS_URCORNER = '+'; */
|
||||
/* ACS_ULCORNER = '+'; */
|
||||
/* ACS_LLCORNER = '+'; */
|
||||
/* ACS_PLUS = '+'; */
|
||||
ACS_HLINE = '-';
|
||||
ACS_S1 = '-';
|
||||
ACS_S9 = '_';
|
||||
/* ACS_LTEE = '+'; */
|
||||
/* ACS_RTEE = '+'; */
|
||||
/* ACS_BTEE = '+'; */
|
||||
/* ACS_TTEE = '+'; */
|
||||
ACS_VLINE = '|';
|
||||
ACS_BULLET = 'o';
|
||||
/* Add the extensions defaults */
|
||||
ACS_S3 = '-';
|
||||
ACS_S7 = '-';
|
||||
ACS_LEQUAL = '<';
|
||||
ACS_GEQUAL = '>';
|
||||
ACS_PI = '*';
|
||||
ACS_NEQUAL = '!';
|
||||
ACS_STERLING = 'f';
|
||||
|
||||
if (t_acs_chars(screen->term) == NULL)
|
||||
goto out;
|
||||
|
||||
aofac = t_acs_chars(screen->term);
|
||||
|
||||
while (*aofac != '\0') {
|
||||
if ((acs = *aofac) == '\0')
|
||||
return;
|
||||
if ((term = *++aofac) == '\0')
|
||||
return;
|
||||
/* Only add characters 1 to 127 */
|
||||
if (acs < NUM_ACS)
|
||||
_acs_char[acs] = term | __ALTCHARSET;
|
||||
aofac++;
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INIT, "__init_acs: %c = %c\n", acs, term);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (t_ena_acs(screen->term) != NULL)
|
||||
ti_puts(screen->term, t_ena_acs(screen->term), 0,
|
||||
__cputchar_args, screen->outfd);
|
||||
|
||||
out:
|
||||
for (count=0; count < NUM_ACS; count++)
|
||||
screen->acs_char[count]= _acs_char[count];
|
||||
}
|
||||
|
||||
void
|
||||
_cursesi_reset_acs(SCREEN *screen)
|
||||
{
|
||||
int count;
|
||||
|
||||
for (count=0; count < NUM_ACS; count++)
|
||||
_acs_char[count]= screen->acs_char[count];
|
||||
}
|
||||
|
||||
#ifdef HAVE_WCHAR
|
||||
/*
|
||||
* __init_wacs --
|
||||
* Fill in the ACS characters. The 'acs_chars' terminfo entry is a list of
|
||||
* character pairs - ACS definition then terminal representation.
|
||||
*/
|
||||
void
|
||||
__init_wacs(SCREEN *screen)
|
||||
{
|
||||
int count;
|
||||
const char *aofac; /* Address of 'ac' */
|
||||
unsigned char acs, term;
|
||||
char *lstr;
|
||||
|
||||
/* Default value '+' for all ACS characters */
|
||||
for (count=0; count < NUM_ACS; count++) {
|
||||
_wacs_char[ count ].vals[ 0 ] = ( wchar_t )btowc( '+' );
|
||||
_wacs_char[ count ].attributes = 0;
|
||||
_wacs_char[ count ].elements = 1;
|
||||
}
|
||||
|
||||
/* Add the SUSv2 defaults (those that are not '+') */
|
||||
if (!strcmp(setlocale(LC_CTYPE, NULL), "C"))
|
||||
setlocale(LC_CTYPE, "");
|
||||
lstr = nl_langinfo(CODESET);
|
||||
_DIAGASSERT(lstr);
|
||||
if (strcasecmp(lstr, "UTF-8")) {
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INIT, "__init_wacs: setting defaults\n" );
|
||||
#endif /* DEBUG */
|
||||
WACS_RARROW->vals[0] = ( wchar_t )btowc( '>' );
|
||||
WACS_LARROW->vals[0] = ( wchar_t )btowc( '<' );
|
||||
WACS_UARROW->vals[0] = ( wchar_t )btowc( '^' );
|
||||
WACS_DARROW->vals[0] = ( wchar_t )btowc( 'v' );
|
||||
WACS_BLOCK->vals[0] = ( wchar_t )btowc( '#' );
|
||||
WACS_CKBOARD->vals[0] = ( wchar_t )btowc( ':' );
|
||||
WACS_DEGREE->vals[0] = ( wchar_t )btowc( 39 ); /* ' */
|
||||
WACS_PLMINUS->vals[0] = ( wchar_t )btowc( '#' );
|
||||
WACS_BOARD->vals[0] = ( wchar_t )btowc( '#' );
|
||||
WACS_LANTERN->vals[0] = ( wchar_t )btowc( '#' );
|
||||
WACS_HLINE->vals[0] = ( wchar_t )btowc( '-' );
|
||||
WACS_S1->vals[0] = ( wchar_t )btowc( '-' );
|
||||
WACS_S9->vals[0] = ( wchar_t )btowc( '_' );
|
||||
WACS_VLINE->vals[0] = ( wchar_t )btowc( '|' );
|
||||
WACS_BULLET->vals[0] = ( wchar_t )btowc( 'o' );
|
||||
WACS_S3->vals[0] = ( wchar_t )btowc( 'p' );
|
||||
WACS_S7->vals[0] = ( wchar_t )btowc( 'r' );
|
||||
WACS_LEQUAL->vals[0] = ( wchar_t )btowc( 'y' );
|
||||
WACS_GEQUAL->vals[0] = ( wchar_t )btowc( 'z' );
|
||||
WACS_PI->vals[0] = ( wchar_t )btowc( '{' );
|
||||
WACS_NEQUAL->vals[0] = ( wchar_t )btowc( '|' );
|
||||
WACS_STERLING->vals[0]= ( wchar_t )btowc( '}' );
|
||||
} else {
|
||||
/* Unicode defaults */
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INIT,
|
||||
"__init_wacs: setting Unicode defaults\n" );
|
||||
#endif /* DEBUG */
|
||||
WACS_RARROW->vals[0] = 0x2192;
|
||||
ACS_RARROW = '+' | __ACS_IS_WACS;
|
||||
WACS_LARROW->vals[0] = 0x2190;
|
||||
ACS_LARROW = ',' | __ACS_IS_WACS;
|
||||
WACS_UARROW->vals[0] = 0x2191;
|
||||
ACS_UARROW = '-' | __ACS_IS_WACS;
|
||||
WACS_DARROW->vals[0] = 0x2193;
|
||||
ACS_DARROW = '.' | __ACS_IS_WACS;
|
||||
WACS_BLOCK->vals[0] = 0x25ae;
|
||||
ACS_BLOCK = '0' | __ACS_IS_WACS;
|
||||
WACS_DIAMOND->vals[0] = 0x25c6;
|
||||
ACS_DIAMOND = '`' | __ACS_IS_WACS;
|
||||
WACS_CKBOARD->vals[0] = 0x2592;
|
||||
ACS_CKBOARD = 'a' | __ACS_IS_WACS;
|
||||
WACS_DEGREE->vals[0] = 0x00b0;
|
||||
ACS_DEGREE = 'f' | __ACS_IS_WACS;
|
||||
WACS_PLMINUS->vals[0] = 0x00b1;
|
||||
ACS_PLMINUS = 'g' | __ACS_IS_WACS;
|
||||
WACS_BOARD->vals[0] = 0x2592;
|
||||
ACS_BOARD = 'h' | __ACS_IS_WACS;
|
||||
WACS_LANTERN->vals[0] = 0x2603;
|
||||
ACS_LANTERN = 'i' | __ACS_IS_WACS;
|
||||
WACS_LRCORNER->vals[0]= 0x2518;
|
||||
ACS_LRCORNER = 'j' | __ACS_IS_WACS;
|
||||
WACS_URCORNER->vals[0]= 0x2510;
|
||||
ACS_URCORNER = 'k' | __ACS_IS_WACS;
|
||||
WACS_ULCORNER->vals[0]= 0x250c;
|
||||
ACS_ULCORNER = 'l' | __ACS_IS_WACS;
|
||||
WACS_LLCORNER->vals[0]= 0x2514;
|
||||
ACS_LLCORNER = 'm' | __ACS_IS_WACS;
|
||||
WACS_PLUS->vals[0] = 0x253c;
|
||||
ACS_PLUS = 'n' | __ACS_IS_WACS;
|
||||
WACS_HLINE->vals[0] = 0x2500;
|
||||
ACS_HLINE = 'q' | __ACS_IS_WACS;
|
||||
WACS_S1->vals[0] = 0x23ba;
|
||||
ACS_S1 = 'o' | __ACS_IS_WACS;
|
||||
WACS_S9->vals[0] = 0x23bd;
|
||||
ACS_S9 = 's' | __ACS_IS_WACS;
|
||||
WACS_LTEE->vals[0] = 0x251c;
|
||||
ACS_LTEE = 't' | __ACS_IS_WACS;
|
||||
WACS_RTEE->vals[0] = 0x2524;
|
||||
ACS_RTEE = 'u' | __ACS_IS_WACS;
|
||||
WACS_BTEE->vals[0] = 0x2534;
|
||||
ACS_BTEE = 'v' | __ACS_IS_WACS;
|
||||
WACS_TTEE->vals[0] = 0x252c;
|
||||
ACS_TTEE = 'w' | __ACS_IS_WACS;
|
||||
WACS_VLINE->vals[0] = 0x2502;
|
||||
ACS_VLINE = 'x' | __ACS_IS_WACS;
|
||||
WACS_BULLET->vals[0] = 0x00b7;
|
||||
ACS_BULLET = '~' | __ACS_IS_WACS;
|
||||
WACS_S3->vals[0] = 0x23bb;
|
||||
ACS_S3 = 'p' | __ACS_IS_WACS;
|
||||
WACS_S7->vals[0] = 0x23bc;
|
||||
ACS_S7 = 'r' | __ACS_IS_WACS;
|
||||
WACS_LEQUAL->vals[0] = 0x2264;
|
||||
ACS_LEQUAL = 'y' | __ACS_IS_WACS;
|
||||
WACS_GEQUAL->vals[0] = 0x2265;
|
||||
ACS_GEQUAL = 'z' | __ACS_IS_WACS;
|
||||
WACS_PI->vals[0] = 0x03C0;
|
||||
ACS_PI = '{' | __ACS_IS_WACS;
|
||||
WACS_NEQUAL->vals[0] = 0x2260;
|
||||
ACS_NEQUAL = '|' | __ACS_IS_WACS;
|
||||
WACS_STERLING->vals[0]= 0x00A3;
|
||||
ACS_STERLING = '}' | __ACS_IS_WACS;
|
||||
}
|
||||
|
||||
if (t_acs_chars(screen->term) == NULL) {
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INIT,
|
||||
"__init_wacs: no alternative characters\n" );
|
||||
#endif /* DEBUG */
|
||||
goto out;
|
||||
}
|
||||
|
||||
aofac = t_acs_chars(screen->term);
|
||||
|
||||
while (*aofac != '\0') {
|
||||
if ((acs = *aofac) == '\0')
|
||||
return;
|
||||
if ((term = *++aofac) == '\0')
|
||||
return;
|
||||
/* Only add characters 1 to 127 */
|
||||
if (acs < NUM_ACS) {
|
||||
_wacs_char[acs].vals[ 0 ] = term;
|
||||
_wacs_char[acs].attributes |= WA_ALTCHARSET;
|
||||
}
|
||||
aofac++;
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INIT, "__init_wacs: %c = %c\n", acs, term);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (t_ena_acs(screen->term) != NULL)
|
||||
ti_puts(screen->term, t_ena_acs(screen->term), 0,
|
||||
__cputchar_args, screen->outfd);
|
||||
|
||||
out:
|
||||
for (count=0; count < NUM_ACS; count++) {
|
||||
memcpy(&screen->wacs_char[count], &_wacs_char[count],
|
||||
sizeof(cchar_t));
|
||||
screen->acs_char[count]= _acs_char[count];
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_cursesi_reset_wacs(SCREEN *screen)
|
||||
{
|
||||
int count;
|
||||
|
||||
for (count=0; count < NUM_ACS; count++)
|
||||
memcpy( &_wacs_char[count], &screen->wacs_char[count],
|
||||
sizeof( cchar_t ));
|
||||
}
|
||||
#endif /* HAVE_WCHAR */
|
||||
+107
@@ -0,0 +1,107 @@
|
||||
/* $NetBSD: add_wch.c,v 1.9 2019/06/09 07:40:14 blymn Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2005 The NetBSD Foundation Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from code donated to the NetBSD Foundation
|
||||
* by Ruibiao Qiu <ruibiao@arl.wustl.edu,ruibiao@gmail.com>.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
|
||||
* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <netbsd_sys/cdefs.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "curses.h"
|
||||
#include "curses_private.h"
|
||||
#ifdef DEBUG
|
||||
#include <assert.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* add_wch --
|
||||
* Add the wide character to the current position in stdscr.
|
||||
*
|
||||
*/
|
||||
int
|
||||
add_wch(const cchar_t *wch)
|
||||
{
|
||||
return wadd_wch(stdscr, wch);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* mvadd_wch --
|
||||
* Add the wide character to stdscr at the given location.
|
||||
*/
|
||||
int
|
||||
mvadd_wch(int y, int x, const cchar_t *wch)
|
||||
{
|
||||
return mvwadd_wch(stdscr, y, x, wch);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* mvwadd_wch --
|
||||
* Add the character to the given window at the given location.
|
||||
*/
|
||||
int
|
||||
mvwadd_wch(WINDOW *win, int y, int x, const cchar_t *wch)
|
||||
{
|
||||
if (wmove(win, y, x) == ERR)
|
||||
return ERR;
|
||||
|
||||
return wadd_wch(win, wch);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* wadd_wch --
|
||||
* Add the wide character to the current position in the
|
||||
* given window.
|
||||
*
|
||||
*/
|
||||
int
|
||||
wadd_wch(WINDOW *win, const cchar_t *wch)
|
||||
{
|
||||
int y = win->cury;
|
||||
__LINE *lnp = NULL;
|
||||
|
||||
#ifdef DEBUG
|
||||
int i;
|
||||
int x = win->curx;
|
||||
|
||||
for (i = 0; i < win->maxy; i++) {
|
||||
assert(win->alines[i]->sentinel == SENTINEL_VALUE);
|
||||
}
|
||||
__CTRACE(__CTRACE_INPUT, "wadd_wch: win(%p), x: %d, y: %d\n",
|
||||
win, x, y);
|
||||
#endif
|
||||
lnp = win->alines[y];
|
||||
return _cursesi_addwchar(win, &lnp, &(win->cury), &(win->curx), wch, 1);
|
||||
}
|
||||
+304
@@ -0,0 +1,304 @@
|
||||
/* $NetBSD: add_wchstr.c,v 1.8 2019/06/09 07:40:14 blymn Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2005 The NetBSD Foundation Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from code donated to the NetBSD Foundation
|
||||
* by Ruibiao Qiu <ruibiao@arl.wustl.edu,ruibiao@gmail.com>.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
|
||||
* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 700
|
||||
#include <netbsd_sys/cdefs.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "curses.h"
|
||||
#include "curses_private.h"
|
||||
|
||||
/*
|
||||
* add_wchstr --
|
||||
* Add a wide string to stdscr starting at (_cury, _curx).
|
||||
*/
|
||||
int
|
||||
add_wchstr(const cchar_t *wchstr)
|
||||
{
|
||||
return wadd_wchnstr(stdscr, wchstr, -1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* wadd_wchstr --
|
||||
* Add a string to the given window starting at (_cury, _curx).
|
||||
*/
|
||||
int
|
||||
wadd_wchstr(WINDOW *win, const cchar_t *wchstr)
|
||||
{
|
||||
return wadd_wchnstr(win, wchstr, -1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* add_wchnstr --
|
||||
* Add a string (at most n characters) to stdscr starting
|
||||
* at (_cury, _curx). If n is negative, add the entire string.
|
||||
*/
|
||||
int
|
||||
add_wchnstr(const cchar_t *wchstr, int n)
|
||||
{
|
||||
return wadd_wchnstr(stdscr, wchstr, n);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* mvadd_wchstr --
|
||||
* Add a string to stdscr starting at (y, x)
|
||||
*/
|
||||
int
|
||||
mvadd_wchstr(int y, int x, const cchar_t *wchstr)
|
||||
{
|
||||
return mvwadd_wchnstr(stdscr, y, x, wchstr, -1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* mvwadd_wchstr --
|
||||
* Add a string to the given window starting at (y, x)
|
||||
*/
|
||||
int
|
||||
mvwadd_wchstr(WINDOW *win, int y, int x, const cchar_t *wchstr)
|
||||
{
|
||||
return mvwadd_wchnstr(win, y, x, wchstr, -1);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* mvadd_wchnstr --
|
||||
* Add a string of at most n characters to stdscr
|
||||
* starting at (y, x).
|
||||
*/
|
||||
int
|
||||
mvadd_wchnstr(int y, int x, const cchar_t *wchstr, int n)
|
||||
{
|
||||
return mvwadd_wchnstr(stdscr, y, x, wchstr, n);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* mvwadd_wchnstr --
|
||||
* Add a string of at most n characters to the given window
|
||||
* starting at (y, x).
|
||||
*/
|
||||
int
|
||||
mvwadd_wchnstr(WINDOW *win, int y, int x, const cchar_t *wchstr, int n)
|
||||
{
|
||||
if (wmove(win, y, x) == ERR)
|
||||
return ERR;
|
||||
|
||||
return wadd_wchnstr(win, wchstr, n);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* wadd_wchnstr --
|
||||
* Add a string (at most n wide characters) to the given window
|
||||
* starting at (_cury, _curx). If n is -1, add the entire string.
|
||||
*/
|
||||
int
|
||||
wadd_wchnstr(WINDOW *win, const cchar_t *wchstr, int n)
|
||||
{
|
||||
const cchar_t *chp;
|
||||
wchar_t wc;
|
||||
int cw, x, y, sx, ex, newx, i, cnt;
|
||||
__LDATA *lp, *tp;
|
||||
nschar_t *np, *tnp;
|
||||
__LINE *lnp;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT,
|
||||
"wadd_wchnstr: win = %p, wchstr = %p, n = %d\n", win, wchstr, n);
|
||||
#endif
|
||||
|
||||
if (!wchstr)
|
||||
return OK;
|
||||
|
||||
/* compute length of the cchar string */
|
||||
if (n < -1)
|
||||
return ERR;
|
||||
if (n >= 0)
|
||||
for (chp = wchstr, cnt = 0; n && chp->vals[0];
|
||||
n--, chp++, ++cnt);
|
||||
else
|
||||
for (chp = wchstr, cnt = 0; chp->vals[0]; chp++, ++cnt);
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT, "wadd_wchnstr: len=%d\n", cnt);
|
||||
#endif /* DEBUG */
|
||||
chp = wchstr;
|
||||
x = win->curx;
|
||||
y = win->cury;
|
||||
lp = &win->alines[y]->line[x];
|
||||
lnp = win->alines[y];
|
||||
|
||||
cw = WCOL(*lp);
|
||||
if (cw >= 0) {
|
||||
sx = x;
|
||||
} else {
|
||||
if (wcwidth(chp->vals[0])) {
|
||||
/* clear the partial character before cursor */
|
||||
for (tp = lp + cw; tp < lp; tp++) {
|
||||
tp->ch = (wchar_t) btowc((int) win->bch);
|
||||
if (_cursesi_copy_nsp(win->bnsp, tp) == ERR)
|
||||
return ERR;
|
||||
tp->attr = win->battr;
|
||||
SET_WCOL(*tp, 1);
|
||||
np = tp->nsp;
|
||||
}
|
||||
} else {
|
||||
/* move to the start of current char */
|
||||
lp += cw;
|
||||
x += cw;
|
||||
}
|
||||
sx = x + cw;
|
||||
}
|
||||
lnp->flags |= __ISDIRTY;
|
||||
newx = sx + win->ch_off;
|
||||
if (newx < *lnp->firstchp)
|
||||
*lnp->firstchp = newx;
|
||||
|
||||
/* add characters in the string */
|
||||
ex = x;
|
||||
while (cnt) {
|
||||
x = ex;
|
||||
wc = chp->vals[0];
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT, "wadd_wchnstr: adding %x", wc);
|
||||
#endif /* DEBUG */
|
||||
cw = wcwidth(wc);
|
||||
if (cw < 0)
|
||||
cw = 1;
|
||||
if (cw) {
|
||||
/* spacing character */
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT,
|
||||
" as a spacing char(width=%d)\n", cw);
|
||||
#endif /* DEBUG */
|
||||
if (cw > win->maxx - ex) {
|
||||
/* clear to EOL */
|
||||
while (ex < win->maxx) {
|
||||
lp->ch = (wchar_t)
|
||||
btowc((int) win->bch);
|
||||
if (_cursesi_copy_nsp(win->bnsp, lp)
|
||||
== ERR)
|
||||
return ERR;
|
||||
lp->attr = win->battr;
|
||||
SET_WCOL(*lp, 1);
|
||||
lp++, ex++;
|
||||
}
|
||||
ex = win->maxx - 1;
|
||||
break;
|
||||
}
|
||||
/* this could combine with the insertion of
|
||||
* non-spacing char */
|
||||
np = lp->nsp;
|
||||
if (np) {
|
||||
while (np) {
|
||||
tnp = np->next;
|
||||
free(np);
|
||||
np = tnp;
|
||||
}
|
||||
lp->nsp = NULL;
|
||||
}
|
||||
lp->ch = chp->vals[0];
|
||||
lp->attr = chp->attributes & WA_ATTRIBUTES;
|
||||
SET_WCOL(*lp, cw);
|
||||
if (chp->elements > 1) {
|
||||
for (i = 1; i < chp->elements; i++) {
|
||||
np = (nschar_t *)
|
||||
malloc(sizeof(nschar_t));
|
||||
if (!np)
|
||||
return ERR;
|
||||
np->ch = chp->vals[i];
|
||||
np->next = lp->nsp;
|
||||
lp->nsp = np;
|
||||
}
|
||||
}
|
||||
lp++, ex++;
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT,
|
||||
"wadd_wchnstr: ex = %d, x = %d, cw = %d\n",
|
||||
ex, x, cw);
|
||||
#endif /* DEBUG */
|
||||
while (ex - x <= cw - 1) {
|
||||
np = lp->nsp;
|
||||
if (np) {
|
||||
while (np) {
|
||||
tnp = np->next;
|
||||
free(np);
|
||||
np = tnp;
|
||||
}
|
||||
lp->nsp = NULL;
|
||||
}
|
||||
lp->ch = chp->vals[0];
|
||||
lp->attr = chp->attributes & WA_ATTRIBUTES;
|
||||
SET_WCOL(*lp, x - ex);
|
||||
lp++, ex++;
|
||||
}
|
||||
} else {
|
||||
/* non-spacing character */
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT,
|
||||
"wadd_wchnstr: as non-spacing char");
|
||||
#endif /* DEBUG */
|
||||
for (i = 0; i < chp->elements; i++) {
|
||||
np = malloc(sizeof(nschar_t));
|
||||
if (!np)
|
||||
return ERR;
|
||||
np->ch = chp->vals[i];
|
||||
np->next = lp->nsp;
|
||||
lp->nsp = np;
|
||||
}
|
||||
}
|
||||
cnt--, chp++;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
for (i = sx; i < ex; i++) {
|
||||
__CTRACE(__CTRACE_INPUT, "wadd_wchnstr: (%d,%d)=(%x,%x,%p)\n",
|
||||
win->cury, i, win->alines[win->cury]->line[i].ch,
|
||||
win->alines[win->cury]->line[i].attr,
|
||||
win->alines[win->cury]->line[i].nsp);
|
||||
}
|
||||
#endif /* DEBUG */
|
||||
lnp->flags |= __ISDIRTY;
|
||||
newx = ex + win->ch_off;
|
||||
if (newx > *lnp->lastchp)
|
||||
*lnp->lastchp = newx;
|
||||
__touchline(win, y, sx, ex);
|
||||
|
||||
return OK;
|
||||
}
|
||||
+598
@@ -0,0 +1,598 @@
|
||||
/* $NetBSD: addbytes.c,v 1.54 2021/02/13 14:30:37 rillig Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1987, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 700
|
||||
#include <netbsd_sys/cdefs.h>
|
||||
|
||||
#include <wchar.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "curses.h"
|
||||
#include "curses_private.h"
|
||||
#ifdef DEBUG
|
||||
#include <assert.h>
|
||||
#endif
|
||||
|
||||
#ifndef _CURSES_USE_MACROS
|
||||
|
||||
/*
|
||||
* addbytes --
|
||||
* Add the characters to the current position in stdscr.
|
||||
*/
|
||||
int
|
||||
addbytes(const char *bytes, int count)
|
||||
{
|
||||
|
||||
return _cursesi_waddbytes(stdscr, bytes, count, 0, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* waddbytes --
|
||||
* Add the characters to the current position in the given window.
|
||||
*/
|
||||
int
|
||||
waddbytes(WINDOW *win, const char *bytes, int count)
|
||||
{
|
||||
|
||||
return _cursesi_waddbytes(win, bytes, count, 0, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* mvaddbytes --
|
||||
* Add the characters to stdscr at the location given.
|
||||
*/
|
||||
int
|
||||
mvaddbytes(int y, int x, const char *bytes, int count)
|
||||
{
|
||||
|
||||
return mvwaddbytes(stdscr, y, x, bytes, count);
|
||||
}
|
||||
|
||||
/*
|
||||
* mvwaddbytes --
|
||||
* Add the characters to the given window at the location given.
|
||||
*/
|
||||
int
|
||||
mvwaddbytes(WINDOW *win, int y, int x, const char *bytes, int count)
|
||||
{
|
||||
|
||||
if (wmove(win, y, x) == ERR)
|
||||
return ERR;
|
||||
|
||||
return _cursesi_waddbytes(win, bytes, count, 0, 1);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int
|
||||
__waddbytes(WINDOW *win, const char *bytes, int count, attr_t attr)
|
||||
{
|
||||
|
||||
return _cursesi_waddbytes(win, bytes, count, attr, 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* _cursesi_waddbytes --
|
||||
* Add the characters to the current position in the given window.
|
||||
* if char_interp is non-zero then character interpretation is done on
|
||||
* the byte (i.e. \n to newline, \r to carriage return, \b to backspace
|
||||
* and so on).
|
||||
*/
|
||||
int
|
||||
_cursesi_waddbytes(WINDOW *win, const char *bytes, int count, attr_t attr,
|
||||
int char_interp)
|
||||
{
|
||||
int *py = &win->cury, *px = &win->curx, err;
|
||||
__LINE *lp;
|
||||
#ifdef HAVE_WCHAR
|
||||
int n;
|
||||
cchar_t cc;
|
||||
wchar_t wc;
|
||||
mbstate_t st;
|
||||
#else
|
||||
int c;
|
||||
#endif
|
||||
#ifdef DEBUG
|
||||
int i;
|
||||
|
||||
for (i = 0; i < win->maxy; i++) {
|
||||
assert(win->alines[i]->sentinel == SENTINEL_VALUE);
|
||||
}
|
||||
|
||||
__CTRACE(__CTRACE_INPUT, "ADDBYTES: add %d bytes\n", count);
|
||||
#endif
|
||||
|
||||
err = OK;
|
||||
lp = win->alines[*py];
|
||||
|
||||
#ifdef HAVE_WCHAR
|
||||
(void)memset(&st, 0, sizeof(st));
|
||||
#endif
|
||||
while (count > 0) {
|
||||
#ifndef HAVE_WCHAR
|
||||
c = *bytes++;
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT, "ADDBYTES('%c', %x) at (%d, %d)\n",
|
||||
c, attr, *py, *px);
|
||||
#endif
|
||||
err = _cursesi_addbyte(win, &lp, py, px, c, attr, char_interp);
|
||||
count--;
|
||||
#else
|
||||
/*
|
||||
* For wide-character support only, try to convert the
|
||||
* given string into a wide character - we do this because
|
||||
* this is how ncurses behaves (not that I think this is
|
||||
* actually the correct thing to do but if we don't do it
|
||||
* a lot of things that rely on this behaviour will break
|
||||
* and we will be blamed). If the conversion succeeds
|
||||
* then we eat the n characters used to make the wide char
|
||||
* from the string.
|
||||
*/
|
||||
n = (int)mbrtowc(&wc, bytes, (size_t)count, &st);
|
||||
if (n < 0) {
|
||||
/* not a valid conversion just eat a char */
|
||||
wc = *bytes;
|
||||
n = 1;
|
||||
(void)memset(&st, 0, sizeof(st));
|
||||
} else if (wc == 0) {
|
||||
break;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT,
|
||||
"ADDBYTES WIDE(0x%x [%s], %x) at (%d, %d), ate %d bytes\n",
|
||||
(unsigned)wc, unctrl((unsigned)wc), attr, *py, *px, n);
|
||||
#endif
|
||||
cc.vals[0] = wc;
|
||||
cc.elements = 1;
|
||||
cc.attributes = attr;
|
||||
err = _cursesi_addwchar(win, &lp, py, px, &cc, char_interp);
|
||||
bytes += n;
|
||||
count -= n;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
for (i = 0; i < win->maxy; i++) {
|
||||
assert(win->alines[i]->sentinel == SENTINEL_VALUE);
|
||||
}
|
||||
#endif
|
||||
|
||||
return (err);
|
||||
}
|
||||
|
||||
/*
|
||||
* _cursesi_addbyte -
|
||||
* Internal function to add a byte and update the row and column
|
||||
* positions as appropriate. If char_interp is non-zero then
|
||||
* character interpretation is done on the byte. This function is
|
||||
* only used in the narrow character version of curses.
|
||||
*/
|
||||
int
|
||||
_cursesi_addbyte(WINDOW *win, __LINE **lp, int *y, int *x, int c,
|
||||
attr_t attr, int char_interp)
|
||||
{
|
||||
static char blank[] = " ";
|
||||
int tabsize;
|
||||
int newx, i;
|
||||
attr_t attributes;
|
||||
|
||||
if (char_interp) {
|
||||
switch (c) {
|
||||
case '\t':
|
||||
tabsize = win->screen->TABSIZE;
|
||||
newx = tabsize - (*x % tabsize);
|
||||
for (i = 0; i < newx; i++) {
|
||||
if (waddbytes(win, blank, 1) == ERR)
|
||||
return ERR;
|
||||
}
|
||||
return OK;
|
||||
|
||||
case '\n':
|
||||
wclrtoeol(win);
|
||||
(*lp)->flags |= __ISPASTEOL;
|
||||
break;
|
||||
|
||||
case '\r':
|
||||
*x = 0;
|
||||
return OK;
|
||||
|
||||
case '\b':
|
||||
if (--(*x) < 0)
|
||||
*x = 0;
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT, "ADDBYTES(%p, %d, %d)\n", win, *y, *x);
|
||||
#endif
|
||||
|
||||
if (char_interp && ((*lp)->flags & __ISPASTEOL)) {
|
||||
*x = 0;
|
||||
(*lp)->flags &= ~__ISPASTEOL;
|
||||
if (*y == win->scr_b) {
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT,
|
||||
"ADDBYTES - on bottom "
|
||||
"of scrolling region\n");
|
||||
#endif
|
||||
if (!(win->flags & __SCROLLOK))
|
||||
return ERR;
|
||||
scroll(win);
|
||||
} else {
|
||||
(*y)++;
|
||||
}
|
||||
*lp = win->alines[*y];
|
||||
if (c == '\n')
|
||||
return OK;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT,
|
||||
"ADDBYTES: 1: y = %d, x = %d, firstch = %d, lastch = %d\n",
|
||||
*y, *x, *win->alines[*y]->firstchp,
|
||||
*win->alines[*y]->lastchp);
|
||||
#endif
|
||||
|
||||
attributes = (win->wattr | attr) & (__ATTRIBUTES & ~__COLOR);
|
||||
if (attr & __COLOR)
|
||||
attributes |= attr & __COLOR;
|
||||
else if (win->wattr & __COLOR)
|
||||
attributes |= win->wattr & __COLOR;
|
||||
|
||||
/*
|
||||
* Always update the change pointers. Otherwise,
|
||||
* we could end up not displaying 'blank' characters
|
||||
* when overlapping windows are displayed.
|
||||
*/
|
||||
newx = *x + win->ch_off;
|
||||
(*lp)->flags |= __ISDIRTY;
|
||||
/*
|
||||
* firstchp/lastchp are shared between
|
||||
* parent window and sub-window.
|
||||
*/
|
||||
if (newx < *(*lp)->firstchp)
|
||||
*(*lp)->firstchp = newx;
|
||||
if (newx > *(*lp)->lastchp)
|
||||
*(*lp)->lastchp = newx;
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT, "ADDBYTES: change gives f/l: %d/%d [%d/%d]\n",
|
||||
*(*lp)->firstchp, *(*lp)->lastchp,
|
||||
*(*lp)->firstchp - win->ch_off,
|
||||
*(*lp)->lastchp - win->ch_off);
|
||||
#endif
|
||||
if (win->bch != ' ' && c == ' ')
|
||||
(*lp)->line[*x].ch = win->bch;
|
||||
else
|
||||
(*lp)->line[*x].ch = c;
|
||||
|
||||
if (attributes & __COLOR)
|
||||
(*lp)->line[*x].attr =
|
||||
attributes | (win->battr & ~__COLOR);
|
||||
else
|
||||
(*lp)->line[*x].attr = attributes | win->battr;
|
||||
|
||||
if (*x == win->maxx - 1)
|
||||
(*lp)->flags |= __ISPASTEOL;
|
||||
else
|
||||
(*x)++;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT,
|
||||
"ADDBYTES: 2: y = %d, x = %d, firstch = %d, lastch = %d\n",
|
||||
*y, *x, *win->alines[*y]->firstchp,
|
||||
*win->alines[*y]->lastchp);
|
||||
#endif
|
||||
__sync(win);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* _cursesi_addwchar -
|
||||
* Internal function to add a wide character and update the row
|
||||
* and column positions.
|
||||
*/
|
||||
int
|
||||
_cursesi_addwchar(WINDOW *win, __LINE **lnp, int *y, int *x,
|
||||
const cchar_t *wch, int char_interp)
|
||||
{
|
||||
#ifndef HAVE_WCHAR
|
||||
return ERR;
|
||||
#else
|
||||
int sx = 0, ex = 0, cw = 0, i = 0, newx = 0, tabsize;
|
||||
__LDATA *lp = &win->alines[*y]->line[*x], *tp = NULL;
|
||||
nschar_t *np = NULL;
|
||||
cchar_t cc;
|
||||
attr_t attributes;
|
||||
|
||||
if (char_interp) {
|
||||
/* special characters handling */
|
||||
switch (wch->vals[0]) {
|
||||
case L'\b':
|
||||
if (--*x < 0)
|
||||
*x = 0;
|
||||
return OK;
|
||||
case L'\r':
|
||||
*x = 0;
|
||||
return OK;
|
||||
case L'\n':
|
||||
wclrtoeol(win);
|
||||
*x = 0;
|
||||
(*lnp)->flags &= ~__ISPASTEOL;
|
||||
if (*y == win->scr_b) {
|
||||
if (!(win->flags & __SCROLLOK))
|
||||
return ERR;
|
||||
scroll(win);
|
||||
} else {
|
||||
(*y)++;
|
||||
}
|
||||
return OK;
|
||||
case L'\t':
|
||||
cc.vals[0] = L' ';
|
||||
cc.elements = 1;
|
||||
cc.attributes = win->wattr;
|
||||
tabsize = win->screen->TABSIZE;
|
||||
newx = tabsize - (*x % tabsize);
|
||||
for (i = 0; i < newx; i++) {
|
||||
if (wadd_wch(win, &cc) == ERR)
|
||||
return ERR;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
}
|
||||
|
||||
/* check for non-spacing character */
|
||||
if (!wcwidth(wch->vals[0])) {
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT,
|
||||
"_cursesi_addwchar: char '%c' is non-spacing\n",
|
||||
wch->vals[0]);
|
||||
#endif /* DEBUG */
|
||||
cw = WCOL(*lp);
|
||||
if (cw < 0) {
|
||||
lp += cw;
|
||||
*x += cw;
|
||||
}
|
||||
for (i = 0; i < wch->elements; i++) {
|
||||
if (!(np = (nschar_t *) malloc(sizeof(nschar_t))))
|
||||
return ERR;;
|
||||
np->ch = wch->vals[i];
|
||||
np->next = lp->nsp;
|
||||
lp->nsp = np;
|
||||
}
|
||||
(*lnp)->flags |= __ISDIRTY;
|
||||
newx = *x + win->ch_off;
|
||||
if (newx < *(*lnp)->firstchp)
|
||||
*(*lnp)->firstchp = newx;
|
||||
if (newx > *(*lnp)->lastchp)
|
||||
*(*lnp)->lastchp = newx;
|
||||
__touchline(win, *y, *x, *x);
|
||||
return OK;
|
||||
}
|
||||
/* check for new line first */
|
||||
if (char_interp && ((*lnp)->flags & __ISPASTEOL)) {
|
||||
*x = 0;
|
||||
(*lnp)->flags &= ~__ISPASTEOL;
|
||||
if (*y == win->scr_b) {
|
||||
if (!(win->flags & __SCROLLOK))
|
||||
return ERR;
|
||||
scroll(win);
|
||||
} else {
|
||||
(*y)++;
|
||||
}
|
||||
(*lnp) = win->alines[*y];
|
||||
lp = &win->alines[*y]->line[*x];
|
||||
}
|
||||
/* clear out the current character */
|
||||
cw = WCOL(*lp);
|
||||
if (cw >= 0) {
|
||||
sx = *x;
|
||||
} else {
|
||||
for (sx = *x - 1; sx >= max(*x + cw, 0); sx--) {
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT,
|
||||
"_cursesi_addwchar: clear current char (%d,%d)\n",
|
||||
*y, sx);
|
||||
#endif /* DEBUG */
|
||||
tp = &win->alines[*y]->line[sx];
|
||||
tp->ch = (wchar_t) btowc((int) win->bch);
|
||||
if (_cursesi_copy_nsp(win->bnsp, tp) == ERR)
|
||||
return ERR;
|
||||
|
||||
tp->attr = win->battr;
|
||||
SET_WCOL(*tp, 1);
|
||||
}
|
||||
sx = *x + cw;
|
||||
(*lnp)->flags |= __ISDIRTY;
|
||||
newx = sx + win->ch_off;
|
||||
if (newx < *(*lnp)->firstchp)
|
||||
*(*lnp)->firstchp = newx;
|
||||
}
|
||||
|
||||
/* check for enough space before the end of line */
|
||||
cw = wcwidth(wch->vals[0]);
|
||||
if (cw < 0)
|
||||
cw = 1;
|
||||
|
||||
if (cw > win->maxx - *x) {
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT,
|
||||
"_cursesi_addwchar: clear EOL (%d,%d)\n",
|
||||
*y, *x);
|
||||
#endif /* DEBUG */
|
||||
(*lnp)->flags |= __ISDIRTY;
|
||||
newx = *x + win->ch_off;
|
||||
if (newx < *(*lnp)->firstchp)
|
||||
*(*lnp)->firstchp = newx;
|
||||
for (tp = lp; *x < win->maxx; tp++, (*x)++) {
|
||||
tp->ch = (wchar_t) btowc((int) win->bch);
|
||||
if (_cursesi_copy_nsp(win->bnsp, tp) == ERR)
|
||||
return ERR;
|
||||
tp->attr = win->battr;
|
||||
SET_WCOL(*tp, 1);
|
||||
}
|
||||
newx = win->maxx - 1 + win->ch_off;
|
||||
if (newx > *(*lnp)->lastchp)
|
||||
*(*lnp)->lastchp = newx;
|
||||
__touchline(win, *y, sx, (int) win->maxx - 1);
|
||||
sx = *x = 0;
|
||||
if (*y == win->scr_b) {
|
||||
if (!(win->flags & __SCROLLOK))
|
||||
return ERR;
|
||||
scroll(win);
|
||||
} else {
|
||||
(*y)++;
|
||||
}
|
||||
lp = &win->alines[*y]->line[0];
|
||||
(*lnp) = win->alines[*y];
|
||||
}
|
||||
|
||||
/* add spacing character */
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT,
|
||||
"_cursesi_addwchar: add character (%d,%d) 0x%x\n",
|
||||
*y, *x, wch->vals[0]);
|
||||
#endif /* DEBUG */
|
||||
(*lnp)->flags |= __ISDIRTY;
|
||||
newx = *x + win->ch_off;
|
||||
if (newx < *(*lnp)->firstchp)
|
||||
*(*lnp)->firstchp = newx;
|
||||
if (lp->nsp) {
|
||||
__cursesi_free_nsp(lp->nsp);
|
||||
lp->nsp = NULL;
|
||||
}
|
||||
|
||||
lp->ch = wch->vals[0];
|
||||
|
||||
attributes = (win->wattr | wch->attributes)
|
||||
& (WA_ATTRIBUTES & ~__COLOR);
|
||||
if (wch->attributes & __COLOR)
|
||||
attributes |= wch->attributes & __COLOR;
|
||||
else if (win->wattr & __COLOR)
|
||||
attributes |= win->wattr & __COLOR;
|
||||
if (attributes & __COLOR)
|
||||
lp->attr = attributes | (win->battr & ~__COLOR);
|
||||
else
|
||||
lp->attr = attributes | win->battr;
|
||||
|
||||
SET_WCOL(*lp, cw);
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT,
|
||||
"_cursesi_addwchar: add spacing char 0x%x, attr 0x%x\n",
|
||||
lp->ch, lp->attr);
|
||||
#endif /* DEBUG */
|
||||
|
||||
if (wch->elements > 1) {
|
||||
for (i = 1; i < wch->elements; i++) {
|
||||
np = malloc(sizeof(nschar_t));
|
||||
if (!np)
|
||||
return ERR;;
|
||||
np->ch = wch->vals[i];
|
||||
np->next = lp->nsp;
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT,
|
||||
"_cursesi_addwchar: add non-spacing char 0x%x\n", np->ch);
|
||||
#endif /* DEBUG */
|
||||
lp->nsp = np;
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT, "_cursesi_addwchar: non-spacing list header: %p\n",
|
||||
lp->nsp);
|
||||
__CTRACE(__CTRACE_INPUT, "_cursesi_addwchar: add rest columns (%d:%d)\n",
|
||||
sx + 1, sx + cw - 1);
|
||||
__CTRACE(__CTRACE_INPUT, "_cursesi_addwchar: *x = %d, win->maxx = %d\n", *x, win->maxx);
|
||||
#endif /* DEBUG */
|
||||
for (tp = lp + 1, *x = sx + 1; *x - sx <= cw - 1; tp++, (*x)++) {
|
||||
if (tp->nsp) {
|
||||
__cursesi_free_nsp(tp->nsp);
|
||||
tp->nsp = NULL;
|
||||
}
|
||||
tp->ch = wch->vals[0];
|
||||
tp->attr = lp->attr & WA_ATTRIBUTES;
|
||||
/* Mark as "continuation" cell */
|
||||
tp->attr |= __WCWIDTH;
|
||||
}
|
||||
|
||||
if (*x == win->maxx) {
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT, "_cursesi_addwchar: do line wrap\n");
|
||||
#endif /* DEBUG */
|
||||
newx = win->maxx - 1 + win->ch_off;
|
||||
if (newx > *(*lnp)->lastchp)
|
||||
*(*lnp)->lastchp = newx;
|
||||
__touchline(win, *y, sx, (int) win->maxx - 1);
|
||||
*x = sx = 0;
|
||||
if (*y == win->scr_b) {
|
||||
if (!(win->flags & __SCROLLOK))
|
||||
return ERR;
|
||||
scroll(win);
|
||||
} else {
|
||||
(*y)++;
|
||||
}
|
||||
lp = &win->alines[*y]->line[0];
|
||||
(*lnp) = win->alines[*y];
|
||||
} else {
|
||||
|
||||
/* clear the remaining of the current character */
|
||||
if (*x && *x < win->maxx) {
|
||||
ex = sx + cw;
|
||||
tp = &win->alines[*y]->line[ex];
|
||||
while (ex < win->maxx && WCOL(*tp) < 0) {
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT,
|
||||
"_cursesi_addwchar: clear "
|
||||
"remaining of current char (%d,%d)nn",
|
||||
*y, ex);
|
||||
#endif /* DEBUG */
|
||||
tp->ch = (wchar_t) btowc((int) win->bch);
|
||||
if (_cursesi_copy_nsp(win->bnsp, tp) == ERR)
|
||||
return ERR;
|
||||
tp->attr = win->battr;
|
||||
SET_WCOL(*tp, 1);
|
||||
tp++, ex++;
|
||||
}
|
||||
newx = ex - 1 + win->ch_off;
|
||||
if (newx > *(*lnp)->lastchp)
|
||||
*(*lnp)->lastchp = newx;
|
||||
__touchline(win, *y, sx, ex - 1);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT, "_cursesi_addwchar: %d : 0x%x\n", lp->ch, lp->attr);
|
||||
__CTRACE(__CTRACE_INPUT, "_cursesi_addwchar: *x = %d, *y = %d, win->maxx = %d\n", *x, *y, win->maxx);
|
||||
#endif /* DEBUG */
|
||||
__sync(win);
|
||||
return OK;
|
||||
#endif
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_addch.3
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
/* $NetBSD: addch.c,v 1.21 2019/06/09 07:40:14 blymn Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <netbsd_sys/cdefs.h>
|
||||
|
||||
#include "curses.h"
|
||||
#include "curses_private.h"
|
||||
|
||||
#ifndef _CURSES_USE_MACROS
|
||||
|
||||
/*
|
||||
* addch --
|
||||
* Add the character to the current position in stdscr.
|
||||
*
|
||||
*/
|
||||
int
|
||||
addch(chtype ch)
|
||||
{
|
||||
|
||||
return waddch(stdscr, ch);
|
||||
}
|
||||
|
||||
/*
|
||||
* mvaddch --
|
||||
* Add the character to stdscr at the given location.
|
||||
*/
|
||||
int
|
||||
mvaddch(int y, int x, chtype ch)
|
||||
{
|
||||
|
||||
return mvwaddch(stdscr, y, x, ch);
|
||||
}
|
||||
|
||||
/*
|
||||
* mvwaddch --
|
||||
* Add the character to the given window at the given location.
|
||||
*/
|
||||
int
|
||||
mvwaddch(WINDOW *win, int y, int x, chtype ch)
|
||||
{
|
||||
|
||||
if (wmove(win, y, x) == ERR)
|
||||
return ERR;
|
||||
|
||||
return waddch(win, ch);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_WCHAR
|
||||
/*
|
||||
* waddch --
|
||||
* Add the character to the current position in the given window.
|
||||
*/
|
||||
int
|
||||
waddch(WINDOW *win, chtype ch)
|
||||
{
|
||||
cchar_t cc;
|
||||
|
||||
__cursesi_chtype_to_cchar(ch, &cc);
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT,
|
||||
"addch: %d : 0x%x (adding char as wide char)\n",
|
||||
cc.vals[0], cc.attributes);
|
||||
#endif
|
||||
|
||||
return wadd_wch(win, &cc);
|
||||
}
|
||||
|
||||
#else /* !HAVE_WCHAR */
|
||||
|
||||
/*
|
||||
* waddch --
|
||||
* Add the character to the current position in the given window.
|
||||
*/
|
||||
int
|
||||
waddch(WINDOW *win, chtype ch)
|
||||
{
|
||||
__LDATA buf;
|
||||
|
||||
buf.ch = (wchar_t)ch & __CHARTEXT;
|
||||
buf.attr = (attr_t)ch & __ATTRIBUTES;
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT, "addch: %d : 0x%x\n", buf.ch, buf.attr);
|
||||
#endif
|
||||
return __waddch(win, &buf);
|
||||
}
|
||||
#endif /* !HAVE_WCHAR */
|
||||
|
||||
int
|
||||
__waddch(WINDOW *win, __LDATA *dp)
|
||||
{
|
||||
char buf[2];
|
||||
|
||||
buf[0] = dp->ch;
|
||||
buf[1] = '\0';
|
||||
return _cursesi_waddbytes(win, buf, 1, dp->attr, 1);
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_addchstr.3
|
||||
+182
@@ -0,0 +1,182 @@
|
||||
/* $NetBSD: addchnstr.c,v 1.8 2019/06/09 07:40:14 blymn Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Douwe Kiela (virtus@wanadoo.nl).
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <netbsd_sys/cdefs.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "curses.h"
|
||||
#include "curses_private.h"
|
||||
|
||||
#ifndef _CURSES_USE_MACROS
|
||||
|
||||
/*
|
||||
* addchstr --
|
||||
* Add a string to stdscr starting at (_cury, _curx).
|
||||
*/
|
||||
int
|
||||
addchstr(const chtype *chstr)
|
||||
{
|
||||
return waddchnstr(stdscr, chstr, -1);
|
||||
}
|
||||
|
||||
/*
|
||||
* waddchstr --
|
||||
* Add a string to the given window starting at (_cury, _curx).
|
||||
*/
|
||||
int
|
||||
waddchstr(WINDOW *win, const chtype *chstr)
|
||||
{
|
||||
return waddchnstr(win, chstr, -1);
|
||||
}
|
||||
|
||||
/*
|
||||
* addchnstr --
|
||||
* Add a string (at most n characters) to stdscr starting
|
||||
* at (_cury, _curx). If n is negative, add the entire string.
|
||||
*/
|
||||
int
|
||||
addchnstr(const chtype *chstr, int n)
|
||||
{
|
||||
return waddchnstr(stdscr, chstr, n);
|
||||
}
|
||||
|
||||
/*
|
||||
* mvaddchstr --
|
||||
* Add a string to stdscr starting at (y, x)
|
||||
*/
|
||||
int
|
||||
mvaddchstr(int y, int x, const chtype *chstr)
|
||||
{
|
||||
return mvwaddchnstr(stdscr, y, x, chstr, -1);
|
||||
}
|
||||
|
||||
/*
|
||||
* mvwaddchstr --
|
||||
* Add a string to the given window starting at (y, x)
|
||||
*/
|
||||
int
|
||||
mvwaddchstr(WINDOW *win, int y, int x, const chtype *chstr)
|
||||
{
|
||||
return mvwaddchnstr(win, y, x, chstr, -1);
|
||||
}
|
||||
|
||||
/*
|
||||
* mvaddchnstr --
|
||||
* Add a string of at most n characters to stdscr
|
||||
* starting at (y, x).
|
||||
*/
|
||||
int
|
||||
mvaddchnstr(int y, int x, const chtype *chstr, int n)
|
||||
{
|
||||
return mvwaddchnstr(stdscr, y, x, chstr, n);
|
||||
}
|
||||
|
||||
/*
|
||||
* mvwaddchnstr --
|
||||
* Add a string of at most n characters to the given window
|
||||
* starting at (y, x).
|
||||
*/
|
||||
int
|
||||
mvwaddchnstr(WINDOW *win, int y, int x, const chtype *chstr, int n)
|
||||
{
|
||||
if (wmove(win, y, x) == ERR)
|
||||
return ERR;
|
||||
|
||||
return waddchnstr(win, chstr, n);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* waddchnstr --
|
||||
* Add a string (at most n characters) to the given window
|
||||
* starting at (_cury, _curx) until the end of line is reached or
|
||||
* n characters have been added. If n is negative, add as much
|
||||
* of the string that will fit on the current line. SUSv2 says
|
||||
* that the addchnstr family does not wrap and strings are truncated
|
||||
* to the RHS of the window.
|
||||
*/
|
||||
int
|
||||
waddchnstr(WINDOW *win, const chtype *chstr, int n)
|
||||
{
|
||||
size_t len;
|
||||
const chtype *chp;
|
||||
attr_t attr;
|
||||
char *ocp, *cp, *start;
|
||||
int i, ret, ox, oy;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT, "waddchnstr: win = %p, chstr = %p, n = %d\n",
|
||||
win, chstr, n);
|
||||
#endif
|
||||
|
||||
if (n >= 0)
|
||||
for (chp = chstr, len = 0; n-- && *chp++; ++len);
|
||||
else
|
||||
for (chp = chstr, len = 0; *chp++; ++len);
|
||||
|
||||
/* check if string is too long for current location */
|
||||
if (len > (win->maxx - win->curx))
|
||||
len = win->maxx - win->curx;
|
||||
|
||||
if ((ocp = malloc(len + 1)) == NULL)
|
||||
return ERR;
|
||||
chp = chstr;
|
||||
cp = ocp;
|
||||
start = ocp;
|
||||
i = 0;
|
||||
attr = (*chp) & __ATTRIBUTES;
|
||||
ox = win->curx;
|
||||
oy = win->cury;
|
||||
while (len) {
|
||||
*cp = (*chp) & __CHARTEXT;
|
||||
cp++;
|
||||
chp++;
|
||||
i++;
|
||||
len--;
|
||||
if (((*chp) & __ATTRIBUTES) != attr) {
|
||||
*cp = '\0';
|
||||
if (_cursesi_waddbytes(win, start, i, attr, 0) == ERR) {
|
||||
free(ocp);
|
||||
return ERR;
|
||||
}
|
||||
attr = (*chp) & __ATTRIBUTES;
|
||||
start = cp;
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
*cp = '\0';
|
||||
ret = _cursesi_waddbytes(win, start, i, attr, 0);
|
||||
free(ocp);
|
||||
wmove(win, oy, ox);
|
||||
return ret;
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_addchstr.3
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_addstr.3
|
||||
+150
@@ -0,0 +1,150 @@
|
||||
/* $NetBSD: addnstr.c,v 1.17 2019/06/09 07:40:14 blymn Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <netbsd_sys/cdefs.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "curses.h"
|
||||
#include "curses_private.h"
|
||||
|
||||
#ifndef _CURSES_USE_MACROS
|
||||
|
||||
/*
|
||||
* addstr --
|
||||
* Add a string to stdscr starting at (_cury, _curx).
|
||||
*/
|
||||
int
|
||||
addstr(const char *s)
|
||||
{
|
||||
return waddnstr(stdscr, s, -1);
|
||||
}
|
||||
|
||||
/*
|
||||
* waddstr --
|
||||
* Add a string to the given window starting at (_cury, _curx).
|
||||
*/
|
||||
int
|
||||
waddstr(WINDOW *win, const char *s)
|
||||
{
|
||||
return waddnstr(win, s, -1);
|
||||
}
|
||||
|
||||
/*
|
||||
* addnstr --
|
||||
* Add a string (at most n characters) to stdscr starting
|
||||
* at (_cury, _curx). If n is negative, add the entire string.
|
||||
*/
|
||||
int
|
||||
addnstr(const char *str, int n)
|
||||
{
|
||||
return waddnstr(stdscr, str, n);
|
||||
}
|
||||
|
||||
/*
|
||||
* mvaddstr --
|
||||
* Add a string to stdscr starting at (y, x)
|
||||
*/
|
||||
int
|
||||
mvaddstr(int y, int x, const char *str)
|
||||
{
|
||||
return mvwaddnstr(stdscr, y, x, str, -1);
|
||||
}
|
||||
|
||||
/*
|
||||
* mvwaddstr --
|
||||
* Add a string to the given window starting at (y, x)
|
||||
*/
|
||||
int
|
||||
mvwaddstr(WINDOW *win, int y, int x, const char *str)
|
||||
{
|
||||
return mvwaddnstr(win, y, x, str, -1);
|
||||
}
|
||||
|
||||
/*
|
||||
* mvaddnstr --
|
||||
* Add a string of at most n characters to stdscr
|
||||
* starting at (y, x).
|
||||
*/
|
||||
int
|
||||
mvaddnstr(int y, int x, const char *str, int count)
|
||||
{
|
||||
return mvwaddnstr(stdscr, y, x, str, count);
|
||||
}
|
||||
|
||||
/*
|
||||
* mvwaddnstr --
|
||||
* Add a string of at most n characters to the given window
|
||||
* starting at (y, x).
|
||||
*/
|
||||
int
|
||||
mvwaddnstr(WINDOW *win, int y, int x, const char *str, int count)
|
||||
{
|
||||
if (wmove(win, y, x) == ERR)
|
||||
return ERR;
|
||||
|
||||
return waddnstr(win, str, count);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* waddnstr --
|
||||
* Add a string (at most n characters) to the given window
|
||||
* starting at (_cury, _curx). If n is negative, add the
|
||||
* entire string.
|
||||
*/
|
||||
int
|
||||
waddnstr(WINDOW *win, const char *s, int n)
|
||||
{
|
||||
size_t len;
|
||||
const char *p;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT, "ADDNSTR: win %p, length %d\n",
|
||||
win, n);
|
||||
#endif
|
||||
/*
|
||||
* behavior changed from traditional BSD curses, for better XCURSES
|
||||
* conformance.
|
||||
*
|
||||
* BSD curses: if (n > 0) then "at most n", else "len = strlen(s)"
|
||||
* ncurses: if (n >= 0) then "at most n", else "len = strlen(s)"
|
||||
* XCURSES: if (n != -1) then "at most n", else "len = strlen(s)"
|
||||
*
|
||||
*/
|
||||
if (n >= 0)
|
||||
for (p = s, len = 0; n-- && *p++; ++len);
|
||||
else
|
||||
len = strlen(s);
|
||||
|
||||
return waddbytes(win, s, (int) len);
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_addstr.3
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
/* $NetBSD: addwstr.c,v 1.6 2019/06/09 07:40:14 blymn Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2005 The NetBSD Foundation Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from code donated to the NetBSD Foundation
|
||||
* by Ruibiao Qiu <ruibiao@arl.wustl.edu,ruibiao@gmail.com>.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
|
||||
* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <netbsd_sys/cdefs.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "curses.h"
|
||||
#include "curses_private.h"
|
||||
|
||||
/*
|
||||
* addwstr --
|
||||
* Add a string to stdscr starting at (_cury, _curx).
|
||||
*/
|
||||
int
|
||||
addwstr(const wchar_t *s)
|
||||
{
|
||||
return waddnwstr(stdscr, s, -1);
|
||||
}
|
||||
|
||||
/*
|
||||
* waddwstr --
|
||||
* Add a string to the given window starting at (_cury, _curx).
|
||||
*/
|
||||
int
|
||||
waddwstr(WINDOW *win, const wchar_t *s)
|
||||
{
|
||||
return waddnwstr(win, s, -1);
|
||||
}
|
||||
|
||||
/*
|
||||
* addnwstr --
|
||||
* Add a string (at most n characters) to stdscr starting
|
||||
* at (_cury, _curx). If n is negative, add the entire string.
|
||||
*/
|
||||
int
|
||||
addnwstr(const wchar_t *str, int n)
|
||||
{
|
||||
return waddnwstr(stdscr, str, n);
|
||||
}
|
||||
|
||||
/*
|
||||
* mvaddwstr --
|
||||
* Add a string to stdscr starting at (y, x)
|
||||
*/
|
||||
int
|
||||
mvaddwstr(int y, int x, const wchar_t *str)
|
||||
{
|
||||
return mvwaddnwstr(stdscr, y, x, str, -1);
|
||||
}
|
||||
|
||||
/*
|
||||
* mvwaddwstr --
|
||||
* Add a string to the given window starting at (y, x)
|
||||
*/
|
||||
int
|
||||
mvwaddwstr(WINDOW *win, int y, int x, const wchar_t *str)
|
||||
{
|
||||
return mvwaddnwstr(win, y, x, str, -1);
|
||||
}
|
||||
|
||||
/*
|
||||
* mvaddnwstr --
|
||||
* Add a string of at most n characters to stdscr
|
||||
* starting at (y, x).
|
||||
*/
|
||||
int
|
||||
mvaddnwstr(int y, int x, const wchar_t *str, int count)
|
||||
{
|
||||
return mvwaddnwstr(stdscr, y, x, str, count);
|
||||
}
|
||||
|
||||
/*
|
||||
* mvwaddnwstr --
|
||||
* Add a string of at most n characters to the given window
|
||||
* starting at (y, x).
|
||||
*/
|
||||
int
|
||||
mvwaddnwstr(WINDOW *win, int y, int x, const wchar_t *str, int count)
|
||||
{
|
||||
if (wmove(win, y, x) == ERR)
|
||||
return ERR;
|
||||
|
||||
return waddnwstr(win, str, count);
|
||||
}
|
||||
|
||||
/*
|
||||
* waddnwstr --
|
||||
* Add a string (at most n characters) to the given window
|
||||
* starting at (_cury, _curx). If n is negative, add the
|
||||
* entire string.
|
||||
*/
|
||||
int
|
||||
waddnwstr(WINDOW *win, const wchar_t *s, int n)
|
||||
{
|
||||
size_t len;
|
||||
const wchar_t *p;
|
||||
cchar_t cc;
|
||||
wchar_t wc[2];
|
||||
|
||||
/*
|
||||
* BSD curses: if (n > 0) then "at most n", else "len = strlen(s)"
|
||||
* ncurses: if (n >= 0) then "at most n", else "len = strlen(s)"
|
||||
* XCURSES: if (n != -1) then "at most n", else "len = strlen(s)"
|
||||
*/
|
||||
/* compute the length and column width of string */
|
||||
if (n < -1)
|
||||
return ERR;
|
||||
if (n >= 0)
|
||||
for (p = s, len = 0; n-- && *p++; ++len);
|
||||
else
|
||||
len = wcslen(s);
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT, "waddnwstr: string len=%ld\n", (long) len);
|
||||
#endif /* DEBUG */
|
||||
|
||||
p = s;
|
||||
while (len) {
|
||||
wc[0] = *p;
|
||||
wc[1] = L'\0';
|
||||
if (setcchar( &cc, wc, win->wattr, 0, NULL ) == ERR)
|
||||
return ERR;
|
||||
if (wadd_wch( win, &cc ) == ERR)
|
||||
return ERR;
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT, "waddnwstr: (%x,%x,%d) added\n",
|
||||
cc.vals[ 0 ], cc.attributes, cc.elements );
|
||||
#endif /* DEBUG */
|
||||
p++, len--;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_default_colors.3
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_attributes.3
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_attributes.3
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_attributes.3
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_attributes.3
|
||||
+486
@@ -0,0 +1,486 @@
|
||||
/* $NetBSD: attributes.c,v 1.31 2019/07/25 20:18:50 uwe Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Julian Coleman.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <netbsd_sys/cdefs.h>
|
||||
|
||||
#include "curses.h"
|
||||
#include "curses_private.h"
|
||||
|
||||
static int __wattr_off(WINDOW *, attr_t);
|
||||
static int __wattr_on(WINDOW *, attr_t);
|
||||
static void __wcolor_set(WINDOW *, attr_t);
|
||||
|
||||
|
||||
#ifndef _CURSES_USE_MACROS
|
||||
#ifdef HAVE_WCHAR
|
||||
/*
|
||||
* attr_get --
|
||||
* Get wide attributes and color pair from stdscr
|
||||
*/
|
||||
/* ARGSUSED */
|
||||
int
|
||||
attr_get(attr_t *attr, short *pair, void *opts)
|
||||
{
|
||||
return wattr_get(stdscr, attr, pair, opts);
|
||||
}
|
||||
|
||||
/*
|
||||
* attr_on --
|
||||
* Test and set wide attributes on stdscr
|
||||
*/
|
||||
/* ARGSUSED */
|
||||
int
|
||||
attr_on(attr_t attr, void *opts)
|
||||
{
|
||||
return wattr_on(stdscr, attr, opts);
|
||||
}
|
||||
|
||||
/*
|
||||
* attr_off --
|
||||
* Test and unset wide attributes on stdscr
|
||||
*/
|
||||
/* ARGSUSED */
|
||||
int
|
||||
attr_off(attr_t attr, void *opts)
|
||||
{
|
||||
return wattr_off(stdscr, attr, opts);
|
||||
}
|
||||
|
||||
/*
|
||||
* attr_set --
|
||||
* Set wide attributes and color pair on stdscr
|
||||
*/
|
||||
/* ARGSUSED */
|
||||
int
|
||||
attr_set(attr_t attr, short pair, void *opts)
|
||||
{
|
||||
return wattr_set(stdscr, attr, pair, opts);
|
||||
}
|
||||
|
||||
/*
|
||||
* color_set --
|
||||
* Set color pair on stdscr
|
||||
*/
|
||||
/* ARGSUSED */
|
||||
int
|
||||
color_set(short pair, void *opts)
|
||||
{
|
||||
return wcolor_set(stdscr, pair, opts);
|
||||
}
|
||||
#endif /* HAVE_WCHAR */
|
||||
|
||||
/*
|
||||
* attron --
|
||||
* Test and set attributes on stdscr
|
||||
*/
|
||||
int
|
||||
attron(int attr)
|
||||
{
|
||||
return wattron(stdscr, attr);
|
||||
}
|
||||
|
||||
/*
|
||||
* attroff --
|
||||
* Test and unset attributes on stdscr.
|
||||
*/
|
||||
int
|
||||
attroff(int attr)
|
||||
{
|
||||
return wattroff(stdscr, attr);
|
||||
}
|
||||
|
||||
/*
|
||||
* attrset --
|
||||
* Set specific attribute modes.
|
||||
* Unset others. On stdscr.
|
||||
*/
|
||||
int
|
||||
attrset(int attr)
|
||||
{
|
||||
return wattrset(stdscr, attr);
|
||||
}
|
||||
#endif /* _CURSES_USE_MACROS */
|
||||
|
||||
|
||||
#ifdef HAVE_WCHAR
|
||||
/*
|
||||
* wattr_get --
|
||||
* Get wide attributes and colour pair from window
|
||||
* Note that attributes also includes colour.
|
||||
*/
|
||||
/* ARGSUSED */
|
||||
int
|
||||
wattr_get(WINDOW *win, attr_t *attr, short *pair, void *opts)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_ATTR, "wattr_get: win %p\n", win);
|
||||
#endif
|
||||
if (attr != NULL) {
|
||||
*attr = win->wattr;
|
||||
#ifdef HAVE_WCHAR
|
||||
*attr &= WA_ATTRIBUTES;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (pair != NULL)
|
||||
*pair = PAIR_NUMBER(win->wattr);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* wattr_on --
|
||||
* Test and set wide attributes on window
|
||||
*/
|
||||
int
|
||||
wattr_on(WINDOW *win, attr_t attr, void *opts)
|
||||
{
|
||||
if (__predict_false(opts != NULL))
|
||||
return ERR;
|
||||
|
||||
return __wattr_on(win, attr);
|
||||
}
|
||||
|
||||
/*
|
||||
* wattr_off --
|
||||
* Test and unset wide attributes on window
|
||||
*
|
||||
* Note that the 'me' sequence unsets all attributes. We handle
|
||||
* which attributes should really be set in refresh.c:makech().
|
||||
*/
|
||||
int
|
||||
wattr_off(WINDOW *win, attr_t attr, void *opts)
|
||||
{
|
||||
if (__predict_false(opts != NULL))
|
||||
return ERR;
|
||||
|
||||
return __wattr_off(win, attr);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* wattr_set --
|
||||
* Set wide attributes and color pair on window
|
||||
*/
|
||||
int
|
||||
wattr_set(WINDOW *win, attr_t attr, short pair, void *opts)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_ATTR, "wattr_set: win %p, attr %08x, pair %d\n",
|
||||
win, attr, pair);
|
||||
#endif
|
||||
if (__predict_false(opts != NULL))
|
||||
return ERR;
|
||||
|
||||
/*
|
||||
* This overwrites any colour setting from the attributes
|
||||
* and is compatible with ncurses.
|
||||
*/
|
||||
attr = (attr & ~__COLOR) | COLOR_PAIR(pair);
|
||||
|
||||
__wattr_off(win, WA_ATTRIBUTES);
|
||||
__wattr_on(win, attr);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* wcolor_set --
|
||||
* Set color pair on window
|
||||
*/
|
||||
/* ARGSUSED */
|
||||
int
|
||||
wcolor_set(WINDOW *win, short pair, void *opts)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_COLOR, "wolor_set: win %p, pair %d\n", win, pair);
|
||||
#endif
|
||||
__wcolor_set(win, (attr_t) COLOR_PAIR(pair));
|
||||
return OK;
|
||||
}
|
||||
#endif /* HAVE_WCHAR */
|
||||
|
||||
|
||||
/*
|
||||
* getattrs --
|
||||
* Get window attributes.
|
||||
*/
|
||||
chtype
|
||||
getattrs(WINDOW *win)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_ATTR, "getattrs: win %p\n", win);
|
||||
#endif
|
||||
return((chtype) win->wattr);
|
||||
}
|
||||
|
||||
/*
|
||||
* wattron --
|
||||
* Test and set attributes.
|
||||
*/
|
||||
int
|
||||
wattron(WINDOW *win, int attr)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_ATTR, "wattron: win %p, attr %08x\n", win, attr);
|
||||
#endif
|
||||
return __wattr_on(win, (attr_t) attr);
|
||||
}
|
||||
|
||||
/*
|
||||
* wattroff --
|
||||
* Test and unset attributes.
|
||||
*/
|
||||
int
|
||||
wattroff(WINDOW *win, int attr)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_ATTR, "wattroff: win %p, attr %08x\n", win, attr);
|
||||
#endif
|
||||
return __wattr_off(win, (attr_t) attr);
|
||||
}
|
||||
|
||||
/*
|
||||
* wattrset --
|
||||
* Set specific attribute modes.
|
||||
* Unset others.
|
||||
*/
|
||||
int
|
||||
wattrset(WINDOW *win, int attr)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_ATTR, "wattrset: win %p, attr %08x\n", win, attr);
|
||||
#endif
|
||||
__wattr_off(win, __ATTRIBUTES);
|
||||
__wattr_on(win, (attr_t) attr);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* termattrs --
|
||||
* Get terminal attributes
|
||||
*/
|
||||
chtype
|
||||
termattrs(void)
|
||||
{
|
||||
chtype ch = 0;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_ATTR, "termattrs\n");
|
||||
#endif
|
||||
if (exit_attribute_mode != NULL) {
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_ATTR, "termattrs: have exit attribute mode\n");
|
||||
#endif
|
||||
if (enter_blink_mode != NULL)
|
||||
ch |= __BLINK;
|
||||
if (enter_bold_mode != NULL)
|
||||
ch |= __BOLD;
|
||||
if (enter_dim_mode != NULL)
|
||||
ch |= __DIM;
|
||||
if (enter_secure_mode != NULL)
|
||||
ch |= __BLANK;
|
||||
if (enter_protected_mode != NULL)
|
||||
ch |= __PROTECT;
|
||||
if (enter_reverse_mode != NULL)
|
||||
ch |= __REVERSE;
|
||||
}
|
||||
if (enter_standout_mode != NULL && exit_standout_mode != NULL)
|
||||
ch |= __STANDOUT;
|
||||
if (enter_underline_mode != NULL && exit_underline_mode != NULL)
|
||||
ch |= __UNDERSCORE;
|
||||
if (enter_alt_charset_mode != NULL && exit_alt_charset_mode != NULL)
|
||||
ch |= __ALTCHARSET;
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_WCHAR
|
||||
/*
|
||||
* term_attrs --
|
||||
* Get terminal wide attributes
|
||||
*/
|
||||
attr_t
|
||||
term_attrs(void)
|
||||
{
|
||||
attr_t attr = 0;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_ATTR, "term_attrs\n");
|
||||
#endif
|
||||
if (exit_attribute_mode != NULL) {
|
||||
if (enter_blink_mode != NULL)
|
||||
attr |= __BLINK;
|
||||
if (enter_bold_mode != NULL)
|
||||
attr |= __BOLD;
|
||||
if (enter_dim_mode != NULL)
|
||||
attr |= __DIM;
|
||||
if (enter_secure_mode != NULL)
|
||||
attr |= __BLANK;
|
||||
if (enter_protected_mode != NULL)
|
||||
attr |= __PROTECT;
|
||||
if (enter_reverse_mode != NULL)
|
||||
attr |= __REVERSE;
|
||||
#ifdef HAVE_WCHAR
|
||||
if (enter_low_hl_mode != NULL)
|
||||
attr |= WA_LOW;
|
||||
if (enter_top_hl_mode != NULL)
|
||||
attr |= WA_TOP;
|
||||
if (enter_left_hl_mode != NULL)
|
||||
attr |= WA_LEFT;
|
||||
if (enter_right_hl_mode != NULL)
|
||||
attr |= WA_RIGHT;
|
||||
if (enter_horizontal_hl_mode != NULL)
|
||||
attr |= WA_HORIZONTAL;
|
||||
if (enter_vertical_hl_mode != NULL)
|
||||
attr |= WA_VERTICAL;
|
||||
#endif /* HAVE_WCHAR */
|
||||
}
|
||||
if (enter_standout_mode != NULL && exit_standout_mode != NULL)
|
||||
attr |= __STANDOUT;
|
||||
if (enter_underline_mode != NULL && exit_underline_mode != NULL)
|
||||
attr |= __UNDERSCORE;
|
||||
if (enter_alt_charset_mode != NULL && exit_alt_charset_mode != NULL)
|
||||
attr |= __ALTCHARSET;
|
||||
|
||||
return attr;
|
||||
}
|
||||
#endif /* HAVE_WCHAR */
|
||||
|
||||
|
||||
static int
|
||||
__wattr_on(WINDOW *win, attr_t attr)
|
||||
{
|
||||
const TERMINAL *t = win->screen->term;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_ATTR, "wattr_on: win %p, attr %08x\n", win, attr);
|
||||
#endif
|
||||
/* If can enter modes, set the relevent attribute bits. */
|
||||
if (t_exit_attribute_mode(t) != NULL) {
|
||||
if (attr & __BLINK && t_enter_blink_mode(t) != NULL)
|
||||
win->wattr |= __BLINK;
|
||||
if (attr & __BOLD && t_enter_bold_mode(t) != NULL)
|
||||
win->wattr |= __BOLD;
|
||||
if (attr & __DIM && t_enter_dim_mode(t) != NULL)
|
||||
win->wattr |= __DIM;
|
||||
if (attr & __BLANK && t_enter_secure_mode(t) != NULL)
|
||||
win->wattr |= __BLANK;
|
||||
if (attr & __PROTECT && t_enter_protected_mode(t) != NULL)
|
||||
win->wattr |= __PROTECT;
|
||||
if (attr & __REVERSE && t_enter_reverse_mode(t) != NULL)
|
||||
win->wattr |= __REVERSE;
|
||||
#ifdef HAVE_WCHAR
|
||||
if (attr & WA_LOW && t_enter_low_hl_mode(t) != NULL)
|
||||
win->wattr |= WA_LOW;
|
||||
if (attr & WA_TOP && t_enter_top_hl_mode(t) != NULL)
|
||||
win->wattr |= WA_TOP;
|
||||
if (attr & WA_LEFT && t_enter_left_hl_mode(t) != NULL)
|
||||
win->wattr |= WA_LEFT;
|
||||
if (attr & WA_RIGHT && t_enter_right_hl_mode(t) != NULL)
|
||||
win->wattr |= WA_RIGHT;
|
||||
if (attr & WA_HORIZONTAL && t_enter_horizontal_hl_mode(t) != NULL)
|
||||
win->wattr |= WA_HORIZONTAL;
|
||||
if (attr & WA_VERTICAL && t_enter_vertical_hl_mode(t) != NULL)
|
||||
win->wattr |= WA_VERTICAL;
|
||||
#endif /* HAVE_WCHAR */
|
||||
}
|
||||
if (attr & __STANDOUT && t_enter_standout_mode(t) != NULL &&
|
||||
t_exit_standout_mode(t) != NULL)
|
||||
wstandout(win);
|
||||
if (attr & __UNDERSCORE && t_enter_underline_mode(t) != NULL &&
|
||||
t_exit_underline_mode(t) != NULL)
|
||||
wunderscore(win);
|
||||
if (attr & __COLOR)
|
||||
__wcolor_set(win, attr);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
__wattr_off(WINDOW *win, attr_t attr)
|
||||
{
|
||||
const TERMINAL *t = win->screen->term;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_ATTR, "wattr_off: win %p, attr %08x\n", win, attr);
|
||||
#endif
|
||||
/* If can do exit modes, unset the relevent attribute bits. */
|
||||
if (t_exit_attribute_mode(t) != NULL) {
|
||||
if (attr & __BLINK)
|
||||
win->wattr &= ~__BLINK;
|
||||
if (attr & __BOLD)
|
||||
win->wattr &= ~__BOLD;
|
||||
if (attr & __DIM)
|
||||
win->wattr &= ~__DIM;
|
||||
if (attr & __BLANK)
|
||||
win->wattr &= ~__BLANK;
|
||||
if (attr & __PROTECT)
|
||||
win->wattr &= ~__PROTECT;
|
||||
if (attr & __REVERSE)
|
||||
win->wattr &= ~__REVERSE;
|
||||
#ifdef HAVE_WCHAR
|
||||
if (attr & WA_LOW)
|
||||
win->wattr &= ~WA_LOW;
|
||||
if (attr & WA_TOP)
|
||||
win->wattr &= ~WA_TOP;
|
||||
if (attr & WA_LEFT)
|
||||
win->wattr &= ~WA_LEFT;
|
||||
if (attr & WA_RIGHT)
|
||||
win->wattr &= ~WA_RIGHT;
|
||||
if (attr & WA_HORIZONTAL)
|
||||
win->wattr &= ~WA_HORIZONTAL;
|
||||
if (attr & WA_VERTICAL)
|
||||
win->wattr &= ~WA_VERTICAL;
|
||||
#endif /* HAVE_WCHAR */
|
||||
}
|
||||
if (attr & __STANDOUT)
|
||||
wstandend(win);
|
||||
if (attr & __UNDERSCORE)
|
||||
wunderend(win);
|
||||
if (attr & __COLOR) {
|
||||
if (max_colors != 0)
|
||||
win->wattr &= ~__COLOR;
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
__wcolor_set(WINDOW *win, attr_t attr)
|
||||
{
|
||||
const TERMINAL *t = win->screen->term;
|
||||
|
||||
/* If another color pair is set, turn that off first. */
|
||||
win->wattr &= ~__COLOR;
|
||||
/* If can do color video, set the color pair bits. */
|
||||
if (t_max_colors(t) != 0 && attr & __COLOR)
|
||||
win->wattr |= attr & __COLOR;
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_attributes.3
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_attributes.3
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_attributes.3
|
||||
+308
@@ -0,0 +1,308 @@
|
||||
/* $NetBSD: background.c,v 1.25 2018/11/19 20:37:04 uwe Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Julian Coleman.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 700
|
||||
#include <netbsd_sys/cdefs.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "curses.h"
|
||||
#include "curses_private.h"
|
||||
|
||||
/*
|
||||
* bkgdset
|
||||
* Set new background attributes on stdscr.
|
||||
*/
|
||||
void
|
||||
bkgdset(chtype ch)
|
||||
{
|
||||
wbkgdset(stdscr, ch);
|
||||
}
|
||||
|
||||
/*
|
||||
* bkgd --
|
||||
* Set new background attributes on stdscr and apply them to its
|
||||
* contents.
|
||||
*/
|
||||
int
|
||||
bkgd(chtype ch)
|
||||
{
|
||||
return(wbkgd(stdscr, ch));
|
||||
}
|
||||
|
||||
/*
|
||||
* wbkgdset
|
||||
* Set new background attributes on the specified window.
|
||||
*/
|
||||
void
|
||||
wbkgdset(WINDOW *win, chtype ch)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_ATTR, "wbkgdset: (%p), '%s', %08x\n",
|
||||
win, unctrl(ch & __CHARTEXT), ch & __ATTRIBUTES);
|
||||
#endif
|
||||
|
||||
/* Background character. */
|
||||
if (ch & __CHARTEXT)
|
||||
win->bch = (wchar_t) ch & __CHARTEXT;
|
||||
|
||||
/* Background attributes (check colour). */
|
||||
if (__using_color && !(ch & __COLOR))
|
||||
ch |= __default_color;
|
||||
win->battr = (attr_t) ch & __ATTRIBUTES;
|
||||
}
|
||||
|
||||
/*
|
||||
* wbkgd --
|
||||
* Set new background attributes on the specified window and
|
||||
* apply them to its contents.
|
||||
*/
|
||||
int
|
||||
wbkgd(WINDOW *win, chtype ch)
|
||||
{
|
||||
chtype obch;
|
||||
int y, x;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_ATTR, "wbkgd: (%p), '%s', %08x\n",
|
||||
win, unctrl(ch & __CHARTEXT), ch & __ATTRIBUTES);
|
||||
#endif
|
||||
obch = win->bch;
|
||||
wbkgdset(win, ch);
|
||||
|
||||
for (y = 0; y < win->maxy; y++) {
|
||||
for (x = 0; x < win->maxx; x++) {
|
||||
__LDATA *cp = &win->alines[y]->line[x];
|
||||
|
||||
/* Update/switch background characters */
|
||||
if (cp->ch == obch)
|
||||
cp->ch = win->bch;
|
||||
|
||||
/* Update/merge attributes */
|
||||
cp->attr = win->battr | (cp->attr & __ALTCHARSET);
|
||||
#ifdef HAVE_WCHAR
|
||||
SET_WCOL(*cp, 1);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
__touchwin(win);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* getbkgd --
|
||||
* Get current background attributes.
|
||||
*/
|
||||
chtype
|
||||
getbkgd(WINDOW *win)
|
||||
{
|
||||
attr_t battr;
|
||||
|
||||
/* Background attributes (check colour). */
|
||||
battr = win->battr & A_ATTRIBUTES;
|
||||
if (__using_color && ((battr & __COLOR) == __default_color))
|
||||
battr &= ~__COLOR;
|
||||
|
||||
return ((chtype) ((win->bch & A_CHARTEXT) | battr));
|
||||
}
|
||||
|
||||
|
||||
#ifdef HAVE_WCHAR
|
||||
|
||||
void
|
||||
bkgrndset(const cchar_t *wch)
|
||||
{
|
||||
wbkgrndset(stdscr, wch);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
bkgrnd(const cchar_t *wch)
|
||||
{
|
||||
return wbkgrnd(stdscr, wch);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
getbkgrnd(cchar_t *wch)
|
||||
{
|
||||
return wgetbkgrnd(stdscr, wch);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
wbkgrndset(WINDOW *win, const cchar_t *wch)
|
||||
{
|
||||
attr_t battr;
|
||||
nschar_t *np, *tnp;
|
||||
int i;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_ATTR, "wbkgrndset: (%p), '%s', %x\n",
|
||||
win, (const char *) wunctrl(wch), wch->attributes);
|
||||
#endif
|
||||
|
||||
/* ignore multi-column characters */
|
||||
if (!wch->elements || wcwidth(wch->vals[0]) > 1)
|
||||
return;
|
||||
|
||||
/* Background character. */
|
||||
tnp = np = win->bnsp;
|
||||
if (wcwidth( wch->vals[0]))
|
||||
win->bch = wch->vals[0];
|
||||
else {
|
||||
if (!np) {
|
||||
np = malloc(sizeof(nschar_t));
|
||||
if (!np)
|
||||
return;
|
||||
np->next = NULL;
|
||||
win->bnsp = np;
|
||||
}
|
||||
np->ch = wch->vals[0];
|
||||
tnp = np;
|
||||
np = np->next;
|
||||
}
|
||||
/* add non-spacing characters */
|
||||
if (wch->elements > 1) {
|
||||
for (i = 1; i < wch->elements; i++) {
|
||||
if ( !np ) {
|
||||
np = malloc(sizeof(nschar_t));
|
||||
if (!np)
|
||||
return;
|
||||
np->next = NULL;
|
||||
if (tnp)
|
||||
tnp->next = np;
|
||||
else
|
||||
win->bnsp = np;
|
||||
}
|
||||
np->ch = wch->vals[i];
|
||||
tnp = np;
|
||||
np = np->next;
|
||||
}
|
||||
}
|
||||
/* clear the old non-spacing characters */
|
||||
while (np) {
|
||||
tnp = np->next;
|
||||
free(np);
|
||||
np = tnp;
|
||||
}
|
||||
|
||||
/* Background attributes (check colour). */
|
||||
battr = wch->attributes & WA_ATTRIBUTES;
|
||||
if (__using_color && !( battr & __COLOR))
|
||||
battr |= __default_color;
|
||||
win->battr = battr;
|
||||
SET_BGWCOL((*win), 1);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
wbkgrnd(WINDOW *win, const cchar_t *wch)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_ATTR, "wbkgrnd: (%p), '%s', %x\n",
|
||||
win, (const char *) wunctrl(wch), wch->attributes);
|
||||
#endif
|
||||
|
||||
/* ignore multi-column characters */
|
||||
if (!wch->elements || wcwidth( wch->vals[ 0 ]) > 1)
|
||||
return ERR;
|
||||
|
||||
wbkgrndset(win, wch);
|
||||
__touchwin(win);
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
wgetbkgrnd(WINDOW *win, cchar_t *wch)
|
||||
{
|
||||
nschar_t *np;
|
||||
|
||||
/* Background attributes (check colour). */
|
||||
wch->attributes = win->battr & WA_ATTRIBUTES;
|
||||
if (__using_color && ((wch->attributes & __COLOR) == __default_color))
|
||||
wch->attributes &= ~__COLOR;
|
||||
wch->vals[0] = win->bch;
|
||||
wch->elements = 1;
|
||||
np = win->bnsp;
|
||||
if (np) {
|
||||
while (np && wch->elements < CURSES_CCHAR_MAX) {
|
||||
wch->vals[wch->elements++] = np->ch;
|
||||
np = np->next;
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
#else /* !HAVE_WCHAR */
|
||||
|
||||
void
|
||||
bkgrndset(const cchar_t *wch)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int
|
||||
bkgrnd(const cchar_t *wch)
|
||||
{
|
||||
return ERR;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
getbkgrnd(cchar_t *wch)
|
||||
{
|
||||
return ERR;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
wbkgrndset(WINDOW *win, const cchar_t *wch)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
wbkgrnd(WINDOW *win, const cchar_t *wch)
|
||||
{
|
||||
return ERR;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
wgetbkgrnd(WINDOW *win, cchar_t *wch)
|
||||
{
|
||||
return ERR;
|
||||
}
|
||||
|
||||
#endif /* !HAVE_WCHAR */
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_tty.3
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
/* $NetBSD: bell.c,v 1.9 2017/01/06 13:53:18 roy Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Julian Coleman.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <netbsd_sys/cdefs.h>
|
||||
|
||||
#include "curses.h"
|
||||
#include "curses_private.h"
|
||||
|
||||
/*
|
||||
* beep
|
||||
* Ring the terminal bell
|
||||
*/
|
||||
int
|
||||
beep(void)
|
||||
{
|
||||
if (bell != NULL) {
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_MISC, "beep: bl\n");
|
||||
#endif
|
||||
tputs(bell, 0, __cputchar);
|
||||
} else if (flash_screen != NULL) {
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_MISC, "beep: vb\n");
|
||||
#endif
|
||||
tputs(flash_screen, 0, __cputchar);
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* flash
|
||||
* Flash the terminal screen
|
||||
*/
|
||||
int
|
||||
flash(void)
|
||||
{
|
||||
if (flash_screen != NULL) {
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_MISC, "flash: vb\n");
|
||||
#endif
|
||||
tputs(flash_screen, 0, __cputchar);
|
||||
} else if (bell != NULL) {
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_MISC, "flash: bl\n");
|
||||
#endif
|
||||
tputs(bell, 0, __cputchar);
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_background.3
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_background.3
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_border.3
|
||||
+613
@@ -0,0 +1,613 @@
|
||||
/* $NetBSD: border.c,v 1.18 2017/01/09 21:17:29 blymn Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Julian Coleman.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 700
|
||||
#include <netbsd_sys/cdefs.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "curses.h"
|
||||
#include "curses_private.h"
|
||||
|
||||
#ifndef _CURSES_USE_MACROS
|
||||
|
||||
/*
|
||||
* border --
|
||||
* Draw a border around stdscr using the specified
|
||||
* delimiting characters.
|
||||
*/
|
||||
int
|
||||
border(chtype left, chtype right, chtype top, chtype bottom, chtype topleft,
|
||||
chtype topright, chtype botleft, chtype botright)
|
||||
{
|
||||
return wborder(stdscr, left, right, top, bottom, topleft, topright,
|
||||
botleft, botright);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* wborder --
|
||||
* Draw a border around the given window using the specified delimiting
|
||||
* characters.
|
||||
*/
|
||||
int
|
||||
wborder(WINDOW *win, chtype left, chtype right, chtype top, chtype bottom,
|
||||
chtype topleft, chtype topright, chtype botleft, chtype botright)
|
||||
{
|
||||
#ifndef HAVE_WCHAR
|
||||
int endy, endx, i;
|
||||
__LDATA *fp, *lp;
|
||||
|
||||
if (!(left & __CHARTEXT))
|
||||
left |= ACS_VLINE;
|
||||
if (!(right & __CHARTEXT))
|
||||
right |= ACS_VLINE;
|
||||
if (!(top & __CHARTEXT))
|
||||
top |= ACS_HLINE;
|
||||
if (!(bottom & __CHARTEXT))
|
||||
bottom |= ACS_HLINE;
|
||||
if (!(topleft & __CHARTEXT))
|
||||
topleft |= ACS_ULCORNER;
|
||||
if (!(topright & __CHARTEXT))
|
||||
topright |= ACS_URCORNER;
|
||||
if (!(botleft & __CHARTEXT))
|
||||
botleft |= ACS_LLCORNER;
|
||||
if (!(botright & __CHARTEXT))
|
||||
botright |= ACS_LRCORNER;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT, "wborder: left = %c, 0x%x\n",
|
||||
left & __CHARTEXT, left & __ATTRIBUTES);
|
||||
__CTRACE(__CTRACE_INPUT, "wborder: right = %c, 0x%x\n",
|
||||
right & __CHARTEXT, right & __ATTRIBUTES);
|
||||
__CTRACE(__CTRACE_INPUT, "wborder: top = %c, 0x%x\n",
|
||||
top & __CHARTEXT, top & __ATTRIBUTES);
|
||||
__CTRACE(__CTRACE_INPUT, "wborder: bottom = %c, 0x%x\n",
|
||||
bottom & __CHARTEXT, bottom & __ATTRIBUTES);
|
||||
__CTRACE(__CTRACE_INPUT, "wborder: topleft = %c, 0x%x\n",
|
||||
topleft & __CHARTEXT, topleft & __ATTRIBUTES);
|
||||
__CTRACE(__CTRACE_INPUT, "wborder: topright = %c, 0x%x\n",
|
||||
topright & __CHARTEXT, topright & __ATTRIBUTES);
|
||||
__CTRACE(__CTRACE_INPUT, "wborder: botleft = %c, 0x%x\n",
|
||||
botleft & __CHARTEXT, botleft & __ATTRIBUTES);
|
||||
__CTRACE(__CTRACE_INPUT, "wborder: botright = %c, 0x%x\n",
|
||||
botright & __CHARTEXT, botright & __ATTRIBUTES);
|
||||
#endif
|
||||
|
||||
/* Merge window and background attributes */
|
||||
left |= (left & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
|
||||
left |= (left & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
|
||||
right |= (right & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
|
||||
right |= (right & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
|
||||
top |= (top & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
|
||||
top |= (top & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
|
||||
bottom |= (bottom & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
|
||||
bottom |= (bottom & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
|
||||
topleft |= (topleft & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
|
||||
topleft |= (topleft & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
|
||||
topright |= (topright & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
|
||||
topright |= (topright & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
|
||||
botleft |= (botleft & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
|
||||
botleft |= (botleft & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
|
||||
botright |= (botright & __COLOR) ? (win->wattr & ~__COLOR) : win->wattr;
|
||||
botright |= (botright & __COLOR) ? (win->battr & ~__COLOR) : win->battr;
|
||||
|
||||
endx = win->maxx - 1;
|
||||
endy = win->maxy - 1;
|
||||
fp = win->alines[0]->line;
|
||||
lp = win->alines[endy]->line;
|
||||
|
||||
/* Sides */
|
||||
for (i = 1; i < endy; i++) {
|
||||
win->alines[i]->line[0].ch = (wchar_t) left & __CHARTEXT;
|
||||
win->alines[i]->line[0].attr = (attr_t) left & __ATTRIBUTES;
|
||||
win->alines[i]->line[endx].ch = (wchar_t) right & __CHARTEXT;
|
||||
win->alines[i]->line[endx].attr = (attr_t) right & __ATTRIBUTES;
|
||||
}
|
||||
for (i = 1; i < endx; i++) {
|
||||
fp[i].ch = (wchar_t) top & __CHARTEXT;
|
||||
fp[i].attr = (attr_t) top & __ATTRIBUTES;
|
||||
lp[i].ch = (wchar_t) bottom & __CHARTEXT;
|
||||
lp[i].attr = (attr_t) bottom & __ATTRIBUTES;
|
||||
}
|
||||
|
||||
/* Corners */
|
||||
if (!(win->maxy == LINES && win->maxx == COLS &&
|
||||
(win->flags & __SCROLLOK) && (win->flags & __SCROLLWIN))) {
|
||||
fp[0].ch = (wchar_t) topleft & __CHARTEXT;
|
||||
fp[0].attr = (attr_t) topleft & __ATTRIBUTES;
|
||||
fp[endx].ch = (wchar_t) topright & __CHARTEXT;
|
||||
fp[endx].attr = (attr_t) topright & __ATTRIBUTES;
|
||||
lp[0].ch = (wchar_t) botleft & __CHARTEXT;
|
||||
lp[0].attr = (attr_t) botleft & __ATTRIBUTES;
|
||||
lp[endx].ch = (wchar_t) botright & __CHARTEXT;
|
||||
lp[endx].attr = (attr_t) botright & __ATTRIBUTES;
|
||||
}
|
||||
__touchwin(win);
|
||||
return OK;
|
||||
#else /* HAVE_WCHAR */
|
||||
cchar_t ls, rs, ts, bs, tl, tr, bl, br;
|
||||
cchar_t *lsp, *rsp, *tsp, *bsp, *tlp, *trp, *blp, *brp;
|
||||
|
||||
#define S(in, out, def) \
|
||||
if (in & __CHARTEXT) { \
|
||||
__cursesi_chtype_to_cchar(in, &out); \
|
||||
} else { \
|
||||
memcpy(&out, def, sizeof(cchar_t)); \
|
||||
out.attributes |= in & __ATTRIBUTES; \
|
||||
} \
|
||||
out##p = &out;
|
||||
|
||||
S(left, ls, WACS_VLINE);
|
||||
S(right, rs, WACS_VLINE);
|
||||
S(top, ts, WACS_HLINE);
|
||||
S(bottom, bs, WACS_HLINE);
|
||||
S(topleft, tl, WACS_ULCORNER);
|
||||
S(topright, tr, WACS_URCORNER);
|
||||
S(botleft, bl, WACS_LLCORNER);
|
||||
S(botright, br, WACS_LRCORNER);
|
||||
#undef S
|
||||
return wborder_set(win, lsp, rsp, tsp, bsp, tlp, trp, blp, brp);
|
||||
#endif /* HAVE_WCHAR */
|
||||
}
|
||||
|
||||
int border_set(const cchar_t *ls, const cchar_t *rs, const cchar_t *ts,
|
||||
const cchar_t *bs, const cchar_t *tl, const cchar_t *tr,
|
||||
const cchar_t *bl, const cchar_t *br)
|
||||
{
|
||||
#ifndef HAVE_WCHAR
|
||||
return ERR;
|
||||
#else
|
||||
return wborder_set(stdscr, ls, rs, ts, bs, tl, tr, bl, br);
|
||||
#endif /* HAVE_WCHAR */
|
||||
}
|
||||
|
||||
int wborder_set(WINDOW *win, const cchar_t *ls, const cchar_t *rs,
|
||||
const cchar_t *ts, const cchar_t *bs,
|
||||
const cchar_t *tl, const cchar_t *tr,
|
||||
const cchar_t *bl, const cchar_t *br)
|
||||
{
|
||||
#ifndef HAVE_WCHAR
|
||||
return ERR;
|
||||
#else
|
||||
int endy, endx, i, j, k, cw, pcw, tlcw, blcw, trcw, brcw;
|
||||
cchar_t left, right, bottom, top, topleft, topright, botleft, botright;
|
||||
nschar_t *np, *tnp;
|
||||
|
||||
if (ls && wcwidth(ls->vals[0]))
|
||||
memcpy(&left, ls, sizeof(cchar_t));
|
||||
else
|
||||
memcpy(&left, WACS_VLINE, sizeof(cchar_t));
|
||||
if (rs && wcwidth( rs->vals[0]))
|
||||
memcpy(&right, rs, sizeof(cchar_t));
|
||||
else
|
||||
memcpy(&right, WACS_VLINE, sizeof(cchar_t));
|
||||
if (ts && wcwidth( ts->vals[0]))
|
||||
memcpy(&top, ts, sizeof(cchar_t));
|
||||
else
|
||||
memcpy( &top, WACS_HLINE, sizeof(cchar_t));
|
||||
if (bs && wcwidth( bs->vals[0]))
|
||||
memcpy(&bottom, bs, sizeof(cchar_t));
|
||||
else
|
||||
memcpy(&bottom, WACS_HLINE, sizeof(cchar_t));
|
||||
if (tl && wcwidth(tl->vals[0]))
|
||||
memcpy( &topleft, tl, sizeof(cchar_t));
|
||||
else
|
||||
memcpy(&topleft, WACS_ULCORNER, sizeof(cchar_t));
|
||||
if (tr && wcwidth( tr->vals[0]))
|
||||
memcpy(&topright, tr, sizeof(cchar_t));
|
||||
else
|
||||
memcpy(&topright, WACS_URCORNER, sizeof( cchar_t ));
|
||||
if (bl && wcwidth( bl->vals[0]))
|
||||
memcpy(&botleft, bl, sizeof(cchar_t));
|
||||
else
|
||||
memcpy(&botleft, WACS_LLCORNER, sizeof(cchar_t));
|
||||
if (br && wcwidth( br->vals[0]))
|
||||
memcpy(&botright, br, sizeof(cchar_t));
|
||||
else
|
||||
memcpy(&botright, WACS_LRCORNER, sizeof(cchar_t));
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT, "wborder_set: left = %c, 0x%x\n",
|
||||
left.vals[0], left.attributes );
|
||||
__CTRACE(__CTRACE_INPUT, "wborder_set: right = %c, 0x%x\n",
|
||||
right.vals[0], right.attributes );
|
||||
__CTRACE(__CTRACE_INPUT, "wborder_set: top = %c, 0x%x\n",
|
||||
top.vals[0], top.attributes );
|
||||
__CTRACE(__CTRACE_INPUT, "wborder_set: bottom = %c, 0x%x\n",
|
||||
bottom.vals[0], bottom.attributes );
|
||||
__CTRACE(__CTRACE_INPUT, "wborder_set: topleft = %c, 0x%x\n",
|
||||
topleft.vals[0], topleft.attributes );
|
||||
__CTRACE(__CTRACE_INPUT, "wborder_set: topright = %c, 0x%x\n",
|
||||
topright.vals[0], topright.attributes );
|
||||
__CTRACE(__CTRACE_INPUT, "wborder_set: botleft = %c, 0x%x\n",
|
||||
botleft.vals[0], botleft.attributes );
|
||||
__CTRACE(__CTRACE_INPUT, "wborder_set: botright = %c, 0x%x\n",
|
||||
botright.vals[0], botright.attributes );
|
||||
#endif
|
||||
|
||||
/* Merge window attributes */
|
||||
left.attributes |= (left.attributes & __COLOR) ?
|
||||
(win->wattr & ~__COLOR) : win->wattr;
|
||||
left.attributes |= (left.attributes & __COLOR) ?
|
||||
(win->battr & ~__COLOR) : win->battr;
|
||||
right.attributes |= (right.attributes & __COLOR) ?
|
||||
(win->wattr & ~__COLOR) : win->wattr;
|
||||
right.attributes |= (right.attributes & __COLOR) ?
|
||||
(win->battr & ~__COLOR) : win->battr;
|
||||
top.attributes |= (top.attributes & __COLOR) ?
|
||||
(win->wattr & ~__COLOR) : win->wattr;
|
||||
top.attributes |= (top.attributes & __COLOR) ?
|
||||
(win->battr & ~__COLOR) : win->battr;
|
||||
bottom.attributes |= (bottom.attributes & __COLOR) ?
|
||||
(win->wattr & ~__COLOR) : win->wattr;
|
||||
bottom.attributes |= (bottom.attributes & __COLOR) ?
|
||||
(win->battr & ~__COLOR) : win->battr;
|
||||
topleft.attributes |= (topleft.attributes & __COLOR) ?
|
||||
(win->wattr & ~__COLOR) : win->wattr;
|
||||
topleft.attributes |= (topleft.attributes & __COLOR) ?
|
||||
(win->battr & ~__COLOR) : win->battr;
|
||||
topright.attributes |= (topright.attributes & __COLOR) ?
|
||||
(win->wattr & ~__COLOR) : win->wattr;
|
||||
topright.attributes |= (topright.attributes & __COLOR) ?
|
||||
(win->battr & ~__COLOR) : win->battr;
|
||||
botleft.attributes |= (botleft.attributes & __COLOR) ?
|
||||
(win->wattr & ~__COLOR) : win->wattr;
|
||||
botleft.attributes |= (botleft.attributes & __COLOR) ?
|
||||
(win->battr & ~__COLOR) : win->battr;
|
||||
botright.attributes |= (botright.attributes & __COLOR) ?
|
||||
(win->wattr & ~__COLOR) : win->wattr;
|
||||
botright.attributes |= (botright.attributes & __COLOR) ?
|
||||
(win->battr & ~__COLOR) : win->battr;
|
||||
|
||||
endx = win->maxx - 1;
|
||||
endy = win->maxy - 1;
|
||||
|
||||
/* Sides */
|
||||
for (i = 1; i < endy; i++) {
|
||||
/* left border */
|
||||
cw = wcwidth(left.vals[0]);
|
||||
if (cw < 0)
|
||||
cw = 1;
|
||||
for ( j = 0; j < cw; j++ ) {
|
||||
win->alines[i]->line[j].ch = left.vals[0];
|
||||
win->alines[i]->line[j].attr = left.attributes;
|
||||
np = win->alines[i]->line[j].nsp;
|
||||
if (np) {
|
||||
while (np) {
|
||||
tnp = np->next;
|
||||
free(np);
|
||||
np = tnp;
|
||||
}
|
||||
win->alines[i]->line[j].nsp = NULL;
|
||||
}
|
||||
if (j)
|
||||
SET_WCOL(win->alines[i]->line[j], -j);
|
||||
else {
|
||||
SET_WCOL(win->alines[i]->line[j], cw);
|
||||
if (left.elements > 1) {
|
||||
for (k = 1; k < left.elements; k++) {
|
||||
np = malloc(sizeof(nschar_t));
|
||||
if (!np)
|
||||
return ERR;
|
||||
np->ch = left.vals[ k ];
|
||||
np->next = win->alines[i]->line[j].nsp;
|
||||
win->alines[i]->line[j].nsp
|
||||
= np;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (j = cw; WCOL(win->alines[i]->line[j]) < 0; j++) {
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT,
|
||||
"wborder_set: clean out partial char[%d]", j);
|
||||
#endif /* DEBUG */
|
||||
win->alines[i]->line[j].ch = ( wchar_t )btowc(win->bch);
|
||||
if (_cursesi_copy_nsp(win->bnsp,
|
||||
&win->alines[i]->line[j]) == ERR)
|
||||
return ERR;
|
||||
SET_WCOL(win->alines[i]->line[j], 1);
|
||||
}
|
||||
/* right border */
|
||||
cw = wcwidth(right.vals[0]);
|
||||
if (cw < 0)
|
||||
cw = 1;
|
||||
pcw = WCOL( win->alines[i]->line[endx - cw]);
|
||||
for ( j = endx - cw + 1; j <= endx; j++ ) {
|
||||
win->alines[i]->line[j].ch = right.vals[0];
|
||||
win->alines[i]->line[j].attr = right.attributes;
|
||||
np = win->alines[i]->line[j].nsp;
|
||||
if (np) {
|
||||
while (np) {
|
||||
tnp = np->next;
|
||||
free(np);
|
||||
np = tnp;
|
||||
}
|
||||
win->alines[i]->line[j].nsp = NULL;
|
||||
}
|
||||
if (j == endx - cw + 1) {
|
||||
SET_WCOL(win->alines[i]->line[j], cw);
|
||||
if (right.elements > 1) {
|
||||
for (k = 1; k < right.elements; k++) {
|
||||
np = malloc(sizeof(nschar_t));
|
||||
if (!np)
|
||||
return ERR;
|
||||
np->ch = right.vals[ k ];
|
||||
np->next = win->alines[i]->line[j].nsp;
|
||||
win->alines[i]->line[j].nsp
|
||||
= np;
|
||||
}
|
||||
}
|
||||
} else
|
||||
SET_WCOL(win->alines[i]->line[j],
|
||||
endx - cw + 1 - j);
|
||||
}
|
||||
if (pcw != 1) {
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_INPUT,
|
||||
"wborder_set: clean out partial chars[%d:%d]",
|
||||
endx - cw + pcw, endx - cw );
|
||||
#endif /* DEBUG */
|
||||
k = pcw < 0 ? endx -cw + pcw : endx - cw;
|
||||
for (j = endx - cw; j >= k; j--) {
|
||||
win->alines[i]->line[j].ch
|
||||
= (wchar_t)btowc(win->bch);
|
||||
if (_cursesi_copy_nsp(win->bnsp,
|
||||
&win->alines[i]->line[j]) == ERR)
|
||||
return ERR;
|
||||
win->alines[i]->line[j].attr = win->battr;
|
||||
SET_WCOL(win->alines[i]->line[j], 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
tlcw = wcwidth(topleft.vals[0]);
|
||||
if (tlcw < 0)
|
||||
tlcw = 1;
|
||||
blcw = wcwidth(botleft.vals[0]);
|
||||
if (blcw < 0)
|
||||
blcw = 1;
|
||||
trcw = wcwidth(topright.vals[0]);
|
||||
if (trcw < 0)
|
||||
trcw = 1;
|
||||
brcw = wcwidth(botright.vals[0]);
|
||||
if (brcw < 0)
|
||||
brcw = 1;
|
||||
/* upper border */
|
||||
cw = wcwidth(top.vals[0]);
|
||||
if (cw < 0)
|
||||
cw = 1;
|
||||
for (i = tlcw; i <= min( endx - cw, endx - trcw); i += cw) {
|
||||
for (j = 0; j < cw; j++) {
|
||||
win->alines[0]->line[i + j].ch = top.vals[0];
|
||||
win->alines[0]->line[i + j].attr = top.attributes;
|
||||
np = win->alines[0]->line[i + j].nsp;
|
||||
if (np) {
|
||||
while (np) {
|
||||
tnp = np->next;
|
||||
free(np);
|
||||
np = tnp;
|
||||
}
|
||||
win->alines[0]->line[i + j].nsp = NULL;
|
||||
}
|
||||
if (j)
|
||||
SET_WCOL(win->alines[ 0 ]->line[ i + j ], -j);
|
||||
else {
|
||||
SET_WCOL(win->alines[ 0 ]->line[ i + j ], cw);
|
||||
if ( top.elements > 1 ) {
|
||||
for (k = 1; k < top.elements; k++) {
|
||||
np = malloc(sizeof(nschar_t));
|
||||
if (!np)
|
||||
return ERR;
|
||||
np->ch = top.vals[k];
|
||||
np->next = win->alines[0]->line[i + j].nsp;
|
||||
win->alines[0]->line[i + j].nsp
|
||||
= np;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
while (i <= endx - trcw) {
|
||||
win->alines[0]->line[i].ch =
|
||||
(wchar_t)btowc((int) win->bch);
|
||||
if (_cursesi_copy_nsp(win->bnsp,
|
||||
&win->alines[0]->line[i]) == ERR)
|
||||
return ERR;
|
||||
win->alines[0]->line[i].attr = win->battr;
|
||||
SET_WCOL(win->alines[0]->line[i], 1);
|
||||
i++;
|
||||
}
|
||||
/* lower border */
|
||||
for (i = blcw; i <= min( endx - cw, endx - brcw); i += cw) {
|
||||
for (j = 0; j < cw; j++) {
|
||||
win->alines[endy]->line[i + j].ch = bottom.vals[0];
|
||||
win->alines[endy]->line[i + j].attr = bottom.attributes;
|
||||
np = win->alines[endy]->line[i + j].nsp;
|
||||
if (np) {
|
||||
while (np) {
|
||||
tnp = np->next;
|
||||
free(np);
|
||||
np = tnp;
|
||||
}
|
||||
win->alines[endy]->line[i + j].nsp = NULL;
|
||||
}
|
||||
if (j)
|
||||
SET_WCOL(win->alines[endy]->line[i + j], -j);
|
||||
else {
|
||||
SET_WCOL(win->alines[endy]->line[i + j], cw);
|
||||
if (bottom.elements > 1) {
|
||||
for (k = 1; k < bottom.elements; k++) {
|
||||
np = malloc(sizeof(nschar_t));
|
||||
if (!np)
|
||||
return ERR;
|
||||
np->ch = bottom.vals[ k ];
|
||||
np->next = win->alines[endy]->line[i + j].nsp;
|
||||
win->alines[endy]->line[i + j].nsp = np;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
while (i <= endx - brcw) {
|
||||
win->alines[endy]->line[i].ch = (wchar_t)btowc((int) win->bch );
|
||||
if (_cursesi_copy_nsp(win->bnsp,
|
||||
&win->alines[endy]->line[i]) == ERR)
|
||||
return ERR;
|
||||
win->alines[endy]->line[i].attr = win->battr;
|
||||
SET_WCOL(win->alines[endy]->line[ i ], 1);
|
||||
i++;
|
||||
}
|
||||
|
||||
/* Corners */
|
||||
if (!(win->maxy == LINES && win->maxx == COLS &&
|
||||
(win->flags & __SCROLLOK) && (win->flags & __SCROLLWIN))) {
|
||||
for (i = 0; i < tlcw; i++) {
|
||||
win->alines[0]->line[i].ch = topleft.vals[0];
|
||||
win->alines[0]->line[i].attr = topleft.attributes;
|
||||
np = win->alines[0]->line[i].nsp;
|
||||
if (np) {
|
||||
while (np) {
|
||||
tnp = np->next;
|
||||
free(np);
|
||||
np = tnp;
|
||||
}
|
||||
win->alines[0]->line[i].nsp = NULL;
|
||||
}
|
||||
if (i)
|
||||
SET_WCOL(win->alines[0]->line[i], -i);
|
||||
else {
|
||||
SET_WCOL(win->alines[0]->line[i], tlcw);
|
||||
if (topleft.elements > 1) {
|
||||
for (k = 1; k < topleft.elements; k++)
|
||||
{
|
||||
np = malloc(sizeof(nschar_t));
|
||||
if (!np)
|
||||
return ERR;
|
||||
np->ch = topleft.vals[k];
|
||||
np->next = win->alines[0]->line[i].nsp;
|
||||
win->alines[0]->line[i].nsp = np;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = endx - trcw + 1; i <= endx; i++) {
|
||||
win->alines[0]->line[i].ch = topright.vals[0];
|
||||
win->alines[0]->line[i].attr = topright.attributes;
|
||||
np = win->alines[0]->line[i].nsp;
|
||||
if (np) {
|
||||
while (np) {
|
||||
tnp = np->next;
|
||||
free(np);
|
||||
np = tnp;
|
||||
}
|
||||
win->alines[0]->line[i].nsp = NULL;
|
||||
}
|
||||
if (i == endx - trcw + 1) {
|
||||
SET_WCOL(win->alines[0]->line[i], trcw);
|
||||
if (topright.elements > 1) {
|
||||
for (k = 1; k < topright.elements;k ++)
|
||||
{
|
||||
np = malloc(sizeof(nschar_t));
|
||||
if (!np)
|
||||
return ERR;
|
||||
np->ch = topright.vals[k];
|
||||
np->next = win->alines[0]->line[i].nsp;
|
||||
win->alines[ 0 ]->line[i].nsp = np;
|
||||
}
|
||||
}
|
||||
} else
|
||||
SET_WCOL(win->alines[0]->line[i],
|
||||
endx - trcw + 1 - i);
|
||||
}
|
||||
for (i = 0; i < blcw; i++) {
|
||||
win->alines[endy]->line[i].ch = botleft.vals[0];
|
||||
win->alines[endy]->line[i].attr = botleft.attributes;
|
||||
np = win->alines[ endy ]->line[i].nsp;
|
||||
if (np) {
|
||||
while (np) {
|
||||
tnp = np->next;
|
||||
free(np);
|
||||
np = tnp;
|
||||
}
|
||||
win->alines[endy]->line[i].nsp = NULL;
|
||||
}
|
||||
if (i)
|
||||
SET_WCOL(win->alines[endy]->line[i], -i);
|
||||
else {
|
||||
SET_WCOL(win->alines[endy]->line[i], blcw);
|
||||
if (botleft.elements > 1) {
|
||||
for (k = 1; k < botleft.elements; k++) {
|
||||
np = malloc(sizeof(nschar_t));
|
||||
if (!np)
|
||||
return ERR;
|
||||
np->ch = botleft.vals[ k ];
|
||||
np->next = win->alines[endy]->line[i].nsp;
|
||||
win->alines[endy]->line[i].nsp = np;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i = endx - brcw + 1; i <= endx; i++) {
|
||||
win->alines[endy]->line[i].ch = botright.vals[0];
|
||||
win->alines[endy]->line[i].attr = botright.attributes;
|
||||
np = win->alines[endy]->line[i].nsp;
|
||||
if (np) {
|
||||
while (np) {
|
||||
tnp = np->next;
|
||||
free(np);
|
||||
np = tnp;
|
||||
}
|
||||
win->alines[endy]->line[i].nsp = NULL;
|
||||
}
|
||||
if (i == endx - brcw + 1) {
|
||||
SET_WCOL(win->alines[endy]->line[i], brcw);
|
||||
if (botright.elements > 1) {
|
||||
for (k = 1; k < botright.elements; k++){
|
||||
np = malloc(sizeof(nschar_t));
|
||||
if (!np)
|
||||
return ERR;
|
||||
np->ch = botright.vals[k];
|
||||
np->next = win->alines[endy]->line[i].nsp;
|
||||
win->alines[endy]->line[i].nsp = np;
|
||||
}
|
||||
}
|
||||
} else
|
||||
SET_WCOL(win->alines[endy]->line[i],
|
||||
endx - brcw + 1 - i);
|
||||
}
|
||||
}
|
||||
__touchwin(win);
|
||||
return OK;
|
||||
#endif /* HAVE_WCHAR */
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_border.3
|
||||
Vendored
+56
@@ -0,0 +1,56 @@
|
||||
/* $NetBSD: box.c,v 1.15 2017/01/06 13:53:18 roy Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <netbsd_sys/cdefs.h>
|
||||
|
||||
#include "curses.h"
|
||||
|
||||
/*
|
||||
* box --
|
||||
* Draw a box around the given window with "vert" as the vertical
|
||||
* delimiting char, and "hor", as the horizontal one. Uses wborder().
|
||||
*/
|
||||
int
|
||||
box(WINDOW *win, chtype vert, chtype hor)
|
||||
{
|
||||
return (wborder(win, vert, vert, hor, hor, 0, 0, 0, 0));
|
||||
}
|
||||
|
||||
int
|
||||
box_set(WINDOW *win, const cchar_t *verch, const cchar_t *horch)
|
||||
{
|
||||
#ifndef HAVE_WCHAR
|
||||
return ERR;
|
||||
#else
|
||||
return wborder_set(win, verch, verch, horch, horch,
|
||||
NULL, NULL, NULL, NULL);
|
||||
#endif /* HAVE_WCHAR */
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_color.3
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_tty.3
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
/* $NetBSD: cchar.c,v 1.12 2020/07/02 23:43:01 uwe Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2005 The NetBSD Foundation Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from code donated to the NetBSD Foundation
|
||||
* by Ruibiao Qiu <ruibiao@arl.wustl.edu,ruibiao@gmail.com>.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
|
||||
* CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#define _XOPEN_SOURCE 700
|
||||
#include <netbsd_sys/cdefs.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "curses.h"
|
||||
#include "curses_private.h"
|
||||
|
||||
/*
|
||||
* getcchar --
|
||||
* get a wide-character string and rendition from a cchar_t
|
||||
*/
|
||||
int
|
||||
getcchar(const cchar_t *wcval, wchar_t *wch, attr_t *attrs,
|
||||
short *color_pair, void *opts)
|
||||
{
|
||||
wchar_t *wp;
|
||||
size_t len;
|
||||
|
||||
if (__predict_false(opts != NULL))
|
||||
return ERR;
|
||||
|
||||
wp = wmemchr(wcval->vals, L'\0', CCHARW_MAX);
|
||||
len = wp ? wp - wcval->vals : CCHARW_MAX;
|
||||
|
||||
if (wch == NULL)
|
||||
return (int)len;
|
||||
|
||||
if (attrs == NULL || color_pair == NULL)
|
||||
return ERR;
|
||||
|
||||
if (len > 0) {
|
||||
*attrs = wcval->attributes;
|
||||
if (__using_color)
|
||||
*color_pair = PAIR_NUMBER(wcval->attributes);
|
||||
else
|
||||
*color_pair = 0;
|
||||
wmemcpy(wch, wcval->vals, len);
|
||||
wch[len] = L'\0';
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* setcchar --
|
||||
* set cchar_t from a wide-character string and rendition
|
||||
*/
|
||||
int
|
||||
setcchar(cchar_t *wcval, const wchar_t *wch, const attr_t attrs,
|
||||
short color_pair, const void *opts)
|
||||
{
|
||||
int i;
|
||||
size_t len;
|
||||
|
||||
if (__predict_false(opts != NULL))
|
||||
return ERR;
|
||||
|
||||
len = wcslen(wch);
|
||||
if (len > CCHARW_MAX || (len > 1 && wcwidth(wch[0]) < 0))
|
||||
return ERR;
|
||||
|
||||
/*
|
||||
* If we have a following spacing-character, stop at that point. We
|
||||
* are only interested in adding non-spacing characters.
|
||||
*/
|
||||
for (i = 1; i < len; ++i) {
|
||||
if (wcwidth(wch[i]) != 0) {
|
||||
len = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
memset(wcval, 0, sizeof(*wcval));
|
||||
if (len != 0) {
|
||||
wcval->attributes = attrs & ~__COLOR;
|
||||
if (__using_color && color_pair)
|
||||
wcval->attributes |= COLOR_PAIR(color_pair);
|
||||
wcval->elements = len;
|
||||
memcpy(&wcval->vals, wch, len * sizeof(wchar_t));
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
void
|
||||
__cursesi_chtype_to_cchar(chtype in, cchar_t *out)
|
||||
{
|
||||
unsigned int idx;
|
||||
|
||||
if (in & __ACS_IS_WACS) {
|
||||
idx = in & __CHARTEXT;
|
||||
if (idx < NUM_ACS) {
|
||||
memcpy(out, &_wacs_char[idx], sizeof(cchar_t));
|
||||
out->attributes |= in & __ATTRIBUTES;
|
||||
return;
|
||||
}
|
||||
}
|
||||
out->vals[0] = in & __CHARTEXT;
|
||||
out->attributes = in & __ATTRIBUTES;
|
||||
out->elements = 1;
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_chgat.3
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
/* $NetBSD: chgat.c,v 1.5 2012/09/28 06:05:19 blymn Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2009 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Joerg Sonnenberger.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <netbsd_sys/cdefs.h>
|
||||
|
||||
#include "curses.h"
|
||||
#include "curses_private.h"
|
||||
|
||||
int
|
||||
chgat(int n, attr_t attr, short color, const void *opts)
|
||||
{
|
||||
return wchgat(stdscr, n, attr, color, opts);
|
||||
}
|
||||
|
||||
int
|
||||
mvchgat(int y, int x, int n, attr_t attr, short color,
|
||||
const void *opts)
|
||||
{
|
||||
return mvwchgat(stdscr, y, x, n, attr, color, opts);
|
||||
}
|
||||
|
||||
int
|
||||
wchgat(WINDOW *win, int n, attr_t attr, short color, const void *opts)
|
||||
{
|
||||
return mvwchgat(win, win->cury, win->curx, n, attr, color, opts);
|
||||
}
|
||||
|
||||
int
|
||||
mvwchgat(WINDOW *win , int y, int x, int count, attr_t attr, short color,
|
||||
const void *opts)
|
||||
{
|
||||
__LINE *lp;
|
||||
__LDATA *lc;
|
||||
|
||||
if (x < 0 || y < 0)
|
||||
return (ERR);
|
||||
if (x >= win->maxx || y >= win->maxy)
|
||||
return (ERR);
|
||||
|
||||
attr = (attr & ~__COLOR) | COLOR_PAIR(color);
|
||||
|
||||
if (count < 0 || count > win->maxx - x)
|
||||
count = win->maxx - x;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_ATTR, "mvwchgat: x: %d y: %d count: %d attr: 0x%x "
|
||||
"color pair %d\n", x, y, count, (attr & ~__COLOR),
|
||||
PAIR_NUMBER(color));
|
||||
#endif
|
||||
lp = win->alines[y];
|
||||
lc = &lp->line[x];
|
||||
|
||||
if (x + win->ch_off < *lp->firstchp)
|
||||
*lp->firstchp = x + win->ch_off;
|
||||
if (x + win->ch_off + count > *lp->lastchp)
|
||||
*lp->lastchp = x + win->ch_off + count;
|
||||
|
||||
while (count-- > 0) {
|
||||
lp->flags |= __ISDIRTY;
|
||||
#ifdef HAVE_WCHAR
|
||||
lc->attr = (lc->attr & ~WA_ATTRIBUTES) | attr;
|
||||
#else
|
||||
lc->attr = attr;
|
||||
#endif
|
||||
++lc;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_clear.3
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
/* $NetBSD: clear.c,v 1.13 2003/08/07 16:44:19 agc Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <netbsd_sys/cdefs.h>
|
||||
|
||||
#include "curses.h"
|
||||
#include "curses_private.h"
|
||||
|
||||
#ifndef _CURSES_USE_MACROS
|
||||
|
||||
/*
|
||||
* clear --
|
||||
* Clear stdscr
|
||||
*/
|
||||
int
|
||||
clear(void)
|
||||
{
|
||||
return wclear(_cursesi_screen->stdscr);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* wclear --
|
||||
* Clear the window.
|
||||
*/
|
||||
int
|
||||
wclear(WINDOW *win)
|
||||
{
|
||||
if (werase(win) == OK) {
|
||||
win->flags |= __CLEAROK;
|
||||
return (OK);
|
||||
}
|
||||
return (ERR);
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_clear.3
|
||||
+49
@@ -0,0 +1,49 @@
|
||||
/* $NetBSD: clearok.c,v 1.5 2008/04/28 20:23:01 martin Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Julian Coleman.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <netbsd_sys/cdefs.h>
|
||||
|
||||
#include "curses.h"
|
||||
#include "curses_private.h"
|
||||
|
||||
/*
|
||||
* clearok --
|
||||
* Turn on and off clear before refresh for the given window.
|
||||
*/
|
||||
int
|
||||
clearok(WINDOW *win, bool bf)
|
||||
{
|
||||
if (bf)
|
||||
win->flags |= __CLEAROK;
|
||||
else
|
||||
win->flags &= ~__CLEAROK;
|
||||
return (OK);
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_clear.3
|
||||
+113
@@ -0,0 +1,113 @@
|
||||
/* $NetBSD: clrtobot.c,v 1.27 2020/03/15 01:18:43 uwe Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <netbsd_sys/cdefs.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "curses.h"
|
||||
#include "curses_private.h"
|
||||
|
||||
#ifndef _CURSES_USE_MACROS
|
||||
|
||||
/*
|
||||
* clrtobot --
|
||||
* Erase everything on stdscr.
|
||||
*/
|
||||
int
|
||||
clrtobot(void)
|
||||
{
|
||||
return wclrtobot(stdscr);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* wclrtobot --
|
||||
* Erase everything on the window.
|
||||
*/
|
||||
int
|
||||
wclrtobot(WINDOW *win)
|
||||
{
|
||||
int minx, startx, starty, y;
|
||||
__LDATA *sp, *end, *maxx;
|
||||
wchar_t bch;
|
||||
attr_t battr;
|
||||
|
||||
#ifdef HAVE_WCHAR
|
||||
bch = (wchar_t)btowc((int)win->bch);
|
||||
#else
|
||||
bch = win->bch;
|
||||
#endif
|
||||
if (win != curscr)
|
||||
battr = win->battr & __ATTRIBUTES;
|
||||
else
|
||||
battr = 0;
|
||||
|
||||
#ifdef __GNUC__
|
||||
maxx = NULL; /* XXX gcc -Wuninitialized */
|
||||
#endif
|
||||
if (win->alines[win->cury]->flags & __ISPASTEOL) {
|
||||
starty = win->cury + 1;
|
||||
startx = 0;
|
||||
} else {
|
||||
starty = win->cury;
|
||||
startx = win->curx;
|
||||
}
|
||||
|
||||
for (y = starty; y < win->maxy; y++) {
|
||||
minx = -1;
|
||||
end = &win->alines[y]->line[win->maxx];
|
||||
for (sp = &win->alines[y]->line[startx]; sp < end; sp++) {
|
||||
if (!(__NEED_ERASE(sp, bch, battr)))
|
||||
continue;
|
||||
|
||||
maxx = sp;
|
||||
if (minx == -1)
|
||||
minx = (int)(sp - win->alines[y]->line);
|
||||
|
||||
sp->ch = bch;
|
||||
sp->attr = battr | (sp->attr & __ALTCHARSET);
|
||||
#ifdef HAVE_WCHAR
|
||||
if (_cursesi_copy_nsp(win->bnsp, sp) == ERR)
|
||||
return ERR;
|
||||
SET_WCOL(*sp, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (minx != -1)
|
||||
__touchline(win, y, minx,
|
||||
(int)(maxx - win->alines[y]->line));
|
||||
startx = 0;
|
||||
}
|
||||
|
||||
__sync(win);
|
||||
return OK;
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_clear.3
|
||||
+117
@@ -0,0 +1,117 @@
|
||||
/* $NetBSD: clrtoeol.c,v 1.31 2020/03/15 01:18:43 uwe Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1981, 1993, 1994
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <netbsd_sys/cdefs.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "curses.h"
|
||||
#include "curses_private.h"
|
||||
|
||||
#ifndef _CURSES_USE_MACROS
|
||||
|
||||
/*
|
||||
* clrtoeol --
|
||||
* Clear up to the end of line.
|
||||
*/
|
||||
int
|
||||
clrtoeol(void)
|
||||
{
|
||||
return wclrtoeol(stdscr);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* wclrtoeol --
|
||||
* Clear up to the end of line.
|
||||
*/
|
||||
int
|
||||
wclrtoeol(WINDOW *win)
|
||||
{
|
||||
int minx, x, y;
|
||||
__LDATA *end, *maxx, *sp;
|
||||
wchar_t bch;
|
||||
attr_t battr;
|
||||
|
||||
#ifdef HAVE_WCHAR
|
||||
bch = (wchar_t)btowc((int)win->bch);
|
||||
#else
|
||||
bch = win->bch;
|
||||
#endif
|
||||
if (win != curscr)
|
||||
battr = win->battr & __ATTRIBUTES;
|
||||
else
|
||||
battr = 0;
|
||||
|
||||
y = win->cury;
|
||||
x = win->curx;
|
||||
if (win->alines[y]->flags & __ISPASTEOL) {
|
||||
if (y < win->maxy - 1) {
|
||||
win->alines[y]->flags &= ~__ISPASTEOL;
|
||||
y++;
|
||||
x = 0;
|
||||
win->cury = y;
|
||||
win->curx = x;
|
||||
} else
|
||||
return OK;
|
||||
}
|
||||
end = &win->alines[y]->line[win->maxx];
|
||||
minx = -1;
|
||||
maxx = &win->alines[y]->line[x];
|
||||
|
||||
for (sp = maxx; sp < end; sp++) {
|
||||
if (!(__NEED_ERASE(sp, bch, battr)))
|
||||
continue;
|
||||
|
||||
maxx = sp;
|
||||
if (minx == -1)
|
||||
minx = (int)(sp - win->alines[y]->line);
|
||||
|
||||
sp->ch = bch;
|
||||
sp->attr = battr | (sp->attr & __ALTCHARSET);
|
||||
#ifdef HAVE_WCHAR
|
||||
if (_cursesi_copy_nsp(win->bnsp, sp) == ERR)
|
||||
return ERR;
|
||||
SET_WCOL(*sp, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_ERASE, "CLRTOEOL: y = %d, minx = %d, maxx = %d, "
|
||||
"firstch = %d, lastch = %d\n",
|
||||
y, minx, (int)(maxx - win->alines[y]->line),
|
||||
*win->alines[y]->firstchp, *win->alines[y]->lastchp);
|
||||
#endif
|
||||
/* Update firstch and lastch for the line. */
|
||||
__touchline(win, y, x, (int)win->maxx - 1);
|
||||
__sync(win);
|
||||
return OK;
|
||||
}
|
||||
+701
@@ -0,0 +1,701 @@
|
||||
/* $NetBSD: color.c,v 1.41 2017/01/06 13:53:18 roy Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
* by Julian Coleman.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <netbsd_sys/cdefs.h>
|
||||
|
||||
#include "curses.h"
|
||||
#include "curses_private.h"
|
||||
|
||||
/* Have we initialised colours? */
|
||||
int __using_color = 0;
|
||||
|
||||
/* Default colour number */
|
||||
attr_t __default_color = 0;
|
||||
|
||||
/* Default colour pair values - white on black. */
|
||||
struct __pair __default_pair = {COLOR_WHITE, COLOR_BLACK, 0};
|
||||
|
||||
/* Default colour values */
|
||||
/* Flags for colours and pairs */
|
||||
#define __USED 0x01
|
||||
|
||||
static void
|
||||
__change_pair(short);
|
||||
|
||||
static int
|
||||
init_color_value(short, short, short, short);
|
||||
|
||||
/*
|
||||
* has_colors --
|
||||
* Check if terminal has colours.
|
||||
*/
|
||||
bool
|
||||
has_colors(void)
|
||||
{
|
||||
if (max_colors > 0 && max_pairs > 0 &&
|
||||
((set_a_foreground != NULL && set_a_background != NULL) ||
|
||||
initialize_pair != NULL || initialize_color != NULL ||
|
||||
(set_background != NULL && set_foreground != NULL)))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* can_change_color --
|
||||
* Check if terminal can change colours.
|
||||
*/
|
||||
bool
|
||||
can_change_color(void)
|
||||
{
|
||||
return can_change ? true : false;
|
||||
}
|
||||
|
||||
/*
|
||||
* start_color --
|
||||
* Initialise colour support.
|
||||
*/
|
||||
int
|
||||
start_color(void)
|
||||
{
|
||||
int i;
|
||||
attr_t temp_nc;
|
||||
struct __winlist *wlp;
|
||||
WINDOW *win;
|
||||
int y, x;
|
||||
|
||||
if (has_colors() == FALSE)
|
||||
return ERR;
|
||||
|
||||
/* Max colours and colour pairs */
|
||||
if (max_colors == -1)
|
||||
COLORS = 0;
|
||||
else {
|
||||
COLORS = max_colors > MAX_COLORS ? MAX_COLORS : max_colors;
|
||||
if (max_pairs == -1) {
|
||||
COLOR_PAIRS = 0;
|
||||
COLORS = 0;
|
||||
} else {
|
||||
COLOR_PAIRS = (max_pairs > MAX_PAIRS - 1 ?
|
||||
MAX_PAIRS - 1 : max_pairs);
|
||||
/* Use the last colour pair for curses default. */
|
||||
__default_color = COLOR_PAIR(MAX_PAIRS - 1);
|
||||
}
|
||||
}
|
||||
if (!COLORS)
|
||||
return ERR;
|
||||
|
||||
_cursesi_screen->COLORS = COLORS;
|
||||
_cursesi_screen->COLOR_PAIRS = COLOR_PAIRS;
|
||||
|
||||
/* Reset terminal colour and colour pairs. */
|
||||
if (orig_colors != NULL)
|
||||
tputs(orig_colors, 0, __cputchar);
|
||||
if (orig_pair != NULL) {
|
||||
tputs(orig_pair, 0, __cputchar);
|
||||
curscr->wattr &= _cursesi_screen->mask_op;
|
||||
}
|
||||
|
||||
/* Type of colour manipulation - ANSI/TEK/HP/other */
|
||||
if (set_a_foreground != NULL && set_a_background != NULL)
|
||||
_cursesi_screen->color_type = COLOR_ANSI;
|
||||
else if (initialize_pair != NULL)
|
||||
_cursesi_screen->color_type = COLOR_HP;
|
||||
else if (initialize_color != NULL)
|
||||
_cursesi_screen->color_type = COLOR_TEK;
|
||||
else if (set_foreground != NULL && set_background != NULL)
|
||||
_cursesi_screen->color_type = COLOR_OTHER;
|
||||
else
|
||||
return(ERR); /* Unsupported colour method */
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_COLOR, "start_color: COLORS = %d, COLOR_PAIRS = %d",
|
||||
COLORS, COLOR_PAIRS);
|
||||
switch (_cursesi_screen->color_type) {
|
||||
case COLOR_ANSI:
|
||||
__CTRACE(__CTRACE_COLOR, " (ANSI style)\n");
|
||||
break;
|
||||
case COLOR_HP:
|
||||
__CTRACE(__CTRACE_COLOR, " (HP style)\n");
|
||||
break;
|
||||
case COLOR_TEK:
|
||||
__CTRACE(__CTRACE_COLOR, " (Tektronics style)\n");
|
||||
break;
|
||||
case COLOR_OTHER:
|
||||
__CTRACE(__CTRACE_COLOR, " (Other style)\n");
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Attributes that cannot be used with color.
|
||||
* Store these in an attr_t for wattrset()/wattron().
|
||||
*/
|
||||
_cursesi_screen->nca = __NORMAL;
|
||||
if (no_color_video != -1) {
|
||||
temp_nc = (attr_t)t_no_color_video(_cursesi_screen->term);
|
||||
if (temp_nc & 0x0001)
|
||||
_cursesi_screen->nca |= __STANDOUT;
|
||||
if (temp_nc & 0x0002)
|
||||
_cursesi_screen->nca |= __UNDERSCORE;
|
||||
if (temp_nc & 0x0004)
|
||||
_cursesi_screen->nca |= __REVERSE;
|
||||
if (temp_nc & 0x0008)
|
||||
_cursesi_screen->nca |= __BLINK;
|
||||
if (temp_nc & 0x0010)
|
||||
_cursesi_screen->nca |= __DIM;
|
||||
if (temp_nc & 0x0020)
|
||||
_cursesi_screen->nca |= __BOLD;
|
||||
if (temp_nc & 0x0040)
|
||||
_cursesi_screen->nca |= __BLANK;
|
||||
if (temp_nc & 0x0080)
|
||||
_cursesi_screen->nca |= __PROTECT;
|
||||
if (temp_nc & 0x0100)
|
||||
_cursesi_screen->nca |= __ALTCHARSET;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_COLOR, "start_color: _cursesi_screen->nca = %08x\n",
|
||||
_cursesi_screen->nca);
|
||||
#endif
|
||||
|
||||
/* Set up initial 8 colours */
|
||||
#define RGB_ON 680 /* Allow for bright colours */
|
||||
if (COLORS >= COLOR_BLACK)
|
||||
(void)init_color_value(COLOR_BLACK, 0, 0, 0);
|
||||
if (COLORS >= COLOR_RED)
|
||||
(void)init_color_value(COLOR_RED, RGB_ON, 0, 0);
|
||||
if (COLORS >= COLOR_GREEN)
|
||||
(void)init_color_value(COLOR_GREEN, 0, RGB_ON, 0);
|
||||
if (COLORS >= COLOR_YELLOW)
|
||||
(void)init_color_value(COLOR_YELLOW, RGB_ON, RGB_ON, 0);
|
||||
if (COLORS >= COLOR_BLUE)
|
||||
(void)init_color_value(COLOR_BLUE, 0, 0, RGB_ON);
|
||||
if (COLORS >= COLOR_MAGENTA)
|
||||
(void)init_color_value(COLOR_MAGENTA, RGB_ON, 0, RGB_ON);
|
||||
if (COLORS >= COLOR_CYAN)
|
||||
(void)init_color_value(COLOR_CYAN, 0, RGB_ON, RGB_ON);
|
||||
if (COLORS >= COLOR_WHITE)
|
||||
(void)init_color_value(COLOR_WHITE, RGB_ON, RGB_ON, RGB_ON);
|
||||
|
||||
/* Initialise other colours */
|
||||
for (i = 8; i < COLORS; i++) {
|
||||
_cursesi_screen->colours[i].red = 0;
|
||||
_cursesi_screen->colours[i].green = 0;
|
||||
_cursesi_screen->colours[i].blue = 0;
|
||||
_cursesi_screen->colours[i].flags = 0;
|
||||
}
|
||||
|
||||
/* Initialise pair 0 to default colours. */
|
||||
_cursesi_screen->colour_pairs[0].fore = -1;
|
||||
_cursesi_screen->colour_pairs[0].back = -1;
|
||||
_cursesi_screen->colour_pairs[0].flags = 0;
|
||||
|
||||
/* Initialise user colour pairs to default (white on black) */
|
||||
for (i = 0; i < COLOR_PAIRS; i++) {
|
||||
_cursesi_screen->colour_pairs[i].fore = COLOR_WHITE;
|
||||
_cursesi_screen->colour_pairs[i].back = COLOR_BLACK;
|
||||
_cursesi_screen->colour_pairs[i].flags = 0;
|
||||
}
|
||||
|
||||
/* Initialise default colour pair. */
|
||||
_cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].fore =
|
||||
__default_pair.fore;
|
||||
_cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].back =
|
||||
__default_pair.back;
|
||||
_cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].flags =
|
||||
__default_pair.flags;
|
||||
|
||||
__using_color = 1;
|
||||
|
||||
/* Set all positions on all windows to curses default colours. */
|
||||
for (wlp = _cursesi_screen->winlistp; wlp != NULL; wlp = wlp->nextp) {
|
||||
win = wlp->winp;
|
||||
if (wlp->winp != __virtscr && wlp->winp != curscr) {
|
||||
/* Set color attribute on other windows */
|
||||
win->battr |= __default_color;
|
||||
for (y = 0; y < win->maxy; y++) {
|
||||
for (x = 0; x < win->maxx; x++) {
|
||||
win->alines[y]->line[x].attr &= ~__COLOR;
|
||||
win->alines[y]->line[x].attr |= __default_color;
|
||||
}
|
||||
}
|
||||
__touchwin(win);
|
||||
}
|
||||
}
|
||||
|
||||
return(OK);
|
||||
}
|
||||
|
||||
/*
|
||||
* init_pair --
|
||||
* Set pair foreground and background colors.
|
||||
* Our default colour ordering is ANSI - 1 = red, 4 = blue, 3 = yellow,
|
||||
* 6 = cyan. The older style (Sb/Sf) uses 1 = blue, 4 = red, 3 = cyan,
|
||||
* 6 = yellow, so we swap them here and in pair_content().
|
||||
*/
|
||||
int
|
||||
init_pair(short pair, short fore, short back)
|
||||
{
|
||||
int changed;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_COLOR, "init_pair: %d, %d, %d\n", pair, fore, back);
|
||||
#endif
|
||||
|
||||
if (pair < 0 || pair >= COLOR_PAIRS)
|
||||
return ERR;
|
||||
|
||||
if (pair == 0) /* Ignore request for pair 0, it is default. */
|
||||
return OK;
|
||||
|
||||
if (fore >= COLORS)
|
||||
return ERR;
|
||||
if (back >= COLORS)
|
||||
return ERR;
|
||||
|
||||
/* Swap red/blue and yellow/cyan */
|
||||
if (_cursesi_screen->color_type == COLOR_OTHER) {
|
||||
switch (fore) {
|
||||
case COLOR_RED:
|
||||
fore = COLOR_BLUE;
|
||||
break;
|
||||
case COLOR_BLUE:
|
||||
fore = COLOR_RED;
|
||||
break;
|
||||
case COLOR_YELLOW:
|
||||
fore = COLOR_CYAN;
|
||||
break;
|
||||
case COLOR_CYAN:
|
||||
fore = COLOR_YELLOW;
|
||||
break;
|
||||
}
|
||||
switch (back) {
|
||||
case COLOR_RED:
|
||||
back = COLOR_BLUE;
|
||||
break;
|
||||
case COLOR_BLUE:
|
||||
back = COLOR_RED;
|
||||
break;
|
||||
case COLOR_YELLOW:
|
||||
back = COLOR_CYAN;
|
||||
break;
|
||||
case COLOR_CYAN:
|
||||
back = COLOR_YELLOW;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ((_cursesi_screen->colour_pairs[pair].flags & __USED) &&
|
||||
(fore != _cursesi_screen->colour_pairs[pair].fore ||
|
||||
back != _cursesi_screen->colour_pairs[pair].back))
|
||||
changed = 1;
|
||||
else
|
||||
changed = 0;
|
||||
|
||||
_cursesi_screen->colour_pairs[pair].flags |= __USED;
|
||||
_cursesi_screen->colour_pairs[pair].fore = fore;
|
||||
_cursesi_screen->colour_pairs[pair].back = back;
|
||||
|
||||
/* XXX: need to initialise HP style (Ip) */
|
||||
|
||||
if (changed)
|
||||
__change_pair(pair);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* pair_content --
|
||||
* Get pair foreground and background colours.
|
||||
*/
|
||||
int
|
||||
pair_content(short pair, short *forep, short *backp)
|
||||
{
|
||||
if (pair < 0 || pair > _cursesi_screen->COLOR_PAIRS)
|
||||
return ERR;
|
||||
|
||||
*forep = _cursesi_screen->colour_pairs[pair].fore;
|
||||
*backp = _cursesi_screen->colour_pairs[pair].back;
|
||||
|
||||
/* Swap red/blue and yellow/cyan */
|
||||
if (_cursesi_screen->color_type == COLOR_OTHER) {
|
||||
switch (*forep) {
|
||||
case COLOR_RED:
|
||||
*forep = COLOR_BLUE;
|
||||
break;
|
||||
case COLOR_BLUE:
|
||||
*forep = COLOR_RED;
|
||||
break;
|
||||
case COLOR_YELLOW:
|
||||
*forep = COLOR_CYAN;
|
||||
break;
|
||||
case COLOR_CYAN:
|
||||
*forep = COLOR_YELLOW;
|
||||
break;
|
||||
}
|
||||
switch (*backp) {
|
||||
case COLOR_RED:
|
||||
*backp = COLOR_BLUE;
|
||||
break;
|
||||
case COLOR_BLUE:
|
||||
*backp = COLOR_RED;
|
||||
break;
|
||||
case COLOR_YELLOW:
|
||||
*backp = COLOR_CYAN;
|
||||
break;
|
||||
case COLOR_CYAN:
|
||||
*backp = COLOR_YELLOW;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* init_color_Value --
|
||||
* Set colour red, green and blue values.
|
||||
*/
|
||||
static int
|
||||
init_color_value(short color, short red, short green, short blue)
|
||||
{
|
||||
if (color < 0 || color >= _cursesi_screen->COLORS)
|
||||
return ERR;
|
||||
|
||||
_cursesi_screen->colours[color].red = red;
|
||||
_cursesi_screen->colours[color].green = green;
|
||||
_cursesi_screen->colours[color].blue = blue;
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* init_color --
|
||||
* Set colour red, green and blue values.
|
||||
* Change color on screen.
|
||||
*/
|
||||
int
|
||||
init_color(short color, short red, short green, short blue)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_COLOR, "init_color: %d, %d, %d, %d\n",
|
||||
color, red, green, blue);
|
||||
#endif
|
||||
if (init_color_value(color, red, green, blue) == ERR)
|
||||
return ERR;
|
||||
if (!can_change || t_initialize_color(_cursesi_screen->term) == NULL)
|
||||
return ERR;
|
||||
tputs(tiparm(t_initialize_color(_cursesi_screen->term),
|
||||
color, red, green, blue), 0, __cputchar);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* color_content --
|
||||
* Get colour red, green and blue values.
|
||||
*/
|
||||
int
|
||||
color_content(short color, short *redp, short *greenp, short *bluep)
|
||||
{
|
||||
if (color < 0 || color >= _cursesi_screen->COLORS)
|
||||
return ERR;
|
||||
|
||||
*redp = _cursesi_screen->colours[color].red;
|
||||
*greenp = _cursesi_screen->colours[color].green;
|
||||
*bluep = _cursesi_screen->colours[color].blue;
|
||||
return OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* use_default_colors --
|
||||
* Use terminal default colours instead of curses default colour.
|
||||
*/
|
||||
int
|
||||
use_default_colors()
|
||||
{
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_COLOR, "use_default_colors\n");
|
||||
#endif
|
||||
|
||||
return (assume_default_colors(-1, -1));
|
||||
}
|
||||
|
||||
/*
|
||||
* assume_default_colors --
|
||||
* Set the default foreground and background colours.
|
||||
*/
|
||||
int
|
||||
assume_default_colors(short fore, short back)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_COLOR, "assume_default_colors: %d, %d\n",
|
||||
fore, back);
|
||||
__CTRACE(__CTRACE_COLOR, "assume_default_colors: default_colour = %d, pair_number = %d\n", __default_color, PAIR_NUMBER(__default_color));
|
||||
#endif
|
||||
|
||||
/* Swap red/blue and yellow/cyan */
|
||||
if (_cursesi_screen->color_type == COLOR_OTHER) {
|
||||
switch (fore) {
|
||||
case COLOR_RED:
|
||||
fore = COLOR_BLUE;
|
||||
break;
|
||||
case COLOR_BLUE:
|
||||
fore = COLOR_RED;
|
||||
break;
|
||||
case COLOR_YELLOW:
|
||||
fore = COLOR_CYAN;
|
||||
break;
|
||||
case COLOR_CYAN:
|
||||
fore = COLOR_YELLOW;
|
||||
break;
|
||||
}
|
||||
switch (back) {
|
||||
case COLOR_RED:
|
||||
back = COLOR_BLUE;
|
||||
break;
|
||||
case COLOR_BLUE:
|
||||
back = COLOR_RED;
|
||||
break;
|
||||
case COLOR_YELLOW:
|
||||
back = COLOR_CYAN;
|
||||
break;
|
||||
case COLOR_CYAN:
|
||||
back = COLOR_YELLOW;
|
||||
break;
|
||||
}
|
||||
}
|
||||
__default_pair.fore = fore;
|
||||
__default_pair.back = back;
|
||||
__default_pair.flags = __USED;
|
||||
|
||||
if (COLOR_PAIRS) {
|
||||
_cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].fore = fore;
|
||||
_cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].back = back;
|
||||
_cursesi_screen->colour_pairs[PAIR_NUMBER(__default_color)].flags = __USED;
|
||||
}
|
||||
|
||||
/*
|
||||
* If we've already called start_color(), make sure all instances
|
||||
* of the curses default colour pair are dirty.
|
||||
*/
|
||||
if (__using_color)
|
||||
__change_pair(PAIR_NUMBER(__default_color));
|
||||
|
||||
return(OK);
|
||||
}
|
||||
|
||||
/* no_color_video is a terminfo macro, but we need to retain binary compat */
|
||||
#ifdef __strong_alias
|
||||
#undef no_color_video
|
||||
__strong_alias(no_color_video, no_color_attributes)
|
||||
#endif
|
||||
/*
|
||||
* no_color_attributes --
|
||||
* Return attributes that cannot be combined with color.
|
||||
*/
|
||||
attr_t
|
||||
no_color_attributes(void)
|
||||
{
|
||||
return(_cursesi_screen->nca);
|
||||
}
|
||||
|
||||
/*
|
||||
* __set_color --
|
||||
* Set terminal foreground and background colours.
|
||||
*/
|
||||
void
|
||||
__set_color( /*ARGSUSED*/ WINDOW *win, attr_t attr)
|
||||
{
|
||||
short pair;
|
||||
|
||||
if ((curscr->wattr & __COLOR) == (attr & __COLOR))
|
||||
return;
|
||||
|
||||
pair = PAIR_NUMBER((uint32_t)attr);
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_COLOR, "__set_color: %d, %d, %d\n", pair,
|
||||
_cursesi_screen->colour_pairs[pair].fore,
|
||||
_cursesi_screen->colour_pairs[pair].back);
|
||||
#endif
|
||||
switch (_cursesi_screen->color_type) {
|
||||
/* Set ANSI forground and background colours */
|
||||
case COLOR_ANSI:
|
||||
if (_cursesi_screen->colour_pairs[pair].fore < 0 ||
|
||||
_cursesi_screen->colour_pairs[pair].back < 0)
|
||||
__unset_color(curscr);
|
||||
if (_cursesi_screen->colour_pairs[pair].fore >= 0)
|
||||
tputs(tiparm(t_set_a_foreground(_cursesi_screen->term),
|
||||
(int)_cursesi_screen->colour_pairs[pair].fore),
|
||||
0, __cputchar);
|
||||
if (_cursesi_screen->colour_pairs[pair].back >= 0)
|
||||
tputs(tiparm(t_set_a_background(_cursesi_screen->term),
|
||||
(int)_cursesi_screen->colour_pairs[pair].back),
|
||||
0, __cputchar);
|
||||
break;
|
||||
case COLOR_HP:
|
||||
/* XXX: need to support HP style */
|
||||
break;
|
||||
case COLOR_TEK:
|
||||
/* XXX: need to support Tek style */
|
||||
break;
|
||||
case COLOR_OTHER:
|
||||
if (_cursesi_screen->colour_pairs[pair].fore < 0 ||
|
||||
_cursesi_screen->colour_pairs[pair].back < 0)
|
||||
__unset_color(curscr);
|
||||
if (_cursesi_screen->colour_pairs[pair].fore >= 0)
|
||||
tputs(tiparm(t_set_foreground(_cursesi_screen->term),
|
||||
(int)_cursesi_screen->colour_pairs[pair].fore),
|
||||
0, __cputchar);
|
||||
if (_cursesi_screen->colour_pairs[pair].back >= 0)
|
||||
tputs(tiparm(t_set_background(_cursesi_screen->term),
|
||||
(int)_cursesi_screen->colour_pairs[pair].back),
|
||||
0, __cputchar);
|
||||
break;
|
||||
}
|
||||
curscr->wattr &= ~__COLOR;
|
||||
curscr->wattr |= attr & __COLOR;
|
||||
}
|
||||
|
||||
/*
|
||||
* __unset_color --
|
||||
* Clear terminal foreground and background colours.
|
||||
*/
|
||||
void
|
||||
__unset_color(WINDOW *win)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_COLOR, "__unset_color\n");
|
||||
#endif
|
||||
switch (_cursesi_screen->color_type) {
|
||||
/* Clear ANSI forground and background colours */
|
||||
case COLOR_ANSI:
|
||||
if (orig_pair != NULL) {
|
||||
tputs(orig_pair, 0, __cputchar);
|
||||
win->wattr &= __mask_op;
|
||||
}
|
||||
break;
|
||||
case COLOR_HP:
|
||||
/* XXX: need to support HP style */
|
||||
break;
|
||||
case COLOR_TEK:
|
||||
/* XXX: need to support Tek style */
|
||||
break;
|
||||
case COLOR_OTHER:
|
||||
if (orig_pair != NULL) {
|
||||
tputs(orig_pair, 0, __cputchar);
|
||||
win->wattr &= __mask_op;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* __restore_colors --
|
||||
* Redo color definitions after restarting 'curses' mode.
|
||||
*/
|
||||
void
|
||||
__restore_colors(void)
|
||||
{
|
||||
if (can_change != 0)
|
||||
switch (_cursesi_screen->color_type) {
|
||||
case COLOR_HP:
|
||||
/* XXX: need to re-initialise HP style (Ip) */
|
||||
break;
|
||||
case COLOR_TEK:
|
||||
/* XXX: need to re-initialise Tek style (Ic) */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* __change_pair --
|
||||
* Mark dirty all positions using pair.
|
||||
*/
|
||||
void
|
||||
__change_pair(short pair)
|
||||
{
|
||||
struct __winlist *wlp;
|
||||
WINDOW *win;
|
||||
int y, x;
|
||||
__LINE *lp;
|
||||
uint32_t cl = COLOR_PAIR(pair);
|
||||
|
||||
|
||||
for (wlp = _cursesi_screen->winlistp; wlp != NULL; wlp = wlp->nextp) {
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_COLOR, "__change_pair: win = %p\n",
|
||||
wlp->winp);
|
||||
#endif
|
||||
win = wlp->winp;
|
||||
if (win == __virtscr)
|
||||
continue;
|
||||
else if (win == curscr) {
|
||||
/* Reset colour attribute on curscr */
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_COLOR,
|
||||
"__change_pair: win == curscr\n");
|
||||
#endif
|
||||
for (y = 0; y < curscr->maxy; y++) {
|
||||
lp = curscr->alines[y];
|
||||
for (x = 0; x < curscr->maxx; x++) {
|
||||
if ((lp->line[x].attr & __COLOR) == cl)
|
||||
lp->line[x].attr &= ~__COLOR;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* Mark dirty those positions with colour pair "pair" */
|
||||
for (y = 0; y < win->maxy; y++) {
|
||||
lp = win->alines[y];
|
||||
for (x = 0; x < win->maxx; x++)
|
||||
if ((lp->line[x].attr &
|
||||
__COLOR) == cl) {
|
||||
if (!(lp->flags & __ISDIRTY))
|
||||
lp->flags |= __ISDIRTY;
|
||||
/*
|
||||
* firstchp/lastchp are shared
|
||||
* between parent window and
|
||||
* sub-window.
|
||||
*/
|
||||
if (*lp->firstchp > x)
|
||||
*lp->firstchp = x;
|
||||
if (*lp->lastchp < x)
|
||||
*lp->lastchp = x;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
if ((win->alines[y]->flags & __ISDIRTY))
|
||||
__CTRACE(__CTRACE_COLOR,
|
||||
"__change_pair: first = %d, "
|
||||
"last = %d\n",
|
||||
*win->alines[y]->firstchp,
|
||||
*win->alines[y]->lastchp);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_color.3
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_attributes.3
|
||||
+1
@@ -0,0 +1 @@
|
||||
curses_window.3
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
/* $NetBSD: copywin.c,v 1.19 2019/06/09 07:40:14 blymn Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1998-1999 Brett Lymn
|
||||
* (blymn@baea.com.au, brett_lymn@yahoo.com.au)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code has been donated to The NetBSD Foundation by the Author.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#include <netbsd_sys/cdefs.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include "curses.h"
|
||||
#include "curses_private.h"
|
||||
|
||||
/*
|
||||
* copywin --
|
||||
* Copy the box starting at (sminrow, smincol) with a size that
|
||||
* matches the destination box (dminrow, dmincol) by (dmaxrow, dmaxcol)
|
||||
* from the source window srcwin to the destination window dstwin.
|
||||
* All these coordindinates are relative to the relevant window.
|
||||
* If dooverlay is true then the copy is nondestructive otherwise the
|
||||
* copy is destructive.
|
||||
*/
|
||||
int copywin(const WINDOW *srcwin, WINDOW *dstwin,
|
||||
int sminrow, int smincol,
|
||||
int dminrow, int dmincol, int dmaxrow, int dmaxcol, int dooverlay)
|
||||
{
|
||||
int dcol;
|
||||
__LDATA *sp, *end;
|
||||
#ifdef HAVE_WCHAR
|
||||
cchar_t cc;
|
||||
nschar_t *np;
|
||||
#endif /* HAVE_WCHAR */
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_WINDOW,
|
||||
"copywin %s mode: from (%d,%d) to (%d,%d-%d,%d)\n",
|
||||
dooverlay ? "overlay" : "overwrite",
|
||||
sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol);
|
||||
#endif
|
||||
|
||||
/* overwrite() and overlay() can come here with -ve srcwin coords */
|
||||
if (sminrow < 0) {
|
||||
dminrow -= sminrow;
|
||||
sminrow = 0;
|
||||
}
|
||||
if (smincol < 0) {
|
||||
dmincol -= smincol;
|
||||
smincol = 0;
|
||||
}
|
||||
|
||||
/* for symmetry allow dstwin coords to be -ve as well */
|
||||
if (dminrow < 0) {
|
||||
sminrow -= dminrow;
|
||||
dminrow = 0;
|
||||
}
|
||||
if (dmincol < 0) {
|
||||
smincol -= dmincol;
|
||||
dmincol = 0;
|
||||
}
|
||||
|
||||
/* Bound dmaxcol for both windows (should be ok for dstwin) */
|
||||
if (dmaxcol >= dstwin->maxx)
|
||||
dmaxcol = dstwin->maxx - 1;
|
||||
if (smincol + (dmaxcol - dmincol) >= srcwin->maxx)
|
||||
dmaxcol = srcwin->maxx + dmincol - smincol - 1;
|
||||
if (dmaxcol < dmincol)
|
||||
/* nothing in the intersection */
|
||||
return OK;
|
||||
|
||||
/* Bound dmaxrow for both windows (should be ok for dstwin) */
|
||||
if (dmaxrow >= dstwin->maxy)
|
||||
dmaxrow = dstwin->maxy - 1;
|
||||
if (sminrow + (dmaxrow - dminrow) >= srcwin->maxy)
|
||||
dmaxrow = srcwin->maxy + dminrow - sminrow - 1;
|
||||
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_WINDOW,
|
||||
"copywin %s mode: from (%d,%d) to (%d,%d-%d,%d)\n",
|
||||
dooverlay ? "overlay" : "overwrite",
|
||||
sminrow, smincol, dminrow, dmincol, dmaxrow, dmaxcol);
|
||||
#endif
|
||||
|
||||
for (; dminrow <= dmaxrow; sminrow++, dminrow++) {
|
||||
sp = &srcwin->alines[sminrow]->line[smincol];
|
||||
end = sp + dmaxcol - dmincol;
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_WINDOW, "copywin: row %d\n", sminrow);
|
||||
#endif
|
||||
for (dcol = dmincol; sp <= end; dcol++, sp++) {
|
||||
/* XXX: Perhaps this should check for the
|
||||
* background character
|
||||
*/
|
||||
if ((dooverlay && !isspace(sp->ch)) || !dooverlay) {
|
||||
wmove(dstwin, dminrow, dcol);
|
||||
#ifdef DEBUG
|
||||
__CTRACE(__CTRACE_WINDOW, "copywin: dcol = %d\n", dcol);
|
||||
#endif
|
||||
#ifndef HAVE_WCHAR
|
||||
__waddch(dstwin, sp);
|
||||
#else
|
||||
cc.vals[0] = sp->ch;
|
||||
cc.attributes = sp->attr;
|
||||
cc.elements = 1;
|
||||
np = sp->nsp;
|
||||
if (np) {
|
||||
while (np && cc.elements <=
|
||||
CURSES_CCHAR_MAX) {
|
||||
cc.vals[cc.elements++] = np->ch;
|
||||
np = np->next;
|
||||
}
|
||||
}
|
||||
wadd_wch(dstwin, &cc);
|
||||
#endif /* HAVE_WCHAR */
|
||||
}
|
||||
}
|
||||
}
|
||||
__touchwin(dstwin);
|
||||
return OK;
|
||||
}
|
||||
Loaded 100 of 793 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user