import elf-only -lcurses

. abandons mixer, gomoku, talk, talkd, top from base system
	. compile top with clang so no ack-compiled program
	  needs -lcurses any more
This commit is contained in:
Ben Gras 2011-07-21 16:29:08 +02:00
parent 1ea07af9da
commit 51ffecc181
232 changed files with 32840 additions and 5877 deletions

View file

@ -12,10 +12,10 @@ SUBDIR= aal add_route adduser advent arp ash at autil awk \
dhrystone diff dirname dis386 dis88 diskctl du dumpcore \
ed eject elle elvis env expand factor file \
find finger fingerd fix fold format fortune fsck.mfs \
ftp101 ftpd200 gcov-pull getty grep gomoku head hexdump host \
ftp101 ftpd200 gcov-pull getty grep head hexdump host \
hostaddr id ifconfig ifdef install \
intr ipcrm ipcs irdpd isoread join kill last leave \
less lex life loadkeys loadramdisk logger login look lp \
less lex loadkeys loadramdisk logger login look lp \
lpd ls lspci M mail make MAKEDEV man \
mdb mdocml mesg mined ackmkdep mkdir mkfifo mkfs.mfs mknod \
mkproto modem mount mt netconf newroot nice acknm nohup \
@ -27,8 +27,8 @@ SUBDIR= aal add_route adduser advent arp ash at autil awk \
rotate rsh rshd sed service setup shar acksize \
sleep slip sort spell split srccrc ackstrip \
stty su sum svclog swapfs swifi sync synctree sysenv \
syslogd tail talk talkd tar tcpd tcpdp tcpstat tee telnet \
telnetd term termcap tget time tinyhalt top touch tr \
syslogd tail tar tcpd tcpdp tcpstat tee telnet \
telnetd term termcap tget time tinyhalt touch tr \
truncate tsort ttt tty udpstat umount uname unexpand \
unstack update uud uue version vol wc \
whereis which who write writeisofs fetch \
@ -41,7 +41,7 @@ SUBDIR += elf2aout
.if ${ARCH} == "i386"
SUBDIR+= atnormalize dosread fdisk loadfont \
mixer autopart part partition playwave postmort \
autopart part partition playwave postmort \
recwave repartition screendump padtext
SUBDIR+= acd asmconv gas2ack
.endif

View file

@ -1,7 +0,0 @@
PROG= gomoku
MAN=
DPADD+= ${LIBCURSES}
LDADD+= -lcurses
.include <bsd.prog.mk>

View file

@ -1,739 +0,0 @@
/* gomoku - 5 in a row game Author: ? */
/* This program plays a very old Japanese game called GO-MOKU,
perhaps better known as 5-in-line. The game is played on
a board with 19 x 19 squares, and the object of the game is
to get 5 stones in a row.
*/
#include <sys/types.h>
#include <curses.h>
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
/* Size of the board */
#define SIZE 19
/* Importance of attack (1..16) */
#define AttackFactor 4
/* Value of having 0, 1,2,3,4 or 5 pieces in line */
int Weight[7] = {0, 0, 4, 20, 100, 500, 0};
#define Null 0
#define Horiz 1
#define DownLeft 2
#define DownRight 3
#define Vert 4
/* The two players */
#define Empty 0
#define Cross 1
#define Nought 2
char PieceChar[Nought + 1] = {' ', 'X', '0'};
int Board[SIZE + 1][SIZE + 1];/* The board */
int Player; /* The player whose move is next */
int TotalLines; /* The number of Empty lines left */
int GameWon; /* Set if one of the players has won */
int Line[4][SIZE + 1][SIZE + 1][Nought + 1];
/* Value of each square for each player */
int Value[SIZE + 1][SIZE + 1][Nought + 1];
int X, Y; /* Move coordinates */
char Command; /* Command from keyboard */
int AutoPlay = FALSE; /* The program plays against itself */
_PROTOTYPE(void Initialize, (void));
_PROTOTYPE(int Abort, (char *s));
_PROTOTYPE(void WriteLetters, (void));
_PROTOTYPE(void WriteLine, (int j, int *s));
_PROTOTYPE(void WriteBoard, (int N, int *Top, int *Middle, int *Bottom));
_PROTOTYPE(void SetUpScreen, (void));
_PROTOTYPE(void GotoSquare, (int x, int y));
_PROTOTYPE(void PrintMove, (int Piece, int X, int Y));
_PROTOTYPE(void ClearMove, (void));
_PROTOTYPE(void PrintMsg, (char *Str));
_PROTOTYPE(void ClearMsg, (void));
_PROTOTYPE(void WriteCommand, (char *S));
_PROTOTYPE(void ResetGame, (int FirstGame));
_PROTOTYPE(int OpponentColor, (int Player));
_PROTOTYPE(void BlinkRow, (int X, int Y, int Dx, int Dy, int Piece));
_PROTOTYPE(void BlinkWinner, (int Piece, int X, int Y, int WinningLine));
_PROTOTYPE(int Random, (int x));
_PROTOTYPE(void Add, (int *Num));
_PROTOTYPE(void Update, (int Lin[], int Valu[], int Opponent));
_PROTOTYPE(void MakeMove, (int X, int Y));
_PROTOTYPE(int GameOver, (void));
_PROTOTYPE(void FindMove, (int *X, int *Y));
_PROTOTYPE(char GetChar, (void));
_PROTOTYPE(void ReadCommand, (int X, int Y, char *Command));
_PROTOTYPE(void InterpretCommand, (int Command));
_PROTOTYPE(void PlayerMove, (void));
_PROTOTYPE(void ProgramMove, (void));
_PROTOTYPE(int main, (void));
/* Set terminal to raw mode. */
void Initialize()
{
srand(getpid() + 13); /* Initialize the random seed with our pid */
initscr();
raw();
noecho();
clear();
}
/* Reset terminal and exit from the program. */
int Abort(s)
char *s;
{
move(LINES - 1, 0);
refresh();
endwin();
exit(0);
}
/* Set up the screen ----------------------------------------------- */
/* Write the letters */
void WriteLetters()
{
int i;
addch(' ');
addch(' ');
for (i = 1; i <= SIZE; i++) printw(" %c", 'A' + i - 1);
addch('\n');
}
/* Write one line of the board */
void WriteLine(j, s)
int j;
int *s;
{
int i;
printw("%2d ", j);
addch(s[0]);
for (i = 2; i <= SIZE - 1; i++) {
addch(s[1]);
addch(s[2]);
}
addch(s[1]);
addch(s[3]);
printw(" %-2d\n", j);
}
/* Print the Empty board and the border */
void WriteBoard(N, Top, Middle, Bottom)
int N;
int *Top, *Middle, *Bottom;
{
int j;
move(1, 0);
WriteLetters();
WriteLine(N, Top);
for (j = N - 1; j >= 2; j--) WriteLine(j, Middle);
WriteLine(1, Bottom);
WriteLetters();
}
/* Sets up the screen with an Empty board */
void SetUpScreen()
{
int top[4], middle[4], bottom[4];
top[0] = ACS_ULCORNER;
top[1] = ACS_HLINE;
top[2] = ACS_TTEE;
top[3] = ACS_URCORNER;
middle[0] = ACS_LTEE;
middle[1] = ACS_HLINE;
middle[2] = ACS_PLUS;
middle[3] = ACS_RTEE;
bottom[0] = ACS_LLCORNER;
bottom[1] = ACS_HLINE;
bottom[2] = ACS_BTEE;
bottom[3] = ACS_LRCORNER;
WriteBoard(SIZE, top, middle, bottom);
}
/* Show moves ----------------------------------------------- */
void GotoSquare(x, y)
int x, y;
{
move(SIZE + 2 - y, 1 + x * 2);
}
/* Prints a move */
void PrintMove(Piece, X, Y)
int Piece;
int X, Y;
{
move(22, 49);
printw("%c %c %d", PieceChar[Piece], 'A' + X - 1, Y);
clrtoeol();
GotoSquare(X, Y);
addch(PieceChar[Piece]);
GotoSquare(X, Y);
refresh();
}
/* Clears the line where a move is displayed */
void ClearMove()
{
move(22, 49);
clrtoeol();
}
/* Message handling ---------------------------------------------- */
/* Prints a message */
void PrintMsg(Str)
char *Str;
{
mvprintw(23, 1, "%s", Str);
}
/* Clears the message about the winner */
void ClearMsg()
{
move(23, 1);
clrtoeol();
}
/* Highlights the first letter of S */
void WriteCommand(S)
char *S;
{
standout();
addch(*S);
standend();
printw("%s", S + 1);
}
/* Display the board ----------------------------------------------- */
/* Resets global variables to start a new game */
void ResetGame(FirstGame)
int FirstGame;
{
int I, J;
int C, D;
SetUpScreen();
if (FirstGame) {
move(1, 49);
addstr("G O M O K U");
move(3, 49);
WriteCommand("Newgame ");
WriteCommand("Quit ");
move(5, 49);
WriteCommand("Auto");
move(7, 49);
WriteCommand("Play");
move(9, 49);
WriteCommand("Hint");
move(14, 60);
WriteCommand("Left, ");
WriteCommand("Right, ");
move(16, 60);
WriteCommand("Up, ");
WriteCommand("Down");
move(18, 60);
standout();
addstr("SPACE");
move(20, 49);
WriteCommand(" NOTE: Use Num Lock & arrows");
standend();
mvaddstr(14, 49, "7 8 9");
mvaddch(15, 52, ACS_UARROW);
mvaddch(16, 49, '4');
addch(ACS_LARROW);
mvaddch(16, 54, ACS_RARROW);
addch('6');
mvaddch(17, 52, ACS_DARROW);
mvaddstr(18, 49, "1 2 3");
FirstGame = FALSE;
} else {
ClearMsg();
ClearMove();
}
/* Clear tables */
for (I = 1; I <= SIZE; I++) for (J = 1; J <= SIZE; J++) {
Board[I][J] = Empty;
for (C = Cross; C <= Nought; C++) {
Value[I][J][C] = 0;
for (D = 0; D <= 3; D++) Line[D][I][J][C] = 0;
}
}
/* Cross starts */
Player = Cross;
/* Total number of lines */
TotalLines = 2 * 2 * (SIZE * (SIZE - 4) + (SIZE - 4) * (SIZE - 4));
GameWon = FALSE;
}
int OpponentColor(Player)
int Player;
{
if (Player == Cross)
return Nought;
else
return Cross;
}
/* Blink the row of 5 stones */
void BlinkRow(X, Y, Dx, Dy, Piece)
int X, Y, Dx, Dy, Piece;
{
int I;
attron(A_BLINK);
for (I = 1; I <= 5; I++) {
GotoSquare(X, Y);
addch(PieceChar[Piece]);
X = X - Dx;
Y = Y - Dy;
}
attroff(A_BLINK);
}
/* Prints the 5 winning stones in blinking color */
void BlinkWinner(Piece, X, Y, WinningLine)
int Piece, X, Y, WinningLine;
{
/* Used to store the position of the winning move */
int XHold, YHold;
/* Change in X and Y */
int Dx, Dy;
/* Display winning move */
PrintMove(Piece, X, Y);
/* Preserve winning position */
XHold = X;
YHold = Y;
switch (WinningLine) {
case Horiz:
{
Dx = 1;
Dy = 0;
break;
}
case DownLeft:
{
Dx = 1;
Dy = 1;
break;
}
case Vert:
{
Dx = 0;
Dy = 1;
break;
}
case DownRight:
{
Dx = -1;
Dy = 1;
break;
}
}
/* Go to topmost, leftmost */
while (Board[X + Dx][Y + Dy] != Empty && Board[X + Dx][Y + Dy] == Piece) {
X = X + Dx;
Y = Y + Dy;
}
BlinkRow(X, Y, Dx, Dy, Piece);
/* Restore winning position */
X = XHold;
Y = YHold;
/* Go back to winning square */
GotoSquare(X, Y);
}
/* Functions for playing a game -------------------------------- */
int Random(x)
int x;
{
return((rand() / 19) % x);
}
/* Adds one to the number of pieces in a line */
void Add(Num)
int *Num;
{
/* Adds one to the number. */
*Num = *Num + 1;
/* If it is the first piece in the line, then the opponent cannot use
* it any more. */
if (*Num == 1) TotalLines = TotalLines - 1;
/* The game is won if there are 5 in line. */
if (*Num == 5) GameWon = TRUE;
}
/* Updates the value of a square for each player, taking into
account that player has placed an extra piece in the square.
The value of a square in a usable line is Weight[Lin[Player]+1]
where Lin[Player] is the number of pieces already placed
in the line */
void Update(Lin, Valu, Opponent)
int Lin[];
int Valu[];
int Opponent;
{
/* If the opponent has no pieces in the line, then simply update the
* value for player */
if (Lin[Opponent] == 0)
Valu[Player] += Weight[Lin[Player] + 1] - Weight[Lin[Player]];
else
/* If it is the first piece in the line, then the line is
* spoiled for the opponent */
if (Lin[Player] == 1) Valu[Opponent] -= Weight[Lin[Opponent] + 1];
}
/* Performs the move X,Y for player, and updates the global variables
(Board, Line, Value, Player, GameWon, TotalLines and the screen) */
void MakeMove(X, Y)
int X, Y;
{
int Opponent;
int X1, Y1;
int K, L, WinningLine;
WinningLine = Null;
Opponent = OpponentColor(Player);
GameWon = FALSE;
/* Each square of the board is part of 20 different lines. The adds
* one to the number of pieces in each of these lines. Then it
* updates the value for each of the 5 squares in each of the 20
* lines. Finally Board is updated, and the move is printed on the
* screen. */
/* Horizontal lines, from left to right */
for (K = 0; K <= 4; K++) {
X1 = X - K; /* Calculate starting point */
Y1 = Y;
if ((1 <= X1) && (X1 <= SIZE - 4)) { /* Check starting point */
Add(&Line[0][X1][Y1][Player]); /* Add one to line */
if (GameWon && (WinningLine == Null)) /* Save winning line */
WinningLine = Horiz;
for (L = 0; L <= 4; L++) /* Update value for the
* 5 squares in the line */
Update(Line[0][X1][Y1], Value[X1 + L][Y1], Opponent);
}
}
for (K = 0; K <= 4; K++) { /* Diagonal lines, from lower left to
* upper right */
X1 = X - K;
Y1 = Y - K;
if ((1 <= X1) && (X1 <= SIZE - 4) &&
(1 <= Y1) && (Y1 <= SIZE - 4)) {
Add(&Line[1][X1][Y1][Player]);
if (GameWon && (WinningLine == Null)) /* Save winning line */
WinningLine = DownLeft;
for (L = 0; L <= 4; L++)
Update(Line[1][X1][Y1], Value[X1 + L][Y1 + L], Opponent);
}
} /* for */
for (K = 0; K <= 4; K++) { /* Diagonal lines, down right to upper left */
X1 = X + K;
Y1 = Y - K;
if ((5 <= X1) && (X1 <= SIZE) &&
(1 <= Y1) && (Y1 <= SIZE - 4)) {
Add(&Line[3][X1][Y1][Player]);
if (GameWon && (WinningLine == Null)) /* Save winning line */
WinningLine = DownRight;
for (L = 0; L <= 4; L++)
Update(Line[3][X1][Y1], Value[X1 - L][Y1 + L], Opponent);
}
} /* for */
for (K = 0; K <= 4; K++) { /* Vertical lines, from down to up */
X1 = X;
Y1 = Y - K;
if ((1 <= Y1) && (Y1 <= SIZE - 4)) {
Add(&Line[2][X1][Y1][Player]);
if (GameWon && (WinningLine == Null)) /* Save winning line */
WinningLine = Vert;
for (L = 0; L <= 4; L++)
Update(Line[2][X1][Y1], Value[X1][Y1 + L], Opponent);
}
}
Board[X][Y] = Player; /* Place piece in board */
if (GameWon)
BlinkWinner(Player, X, Y, WinningLine);
else
PrintMove(Player, X, Y);/* Print move on screen */
Player = Opponent; /* The opponent is next to move */
}
int GameOver()
/* A game is over if one of the players have
won, or if there are no more Empty lines */
{
return(GameWon || (TotalLines <= 0));
}
/* Finds a move X,Y for player, simply by picking the one with the
highest value */
void FindMove(X, Y)
int *X, *Y;
{
int Opponent;
int I, J;
int Max, Valu;
Opponent = OpponentColor(Player);
Max = -10000;
/* If no square has a high value then pick the one in the middle */
*X = (SIZE + 1) / 2;
*Y = (SIZE + 1) / 2;
if (Board[*X][*Y] == Empty) Max = 4;
/* The evaluation for a square is simply the value of the square for
* the player (attack points) plus the value for the opponent
* (defense points). Attack is more important than defense, since it
* is better to get 5 in line yourself than to prevent the op- ponent
* from getting it. */
/* For all Empty squares */
for (I = 1; I <= SIZE; I++) for (J = 1; J <= SIZE; J++)
if (Board[I][J] == Empty) {
/* Calculate evaluation */
Valu = Value[I][J][Player] * (16 + AttackFactor) / 16 + Value[I][J][Opponent] + Random(4);
/* Pick move with highest value */
if (Valu > Max) {
*X = I;
*Y = J;
Max = Valu;
}
}
}
char GetChar()
/* Get a character from the keyboard */
{
int c;
c = getch();
if (c < 0) abort();
if (c == '\033') { /* arrow key */
if ((c = getch()) == '[') {
c = getch();
switch (c) {
case 'A': c = 'U'; break;
case 'B': c = 'D'; break;
case 'C': c = 'R'; break;
case 'D': c = 'L'; break;
default:
c = '?';
break;
}
}
else
c = '?';
}
if (islower(c))
return toupper(c);
else
return c;
}
/* Reads in a valid command character */
void ReadCommand(X, Y, Command)
int X, Y;
char *Command;
{
int ValidCommand;
do {
ValidCommand = TRUE;
GotoSquare(X, Y); /* Goto square */
refresh();
*Command = GetChar(); /* Read from keyboard */
switch (*Command) {
case '\n': /* '\n', '\r' or space means place a */
case '\r':
case ' ':
*Command = 'E';
break; /* stone at the cursor position */
case 'L':
case 'R':
case 'U':
case 'D':
case '7':
case '9':
case '1':
case '3':
case 'N':
case 'Q':
case 'A':
case 'P':
case 'H':
break;
case '8': *Command = 'U'; break;
case '2': *Command = 'D'; break;
case '4': *Command = 'L'; break;
case '6': *Command = 'R'; break;
default:
{
if (GameOver())
*Command = 'P';
else
ValidCommand = FALSE;
break;
}
}
} while (!ValidCommand);
}
void InterpretCommand(Command)
char Command;
{
int Temp;
switch (Command) {
case 'N':{ /* Start new game */
ResetGame(FALSE); /* ResetGame but only redraw
* the board */
X = (SIZE + 1) / 2;
Y = X;
break;
}
case 'H':
FindMove(&X, &Y);
break; /* Give the user a hint */
case 'L':
X = (X + SIZE - 2) % SIZE + 1;
break; /* Left */
case 'R':
X = X % SIZE + 1;
break; /* Right */
case 'D':
Y = (Y + SIZE - 2) % SIZE + 1;
break; /* Down */
case 'U':
Y = Y % SIZE + 1;
break; /* Up */
case '7':{
if ((X == 1) || (Y == SIZE)) { /* Move diagonally *//* t
* owards upper left */
Temp = X;
X = Y;
Y = Temp;
} else {
X = X - 1;
Y = Y + 1;
}
break;
}
case '9':{ /* Move diagonally */
if (X == SIZE) {/* toward upper right */
X = (SIZE - Y) + 1;
Y = 1;
} else if (Y == SIZE) {
Y = (SIZE - X) + 1;
X = 1;
} else {
X = X + 1;
Y = Y + 1;
}
break;
}
case '1':{ /* Move diagonally */
if (Y == 1) { /* toward lower left */
Y = (SIZE - X) + 1;
X = SIZE;
} else if (X == 1) {
X = (SIZE - Y) + 1;
Y = SIZE;
} else {
X = X - 1;
Y = Y - 1;
}
break;
}
case '3':{ /* Move diagonally */
if ((X == SIZE) || (Y == 1)) { /* toward lower right */
Temp = X;
X = Y;
Y = Temp;
} else {
X = X + 1;
Y = Y - 1;
}
break;
}
case 'A':
AutoPlay = TRUE;
break; /* Auto play mode */
} /* case */
} /* InterpretCommand */
void PlayerMove()
/* Enter and make a move */
{
if (Board[X][Y] == Empty) {
MakeMove(X, Y);
if (GameWon) PrintMsg("Congratulations, You won!");
Command = 'P';
}
refresh();
} /* PlayerMove */
void ProgramMove()
/* Find and perform programs move */
{
do {
if (GameOver()) {
AutoPlay = FALSE;
if ((Command != 'Q') && (!GameWon)) PrintMsg("Tie game!");
} else {
FindMove(&X, &Y);
MakeMove(X, Y);
if (GameWon) PrintMsg("I won!");
}
refresh();
} while (AutoPlay);
}
int main()
{
Initialize();
ResetGame(TRUE); /* ResetGame and draw the entire screen */
refresh();
X = (SIZE + 1) / 2; /* Set starting position to */
Y = X; /* the middle of the board */
do {
ReadCommand(X, Y, &Command);
if (GameOver())
if (Command != 'Q') Command = 'N';
InterpretCommand(Command);
if (Command == 'E') PlayerMove();
if (Command == 'P' || Command == 'A') ProgramMove();
} while (Command != 'Q');
Abort("Good bye!");
return(0);
}

View file

@ -1,7 +0,0 @@
PROG= life
MAN=
DPADD+= ${LIBCURSES}
LDADD+= -lcurses
.include <bsd.prog.mk>

View file

@ -1,241 +0,0 @@
/* life - Conway's game of life Author: Jim King */
/* clife.c - curses life simulator. Translated from Pascal to C implementing
* curses Oct 1988 by pulsar@lsrhs, not jek5036@ritvax.isc.rit.edu
* life needs about 18kb stack space on MINIX.
*
* Flags: -d draw your own screen using arrows and space bar
* -p print statistics on the bottom line during the game
*/
#include <sys/types.h>
#include <signal.h>
#include <time.h>
#include <curses.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#if __minix_vmd /* Use a more random rand(). */
#define srand(seed) srandom(seed)
#define rand() random()
#endif
/* A value of -1 will make it go forever */
/* A value of 0 will make it exit immediately */
#define REPSTOP -1 /* number of repetitions before stop */
int present[23][80]; /* screen 1 cycle ago */
int past[23][80]; /* screen this cycle */
int total; /* total # of changes */
int icnt; /* counter to check for repetition */
int maxrow = 22; /* some defines to represent the screen */
int maxcol = 79;
int minrow = 0;
int mincol = 0;
int pri = 0; /* flag for printing stats on bottom line */
int draw = 0; /* flag for drawing your own screen */
int i, j, k; /* loop counters */
int cycle; /* current cycle # */
int changes; /* # of changes this cycle (live + die) */
int die; /* number of deaths this cycle */
int live; /* number of births this cycle */
WINDOW *mns; /* Main Screen */
WINDOW *info; /* Bottom line */
_PROTOTYPE(void cleanup, (int s));
_PROTOTYPE(void initialize, (void));
_PROTOTYPE(void makscr, (void));
_PROTOTYPE(void update, (void));
_PROTOTYPE(void print, (void));
_PROTOTYPE(int main, (int ac, char *av[]));
/* Cleanup - cleanup then exit */
void cleanup(s)
int s;
{
move(23, 0); /* go to bottom of screen */
refresh(); /* update cursor */
endwin(); /* shutdown curses */
exit(1); /* exit */
}
/* Initialize - init windows, variables, and signals */
void initialize()
{
srand(getpid()); /* init random seed */
initscr(); /* init curses */
noecho();
curs_set(0);
signal(SIGINT, cleanup); /* catch ^C */
mns = newwin(maxrow, maxcol, 0, 0); /* new window */
scrollok(mns, FALSE);
info = newwin(1, 80, 23, 0);
scrollok(info, FALSE);
wclear(mns);
wclear(info);
wmove(info, 0, 0);
wrefresh(info);
if (!draw) { /* if no draw, make random pattern */
for (j = 0; j < maxrow; j++) {
for (k = 0; k < maxcol; k++) {
present[j][k] = rand() % 2;
if (present[j][k] == 1) changes++, live++;
}
}
}
}
/* Makscr - make your own screen using arrow keys and space bar */
void makscr()
{
int curx, cury; /* current point on screen */
char c; /* input char */
wclear(info);
wmove(info, 0, 0);
wprintw(info, "Use arrow keys to move, space to place / erase, ^D to start", NULL);
wrefresh(info);
curx = cury = 1;
wmove(mns, cury - 1, curx - 1);
wrefresh(mns);
noecho();
for (;;) {
c = wgetch(mns);
if (c == '\004')
break;
else if (c == ' ') {
if (present[cury][curx]) {
--present[cury][curx];
changes++;
die++;
mvwaddch(mns, cury, curx, ' ');
} else {
++present[cury][curx];
changes++;
live++;
mvwaddch(mns, cury, curx, '*');
}
} else if (c == '\033') {
wgetch(mns);
switch (wgetch(mns)) {
case 'A': --cury; break;
case 'B': ++cury; break;
case 'C': ++curx; break;
case 'D': --curx; break;
default: break;
}
}
if (cury > maxrow) cury = minrow;
if (cury < minrow) cury = maxrow;
if (curx > maxcol) curx = mincol;
if (curx < mincol) curx = maxcol;
wmove(mns, cury, curx);
wrefresh(mns);
}
wclear(info);
}
/* Update rules: 2 or 3 adjacent alive --- stay alive
* 3 adjacent alive -- dead to live
* all else die or stay dead
*/
void update()
{ /* Does all mathmatical calculations */
int howmany, w, x, y, z;
changes = die = live = 0;
for (j = 0; j < maxrow; j++) {
for (k = 0; k < maxcol; k++) {
w = j - 1;
x = j + 1;
y = k - 1;
z = k + 1;
howmany = (past[w][y] + past[w][k] + past[w][z] +
past[j][y] + past[j][z] + past[x][y] +
past[x][k] + past[x][z]);
switch (howmany) {
case 0:
case 1:
case 4:
case 5:
case 6:
case 7:
case 8:
present[j][k] = 0;
if (past[j][k]) changes++, die++;
break;
case 3:
present[j][k] = 1;
if (!past[j][k]) changes++, live++;
break;
default: break;
}
}
}
if (live == die)
++icnt;
else
icnt = 0;
if (icnt == REPSTOP) cleanup(0);
}
/* Print - updates the screen according to changes from past to present */
void print()
{
/* Updates the screen, greatly improved using curses */
if (pri) {
wmove(info, 0, 0);
total += changes;
cycle++;
wprintw(info, "Cycle %5d | %5d changes: %5d died + %5d born = %5u total changes", (char *) cycle, changes, die, live, total);
wclrtoeol(info);
}
for (j = 1; j < maxrow; j++) {
for (k = 1; k < maxcol; k++) {
if (present[j][k] != past[j][k] && present[j][k] == 1) {
wmove(mns, j, k);
wprintw(mns, "*", NULL);
} else if (present[j][k] != past[j][k] && present[j][k] == 0) {
wmove(mns, j, k);
wprintw(mns, " ", NULL);
}
}
}
if (pri) wrefresh(info);
wrefresh(mns);
}
/* Main - main procedure */
int main(ac, av)
int ac;
char *av[];
{
if (ac > 1) {
for (j = 1; j < ac; j++) {
switch (av[j][1]) {
case 'd': ++draw; break;
case 'p': ++pri; break;
default:
fprintf(stderr, "%s: usage: %s [-d] [-p]\n", av[0], av[0]);
exit(1);
}
}
}
initialize();
if (draw) makscr();
for (;;) {
print();
for (j = 0; j < maxrow; j++) {
for (k = 0; k < maxcol; k++) past[j][k] = present[j][k];
}
update();
}
}

View file

@ -1,7 +0,0 @@
PROG= mixer
MAN=
DPADD+= ${LIBCURSES}
LDADD+= -lcurses
.include <bsd.prog.mk>

View file

@ -1,658 +0,0 @@
/*
* mixer
*
* Michel R. Prevenier.
*/
#include <sys/types.h>
#include <errno.h>
#include <curses.h>
#include <signal.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <minix/sound.h>
#define CURS_CTRL '\033'
#define ESCAPE 27
#define UP 'A'
#define DOWN 'B'
#define LEFT 'D'
#define RIGHT 'C'
#define SPACE ' '
_PROTOTYPE ( int main, (int arg, char **argv));
_PROTOTYPE ( void usage, (void));
_PROTOTYPE ( void non_interactive, (void));
_PROTOTYPE ( void setup_screen, (void));
_PROTOTYPE ( int read_settings, (void));
_PROTOTYPE ( int write_settings, (void));
_PROTOTYPE ( void rdwr_levels, (int flag));
_PROTOTYPE ( void rdwr_inputs, (int flag));
_PROTOTYPE ( void rdwr_outputs, (int flag));
_PROTOTYPE ( void create_slider, (int x, int y, enum Device device));
_PROTOTYPE ( void show_inputs, (int x, int y));
_PROTOTYPE ( void show_outputs, (int x, int y));
_PROTOTYPE ( char *d_name, (enum Device device, char *name));
_PROTOTYPE ( void user_interface, (void));
_PROTOTYPE ( void terminate, (int s));
WINDOW *main_win;
int old_stdin;
int fd;
char name[9];
char *file_name;
struct volume_level levels[9];
struct inout_ctrl inputs_left[9];
struct inout_ctrl inputs_right[9];
struct inout_ctrl outputs[9];
void usage()
{
fprintf(stderr, "Usage: mixer [-r]\n");
exit(-1);
}
void terminate(s)
int s;
{
/* Restore terminal parameters and exit */
(void) fcntl(0,F_SETFL,old_stdin);
move(23, 0);
refresh();
resetty();
endwin();
exit(1);
}
int write_settings()
{
/* Write the current mixer settings to $HOME/.mixer */
int fd;
if ((fd = creat(file_name, 0x124)) > 0)
{
write(fd, levels, sizeof(levels));
write(fd, inputs_left, sizeof(inputs_left));
write(fd, inputs_right, sizeof(inputs_right));
write(fd, outputs, sizeof(outputs));
close(fd);
return 1;
}
return 0;
}
int read_settings()
{
/* Restore mixer settings saved in $HOME/.mixer */
int fd;
if ((fd = open(file_name, O_RDONLY)) > 0)
{
read(fd, levels, sizeof(levels));
read(fd, inputs_left, sizeof(inputs_left));
read(fd, inputs_right, sizeof(inputs_right));
read(fd, outputs, sizeof(outputs));
close(fd);
rdwr_levels(1);
rdwr_outputs(1);
rdwr_inputs(1);
return 1;
}
return 0;
}
void rdwr_levels(flag)
int flag; /* 0 = read, 1 = write */
{
/* Get or set mixer settings */
int i;
int cmd;
cmd = (flag == 0 ? MIXIOGETVOLUME : MIXIOSETVOLUME);
for(i = Master; i <= Bass; i++)
(void) (ioctl(fd, cmd, &levels[i]));
}
void rdwr_inputs(flag)
int flag; /* 0 = read, 1 = write */
{
/* Get or set input settings */
int i;
int cmd_left, cmd_right;
cmd_left = (flag == 0 ? MIXIOGETINPUTLEFT : MIXIOSETINPUTLEFT);
cmd_right = (flag == 0 ? MIXIOGETINPUTRIGHT : MIXIOSETINPUTRIGHT);
for(i = Fm; i <= Mic; i++)
{
(void) (ioctl(fd, cmd_left, &inputs_left[i]));
(void) (ioctl(fd, cmd_right, &inputs_right[i]));
}
}
void rdwr_outputs(flag)
int flag; /* 0 = read, 1 = write */
{
/* Get or set output settings */
int i;
int cmd;
cmd = (flag == 0 ? MIXIOGETOUTPUT : MIXIOSETOUTPUT);
for(i = Cd; i <= Mic; i++)
(void) (ioctl(fd, cmd, &outputs[i]));
}
int main(argc, argv)
int argc;
char **argv;
{
int i;
char *home_ptr;
int fd2;
/* Open mixer */
if ((fd = open("/dev/mixer",O_RDONLY)) < 0)
{
fprintf(stderr, "Cannot open /dev/mixer\n");
exit(-1);
}
/* Get user's home directory and construct the $HOME/.mixer
* file name
*/
home_ptr = getenv("HOME");
file_name = malloc(strlen(home_ptr)+strlen("mixer.ini\0"));
if (file_name == (char *)0)
{
fprintf(stderr, "Not enough memory\n");
exit(-1);
}
strncpy(file_name, home_ptr, strlen(home_ptr));
strncpy(file_name+strlen(home_ptr), "/.mixer\0", 9);
/* Fill in the device numbers */
for(i = Master; i <= Bass; i++)
{
levels[i].device = i;
inputs_left[i].device = i;
inputs_right[i].device = i;
outputs[i].device = i;
}
/* Get arguments */
if (argc > 1)
{
if (strncmp(argv[1], "-r", 2) == 0)
{
if (read_settings())
{
printf("Mixer settings restored\n");
exit(0);
}
else
{
fprintf(stderr, "Could not restore mixer settings\n");
exit(-1);
}
}
else usage();
}
/* Initialize windows. */
(void) initscr();
signal(SIGINT, terminate);
old_stdin = fcntl(0,F_GETFL);
cbreak();
noecho();
main_win = newwin(23,80,0,0);
scrollok(main_win, FALSE);
/* Read all current mixer settings */
rdwr_levels(0);
rdwr_inputs(0);
rdwr_outputs(0);
/* Set up the user screen and handle user input */
setup_screen();
user_interface();
}
void user_interface()
{
/* This is the user interface. */
char c;
int x,y;
int right;
int input_scr, input_pos;
int output_scr, output_pos;
int max_level;
enum Device device;
int fd2;
device = Master;
right = 0;
input_scr = 0;
output_scr = 0;
input_pos = 0;
output_pos = 0;
while(1)
{
if (input_scr)
{
y = device + 9;
x = 51 + input_pos + (device == Mic ? 2 : 0);
}
else if (output_scr)
{
y = device + 15;
x = 53 + output_pos + (device == Mic ? 4 : 0);
}
else
{
y = (device != Speaker ? 2 : 1) +
(device - (device < Treble ? 0 : Treble)) * 3 +
(right == 0 ? 0 : 1);
if (!right)
x = 9 + levels[device].left / (device < Speaker ? 2 : 1 ) +
(device > Speaker ? 39 : 0);
else
x = 9 + levels[device].right / (device < Speaker ? 2 : 1) +
(device > Speaker ? 39 : 0);
}
wmove(main_win,y,x);
wrefresh(main_win);
c = wgetch(main_win);
switch(c)
{
case CURS_CTRL:
{
(void) wgetch(main_win);
c = wgetch(main_win);
switch(c)
{
case DOWN:
{
if (output_scr)
{
if (device < Mic)
{
device++;
if (device == Mic) output_pos = 0;
}
}
else if (right || input_scr)
{
if (!input_scr)
{
if (device < Bass)
{
device++;
right = 0;
}
else
{
input_scr = 1;
input_pos = 0;
device = Fm;
}
}
else
{
if (device < Mic)
{
device++;
if (device == Mic && input_pos > 8) input_pos = 8;
}
else
{
device = Cd;
output_scr = 1;
input_scr = 0;
output_pos = 0;
}
}
}
else
{
if (device != Mic && device != Speaker) right = 1;
else { device++; right = 0; }
}
};break;
case UP:
{
if (output_scr)
{
if (device > Cd) device--;
else
{
device = Mic;
output_scr = 0;
input_scr = 1;
}
}
else if (!right || input_scr)
{
if (input_scr)
{
if (device > Fm) device--;
else
{
input_scr = 0;
device = Bass;
right = 1;
}
}
else
{
if (device > Master)
{
device--;
if (device != Mic && device != Speaker) right = 1;
}
}
}
else
right = 0;
};break;
case RIGHT:
{
if (output_scr)
{
if (output_pos < 8 && device != Mic) output_pos = 8;
}
else if (!input_scr)
{
if (device < Speaker) max_level = 31;
else if (device > Speaker) max_level = 15;
else max_level = 4;
if (!right)
{
if (levels[device].left < max_level) levels[device].left+=
(device < Speaker ? 2 : 1);
}
else
{
if (levels[device].right < max_level) levels[device].right+=
(device < Speaker ? 2 : 1);
}
ioctl(fd, MIXIOSETVOLUME, &levels[device]);
ioctl(fd, MIXIOGETVOLUME, &levels[device]);
create_slider(1 + (device < Treble ? 0 : 39),
(device - (device < Treble ? 0 : Treble))*3 +
(device != Speaker ? 2 : 1), device);
}
else
{
if ((device != Mic && input_pos < 12) ||
(device == Mic && input_pos < 8))
input_pos += (4 + (device == Mic ? 4 : 0));
}
};break;
case LEFT:
{
if (output_scr)
{
if (output_pos > 0) output_pos = 0;
}
else if (!input_scr)
{
if (!right)
{
if (levels[device].left > 0) levels[device].left-=
(device < Speaker ? 2 : 1);
}
else
{
if (levels[device].right > 0) levels[device].right-=
(device < Speaker ? 2 : 1);
}
ioctl(fd, MIXIOSETVOLUME, &levels[device]);
ioctl(fd, MIXIOGETVOLUME, &levels[device]);
create_slider(1 + (device < Treble ? 0 : 39),
(device - (device < Treble ? 0 : Treble))*3 +
(device != Speaker ? 2 : 1), device);
}
else
{
if (input_pos > 0)
input_pos -= (4 + (device == Mic ? 4 : 0));
}
};break;
}
};break;
case SPACE:
{
if (output_scr)
{
switch(output_pos)
{
case 0:
case 4:
{
outputs[device].left =
(outputs[device].left == ON ? OFF : ON);
ioctl(fd, MIXIOSETOUTPUT, &outputs[device]);
};break;
case 8:
{
outputs[device].right =
(outputs[device].right == ON ? OFF : ON);
ioctl(fd, MIXIOSETOUTPUT, &outputs[device]);
};break;
}
ioctl(fd, MIXIOGETOUTPUT, &outputs[device]);
show_outputs(41,16);
}
else if (input_scr)
{
switch(input_pos)
{
case 0:
{
inputs_left[device].left =
(inputs_left[device].left == ON ? OFF : ON);
ioctl(fd, MIXIOSETINPUTLEFT, &inputs_left[device]);
};break;
case 4:
{
inputs_left[device].right =
(inputs_left[device].right == ON ? OFF : ON);
ioctl(fd, MIXIOSETINPUTLEFT, &inputs_left[device]);
};break;
case 8:
{
inputs_right[device].left =
(inputs_right[device].left == ON ? OFF : ON);
ioctl(fd, MIXIOSETINPUTRIGHT, &inputs_right[device]);
};break;
case 12:
{
inputs_right[device].right =
(inputs_right[device].right == ON ? OFF : ON);
ioctl(fd, MIXIOSETINPUTRIGHT, &inputs_right[device]);
};break;
}
ioctl(fd, MIXIOGETINPUTLEFT, &inputs_left[device]);
ioctl(fd, MIXIOGETINPUTRIGHT, &inputs_right[device]);
show_inputs(41,8);
}
};break;
case 's':
{
if (write_settings())
mvwprintw(main_win,22,28, "mixer settings saved");
else
mvwprintw(main_win,22,28, "error: file not saved");
wrefresh(main_win);
sleep(1);
mvwprintw(main_win,22,28, " ");
};break;
case 'r':
{
if (read_settings())
mvwprintw(main_win,22,28, "mixer settings restored");
else
mvwprintw(main_win,22,28, "error: could not open");
wrefresh(main_win);
sleep(1);
setup_screen();
};break;
case 'e': terminate(1);
}
}
}
char *d_name(device, name)
enum Device device;
char *name;
{
/* Convert the device number to a name */
switch (device)
{
case Master: strncpy(name, "Master \0", 9);break;
case Dac: strncpy(name, "Dac \0", 9);break;
case Fm: strncpy(name, "Fm \0", 9);break;
case Cd: strncpy(name, "CD \0", 9);break;
case Line: strncpy(name, "Line \0", 9);break;
case Mic: strncpy(name, "Mic \0", 9);break;
case Speaker: strncpy(name, "Speaker \0", 9);break;
case Treble: strncpy(name, "Treble \0", 9);break;
case Bass: strncpy(name, "Bass \0", 9);break;
}
return name;
}
void create_slider(x, y, device)
int x;
int y;
enum Device device;
{
/* Create a slider on the screen */
int left;
int right;
int i;
mvwprintw(main_win,y,x, "%s", d_name(device, name));
left = levels[device].left / (device < Speaker ? 2 : 1);
right = levels[device].right / (device < Speaker ? 2 : 1);
for (i = 0; i < 16; i++)
{
if (device != Speaker || i < 4)
mvwprintw(main_win,y,x+i+8, (i == left ? "*" : "-"));
if (device < Mic || device > Speaker)
mvwprintw(main_win,y+1,x+i+8, (i == right ? "*" : "-"));
}
if (device < Mic || device > Speaker)
{
mvwprintw(main_win,y,x+i+10, "left");
mvwprintw(main_win,y+1,x+i+10, "right");
}
wrefresh(main_win);
}
void show_inputs(x,y)
int x;
int y;
{
/* Show the input settings */
int i;
mvwprintw(main_win,y,x, " Rec-In ");
mvwprintw(main_win,y+1,x," left right");
mvwprintw(main_win,y+2,x," l r l r");
for (i = Fm; i <= Line; i++)
{
mvwprintw(main_win,y+i+1,x, "%s %d %d %d %d",
d_name(i, (char *)name),
(inputs_left[i].left == ON ? 1 : 0),
(inputs_left[i].right == ON ? 1 : 0),
(inputs_right[i].left == ON ? 1 : 0),
(inputs_right[i].right == ON ? 1 : 0));
}
mvwprintw(main_win,y+i+1,x, "%s %d %d",
d_name(Mic, (char *)name),
(inputs_left[Mic].left == ON ? 1 : 0),
(inputs_right[Mic].left == ON ? 1 : 0));
wrefresh(main_win);
}
void show_outputs(x,y)
int x;
int y;
{
/* Show the output settings */
int i;
mvwprintw(main_win,y,x, " Mix-Out ");
mvwprintw(main_win,y+1,x, " left right");
for (i = Cd; i <= Line; i++)
{
mvwprintw(main_win,y+i-1,x,"%s %d %d",
d_name(i, (char *)name),
(outputs[i].left == ON ? 1 : 0),
(outputs[i].right == ON ? 1 : 0));
}
mvwprintw(main_win,y+i-1,x,"%s %d",
d_name(Mic, (char *)name),
(outputs[Mic].left == ON ? 1 : 0));
wrefresh(main_win);
}
void setup_screen()
{
int i;
wclear(main_win);
mvwprintw(main_win,0,23,"------- Mixer Controls -------");
wrefresh(main_win);
for(i = 0; i <= Speaker; i++)
create_slider(1, i*3+(i <= Mic ? 2 : 1), i);
create_slider(40, 2, Treble);
create_slider(40, 5, Bass);
show_inputs(41,8);
show_outputs(41,16);
}

View file

@ -1,13 +0,0 @@
# Makefile for talk
#
# 08/01/96 Michael Temari, <temari@ix.netcom.com>
#
PROG= talk
SRCS= talk.c screen.c net.c proto.c
MAN=
DPADD+= ${LIBCURSES}
LDADD+= -lcurses
.include <bsd.prog.mk>

View file

@ -1,264 +0,0 @@
/* net.c Copyright Michael Temari 08/01/1996 All Rights Reserved */
#include <sys/types.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include <net/netlib.h>
#include <net/hton.h>
#include <net/gen/netdb.h>
#include <net/gen/in.h>
#include <net/gen/inet.h>
#include <net/gen/tcp.h>
#include <net/gen/tcp_io.h>
#include <net/gen/udp.h>
#include <net/gen/udp_io.h>
#include <net/gen/udp_hdr.h>
#include "talk.h"
#include "net.h"
_PROTOTYPE(void TimeOut, (int sig));
static unsigned char buffer[8192];
static int udp_ctl;
int tcp_fd;
static udpport_t ntalk_port;
char luser[USER_SIZE+1], ruser[USER_SIZE+1];
char lhost[HOST_SIZE+1], rhost[HOST_SIZE+1];
char ltty[TTY_SIZE+1], rtty[TTY_SIZE+1];
udpport_t ctlport;
tcpport_t dataport;
ipaddr_t laddr, raddr;
int NetInit()
{
int s;
struct servent *servent;
char *udp_device;
char *tcp_device;
nwio_udpopt_t udpopt;
nwio_tcpconf_t tcpconf;
if((udp_device = getenv("UDP_DEVICE")) == (char *)NULL)
udp_device = UDP_DEVICE;
if((udp_ctl = open(udp_device, O_RDWR)) < 0) {
fprintf(stderr, "talk: Could not open %s: %s\n",
udp_device, strerror(errno));
return(-1);
}
if((servent = getservbyname("ntalk", "udp")) == (struct servent *)NULL) {
fprintf(stderr, "talk: Could not find ntalk udp service\n");
close(udp_ctl);
return(-1);
}
ntalk_port = (udpport_t)servent->s_port;
udpopt.nwuo_flags = NWUO_NOFLAGS;
udpopt.nwuo_flags |= NWUO_COPY | NWUO_LP_SEL | NWUO_EN_LOC;
udpopt.nwuo_flags |= NWUO_DI_BROAD | NWUO_RP_SET | NWUO_RA_SET;
udpopt.nwuo_flags |= NWUO_RWDATONLY | NWUO_DI_IPOPT;
udpopt.nwuo_remaddr = raddr;
udpopt.nwuo_remport = ntalk_port;
s = ioctl(udp_ctl, NWIOSUDPOPT, &udpopt);
if(s < 0) {
perror("talk: ioctl NWIOSUDPOPT");
close(udp_ctl);
return(-1);
}
s = ioctl(udp_ctl, NWIOGUDPOPT, &udpopt);
if(s < 0) {
perror("talk: ioctl NWIOGUDPOPT");
close(udp_ctl);
return(-1);
}
laddr = udpopt.nwuo_locaddr;
ctlport = udpopt.nwuo_locport;
if((tcp_device = getenv("TCP_DEVICE")) == (char *)NULL)
tcp_device = TCP_DEVICE;
if((tcp_fd = open(tcp_device, O_RDWR)) < 0) {
fprintf(stderr, "talk: Could not open %s: %s\n",
tcp_device, strerror(errno));
close(udp_ctl);
return(-1);
}
tcpconf.nwtc_flags = NWTC_NOFLAGS;
tcpconf.nwtc_flags |= NWTC_LP_SEL | NWTC_SET_RA | NWTC_UNSET_RP;
tcpconf.nwtc_remaddr = raddr;
s = ioctl(tcp_fd, NWIOSTCPCONF, &tcpconf);
if(s < 0) {
perror("talk: ioctl NWIOSTCPCONF");
close(udp_ctl);
close(tcp_fd);
return(-1);
}
s = ioctl(tcp_fd, NWIOGTCPCONF, &tcpconf);
if(s < 0) {
perror("talk: ioctl NWIOGTCPCONF");
close(udp_ctl);
close(tcp_fd);
return(-1);
}
dataport = tcpconf.nwtc_locport;
return(0);
}
int getreply(reply, timeout)
struct talk_reply *reply;
int timeout;
{
int s;
int terrno;
udp_io_hdr_t *udp_io_hdr;
signal(SIGALRM, TimeOut);
alarm(timeout);
s = read(udp_ctl, buffer, sizeof(buffer));
terrno = errno;
alarm(0);
errno = terrno;
if(s < 0 && errno == EINTR)
return(1);
if(s < 0) {
perror("talk: Read error in getreply");
return(-1);
}
if(s == sizeof(struct talk_reply))
memcpy((char *)reply, buffer, s);
return(0);
}
int sendrequest(request, here)
struct talk_request *request;
int here;
{
int s;
nwio_udpopt_t udpopt;
udp_io_hdr_t *udp_io_hdr;
udpopt.nwuo_flags = NWUO_NOFLAGS;
udpopt.nwuo_flags |= NWUO_COPY | NWUO_LP_SET | NWUO_EN_LOC;
udpopt.nwuo_flags |= NWUO_DI_BROAD | NWUO_RP_SET | NWUO_RA_SET;
udpopt.nwuo_flags |= NWUO_RWDATONLY | NWUO_DI_IPOPT;
udpopt.nwuo_locport = ctlport;
if(here)
udpopt.nwuo_remaddr = laddr;
else
udpopt.nwuo_remaddr = raddr;
udpopt.nwuo_remport = ntalk_port;
s = ioctl(udp_ctl, NWIOSUDPOPT, &udpopt);
if(s < 0) {
perror("talk: ioctl NWIOSUDPOPT");
return(-1);
}
s = ioctl(udp_ctl, NWIOGUDPOPT, &udpopt);
if(s < 0) {
perror("talk: ioctl NWIOGUDPOPT");
return(-1);
}
s = write(udp_ctl, request, sizeof(struct talk_request));
if(s < 0) {
perror("talk: write error in sendrequest");
return(-1);
}
if(s != sizeof(struct talk_request)) {
fprintf(stderr, "talk: sendrequest size mismatch %d %d\n", s, sizeof(struct talk_request));
return(-1);
}
return(0);
}
void TimeOut(int sig)
{
}
int NetConnect(u16_t port)
{
int s;
nwio_tcpconf_t tcpconf;
nwio_tcpcl_t tcpcopt;
tcpconf.nwtc_flags = NWTC_NOFLAGS;
tcpconf.nwtc_flags |= NWTC_LP_SET | NWTC_SET_RA | NWTC_SET_RP;
tcpconf.nwtc_locport = dataport;
tcpconf.nwtc_remaddr = raddr;
tcpconf.nwtc_remport = port;
s = ioctl(tcp_fd, NWIOSTCPCONF, &tcpconf);
if(s < 0) {
perror("talk: ioctl NWIOSTCPCONF");
return(-1);
}
s = ioctl(tcp_fd, NWIOGTCPCONF, &tcpconf);
if(s < 0) {
perror("talk: ioctl NWIOGTCPCONF");
return(-1);
}
tcpcopt.nwtcl_flags = 0;
s = ioctl(tcp_fd, NWIOTCPCONN, &tcpcopt);
if(s < 0 && errno == ECONNREFUSED)
return(1);
if(s < 0) {
perror("talk: ioctl NWIOTCPCONN");
return(-1);
}
return(0);
}
int NetListen(timeout)
int timeout;
{
int s;
nwio_tcpcl_t tcplopt;
int terrno;
tcplopt.nwtcl_flags = 0;
signal(SIGALRM, TimeOut);
alarm(timeout);
s = ioctl(tcp_fd, NWIOTCPLISTEN, &tcplopt);
terrno = errno;
alarm(0);
errno = terrno;
if(s < 0 && errno == EINTR)
return(1);
if(s < 0) {
perror("talk: ioctl NWIOTCPLISTEN");
return(-1);
}
return(0);
}

View file

@ -1,15 +0,0 @@
/* net.h Copyright Michael Temari 08/01/1996 All Rights Reserved */
extern char luser[], ruser[];
extern char lhost[], rhost[];
extern char ltty[], rtty[];
extern udpport_t ctlport;
extern tcpport_t dataport;
extern ipaddr_t laddr, raddr;
extern int tcp_fd;
_PROTOTYPE(int NetInit, (void));
_PROTOTYPE(int getreply, (struct talk_reply *reply, int timeout));
_PROTOTYPE(int sendrequest, (struct talk_request *request, int here));
_PROTOTYPE(int NetConnect, (u16_t port));
_PROTOTYPE(int NetListen, (int timeout));

View file

@ -1,142 +0,0 @@
/* proto.c Copyright Michael Temari 08/01/1996 All Rights Reserved */
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <net/hton.h>
#include <net/gen/socket.h>
#include <net/gen/in.h>
#include <net/gen/inet.h>
#include <net/gen/tcp.h>
#include <net/gen/udp.h>
#include "talk.h"
#include "proto.h"
#include "net.h"
#include "screen.h"
_PROTOTYPE(static int TalkChk, (int gotreply, struct talk_reply *reply, char *msg));
_PROTOTYPE(static int TalkTrans, (int type, long id, struct talk_reply *reply, int here));
static char *AnswerMsgs[] = {
"Success",
"User Not Logged In",
"Failure",
"Remote Does Not Know who we are",
"User is not accepting calls",
"Are request was not know",
"Incorrect Version",
"Bad Address",
"Bad Control Address"
};
static int TalkChk(gotreply, reply, msg)
int gotreply;
struct talk_reply *reply;
char *msg;
{
if(!gotreply) {
ScreenMsg(msg);
return(-1);
}
if(reply->answer == SUCCESS) return(0);
if(reply->answer < (sizeof(AnswerMsgs) / sizeof(AnswerMsgs[0])))
ScreenMsg(AnswerMsgs[reply->answer]);
else
ScreenMsg("Bad Answer");
return(-1);
}
static int TalkTrans(type, id, reply, here)
int type;
long id;
struct talk_reply *reply;
int here;
{
struct talk_request request;
int tries;
int gotreply;
memset(&request, 0, sizeof(request));
request.version = TALK_VERSION;
request.type = type;
request.id = id;
request.addr.sa_family = htons(AF_INET);
request.addr.sin_port = dataport;
request.addr.sin_addr = laddr;
request.ctl_addr.sa_family = htons(AF_INET);
request.ctl_addr.sin_port = ctlport;
request.ctl_addr.sin_addr = laddr;
request.pid = getpid();
strncpy(request.luser, luser, USER_SIZE);
strncpy(request.ruser, ruser, USER_SIZE);
strncpy(request.rtty, rtty, TTY_SIZE);
tries = 0;
gotreply = 0;
while(!ScreenDone && tries++ < 3 && !gotreply) {
if(!sendrequest(&request, here))
if(!getreply(reply, 5))
gotreply = 1;
if(!gotreply) continue;
if(reply->version != request.version ||
reply->type != request.type)
gotreply = 0;
}
return(gotreply);
}
int TalkInit()
{
struct talk_reply reply;
long id = 0;
long rid;
int s;
int ring;
char buff[32];
/* Check if someone was calling us */
ScreenMsg("Initiating Talk Protocol");
/* Check is someone was calling us */
s = TalkTrans(LOOK_UP, ++id, &reply, 0);
/* Someone was calling us */
if(s && reply.answer == SUCCESS) {
s = NetConnect(reply.addr.sin_port);
if(s == 1) {
ScreenMsg("Your party has hung up");
TalkTrans(DELETE, reply.id, &reply, 0);
}
return(s == 0 ? 0 : -1);
}
ScreenMsg("Ringing User");
ring = 0;
while(!ScreenDone && ring++ < 5) {
if(TalkChk(TalkTrans(ANNOUNCE, -1, &reply, 0),
&reply, "No response to are ring"))
return(-1);
rid = reply.id;
sprintf(buff, "Ring #%d", ring);
ScreenMsg(buff);
if(ring == 1) {
if(TalkChk(TalkTrans(LEAVE_INVITE, ++id, &reply, 1),
&reply, "Could not leave are invitaion locally"))
return(-1);
}
s = NetListen(RING_WAIT);
if(s <= 0) {
TalkTrans(DELETE, reply.id, &reply, 1);
TalkTrans(DELETE, rid, &reply, 0);
return(s);
}
}
return(-1);
}

View file

@ -1,3 +0,0 @@
/* proto.h Copyright Michael Temari 08/01/1996 All Rights Reserved */
_PROTOTYPE(int TalkInit, (void));

View file

@ -1,208 +0,0 @@
/* screen.c Copyright Michael Temari 08/01/1996 All Rights Reserved */
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <signal.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>
#include <curses.h>
#include "screen.h"
_PROTOTYPE(void gotsig, (int sig));
_PROTOTYPE(static char *delword, (WINDOW *w));
struct {
WINDOW *win;
char erase;
char kill;
char werase;
} window[2];
static char line[80+1];
int ScreenDone = 0;
static WINDOW *dwin;
void gotsig(sig)
int sig;
{
ScreenDone = 1;
signal(sig, gotsig);
}
int ScreenInit()
{
int i;
if(initscr() == (WINDOW *)NULL) {
fprintf(stderr, "talk: Could not initscr\n");
return(-1);
}
signal(SIGINT, gotsig);
signal(SIGQUIT, gotsig);
signal(SIGPIPE, gotsig);
signal(SIGHUP, gotsig);
clear();
refresh();
noecho();
cbreak();
/* local window */
window[LOCALWIN].win = newwin(LINES / 2, COLS, 0, 0);
scrollok(window[LOCALWIN].win, TRUE);
wclear(window[LOCALWIN].win);
/* divider between windows */
dwin = newwin(1, COLS, LINES / 2, 0);
i = COLS;
while(i-- > 0)
waddch(dwin, '-');
wrefresh(dwin);
/* remote window */
window[REMOTEWIN].win = newwin(LINES - (LINES / 2) - 1, COLS, LINES / 2 + 1, 0);
scrollok(window[REMOTEWIN].win, TRUE);
wclear(window[REMOTEWIN].win);
return(0);
}
void ScreenMsg(msg)
char *msg;
{
WINDOW *w;
w =window[LOCALWIN].win;
wmove(w, 0, 0);
if(*msg != '\0') {
wprintw(w, "[%s]", msg);
wclrtoeol(w);
} else
werase(w);
wrefresh(w);
}
void ScreenWho(user, host)
char *user;
char *host;
{
if(*host != '\0') {
wmove(dwin, 0, (COLS - (1 + strlen(user) + 1 + strlen(host) + 1)) / 2);
wprintw(dwin, " %s@%s ", user, host);
} else {
wmove(dwin, 0, (COLS - (1 + strlen(user) + 1)) / 2);
wprintw(dwin, " %s ", user);
}
wrefresh(dwin);
}
void ScreenEdit(lcc, rcc)
char lcc[];
char rcc[];
{
window[LOCALWIN].erase = lcc[0];
window[LOCALWIN].kill = lcc[1];
window[LOCALWIN].werase = lcc[2];
window[REMOTEWIN].erase = rcc[0];
window[REMOTEWIN].kill = rcc[1];
window[REMOTEWIN].werase = rcc[2];
}
void ScreenPut(data, len, win)
char *data;
int len;
int win;
{
WINDOW *w;
unsigned char ch;
int r, c;
w = window[win].win;
while(len-- > 0) {
ch = *data++;
/* new line CR, NL */
if(ch == '\r' || ch == '\n') {
waddch(w, '\n');
} else
/* erase a character, BS, DEL */
if(ch == 0x08 || ch == 0x7f || ch == window[win].erase) {
getyx(w, r, c);
if(c > 0)
c--;
wmove(w, r, c);
waddch(w, ' ');
wmove(w, r, c);
} else
/* erase line CTL-U */
if(ch == 0x15 || ch == window[win].kill) {
getyx(w, r, c);
wmove(w, r, 0);
wclrtoeol(w);
} else
/* refresh CTL-L */
if(ch == 0x0c) {
if(win == LOCALWIN) {
touchwin(w);
wrefresh(w);
touchwin(window[REMOTEWIN].win);
wrefresh(window[REMOTEWIN].win);
}
} else
/* bell CTL-G */
if(ch == 0x07) {
putchar(ch);
}
else
/* erase last word CTL-W */
if(ch == 0x17 || ch == window[win].werase) {
(void) delword(w);
} else {
getyx(w, r, c);
if(1 || isprint(ch)) {
if(ch != ' ' && c == (COLS - 1))
wprintw(w, "\n%s", delword(w));
waddch(w, ch);
}
}
}
wrefresh(w);
}
static char *delword(w)
WINDOW *w;
{
int r, c;
int i = 0;
char ch;
char *p = &line[80];
*p-- = '\0';
getyx(w, r, c);
if(c == 0) return NULL;
while(c >= 0) {
c--;
ch = mvwinch(w, r, c);
if(ch == ' ') break;
*p-- = ch;
i = 1;
waddch(w, ' ');
}
c += i;
wmove(w, r, c);
return(++p);
}
void ScreenEnd()
{
move(LINES - 1, 0);
refresh();
endwin();
}

View file

@ -1,13 +0,0 @@
/* screen.h Copyright Michael Temari 08/01/1996 All Rights Reserved */
_PROTOTYPE(int ScreenInit, (void));
_PROTOTYPE(void ScreenMsg, (char *msg));
_PROTOTYPE(void ScreenWho, (char *user, char *host));
_PROTOTYPE(void ScreenEdit, (char lcc[], char rcc[]));
_PROTOTYPE(void ScreenPut, (char *data, int len, int mywin));
_PROTOTYPE(void ScreenEnd, (void));
extern int ScreenDone;
#define LOCALWIN 0
#define REMOTEWIN 1

View file

@ -1,242 +0,0 @@
/* talk.c Copyright Michael Temari 08/01/1996 All Rights Reserved */
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <utmp.h>
#include <termios.h>
#include <net/gen/netdb.h>
#include <net/hton.h>
#include <net/gen/socket.h>
#include <net/gen/in.h>
#include <net/gen/inet.h>
#include <net/gen/tcp.h>
#include <net/gen/udp.h>
#include "talk.h"
#include "proto.h"
#include "net.h"
#include "screen.h"
_PROTOTYPE(int main, (int argc, char *argv[]));
_PROTOTYPE(void DoTalk, (void));
int main(argc, argv)
int argc;
char *argv[];
{
char *p;
struct hostent *hp;
struct stat st;
struct utmp utmp;
int slot;
FILE *fp;
if(argc < 2 || argc > 3) {
fprintf(stderr, "Usage: talk user[@host] [tty]\n");
return(-1);
}
/* get local host name */
if(gethostname(lhost, HOST_SIZE) < 0) {
fprintf(stderr, "talk: Error getting local host name\n");
return(-1);
}
/* get local user name and tty */
if((slot = ttyslot()) < 0) {
fprintf(stderr, "talk: You are not on a terminal\n");
return(-1);
}
if((fp = fopen(UTMP, "r")) == (FILE *)NULL) {
fprintf(stderr, "talk: Could not open %s\n", UTMP);
return(-1);
}
if(fseek(fp, (off_t) sizeof(utmp) * slot, SEEK_SET)) {
fprintf(stderr, "talk: Could not seek %s\n", UTMP);
fclose(fp);
return(-1);
}
if(fread((char *)&utmp, sizeof(utmp), 1 , fp) != 1) {
fprintf(stderr, "talk: Could not read %s\n", UTMP);
fclose(fp);
return(-1);
}
fclose(fp);
#ifdef __NBSD_LIBC
strncpy(luser, utmp.ut_name, USER_SIZE < sizeof(utmp.ut_name) ?
USER_SIZE : sizeof(utmp.ut_name));
#else
strncpy(luser, utmp.ut_user, USER_SIZE < sizeof(utmp.ut_user) ?
USER_SIZE : sizeof(utmp.ut_user));
#endif
luser[USER_SIZE] = '\0';
/* get local tty */
if((p = ttyname(0)) == (char *)NULL) {
fprintf(stderr, "talk: You are not on a terminal\n");
return(-1);
}
strncpy(ltty, p+5, TTY_SIZE);
ltty[TTY_SIZE] = '\0';
/* check if local tty is going to be writable */
if(stat(p, &st) < 0) {
perror("talk: Could not stat local tty");
return(-1);
}
if((st.st_mode & S_IWGRP) == 0) {
fprintf(stderr, "talk: Your terminal is not writable. Use: mesg y\n");
return(-1);
}
/* get remote user and host name */
if((p = strchr(argv[1], '@')) != (char *)NULL)
*p++ = '\0';
else
p = lhost;
strncpy(ruser, argv[1], USER_SIZE);
ruser[USER_SIZE] = '\0';
strncpy(rhost, p, HOST_SIZE);
rhost[HOST_SIZE] = '\0';
/* get remote tty */
if(argc > 2)
strncpy(rtty, argv[2], TTY_SIZE);
else
rtty[0] = '\0';
rtty[TTY_SIZE] = '\0';
if((hp = gethostbyname(rhost)) == (struct hostent *)NULL) {
fprintf(stderr, "talk: Could not determine address of %s\n", rhost);
return(-1);
}
memcpy((char *)&raddr, (char *)hp->h_addr, hp->h_length);
if(NetInit()) {
fprintf(stderr, "talk: Error in NetInit\n");
return(-1);
}
if(ScreenInit())
return(-1);
if(!TalkInit())
DoTalk();
ScreenEnd();
return(0);
}
struct pdata {
int win;
int len;
char buffer[64];
} pdata;
void DoTalk()
{
int s;
int s2;
int kid;
int pfd[2];
int win;
int len;
struct termios termios;
char lcc[3];
char rcc[3];
ScreenMsg("");
ScreenWho(ruser, rhost);
/* Get and send edit characters */
s = tcgetattr(0, &termios);
if(s < 0) {
perror("talk: tcgetattr");
return;
}
lcc[0] = termios.c_cc[VERASE];
lcc[1] = termios.c_cc[VKILL];
lcc[2] = 0x17; /* Control - W */
s = write(tcp_fd, lcc, sizeof(lcc));
if(s != sizeof(lcc)) {
ScreenMsg("Connection Closing due to error");
return;
}
s = read(tcp_fd, rcc, sizeof(rcc));
if(s != sizeof(rcc)) {
ScreenMsg("Connection Closing due to error");
return;
}
ScreenEdit(lcc, rcc);
s = pipe(pfd);
if(s < 0) {
ScreenMsg("Could not create pipes");
return;
}
if((kid = fork()) < 0) {
ScreenMsg("Could not fork");
close(pfd[0]);
close(pfd[1]);
return;
}
if(kid == 0) {
close(tcp_fd);
close(pfd[1]);
while(1) {
s = read(pfd[0], &pdata, sizeof(pdata));
if(s != sizeof(pdata)) {
close(pfd[0]);
exit(-1);
}
ScreenPut(pdata.buffer, pdata.len, pdata.win);
}
}
close(pfd[0]);
if((kid = fork()) < 0) {
ScreenMsg("Could not fork");
close(pfd[1]);
return;
}
if(kid == 0) {
pdata.win = REMOTEWIN;
while(!ScreenDone) {
s = read(tcp_fd, pdata.buffer, sizeof(pdata.buffer));
if(s <= 0)
break;
pdata.len = s;
write(pfd[1], &pdata, sizeof(pdata));
}
close(pfd[1]);
close(tcp_fd);
kill(getppid(), SIGINT);
exit(-1);
}
pdata.win = LOCALWIN;
while(!ScreenDone) {
s = read(0, pdata.buffer, sizeof(pdata.buffer));
if(s <= 0)
break;
pdata.len = s;
write(pfd[1], &pdata, sizeof(pdata));
s2 = write(tcp_fd, pdata.buffer, s);
if(s2 != s)
break;
}
kill(kid, SIGINT);
close(pfd[1]);
close(tcp_fd);
return;
}

View file

@ -1,57 +0,0 @@
/* talk.h Copyright Michael Temari 07/22/1996 All Rights Reserved */
#define USER_SIZE 12
#define TTY_SIZE 16
#define HOST_SIZE 255
struct osockaddr {
u16_t sa_family;
u16_t sin_port;
ipaddr_t sin_addr;
char junk[8];
};
struct talk_request {
u8_t version;
u8_t type;
u8_t answer;
u8_t junk;
u32_t id;
struct osockaddr addr;
struct osockaddr ctl_addr;
long pid;
char luser[USER_SIZE];
char ruser[USER_SIZE];
char rtty[TTY_SIZE];
};
struct talk_reply {
u8_t version;
u8_t type;
u8_t answer;
u8_t junk;
u32_t id;
struct osockaddr addr;
};
#define TALK_VERSION 1
/* message type values */
#define LEAVE_INVITE 0 /* leave invitation with server */
#define LOOK_UP 1 /* check for invitation by callee */
#define DELETE 2 /* delete invitation by caller */
#define ANNOUNCE 3 /* announce invitation by caller */
/* answer values */
#define SUCCESS 0 /* operation completed properly */
#define NOT_HERE 1 /* callee not logged in */
#define FAILED 2 /* operation failed for unexplained reason */
#define MACHINE_UNKNOWN 3 /* caller's machine name unknown */
#define PERMISSION_DENIED 4 /* callee's tty doesn't permit announce */
#define UNKNOWN_REQUEST 5 /* request has invalid type value */
#define BADVERSION 6 /* request has invalid protocol version */
#define BADADDR 7 /* request has invalid addr value */
#define BADCTLADDR 8 /* request has invalid ctl_addr value */
#define MAX_LIFE 60 /* max time daemon saves invitations */
#define RING_WAIT 30 /* time to wait before resending invitation */

View file

@ -1,10 +0,0 @@
# Makefile for talkd
#
# 07/22/96 Michael Temari, <temari@ix.netcom.com>
#
PROG= talkd
SRCS= talkd.c net.c process.c finduser.c
MAN=
.include <bsd.prog.mk>

View file

@ -1,48 +0,0 @@
/* finduser.c Copyright Michael Temari 07/22/1996 All Rights Reserved */
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <fcntl.h>
#include <time.h>
#include <utmp.h>
#include <net/gen/in.h>
#include "talk.h"
#include "finduser.h"
int find_user(name, tty)
char *name;
char *tty;
{
int fd;
int ret;
struct utmp utmp;
/* Now find out if the requested user is logged in. */
if((fd = open(UTMP, O_RDONLY)) < 0) {
perror("talkd: opening UTMP file");
return(FAILED);
}
ret = NOT_HERE;
while(read(fd, &utmp, sizeof(struct utmp)) == sizeof(struct utmp)) {
if(utmp.ut_type != USER_PROCESS) continue;
#ifdef __NBSD_LIBC
if(strncmp(utmp.ut_name, name, sizeof(utmp.ut_name))) continue;
#else
if(strncmp(utmp.ut_user, name, sizeof(utmp.ut_user))) continue;
#endif
if(*tty && strncmp(utmp.ut_line, tty, sizeof(utmp.ut_line))) continue;
strcpy(tty, utmp.ut_line);
ret = SUCCESS;
break;
}
close(fd);
return(ret);
}

View file

@ -1,3 +0,0 @@
/* finduser.h Copyright Michael Temari 07/22/1996 All Rights Reserved */
_PROTOTYPE(int find_user, (char *name, char *tty));

View file

@ -1,188 +0,0 @@
/* net.c Copyright Michael Temari 07/22/1996 All Rights Reserved */
#include <sys/types.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <net/netlib.h>
#include <net/hton.h>
#include <net/gen/netdb.h>
#include <net/gen/in.h>
#include <net/gen/udp.h>
#include <net/gen/udp_io.h>
#include <net/gen/udp_hdr.h>
#include "talk.h"
#include "talkd.h"
#include "net.h"
static unsigned char buffer[8192];
static int udp_in;
static int udp_out;
static udpport_t ntalk_port;
int NetInit()
{
int s;
struct servent *servent;
char *udp_device;
nwio_udpopt_t udpopt;
if((udp_device = getenv("UDP_DEVICE")) == (char *)NULL)
udp_device = UDP_DEVICE;
if((udp_in = open(udp_device, O_RDWR)) < 0) {
fprintf(stderr, "talkd: Could not open %s: %s\n",
udp_device, strerror(errno));
return(-1);
}
if((udp_out = open(udp_device, O_RDWR)) < 0) {
fprintf(stderr, "talkd: Could not open %s: %s\n",
udp_device, strerror(errno));
close(udp_in);
return(-1);
}
if((servent = getservbyname("ntalk", "udp")) == (struct servent *)NULL) {
fprintf(stderr, "talkd: Could not find ntalk udp service\n");
close(udp_in);
close(udp_out);
return(-1);
}
ntalk_port = (udpport_t)servent->s_port;
udpopt.nwuo_flags = NWUO_NOFLAGS;
udpopt.nwuo_flags |= NWUO_COPY | NWUO_LP_SET | NWUO_EN_LOC;
udpopt.nwuo_flags |= NWUO_DI_BROAD | NWUO_RP_ANY | NWUO_RA_ANY;
udpopt.nwuo_flags |= NWUO_RWDATALL | NWUO_DI_IPOPT;
udpopt.nwuo_locport = ntalk_port;
s = ioctl(udp_in, NWIOSUDPOPT, &udpopt);
if(s < 0) {
perror("talkd: ioctl NWIOSUDPOPT");
close(udp_in);
close(udp_out);
return(-1);
}
s = ioctl(udp_in, NWIOGUDPOPT, &udpopt);
if(s < 0) {
perror("talkd: ioctl NWIOGUDPOPT");
close(udp_in);
close(udp_out);
return(-1);
}
return(0);
}
int getrequest(request)
struct talk_request *request;
{
int s;
udp_io_hdr_t *udp_io_hdr;
s = read(udp_in, buffer, sizeof(buffer));
if(s < 0) {
perror("talkd: Read error in getrequest");
return(-1);
}
if(s < sizeof(udp_io_hdr_t)) {
fprintf(stderr, "talkd: Packet size read %d is smaller the udp_io_hdr\n", s);
return(-1);
}
udp_io_hdr = (udp_io_hdr_t *)buffer;
s = s - sizeof(udp_io_hdr_t);
/* why is uih_data_len already in host order??? */
if(udp_io_hdr->uih_data_len != s) {
fprintf(stderr, "talkd: Size mismatch Packet %d Udp Data %d\n",
s, udp_io_hdr->uih_data_len);
return(-1);
}
if(s != sizeof(struct talk_request)) {
fprintf(stderr, "talkd: Size mismatch in request %d %d\n",
s, sizeof(struct talk_request));
return(-1);
}
memcpy((char *)request, buffer + sizeof(udp_io_hdr_t), s);
if(opt_d) {
fprintf(stderr, "Request: ");
fprintf(stderr, "%02x %02x %02x %02x ",
request->version, request->type, request->answer, request->junk);
fprintf(stderr, "%08lx ", request->id);
fprintf(stderr, "%04x %08lx:%04x\n",
request->addr.sa_family, request->addr.sin_addr, request->addr.sin_port);
fprintf(stderr, " %08lx ", request->pid);
fprintf(stderr, "%04x %08lx:%04x\n",
request->ctl_addr.sa_family, request->ctl_addr.sin_addr, request->ctl_addr.sin_port);
fprintf(stderr, " %-12.12s %-12.12s %-16.16s\n",
request->luser, request->ruser, request->rtty);
}
return(0);
}
int sendreply(request, reply)
struct talk_request *request;
struct talk_reply *reply;
{
int s;
nwio_udpopt_t udpopt;
udp_io_hdr_t *udp_io_hdr;
udpopt.nwuo_flags = NWUO_NOFLAGS;
udpopt.nwuo_flags |= NWUO_COPY | NWUO_LP_SET | NWUO_EN_LOC;
udpopt.nwuo_flags |= NWUO_DI_BROAD | NWUO_RP_SET | NWUO_RA_SET;
udpopt.nwuo_flags |= NWUO_RWDATONLY | NWUO_DI_IPOPT;
udpopt.nwuo_locport = ntalk_port;
udpopt.nwuo_remaddr = request->ctl_addr.sin_addr;
udpopt.nwuo_remport = request->ctl_addr.sin_port;
s = ioctl(udp_out, NWIOSUDPOPT, &udpopt);
if(s < 0) {
perror("talkd: ioctl NWIOSUDPOPT");
return(-1);
}
s = ioctl(udp_out, NWIOGUDPOPT, &udpopt);
if(s < 0) {
perror("talkd: ioctl NWIOGUDPOPT");
return(-1);
}
if(opt_d) {
fprintf(stderr, "Reply: ");
fprintf(stderr, "%02x %02x %02x %02x ",
reply->version, reply->type, reply->answer, reply->junk);
fprintf(stderr, "%08lx ", reply->id);
fprintf(stderr, "%04x %08lx:%04x",
reply->addr.sa_family, reply->addr.sin_addr, reply->addr.sin_port);
fprintf(stderr, "\n");
}
s = write(udp_out, reply, sizeof(struct talk_reply));
if(s < 0) {
perror("talkd: write");
return(-1);
}
if(s != sizeof(struct talk_reply)) {
fprintf(stderr, "talkd: write size mismatch %d %d\n",
s, sizeof(struct talk_reply));
return(-1);
}
return(0);
}

View file

@ -1,5 +0,0 @@
/* net.h Copyright Michael Temari 07/22/1996 All Rights Reserved */
_PROTOTYPE(int NetInit, (void));
_PROTOTYPE(int getrequest, (struct talk_request *request));
_PROTOTYPE(int sendreply, (struct talk_request *request, struct talk_reply *reply));

View file

@ -1,269 +0,0 @@
/* process.c Copyright Michael Temari 07/22/1996 All Rights Reserved */
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#include <net/hton.h>
#include <net/gen/socket.h>
#include <net/gen/in.h>
#include <net/gen/netdb.h>
#include "talk.h"
#include "talkd.h"
#include "process.h"
#include "finduser.h"
struct entry {
struct entry *prev;
struct talk_request rq;
time_t expire;
struct entry *next;
};
_PROTOTYPE(static int announce, (struct talk_request *request, char *rhost));
_PROTOTYPE(static struct talk_request *lookup, (struct talk_request *request, int type));
_PROTOTYPE(static int addreq, (struct talk_request *request));
_PROTOTYPE(static delete_invite, (long id));
_PROTOTYPE(static long nextid, (void));
_PROTOTYPE(static void delete, (struct entry *e));
static struct entry *entry = (struct entry *)NULL;
int processrequest(request, reply)
struct talk_request *request;
struct talk_reply *reply;
{
char *p;
struct talk_request *rq;
struct hostent *hp;
reply->version = TALK_VERSION;
reply->type = request->type;
reply->answer = 0;
reply->junk = 0;
reply->id = htonl(0);
/* check version */
if(request->version != TALK_VERSION) {
reply->answer = BADVERSION;
return(0);
}
/* check address family */
if(ntohs(request->addr.sa_family) != AF_INET) {
reply->answer = BADADDR;
return(0);
}
/* check control address family */
if(ntohs(request->ctl_addr.sa_family) != AF_INET) {
reply->answer = BADCTLADDR;
return(0);
}
/* check local name */
p = request->luser;
while(*p)
if(!isprint(*p)) {
reply->answer = FAILED;
return(0);
} else
p++;
switch(request->type) {
case ANNOUNCE:
reply->answer = find_user(request->ruser, request->rtty);
if(reply->answer != SUCCESS) break;
hp = gethostbyaddr((char *)&request->ctl_addr.sin_addr, sizeof(ipaddr_t), AF_INET);
if(hp == (struct hostent *)NULL) {
reply->answer = MACHINE_UNKNOWN;
break;
}
if((rq = lookup(request, 1)) == (struct talk_request *)NULL) {
reply->id = addreq(request);
reply->answer = announce(request, hp->h_name);
break;
}
if(ntohl(request->id) > ntohl(rq->id)) {
rq->id = nextid();
reply->id = rq->id;
reply->answer = announce(request, hp->h_name);
} else {
reply->id = rq->id;
reply->answer = SUCCESS;
}
break;
case LEAVE_INVITE:
rq = lookup(request, 1);
if(rq == (struct talk_request *)NULL)
reply->id = addreq(request);
else {
reply->id = rq->id;
reply->answer = SUCCESS;
}
break;
case LOOK_UP:
if((rq = lookup(request, 0)) == (struct talk_request *)NULL)
reply->answer = NOT_HERE;
else {
reply->id = rq->id;
memcpy((char *)&reply->addr, (char *)&rq->addr, sizeof(reply->addr));
reply->answer = SUCCESS;
}
break;
case DELETE:
reply->answer = delete_invite(request->id);
break;
default:
reply->answer = UNKNOWN_REQUEST;
}
return(0);
}
static int announce(request, rhost)
struct talk_request *request;
char *rhost;
{
char tty[5+TTY_SIZE+1];
struct stat st;
FILE *fp;
time_t now;
struct tm *tm;
sprintf(tty, "/dev/%s", request->rtty);
if(stat(tty, &st) < 0)
return(PERMISSION_DENIED);
if(!(st.st_mode & S_IWGRP))
return(PERMISSION_DENIED);
if((fp = fopen(tty, "w")) == (FILE *)NULL)
return(PERMISSION_DENIED);
(void) time(&now);
tm = localtime(&now);
fprintf(fp, "\007\007\007\rtalkd: Message from talkd@%s at %d:%02d:%02d\r\n",
myhostname, tm->tm_hour, tm->tm_min, tm->tm_sec);
fprintf(fp, "talkd: %s@%s would like to talk to you\r\n",
request->luser, rhost);
fprintf(fp, "talkd: to answer type: talk %s@%s\r\n",
request->luser, rhost);
fclose(fp);
return(SUCCESS);
}
static struct talk_request *lookup(request, type)
struct talk_request *request;
int type;
{
time_t now;
struct entry *e;
(void) time(&now);
for(e = entry; e != (struct entry *)NULL; e = e->next) {
if(now > e->expire) {
delete(e);
continue;
}
if(type == 0) {
if(!strncmp(request->luser, e->rq.ruser, USER_SIZE) &&
!strncmp(request->ruser, e->rq.luser, USER_SIZE) &&
e->rq.type == LEAVE_INVITE)
return(&e->rq);
} else {
if(request->type == e->rq.type &&
request->pid == e->rq.pid &&
!strncmp(request->luser, e->rq.luser, USER_SIZE) &&
!strncmp(request->ruser, e->rq.ruser, USER_SIZE)) {
e->expire = now + MAX_LIFE;
return(&e->rq);
}
}
}
return((struct talk_request *)NULL);
}
static int addreq(request)
struct talk_request *request;
{
time_t now;
struct entry *e;
(void) time(&now);
request->id = nextid();
e = (struct entry *) malloc(sizeof(struct entry));
if(e == (struct entry *)NULL) {
fprintf(stderr, "talkd: out of memory in insert table\n");
exit(1);
}
e->expire = now + MAX_LIFE;
memcpy((char *)&e->rq, (char *)request, sizeof(struct talk_request));
e->next = entry;
if(e->next != (struct entry *)NULL)
e->next->prev = e;
e->prev = (struct entry *)NULL;
entry = e;
return(request->id);
}
static int delete_invite(id)
long id;
{
time_t now;
struct entry *e;
(void) time(&now);
for(e = entry; e != (struct entry *)NULL; e = e->next) {
if(now > e->expire) {
delete(e);
continue;
}
if(e->rq.id == id) {
delete(e);
return(SUCCESS);
}
}
return(NOT_HERE);
}
static void delete(e)
struct entry *e;
{
if(e == (struct entry *)NULL) return;
if(entry == e)
entry = e->next;
else
if(e->prev != (struct entry *)NULL)
e->prev->next = e->next;
if(e->next != (struct entry *)NULL)
e->next->prev = e->prev;
free((char *)e);
return;
}
static long nextid()
{
static long id = 0;
id++;
if(id <= 0) id = 1;
return(htonl(id));
}

View file

@ -1,3 +0,0 @@
/* process.h Copyright Michael Temari 07/22/1996 All Rights Reserved */
_PROTOTYPE(int processrequest, (struct talk_request *request, struct talk_reply *reply));

View file

@ -1,57 +0,0 @@
/* talk.h Copyright Michael Temari 07/22/1996 All Rights Reserved */
#define USER_SIZE 12
#define TTY_SIZE 16
#define HOST_SIZE 255
struct osockaddr {
u16_t sa_family;
u16_t sin_port;
ipaddr_t sin_addr;
char junk[8];
};
struct talk_request {
u8_t version;
u8_t type;
u8_t answer;
u8_t junk;
u32_t id;
struct osockaddr addr;
struct osockaddr ctl_addr;
long pid;
char luser[USER_SIZE];
char ruser[USER_SIZE];
char rtty[TTY_SIZE];
};
struct talk_reply {
u8_t version;
u8_t type;
u8_t answer;
u8_t junk;
u32_t id;
struct osockaddr addr;
};
#define TALK_VERSION 1
/* message type values */
#define LEAVE_INVITE 0 /* leave invitation with server */
#define LOOK_UP 1 /* check for invitation by callee */
#define DELETE 2 /* delete invitation by caller */
#define ANNOUNCE 3 /* announce invitation by caller */
/* answer values */
#define SUCCESS 0 /* operation completed properly */
#define NOT_HERE 1 /* callee not logged in */
#define FAILED 2 /* operation failed for unexplained reason */
#define MACHINE_UNKNOWN 3 /* caller's machine name unknown */
#define PERMISSION_DENIED 4 /* callee's tty doesn't permit announce */
#define UNKNOWN_REQUEST 5 /* request has invalid type value */
#define BADVERSION 6 /* request has invalid protocol version */
#define BADADDR 7 /* request has invalid addr value */
#define BADCTLADDR 8 /* request has invalid ctl_addr value */
#define MAX_LIFE 60 /* max time daemon saves invitations */
#define RING_WAIT 30 /* time to wait before resending invitation */

View file

@ -1,54 +0,0 @@
/* talkd.c Copyright Michael Temari 07/22/1996 All Rights Reserved */
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <net/gen/in.h>
#include "talk.h"
#include "talkd.h"
#include "net.h"
#include "process.h"
_PROTOTYPE(int main, (int argc, char *argv[]));
int opt_d = 0;
char myhostname[HOST_SIZE+1];
int main(argc, argv)
int argc;
char *argv[];
{
struct talk_request request;
struct talk_reply reply;
if(argc > 1)
if(strcmp(argv[1], "-d") || argc > 2) {
fprintf(stderr, "Usage: talkd [-d]\n");
return(-1);
} else
opt_d = 1;
if(getuid() != 0) {
fprintf(stderr, "talkd: Must be run as super user\n");
return(-1);
}
if(gethostname(myhostname, HOST_SIZE) < 0) {
fprintf(stderr, "talkd: Error getting hostname\n");
return(-1);
}
if(NetInit()) {
fprintf(stderr, "talkd: Error in NetInit\n");
return(-1);
}
while(getrequest(&request) == 0) {
if(processrequest(&request, &reply)) break;
if(sendreply(&request, &reply)) break;
}
return(-1);
}

View file

@ -1,4 +0,0 @@
/* talkd.h Copyright Michael Temari 07/22/1996 All Rights Reserved */
extern int opt_d; /* debug option */
extern char myhostname[];

View file

@ -1,7 +0,0 @@
PROG= top
MAN=
DPADD+= ${LIBCURSES}
LDADD+= -lcurses
.include <bsd.prog.mk>

View file

@ -2,7 +2,7 @@
.PATH: ${MINIXSRCDIR}/common/include
INCS+= curses.h env.h fetch.h hgfs.h lib.h libutil.h timers.h
INCS+= env.h fetch.h hgfs.h lib.h libutil.h timers.h
INCS+= minix/acpi.h minix/ansi.h minix/audio_fw.h minix/bitmap.h \
minix/callnr.h minix/com.h minix/compiler.h minix/config.h \

View file

@ -1,226 +0,0 @@
/* curses.h - defines macros and prototypes for curses */
#ifndef _CURSES_H
#define _CURSES_H
#include <termios.h>
#include <stdarg.h>
#include <stdio.h>
typedef int bool;
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef ERR
#define ERR (-1) /* general error flag */
#endif
#ifndef OK
#define OK 0 /* general OK flag */
#endif
/* Macros. */
#define box(win,vc,hc) wbox(win,0,0,0,0,vc,hc)
#define addch(ch) waddch(stdscr,ch)
#define mvaddch(y,x,ch) (wmove(stdscr,y,x)==ERR?ERR:waddch(stdscr,ch))
#define mvwaddch(win,y,x,ch) (wmove(win,y,x)==ERR?ERR:waddch(win,ch))
#define getch() wgetch(stdscr)
#define mvgetch(y,x) (wmove(stdscr,y,x)==ERR?ERR:wgetch(stdscr))
#define mvwgetch(win,y,x) (wmove(win,y,x)==ERR?ERR:wgetch(win))
#define addstr(str) waddstr(stdscr,str)
#define mvaddstr(y,x,str) (wmove(stdscr,y,x)==ERR?ERR:waddstr(stdscr,str))
#define mvwaddstr(win,y,x,str) (wmove(win,y,x)==ERR?ERR:waddstr(win,str))
#define getstr(str) wgetstr(stdscr,str)
#define mvgetstr(y,x,str) (wmove(stdscr,y,x)==ERR?ERR:wgetstr(stdscr,str))
#define mvwgetstr(win,y,x,str) (wmove(win,y,x)==ERR?ERR:wgetstr(win,str))
#define move(y,x) wmove(stdscr,y,x)
#define clear() wclear(stdscr)
#define erase() werase(stdscr)
#define clrtobot() wclrtobot(stdscr)
#define mvclrtobot(y,x) (wmove(stdscr,y,x)==ERR?ERR:wclrtobot(stdscr))
#define mvwclrtobot(win,y,x) (wmove(win,y,x)==ERR?ERR:wclrtobot(win))
#define clrtoeol() wclrtoeol(stdscr)
#define mvclrtoeol(y,x) (wmove(stdscr,y,x)==ERR?ERR:wclrtoeol(stdscr))
#define mvwclrtoeol(win,y,x) (wmove(win,y,x)==ERR?ERR:wclrtoeol(win))
#define insertln() winsertln(stdscr)
#define mvinsertln(y,x) (wmove(stdscr,y,x)==ERR?ERR:winsertln(stdscr))
#define mvwinsertln(win,y,x) (wmove(win,y,x)==ERR?ERR:winsertln(win))
#define deleteln() wdeleteln(stdscr)
#define mvdeleteln(y,x) (wmove(stdscr,y,x)==ERR?ERR:wdeleteln(stdscr))
#define mvwdeleteln(win,y,x) (wmove(win,y,x)==ERR?ERR:wdeleteln(win))
#define refresh() wrefresh(stdscr)
#define inch() winch(stdscr)
#define insch(ch) winsch(stdscr,ch)
#define mvinsch(y,x,ch) (wmove(stdscr,y,x)==ERR?ERR:winsch(stdscr,ch))
#define mvwinsch(win,y,x,ch) (wmove(win,y,x)==ERR?ERR:winsch(win,ch))
#define delch() wdelch(stdscr)
#define mvdelch(y,x) (wmove(stdscr,y,x)==ERR?ERR:wdelch(stdscr))
#define mvwdelch(win,y,x) (wmove(win,y,x)==ERR?ERR:wdelch(win))
#define standout() wstandout(stdscr)
#define wstandout(win) ((win)->_attrs |= A_STANDOUT)
#define standend() wstandend(stdscr)
#define wstandend(win) ((win)->_attrs &= ~A_STANDOUT)
#define attrset(attrs) wattrset(stdscr, attrs)
#define wattrset(win, attrs) ((win)->_attrs = (attrs))
#define attron(attrs) wattron(stdscr, attrs)
#define wattron(win, attrs) ((win)->_attrs |= (attrs))
#define attroff(attrs) wattroff(stdscr,attrs)
#define wattroff(win, attrs) ((win)->_attrs &= ~(attrs))
#define resetty() tcsetattr(1, TCSANOW, &_orig_tty)
#define getyx(win,y,x) (y = (win)->_cury, x = (win)->_curx)
/* Video attribute definitions. */
#define A_BLINK 0x0100
#define A_BLANK 0
#define A_BOLD 0x0200
#define A_DIM 0
#define A_PROTECT 0
#define A_REVERSE 0x0400
#define A_STANDOUT 0x0800
#define A_UNDERLINE 0x1000
#define A_ALTCHARSET 0x2000
/* Type declarations. */
typedef struct {
int _cury; /* current pseudo-cursor */
int _curx;
int _maxy; /* max coordinates */
int _maxx;
int _begy; /* origin on screen */
int _begx;
int _flags; /* window properties */
int _attrs; /* attributes of written characters */
int _tabsize; /* tab character size */
bool _clear; /* causes clear at next refresh */
bool _leave; /* leaves cursor as it happens */
bool _scroll; /* allows window scrolling */
bool _nodelay; /* input character wait flag */
bool _keypad; /* flags keypad key mode active */
int **_line; /* pointer to line pointer array */
int *_minchng; /* First changed character in line */
int *_maxchng; /* Last changed character in line */
int _regtop; /* Top/bottom of scrolling region */
int _regbottom;
} WINDOW;
/* External variables */
extern int LINES; /* terminal height */
extern int COLS; /* terminal width */
extern bool NONL; /* \n causes CR too ? */
extern WINDOW *curscr; /* the current screen image */
extern WINDOW *stdscr; /* the default screen window */
extern struct termios _orig_tty, _tty;
extern unsigned int ACS_ULCORNER; /* terminal dependent block grafic */
extern unsigned int ACS_LLCORNER; /* charcters. Forget IBM, we are */
extern unsigned int ACS_URCORNER; /* independent of their charset. :-) */
extern unsigned int ACS_LRCORNER;
extern unsigned int ACS_RTEE;
extern unsigned int ACS_LTEE;
extern unsigned int ACS_BTEE;
extern unsigned int ACS_TTEE;
extern unsigned int ACS_HLINE;
extern unsigned int ACS_VLINE;
extern unsigned int ACS_PLUS;
extern unsigned int ACS_S1;
extern unsigned int ACS_S9;
extern unsigned int ACS_DIAMOND;
extern unsigned int ACS_CKBOARD;
extern unsigned int ACS_DEGREE;
extern unsigned int ACS_PLMINUS;
extern unsigned int ACS_BULLET;
extern unsigned int ACS_LARROW;
extern unsigned int ACS_RARROW;
extern unsigned int ACS_DARROW;
extern unsigned int ACS_UARROW;
extern unsigned int ACS_BOARD;
extern unsigned int ACS_LANTERN;
extern unsigned int ACS_BLOCK;
_PROTOTYPE( char *unctrl, (int _c) );
_PROTOTYPE( int baudrate, (void));
_PROTOTYPE( void beep, (void));
_PROTOTYPE( void cbreak, (void));
_PROTOTYPE( void clearok, (WINDOW *_win, bool _flag) );
_PROTOTYPE( void clrscr, (void));
_PROTOTYPE( void curs_set, (int _visibility) );
_PROTOTYPE( void delwin, (WINDOW *_win) );
_PROTOTYPE( void doupdate, (void));
_PROTOTYPE( void echo, (void));
_PROTOTYPE( int endwin, (void));
_PROTOTYPE( int erasechar, (void));
_PROTOTYPE( void fatal, (char *_s) );
_PROTOTYPE( int fixterm, (void));
_PROTOTYPE( void flash, (void));
_PROTOTYPE( void gettmode, (void));
_PROTOTYPE( void idlok, (WINDOW *_win, bool _flag) );
_PROTOTYPE( WINDOW *initscr, (void));
_PROTOTYPE( void keypad, (WINDOW *_win, bool _flag) );
_PROTOTYPE( int killchar, (void));
_PROTOTYPE( void leaveok, (WINDOW *_win, bool _flag) );
_PROTOTYPE( char *longname, (void));
_PROTOTYPE( void meta, (WINDOW *_win, bool _flag) );
_PROTOTYPE( int mvcur, (int _oldy, int _oldx, int _newy, int _newx) );
_PROTOTYPE( int mvinch, (int _y, int _x) );
_PROTOTYPE( int mvprintw, (int _y, int _x, const char *_fmt, ...) );
_PROTOTYPE( int mvscanw, (int _y, int _x, const char *_fmt, ...) );
_PROTOTYPE( int mvwin, (WINDOW *_win, int _begy, int _begx) );
_PROTOTYPE( int mvwinch, (WINDOW *_win, int _y, int _x) );
_PROTOTYPE( int mvwprintw, (WINDOW *_win, int _y, int _x, const char *_fmt,
...) );
_PROTOTYPE( int mvwscanw, (WINDOW *_win, int _y, int _x, const char *_fmt,
...) );
_PROTOTYPE( WINDOW *newwin, (int _num_lines, int _num_cols, int _y, int _x));
_PROTOTYPE( void nl, (void));
_PROTOTYPE( void nocbreak, (void));
_PROTOTYPE( void nodelay, (WINDOW *_win, bool _flag) );
_PROTOTYPE( void noecho, (void));
_PROTOTYPE( void nonl, (void));
_PROTOTYPE( void noraw, (void));
_PROTOTYPE( void outc, (int _c) );
_PROTOTYPE( void overlay, (WINDOW *_win1, WINDOW *_win2) );
_PROTOTYPE( void overwrite, (WINDOW *_win1, WINDOW *_win2) );
_PROTOTYPE( void poscur, (int _r, int _c) );
_PROTOTYPE( int printw, (const char *_fmt, ...) );
_PROTOTYPE( void raw, (void));
_PROTOTYPE( int resetterm, (void));
_PROTOTYPE( int saveoldterm, (void));
_PROTOTYPE( int saveterm, (void));
_PROTOTYPE( int savetty, (void));
_PROTOTYPE( int scanw, (const char *_fmt, ...) );
_PROTOTYPE( void scroll, (WINDOW *_win) );
_PROTOTYPE( void scrollok, (WINDOW *_win, bool _flag) );
_PROTOTYPE( int setscrreg, (int _top, int _bottom) );
_PROTOTYPE( int setterm, (char *_type) );
_PROTOTYPE( int setupterm, (void));
_PROTOTYPE( WINDOW *subwin, (WINDOW *_orig, int _nlines, int _ncols, int _y,
int _x));
_PROTOTYPE( int tabsize, (int _ts) );
_PROTOTYPE( void touchwin, (WINDOW *_win) );
_PROTOTYPE( int waddch, (WINDOW *_win, int _c) );
_PROTOTYPE( int waddstr, (WINDOW *_win, char *_str) );
_PROTOTYPE( int wbox, (WINDOW *_win, int _ymin, int _xmin, int _ymax,
int _xmax, unsigned int _v, unsigned int _h) );
_PROTOTYPE( void wclear, (WINDOW *_win) );
_PROTOTYPE( int wclrtobot, (WINDOW *_win) );
_PROTOTYPE( int wclrtoeol, (WINDOW *_win) );
_PROTOTYPE( int wdelch, (WINDOW *_win) );
_PROTOTYPE( int wdeleteln, (WINDOW *_win) );
_PROTOTYPE( void werase, (WINDOW *_win) );
_PROTOTYPE( int wgetch, (WINDOW *_win) );
_PROTOTYPE( int wgetstr, (WINDOW *_win, char *_str) );
_PROTOTYPE( int winch, (WINDOW *_win) );
_PROTOTYPE( int winsch, (WINDOW *_win, int _c) );
_PROTOTYPE( int winsertln, (WINDOW *_win) );
_PROTOTYPE( int wmove, (WINDOW *_win, int _y, int _x) );
_PROTOTYPE( void wnoutrefresh, (WINDOW *_win) );
_PROTOTYPE( int wprintw, (WINDOW *_win, const char *_fmt, ...));
_PROTOTYPE( void wrefresh, (WINDOW *_win) );
_PROTOTYPE( int wscanw, (WINDOW *_win, const char *_fmt, ...));
_PROTOTYPE( int wsetscrreg, (WINDOW *_win, int _top, int _bottom) );
_PROTOTYPE( int wtabsize, (WINDOW *_win, int _ts) );
#endif /* _CURSES_H */

View file

@ -72,6 +72,9 @@
700 root operator /usr/preserve
755 root operator /usr/run
755 root operator /usr/share
755 root operator /usr/share/doc
755 root operator /usr/share/doc/psd
755 root operator /usr/share/doc/psd/19.curses
755 root operator /usr/share/mk
755 root operator /usr/share/terminfo
755 root operator /usr/share/zoneinfo

View file

@ -1,7 +1,7 @@
# Doing a make includes builds /usr/include
INCS= alloca.h a.out.h ar.h assert.h configfile.h ctype.h \
curses.h dirent.h env.h err.h errno.h fcntl.h fenv.h \
dirent.h env.h err.h errno.h fcntl.h fenv.h \
float.h fnmatch.h fts.h getopt.h glob.h grp.h ifaddrs.h \
inttypes.h libgen.h libutil.h limits.h locale.h \
mathconst.h math.h midiparser.h netdb.h pwd.h regex.h \

View file

@ -14,14 +14,14 @@ LIBCOMPAT_DIR?=
LIBMINLIB_DIR?=
LIBASYN_DIR?=
SUBDIR= csu ${LIBCOMPAT_DIR} ${LIBC_DIR} libcurses libdriver libnetdriver \
SUBDIR= csu ${LIBCOMPAT_DIR} ${LIBC_DIR} libdriver libnetdriver \
libedit ${LIBM_DIR} libsys libtimers libutil libbz2 libl libhgfs \
libz libfetch libarchive libvtreefs libaudiodriver libmthread \
libexec libdevman libusb ${LIBMINLIB_DIR} ${LIBASYN_DIR} \
libddekit
.if defined(NBSD_LIBC) && (${NBSD_LIBC} != "no")
SUBDIR+= libelf libminc libcrypt libterminfo
SUBDIR+= libelf libminc libcrypt libterminfo libcurses
.endif
.if ${COMPILER_TYPE} == "ack"

View file

@ -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..

View file

@ -0,0 +1,342 @@
/* $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.
*/
#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1992, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)ex1.c 8.1 (Berkeley) 6/4/93";
#endif /* not lint */
#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 );
}

View file

@ -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();
}

View file

@ -1,45 +1,186 @@
# Makefile for libcurses
# $NetBSD: Makefile,v 1.64 2010/02/03 15:34:40 roy Exp $
# @(#)Makefile 8.2 (Berkeley) 1/2/94
LIB= curses
.include <bsd.own.mk>
SRCS= \
beep.c \
charpick.c \
curs_set.c \
cursesio.c \
endwin.c \
flash.c \
initscr.c \
longname.c \
move.c \
mvcursor.c \
newwin.c \
options.c \
overlay.c \
prntscan.c \
refresh.c \
scrreg.c \
setterm.c \
tabsize.c \
termmisc.c \
unctrl.c \
update.c \
waddch.c \
waddstr.c \
wbox.c \
wclear.c \
wclrtobot.c \
wclrtoeol.c \
wdelch.c \
wdeleteln.c \
werase.c \
wgetch.c \
wgetstr.c \
windel.c \
winmove.c \
winsch.c \
winscrol.c \
winsertln.c \
wintouch.c
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 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
.if !defined(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_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_termcap.3 getcap.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_termcap.3 longname.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
.if make(install)
SUBDIR+= PSD.doc
.endif
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>

View file

@ -0,0 +1,40 @@
# $NetBSD: Makefile,v 1.10 2003/07/10 10:34:22 lukem Exp $
# from: @(#)Makefile 8.2 (Berkeley) 5/23/94
DIR= psd/19.curses
SRCS= Master
MACROS= -me
OTHER= appen.A appen.B appen.C doc.I doc.II doc.III doc.IV fns.doc \
intro.0 intro.1 intro.3 intro.4 intro.5 intro.6 \
macros c_macros
CEXAMPLES= ex1.gr ex2.gr life.gr twinkle1.gr twinkle2.gr win_st.gr
TBLFILES= intro.2.tbl
EXTRA= ${OTHER} ${CEXAMPLES:R:S/$/.c/g} ${TBLFILES:R}
CLEANFILES+= ${CEXAMPLES} ${TBLFILES}
.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.
# XXXBUILDSH: can we use TOOL_VGRIND here ?
VFONT= /usr/libexec/vfontedpr
.c.gr:
${VFONT} ${.IMPSRC} | grep -v "^'wh" > ${.TARGET}
paper.ps: ${SRCS} ${OTHER} ${CEXAMPLES} ${TBLFILES}
${TOOL_SOELIM} -I${.CURDIR} Master | \
${TOOL_ROFF_PS} ${MACROS} > ${.TARGET}
# Unfortunately our make doesn't handle single-suffix rules.
intro.2.tbl: intro.2
${TOOL_TBL} ${.ALLSRC} > ${.TARGET}
.include <bsd.doc.mk>

View file

@ -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

View file

@ -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

View file

@ -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 .

View file

@ -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

View file

@ -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
lib/libcurses/PSD.doc/doc.I Normal file
View file

@ -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).

View file

@ -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

View file

@ -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.

View file

@ -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
lib/libcurses/PSD.doc/ex1.c Normal file
View file

@ -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
lib/libcurses/PSD.doc/ex2.c Normal file
View file

@ -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);
}

File diff suppressed because it is too large Load diff

View file

@ -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"

View file

@ -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.

View file

@ -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

View file

@ -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.

View file

@ -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

View file

@ -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.

View file

@ -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

View file

@ -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();
}

View file

@ -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
..

View file

@ -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();
}
}

View file

@ -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 */
}

View file

@ -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

309
lib/libcurses/acs.c Normal file
View file

@ -0,0 +1,309 @@
/* $NetBSD: acs.c,v 1.19 2010/02/25 10:56:24 drochner 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 <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: acs.c,v 1.19 2010/02/25 10:56:24 drochner Exp $");
#endif /* not lint */
#include "curses.h"
#include "curses_private.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 'ac' termcap 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 'ac' termcap 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 */

124
lib/libcurses/add_wch.c Normal file
View file

@ -0,0 +1,124 @@
/* $NetBSD: add_wch.c,v 1.3 2009/07/22 16:57:14 roy 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 <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: add_wch.c,v 1.3 2009/07/22 16:57:14 roy Exp $");
#endif /* not lint */
#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)
{
#ifndef HAVE_WCHAR
return ERR;
#else
return wadd_wch(stdscr, wch);
#endif /* HAVE_WCHAR */
}
/*
* mvadd_wch --
* Add the wide character to stdscr at the given location.
*/
int
mvadd_wch(int y, int x, const cchar_t *wch)
{
#ifndef HAVE_WCHAR
return ERR;
#else
return mvwadd_wch(stdscr, y, x, wch);
#endif /* HAVE_WCHAR */
}
/*
* 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)
{
#ifndef HAVE_WCHAR
return ERR;
#else
if (wmove(win, y, x) == ERR)
return ERR;
return wadd_wch(win, wch);
#endif /* HAVE_WCHAR */
}
/*
* wadd_wch --
* Add the wide character to the current position in the
* given window.
*
*/
int
wadd_wch(WINDOW *win, const cchar_t *wch)
{
#ifndef HAVE_WCHAR
return ERR;
#else
int x = win->curx, y = win->cury;
__LINE *lnp = NULL;
#ifdef DEBUG
int i;
for (i = 0; i < win->maxy; i++) {
assert(win->alines[i]->sentinel == SENTINEL_VALUE);
}
__CTRACE(__CTRACE_INPUT, "wadd_wch: win(%p)", win);
#endif
lnp = win->alines[y];
return _cursesi_addwchar(win, &lnp, &y, &x, wch);
#endif /* HAVE_WCHAR */
}

338
lib/libcurses/add_wchstr.c Normal file
View file

@ -0,0 +1,338 @@
/* $NetBSD: add_wchstr.c,v 1.4 2010/02/23 19:48:26 drochner 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 <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: add_wchstr.c,v 1.4 2010/02/23 19:48:26 drochner Exp $");
#endif /* not lint */
#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)
{
#ifndef HAVE_WCHAR
return ERR;
#else
return wadd_wchnstr(stdscr, wchstr, -1);
#endif
}
/*
* wadd_wchstr --
* Add a string to the given window starting at (_cury, _curx).
*/
int
wadd_wchstr(WINDOW *win, const cchar_t *wchstr)
{
#ifndef HAVE_WCHAR
return ERR;
#else
return wadd_wchnstr(win, wchstr, -1);
#endif
}
/*
* 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)
{
#ifndef HAVE_WCHAR
return ERR;
#else
return wadd_wchnstr(stdscr, wchstr, n);
#endif
}
/*
* mvadd_wchstr --
* Add a string to stdscr starting at (y, x)
*/
int
mvadd_wchstr(int y, int x, const cchar_t *wchstr)
{
#ifndef HAVE_WCHAR
return ERR;
#else
return mvwadd_wchnstr(stdscr, y, x, wchstr, -1);
#endif
}
/*
* 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)
{
#ifndef HAVE_WCHAR
return ERR;
#else
return mvwadd_wchnstr(win, y, x, wchstr, -1);
#endif
}
/*
* 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)
{
#ifndef HAVE_WCHAR
return ERR;
#else
return mvwadd_wchnstr(stdscr, y, x, wchstr, n);
#endif
}
/*
* 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)
{
#ifndef HAVE_WCHAR
return ERR;
#else
if (wmove(win, y, x) == ERR)
return ERR;
return wadd_wchnstr(win, wchstr, n);
#endif
}
/*
* 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)
{
#ifndef HAVE_WCHAR
return ERR;
#else
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 = (nschar_t *)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;
#endif /* HAVE_WCHAR */
}

586
lib/libcurses/addbytes.c Normal file
View file

@ -0,0 +1,586 @@
/* $NetBSD: addbytes.c,v 1.38 2010/12/16 17:42:28 wiz 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.
*/
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)addbytes.c 8.4 (Berkeley) 5/4/94";
#else
__RCSID("$NetBSD: addbytes.c,v 1.38 2010/12/16 17:42:28 wiz Exp $");
#endif
#endif /* not lint */
#include <stdlib.h>
#include <string.h>
#include "curses.h"
#include "curses_private.h"
#ifdef DEBUG
#include <assert.h>
#endif
#define SYNCH_IN {y = win->cury; x = win->curx;}
#define SYNCH_OUT {win->cury = y; win->curx = x;}
#define PSYNCH_IN {*y = win->cury; *x = win->curx;}
#define PSYNCH_OUT {win->cury = *y; win->curx = *x;}
#ifndef _CURSES_USE_MACROS
/*
* addbytes --
* Add the character to the current position in stdscr.
*/
int
addbytes(const char *bytes, int count)
{
return __waddbytes(stdscr, bytes, count, 0);
}
/*
* waddbytes --
* Add the character to the current position in the given window.
*/
int
waddbytes(WINDOW *win, const char *bytes, int count)
{
return __waddbytes(win, bytes, count, 0);
}
/*
* 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 __waddbytes(win, bytes, count, 0);
}
#endif
/*
* waddbytes --
* Add the character to the current position in the given window.
*/
int
__waddbytes(WINDOW *win, const char *bytes, int count, attr_t attr)
{
int x, y, 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;
SYNCH_IN;
lp = win->alines[y];
#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, y, x);
#endif
err = _cursesi_addbyte(win, &lp, &y, &x, c, attr);
count--;
#else
/*
* For wide-character support only, try and 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, y, x, n);
#endif
cc.vals[0] = wc;
cc.elements = 1;
cc.attributes = attr;
err = _cursesi_addwchar(win, &lp, &y, &x, &cc);
bytes += n;
count -= n;
#endif
}
SYNCH_OUT;
#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. 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)
{
static char blanks[] = " ";
int newx;
attr_t attributes;
switch (c) {
case '\t':
PSYNCH_OUT;
if (waddbytes(win, blanks, 8 - (*x % 8)) == ERR)
return (ERR);
PSYNCH_IN;
break;
default:
#ifdef DEBUG
__CTRACE(__CTRACE_INPUT, "ADDBYTES(%p, %d, %d)\n",
win, *y, *x);
#endif
if ((*lp)->flags & __ISPASTEOL) {
new_line:
*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;
PSYNCH_OUT;
scroll(win);
PSYNCH_IN;
} else {
(*y)++;
}
*lp = win->alines[*y];
if (c == '\n')
break;
}
attributes = (win->wattr | attr) &
(__ATTRIBUTES & ~__COLOR);
if (attr & __COLOR)
attributes |= attr & __COLOR;
else if (win->wattr & __COLOR)
attributes |= win->wattr & __COLOR;
#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
/*
* 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
break;
case '\n':
PSYNCH_OUT;
wclrtoeol(win);
PSYNCH_IN;
goto new_line;
case '\r':
*x = 0;
break;
case '\b':
if (--(*x) < 0)
*x = 0;
break;
}
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)
{
#ifndef HAVE_WCHAR
return (ERR);
#else
int sx = 0, ex = 0, cw = 0, i = 0, newx = 0;
__LDATA *lp = &win->alines[*y]->line[*x], *tp = NULL;
nschar_t *np = NULL;
cchar_t cc;
attr_t attributes;
/* special characters handling */
switch (wch->vals[0]) {
case L'\b':
if (--*x < 0)
*x = 0;
win->curx = *x;
return OK;
case L'\r':
*x = 0;
return OK;
case L'\n':
wclrtoeol(win);
PSYNCH_IN;
*x = 0;
(*lnp)->flags &= ~__ISPASTEOL;
if (*y == win->scr_b) {
if (!(win->flags & __SCROLLOK))
return ERR;
PSYNCH_OUT;
scroll(win);
PSYNCH_IN;
} else {
(*y)++;
}
PSYNCH_OUT;
return OK;
case L'\t':
cc.vals[0] = L' ';
cc.elements = 1;
cc.attributes = win->wattr;
for (i = 0; i < 8 - (*x % 8); 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 ((*lnp)->flags & __ISPASTEOL) {
*x = 0;
(*lnp)->flags &= ~__ISPASTEOL;
if (*y == win->scr_b) {
if (!(win->flags & __SCROLLOK))
return ERR;
PSYNCH_OUT;
scroll(win);
PSYNCH_IN;
} 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;
PSYNCH_OUT;
scroll(win);
PSYNCH_IN;
} else {
(*y)++;
}
lp = &win->alines[*y]->line[0];
(*lnp) = win->alines[*y];
}
win->cury = *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 = (nschar_t *)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);
#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) {
(*lnp)->flags |= __ISPASTEOL;
newx = win->maxx - 1 + win->ch_off;
if (newx > *(*lnp)->lastchp)
*(*lnp)->lastchp = newx;
__touchline(win, *y, sx, (int) win->maxx - 1);
win->curx = sx;
} else {
win->curx = *x;
/* clear the remining of the current characer */
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, "add_wch: %d : 0x%x\n", lp->ch, lp->attr);
#endif /* DEBUG */
return OK;
#endif
}

128
lib/libcurses/addch.c Normal file
View file

@ -0,0 +1,128 @@
/* $NetBSD: addch.c,v 1.16 2010/02/23 19:48:26 drochner 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 <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)addch.c 8.2 (Berkeley) 5/4/94";
#else
__RCSID("$NetBSD: addch.c,v 1.16 2010/02/23 19:48:26 drochner Exp $");
#endif
#endif /* not lint */
#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
/*
* waddch --
* Add the character to the current position in the given window.
*
*/
int
waddch(WINDOW *win, chtype ch)
{
#ifdef HAVE_WCHAR
cchar_t cc;
#else
__LDATA buf;
#endif
#ifdef HAVE_WCHAR
__cursesi_chtype_to_cchar(ch, &cc);
#else
buf.ch = (wchar_t) ch & __CHARTEXT;
buf.attr = (attr_t) ch & __ATTRIBUTES;
#endif
#ifdef DEBUG
#ifdef HAVE_WCHAR
__CTRACE(__CTRACE_INPUT,
"addch: %d : 0x%x (adding char as wide char)\n",
cc.vals[0], cc.attributes);
#else
__CTRACE(__CTRACE_INPUT, "addch: %d : 0x%x\n", buf.ch, buf.attr);
#endif
#endif
#ifdef HAVE_WCHAR
return (wadd_wch(win, &cc));
#else
return (__waddch(win, &buf));
#endif
}
int
__waddch(WINDOW *win, __LDATA *dp)
{
char buf[2];
buf[0] = dp->ch;
buf[1] = '\0';
return (__waddbytes(win, buf, 1, dp->attr));
}

175
lib/libcurses/addchnstr.c Normal file
View file

@ -0,0 +1,175 @@
/* $NetBSD: addchnstr.c,v 1.4 2008/04/28 20:23:01 martin 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 <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: addchnstr.c,v 1.4 2008/04/28 20:23:01 martin Exp $");
#endif /* not lint */
#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). If n is negative, add the
* entire string.
*/
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;
#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);
if ((ocp = malloc(len + 1)) == NULL)
return ERR;
chp = chstr;
cp = ocp;
start = ocp;
i = 0;
attr = (*chp) & __ATTRIBUTES;
while (len) {
*cp = (*chp) & __CHARTEXT;
cp++;
chp++;
i++;
len--;
if (((*chp) & __ATTRIBUTES) != attr) {
*cp = '\0';
if (__waddbytes(win, start, i, attr) == ERR) {
free(ocp);
return ERR;
}
attr = (*chp) & __ATTRIBUTES;
start = cp;
i = 0;
}
}
*cp = '\0';
ret = __waddbytes(win, start, i, attr);
free(ocp);
return ret;
}

155
lib/libcurses/addnstr.c Normal file
View file

@ -0,0 +1,155 @@
/* $NetBSD: addnstr.c,v 1.12 2007/05/28 15:01:54 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 <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)addnstr.c 8.2 (Berkeley) 5/4/94";
#else
__RCSID("$NetBSD: addnstr.c,v 1.12 2007/05/28 15:01:54 blymn Exp $");
#endif
#endif /* not lint */
#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));
}

201
lib/libcurses/addwstr.c Normal file
View file

@ -0,0 +1,201 @@
/* $NetBSD: addwstr.c,v 1.2 2007/05/28 15:01:54 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 <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: addwstr.c,v 1.2 2007/05/28 15:01:54 blymn Exp $");
#endif /* not lint */
#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)
{
#ifndef HAVE_WCHAR
return ERR;
#else
return waddnwstr(stdscr, s, -1);
#endif /* HAVE_WCHAR */
}
/*
* waddwstr --
* Add a string to the given window starting at (_cury, _curx).
*/
int
waddwstr(WINDOW *win, const wchar_t *s)
{
#ifndef HAVE_WCHAR
return ERR;
#else
return waddnwstr(win, s, -1);
#endif /* HAVE_WCHAR */
}
/*
* 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)
{
#ifndef HAVE_WCHAR
return ERR;
#else
return waddnwstr(stdscr, str, n);
#endif /* HAVE_WCHAR */
}
/*
* mvaddwstr --
* Add a string to stdscr starting at (y, x)
*/
int
mvaddwstr(int y, int x, const wchar_t *str)
{
#ifndef HAVE_WCHAR
return ERR;
#else
return mvwaddnwstr(stdscr, y, x, str, -1);
#endif /* HAVE_WCHAR */
}
/*
* mvwaddwstr --
* Add a string to the given window starting at (y, x)
*/
int
mvwaddwstr(WINDOW *win, int y, int x, const wchar_t *str)
{
#ifndef HAVE_WCHAR
return ERR;
#else
return mvwaddnwstr(win, y, x, str, -1);
#endif /* HAVE_WCHAR */
}
/*
* 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)
{
#ifndef HAVE_WCHAR
return ERR;
#else
return mvwaddnwstr(stdscr, y, x, str, count);
#endif /* HAVE_WCHAR */
}
/*
* 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)
{
#ifndef HAVE_WCHAR
return ERR;
#else
if (wmove(win, y, x) == ERR)
return ERR;
return waddnwstr(win, str, count);
#endif /* HAVE_WCHAR */
}
/*
* 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)
{
#ifndef HAVE_WCHAR
return ERR;
#else
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;
#endif /* HAVE_WCHAR */
}

449
lib/libcurses/attributes.c Normal file
View file

@ -0,0 +1,449 @@
/* $NetBSD: attributes.c,v 1.21 2010/12/25 10:08:20 blymn 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 <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: attributes.c,v 1.21 2010/12/25 10:08:20 blymn Exp $");
#endif /* not lint */
#include "curses.h"
#include "curses_private.h"
void __wcolor_set(WINDOW *, attr_t);
#ifndef _CURSES_USE_MACROS
/*
* attr_get --
* Get wide attributes and color pair from stdscr
*/
/* ARGSUSED */
int
attr_get(attr_t *attr, short *pair, void *opt)
{
return wattr_get(stdscr, attr, pair, opt);
}
/*
* attr_on --
* Test and set wide attributes on stdscr
*/
/* ARGSUSED */
int
attr_on(attr_t attr, void *opt)
{
return wattr_on(stdscr, attr, opt);
}
/*
* attr_off --
* Test and unset wide attributes on stdscr
*/
/* ARGSUSED */
int
attr_off(attr_t attr, void *opt)
{
return wattr_off(stdscr, attr, opt);
}
/*
* attr_set --
* Set wide attributes and color pair on stdscr
*/
/* ARGSUSED */
int
attr_set(attr_t attr, short pair, void *opt)
{
return wattr_set(stdscr, attr, pair, opt);
}
/*
* color_set --
* Set color pair on stdscr
*/
/* ARGSUSED */
int
color_set(short pair, void *opt)
{
return wcolor_set(stdscr, pair, opt);
}
/*
* attron --
* Test and set attributes on stdscr
*/
int
attron(int attr)
{
return wattr_on(stdscr, (attr_t) attr, NULL);
}
/*
* attroff --
* Test and unset attributes on stdscr.
*/
int
attroff(int attr)
{
return wattr_off(stdscr, (attr_t) attr, NULL);
}
/*
* attrset --
* Set specific attribute modes.
* Unset others. On stdscr.
*/
int
attrset(int attr)
{
return wattrset(stdscr, attr);
}
#endif /* _CURSES_USE_MACROS */
/*
* 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 *opt)
{
#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
*/
/* ARGSUSED */
int
wattr_on(WINDOW *win, attr_t attr, void *opt)
{
#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 (exit_attribute_mode != NULL) {
if (attr & __BLINK && enter_blink_mode != NULL)
win->wattr |= __BLINK;
if (attr & __BOLD && enter_bold_mode != NULL)
win->wattr |= __BOLD;
if (attr & __DIM && enter_dim_mode != NULL)
win->wattr |= __DIM;
if (attr & __BLANK && enter_secure_mode != NULL)
win->wattr |= __BLANK;
if (attr & __PROTECT && enter_protected_mode != NULL)
win->wattr |= __PROTECT;
if (attr & __REVERSE && enter_reverse_mode != NULL)
win->wattr |= __REVERSE;
#ifdef HAVE_WCHAR
if (attr & WA_LOW && enter_low_hl_mode != NULL)
win->wattr |= WA_LOW;
if (attr & WA_TOP && enter_top_hl_mode != NULL)
win->wattr |= WA_TOP;
if (attr & WA_LEFT && enter_left_hl_mode != NULL)
win->wattr |= WA_LEFT;
if (attr & WA_RIGHT && enter_right_hl_mode != NULL)
win->wattr |= WA_RIGHT;
if (attr & WA_HORIZONTAL && enter_horizontal_hl_mode != NULL)
win->wattr |= WA_HORIZONTAL;
if (attr & WA_VERTICAL && enter_vertical_hl_mode != NULL)
win->wattr |= WA_VERTICAL;
#endif /* HAVE_WCHAR */
}
if (attr & __STANDOUT && enter_standout_mode != NULL && exit_standout_mode != NULL)
wstandout(win);
if (attr & __UNDERSCORE && enter_underline_mode != NULL && exit_underline_mode != NULL)
wunderscore(win);
if ((attr_t) attr & __COLOR)
__wcolor_set(win, (attr_t) attr);
return OK;
}
/*
* 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().
*/
/* ARGSUSED */
int
wattr_off(WINDOW *win, attr_t attr, void *opt)
{
#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 (exit_attribute_mode != 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_t) attr & __COLOR) {
if (max_colors != 0)
win->wattr &= ~__COLOR;
}
return OK;
}
/*
* wattr_set --
* Set wide attributes and color pair on window
*/
int
wattr_set(WINDOW *win, attr_t attr, short pair, void *opt)
{
#ifdef DEBUG
__CTRACE(__CTRACE_ATTR, "wattr_set: win %p, attr %08x, pair %d\n",
win, attr, pair);
#endif
wattr_off(win, __ATTRIBUTES, opt);
/*
* This overwrites any colour setting from the attributes
* and is compatible with ncurses.
*/
attr = (attr & ~__COLOR) | COLOR_PAIR(pair);
wattr_on(win, attr, opt);
return OK;
}
/*
* 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, NULL);
}
/*
* 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, NULL);
}
/*
* 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, NULL);
wattr_on(win, (attr_t) attr, NULL);
return OK;
}
/*
* wcolor_set --
* Set color pair on window
*/
/* ARGSUSED */
int
wcolor_set(WINDOW *win, short pair, void *opt)
{
#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;
}
/*
* getattrs --
* Get window attributes.
*/
chtype
getattrs(WINDOW *win)
{
#ifdef DEBUG
__CTRACE(__CTRACE_ATTR, "getattrs: win %p\n", win);
#endif
return((chtype) win->wattr);
}
/*
* 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;
}
/*
* 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;
}
/*
* __wcolor_set --
* Set color attribute on window
*/
void
__wcolor_set(WINDOW *win, attr_t attr)
{
/* If another color pair is set, turn that off first. */
win->wattr &= ~__COLOR;
/* If can do color video, set the color pair bits. */
if (max_colors != 0 && attr & __COLOR)
win->wattr |= attr & __COLOR;
}

285
lib/libcurses/background.c Normal file
View file

@ -0,0 +1,285 @@
/* $NetBSD: background.c,v 1.15 2009/07/22 16:57:14 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 <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: background.c,v 1.15 2009/07/22 16:57:14 roy Exp $");
#endif /* not lint */
#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 and new background attributes on stdscr.
*/
int
bkgd(chtype ch)
{
return(wbkgd(stdscr, ch));
}
/*
* wbkgdset
* Set new background attributes.
*/
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 and new background attributes.
*/
int
wbkgd(WINDOW *win, chtype ch)
{
int y, x;
#ifdef DEBUG
__CTRACE(__CTRACE_ATTR, "wbkgd: (%p), '%s', %08x\n",
win, unctrl(ch & +__CHARTEXT), ch & __ATTRIBUTES);
#endif
/* Background attributes (check colour). */
if (__using_color && !(ch & __COLOR))
ch |= __default_color;
win->battr = (attr_t) ch & __ATTRIBUTES;
wbkgdset(win, ch);
for (y = 0; y < win->maxy; y++)
for (x = 0; x < win->maxx; x++) {
/* Copy character if space */
if (ch & A_CHARTEXT && win->alines[y]->line[x].ch == ' ')
win->alines[y]->line[x].ch = ch & __CHARTEXT;
/* Merge attributes */
if (win->alines[y]->line[x].attr & __ALTCHARSET)
win->alines[y]->line[x].attr =
(ch & __ATTRIBUTES) | __ALTCHARSET;
else
win->alines[y]->line[x].attr =
ch & __ATTRIBUTES;
#ifdef HAVE_WCHAR
SET_WCOL(win->alines[y]->line[x], 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 &= ~__default_color;
return ((chtype) ((win->bch & A_CHARTEXT) | battr));
}
int bkgrnd(const cchar_t *wch)
{
#ifndef HAVE_WCHAR
return ERR;
#else
return wbkgrnd( stdscr, wch );
#endif /* HAVE_WCHAR */
}
void bkgrndset(const cchar_t *wch)
{
#ifdef HAVE_WCHAR
wbkgrndset( stdscr, wch );
#endif /* HAVE_WCHAR */
}
int getbkgrnd(cchar_t *wch)
{
#ifndef HAVE_WCHAR
return ERR;
#else
return wgetbkgrnd( stdscr, wch );
#endif /* HAVE_WCHAR */
}
int wbkgrnd(WINDOW *win, const cchar_t *wch)
{
#ifndef HAVE_WCHAR
return ERR;
#else
/* int y, x, i; */
attr_t battr;
/* nschar_t *np, *tnp, *pnp; */
#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;
/* Background attributes (check colour). */
battr = wch->attributes & WA_ATTRIBUTES;
if (__using_color && !( battr & __COLOR))
battr |= __default_color;
win->battr = battr;
wbkgrndset(win, wch);
__touchwin(win);
return OK;
#endif /* HAVE_WCHAR */
}
void wbkgrndset(WINDOW *win, const cchar_t *wch)
{
#ifdef HAVE_WCHAR
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 = (nschar_t *)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 = (nschar_t *)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);
#endif /* HAVE_WCHAR */
}
int wgetbkgrnd(WINDOW *win, cchar_t *wch)
{
#ifndef HAVE_WCHAR
return ERR;
#else
nschar_t *np;
/* Background attributes (check colour). */
wch->attributes = win->battr & WA_ATTRIBUTES;
if (__using_color && (( wch->attributes & __COLOR )
== __default_color))
wch->attributes &= ~__default_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;
#endif /* HAVE_WCHAR */
}

View file

@ -1,13 +0,0 @@
#include <curses.h>
#include <termcap.h>
extern char *bl, *vb;
/* Beep() sounds the terminal bell. */
void beep()
{
if (bl)
tputs(bl, 1, outc);
else if (vb)
tputs(vb, 1, outc);
}

80
lib/libcurses/bell.c Normal file
View file

@ -0,0 +1,80 @@
/* $NetBSD: bell.c,v 1.8 2010/02/03 15:34:40 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 <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: bell.c,v 1.8 2010/02/03 15:34:40 roy Exp $");
#endif /* not lint */
#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 (1);
}
/*
* 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 (1);
}

606
lib/libcurses/border.c Normal file
View file

@ -0,0 +1,606 @@
/* $NetBSD: border.c,v 1.14 2010/12/25 09:59:52 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.
*/
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: border.c,v 1.14 2010/12/25 09:59:52 blymn Exp $");
#endif /* not lint */
#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->maxx == LINES && win->maxy == 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;
right.attributes |= (right.attributes & __COLOR) ?
(win->wattr & ~__COLOR) : win->wattr;
top.attributes |= (top.attributes & __COLOR) ?
(win->wattr & ~__COLOR) : win->wattr;
bottom.attributes |= (bottom.attributes & __COLOR) ?
(win->wattr & ~__COLOR) : win->wattr;
topleft.attributes |= (topleft.attributes & __COLOR) ?
(win->wattr & ~__COLOR) : win->wattr;
topright.attributes |= (topright.attributes & __COLOR) ?
(win->wattr & ~__COLOR) : win->wattr;
botleft.attributes |= (botleft.attributes & __COLOR) ?
(win->wattr & ~__COLOR) : win->wattr;
botright.attributes |= (botright.attributes & __COLOR) ?
(win->wattr & ~__COLOR) : win->wattr;
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 = (nschar_t *)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 = (nschar_t *)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 = (nschar_t *)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++ ) {
if ( !( np = ( nschar_t *)malloc( sizeof( nschar_t ))))
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->maxx == LINES && win->maxy == 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 = (nschar_t *)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 = (nschar_t *)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 = (nschar_t *)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 = (nschar_t *)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 */
}

62
lib/libcurses/box.c Normal file
View file

@ -0,0 +1,62 @@
/* $NetBSD: box.c,v 1.14 2007/05/28 15:01:54 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 <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)box.c 8.2 (Berkeley) 5/4/94";
#else
__RCSID("$NetBSD: box.c,v 1.14 2007/05/28 15:01:54 blymn Exp $");
#endif
#endif /* not lint */
#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 */
}

138
lib/libcurses/cchar.c Normal file
View file

@ -0,0 +1,138 @@
/* $NetBSD: cchar.c,v 1.5 2010/12/16 17:42:28 wiz 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 <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: cchar.c,v 1.5 2010/12/16 17:42:28 wiz Exp $");
#endif /* not lint */
#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)
{
#ifndef HAVE_WCHAR
return ERR;
#else
wchar_t *wp;
size_t len;
if ( opts )
return ERR;
len = (wp = wmemchr(wcval->vals, L'\0', CCHARW_MAX))
? wp - wcval->vals : CCHARW_MAX;
if (wch == NULL)
return (int) len;
if (attrs == 0 || color_pair == 0)
return ERR;
if (len > 0) {
*attrs = wcval->attributes;
*color_pair = COLOR_PAIR( wcval -> attributes );
wmemcpy(wch, wcval->vals, (unsigned) len);
wch[len] = L'\0';
}
return OK;
#endif /* HAVE_WCHAR */
}
/*
* 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)
{
#ifndef HAVE_WCHAR
return ERR;
#else
int i;
size_t len;
if (opts || (len = wcslen(wch)) > 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_pair;
wcval -> elements = 1;
memcpy(&wcval->vals, wch, len * sizeof(wchar_t));
}
return OK;
#endif /* HAVE_WCHAR */
}
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;
}

View file

@ -1,39 +0,0 @@
#include <curses.h>
/****************************************************************/
/* Winch(win) returns the character at the current position in */
/* Window 'win'. */
/****************************************************************/
int winch(win)
WINDOW *win;
{
return((win->_line[win->_cury][win->_curx]) & 0xff);
} /* winch */
/****************************************************************/
/* Mvinch() moves the stdscr cursor to a new position, then */
/* Returns the character at that position. */
/****************************************************************/
int mvinch(y, x)
int y;
int x;
{
if (wmove(stdscr, y, x) == ERR) return(ERR);
return((stdscr->_line[stdscr->_cury][stdscr->_curx]) & 0xff);
}
/****************************************************************/
/* Mvwinch() moves the cursor of window 'win' to a new posi- */
/* Tion, then returns the character at that position. */
/****************************************************************/
int mvwinch(win, y, x)
WINDOW *win;
int y;
int x;
{
if (wmove(win, y, x) == ERR) return(ERR);
return((win->_line[win->_cury][win->_curx]) & 0xff);
}

93
lib/libcurses/chgat.c Normal file
View file

@ -0,0 +1,93 @@
/* $NetBSD: chgat.c,v 1.4 2009/07/22 16:57:14 roy 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 <sys/cdefs.h>
__RCSID("$NetBSD: chgat.c,v 1.4 2009/07/22 16:57:14 roy Exp $");
#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;
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;
}

70
lib/libcurses/clear.c Normal file
View file

@ -0,0 +1,70 @@
/* $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 <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)clear.c 8.2 (Berkeley) 5/4/94";
#else
__RCSID("$NetBSD: clear.c,v 1.13 2003/08/07 16:44:19 agc Exp $");
#endif
#endif /* not lint */
#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);
}

52
lib/libcurses/clearok.c Normal file
View file

@ -0,0 +1,52 @@
/* $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 <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: clearok.c,v 1.5 2008/04/28 20:23:01 martin Exp $");
#endif /* not lint */
#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);
}

115
lib/libcurses/clrtobot.c Normal file
View file

@ -0,0 +1,115 @@
/* $NetBSD: clrtobot.c,v 1.21 2009/07/22 16:57:14 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 <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)clrtobot.c 8.2 (Berkeley) 5/4/94";
#else
__RCSID("$NetBSD: clrtobot.c,v 1.21 2009/07/22 16:57:14 roy Exp $");
#endif
#endif /* not lint */
#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;
attr_t attr;
#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;
}
if (__using_color && win != curscr)
attr = win->battr & __COLOR;
else
attr = 0;
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++) {
#ifndef HAVE_WCHAR
if (sp->ch != win->bch || sp->attr != attr) {
#else
if (sp->ch != (wchar_t)btowc((int) win->bch) ||
(sp->attr & WA_ATTRIBUTES) != 0 || sp->nsp) {
#endif /* HAVE_WCHAR */
maxx = sp;
if (minx == -1)
minx = (int)(sp - win->alines[y]->line);
sp->attr = attr;
#ifdef HAVE_WCHAR
sp->ch = ( wchar_t )btowc(( int ) win->bch);
if (_cursesi_copy_nsp(win->bnsp, sp) == ERR)
return ERR;
SET_WCOL( *sp, 1 );
#else
sp->ch = win->bch;
#endif /* HAVE_WCHAR */
}
}
if (minx != -1)
__touchline(win, y, minx,
(int) (maxx - win->alines[y]->line));
startx = 0;
}
return (OK);
}

118
lib/libcurses/clrtoeol.c Normal file
View file

@ -0,0 +1,118 @@
/* $NetBSD: clrtoeol.c,v 1.25 2009/07/22 16:57:14 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 <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)clrtoeol.c 8.2 (Berkeley) 5/4/94";
#else
__RCSID("$NetBSD: clrtoeol.c,v 1.25 2009/07/22 16:57:14 roy Exp $");
#endif
#endif /* not lint */
#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;
attr_t attr;
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];
if (__using_color && win != curscr)
attr = win->battr & __COLOR;
else
attr = 0;
for (sp = maxx; sp < end; sp++)
#ifndef HAVE_WCHAR
if (sp->ch != win->bch || sp->attr != attr) {
#else
if (sp->ch != ( wchar_t )btowc(( int ) win->bch ) ||
(sp->attr & WA_ATTRIBUTES) != attr || sp->nsp
|| (WCOL(*sp) < 0)) {
#endif /* HAVE_WCHAR */
maxx = sp;
if (minx == -1)
minx = (int) (sp - win->alines[y]->line);
sp->attr = attr;
#ifdef HAVE_WCHAR
sp->ch = ( wchar_t )btowc(( int ) win->bch);
if (_cursesi_copy_nsp(win->bnsp, sp) == ERR)
return ERR;
SET_WCOL( *sp, 1 );
#else
sp->ch = win->bch;
#endif /* HAVE_WCHAR */
}
#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. */
return (__touchline(win, y, x, (int) win->maxx - 1));
}

687
lib/libcurses/color.c Normal file
View file

@ -0,0 +1,687 @@
/* $NetBSD: color.c,v 1.37 2011/01/06 11:29:40 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.
*/
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: color.c,v 1.37 2011/01/06 11:29:40 blymn Exp $");
#endif /* not lint */
#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);
/*
* 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)
{
if (can_change)
return(TRUE);
else
return(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 */
if (COLORS >= COLOR_BLACK)
(void) init_color(COLOR_BLACK, 0, 0, 0);
if (COLORS >= COLOR_RED)
(void) init_color(COLOR_RED, 1000, 0, 0);
if (COLORS >= COLOR_GREEN)
(void) init_color(COLOR_GREEN, 0, 1000, 0);
if (COLORS >= COLOR_YELLOW)
(void) init_color(COLOR_YELLOW, 1000, 1000, 0);
if (COLORS >= COLOR_BLUE)
(void) init_color(COLOR_BLUE, 0, 0, 1000);
if (COLORS >= COLOR_MAGENTA)
(void) init_color(COLOR_MAGENTA, 1000, 0, 1000);
if (COLORS >= COLOR_CYAN)
(void) init_color(COLOR_CYAN, 0, 1000, 1000);
if (COLORS >= COLOR_WHITE)
(void) init_color(COLOR_WHITE, 1000, 1000, 1000);
/* 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 --
* Set colour red, green and blue values.
*/
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 (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;
/* XXX Not yet implemented */
return(ERR);
/* XXX: need to initialise Tek style (Ic) and support HLS */
}
/*
* 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((u_int32_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(vtparm(t_set_a_foreground(_cursesi_screen->term),
_cursesi_screen->colour_pairs[pair].fore),
0, __cputchar);
if (_cursesi_screen->colour_pairs[pair].back >= 0)
tputs(vtparm(t_set_a_background(_cursesi_screen->term),
_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(vtparm(t_set_foreground(_cursesi_screen->term),
_cursesi_screen->colour_pairs[pair].fore),
0, __cputchar);
if (_cursesi_screen->colour_pairs[pair].back >= 0)
tputs(vtparm(t_set_background(_cursesi_screen->term),
_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
}
}
}
}

135
lib/libcurses/copywin.c Normal file
View file

@ -0,0 +1,135 @@
/* $NetBSD: copywin.c,v 1.15 2009/07/22 16:57:14 roy 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 <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: copywin.c,v 1.15 2009/07/22 16:57:14 roy Exp $");
#endif /* not lint */
#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 */
/* 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;
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);
#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;
}

480
lib/libcurses/cr_put.c Normal file
View file

@ -0,0 +1,480 @@
/* $NetBSD: cr_put.c,v 1.30 2010/02/12 10:06:15 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 <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)cr_put.c 8.3 (Berkeley) 5/4/94";
#else
__RCSID("$NetBSD: cr_put.c,v 1.30 2010/02/12 10:06:15 roy Exp $");
#endif
#endif /* not lint */
#include <string.h>
#include "curses.h"
#include "curses_private.h"
#define HARDTABS 8
/*
* Terminal driving and line formatting routines. Basic motion optimizations
* are done here as well as formatting lines (printing of control characters,
* line numbering and the like).
*/
/* Stub function for the users. */
int
mvcur(int ly, int lx, int y, int x)
{
return (__mvcur(ly, lx, y, x, 0));
}
static void fgoto __P((int));
static int plod __P((int, int));
static int plodput __P((int));
static int tabcol __P((int, int));
static int outcol, outline, destcol, destline;
/*
* Sync the position of the output cursor. Most work here is rounding for
* terminal boundaries getting the column position implied by wraparound or
* the lack thereof and rolling up the screen to get destline on the screen.
*/
int
__mvcur(int ly, int lx, int y, int x, int in_refresh)
{
#ifdef DEBUG
__CTRACE(__CTRACE_OUTPUT,
"mvcur: moving cursor from (%d, %d) to (%d, %d)\n", ly, lx, y, x);
#endif
destcol = x;
destline = y;
outcol = lx;
outline = ly;
fgoto(in_refresh);
return (OK);
}
static void
fgoto(in_refresh)
int in_refresh;
{
int c, l;
char *cgp;
#ifdef DEBUG
__CTRACE(__CTRACE_OUTPUT, "fgoto: in_refresh=%d\n", in_refresh);
#endif /* DEBUG */
if (destcol >= COLS) {
destline += destcol / COLS;
destcol %= COLS;
}
if (outcol >= COLS) {
l = (outcol + 1) / COLS;
outline += l;
outcol %= COLS;
if (auto_left_margin == 0) {
while (l > 0) {
if (__pfast) {
if (carriage_return)
tputs(carriage_return,
0, __cputchar);
else
__cputchar('\r');
}
if (cursor_down)
tputs(cursor_down, 0, __cputchar);
else
__cputchar('\n');
l--;
}
outcol = 0;
}
if (outline > LINES - 1) {
destline -= outline - (LINES - 1);
outline = LINES - 1;
}
}
if (destline >= LINES) {
l = destline;
destline = LINES - 1;
if (outline < LINES - 1) {
c = destcol;
if (__pfast == 0 && !cursor_address)
destcol = 0;
fgoto(in_refresh);
destcol = c;
}
while (l >= LINES) {
/* The following linefeed (or simulation thereof) is
* supposed to scroll up the screen, since we are on
* the bottom line. We make the assumption that
* linefeed will scroll. If ns is in the capability
* list this won't work. We should probably have an
* sc capability but sf will generally take the place
* if it works.
*
* Superbee glitch: in the middle of the screen have to
* use esc B (down) because linefeed screws up in
* "Efficient Paging" (what a joke) mode (which is
* essential in some SB's because CRLF mode puts
* garbage in at end of memory), but you must use
* linefeed to scroll since down arrow won't go past
* memory end. I turned this off after recieving Paul
* Eggert's Superbee description which wins better. */
if (cursor_down /* && !__tc_xb */ && __pfast)
tputs(cursor_down, 0, __cputchar);
else
__cputchar('\n');
l--;
if (__pfast == 0)
outcol = 0;
}
}
if (destline < outline && !(cursor_address || cursor_up))
destline = outline;
if (cursor_address &&
(cgp = t_vparm(NULL, cursor_address, destline, destcol)))
{
/*
* Need this condition due to inconsistent behavior
* of backspace on the last column.
*/
#ifdef DEBUG
__CTRACE(__CTRACE_OUTPUT, "fgoto: cgp=%s\n", cgp);
#endif /* DEBUG */
if (outcol != COLS - 1 &&
plod((int) strlen(cgp), in_refresh) > 0)
plod(0, in_refresh);
else
tputs(cgp, 0, __cputchar);
} else
plod(0, in_refresh);
outline = destline;
outcol = destcol;
}
/*
* Move (slowly) to destination.
* Hard thing here is using home cursor on really deficient terminals.
* Otherwise just use cursor motions, hacking use of tabs and overtabbing
* and backspace.
*
* XXX this needs to be revisited for wide characters since we may output
* XXX more than one byte for a character.
*/
static int plodcnt, plodflg;
static int
plodput(c)
int c;
{
if (plodflg)
--plodcnt;
else
__cputchar(c);
return (0);
}
static int
plod(cnt, in_refresh)
int cnt, in_refresh;
{
int i, j, k, soutcol, soutline;
#ifdef DEBUG
__CTRACE(__CTRACE_OUTPUT, "plod: cnt=%d, in_refresh=%d\n",
cnt, in_refresh);
#endif /* DEBUG */
plodcnt = plodflg = cnt;
soutcol = outcol;
soutline = outline;
/*
* Consider homing and moving down/right from there, vs. moving
* directly with local motions to the right spot.
*/
if (cursor_home) {
/*
* i is the cost to home and tab/space to the right to get to
* the proper column. This assumes nd space costs 1 char. So
* i + destcol is cost of motion with home.
*/
if (__GT)
i = (destcol / HARDTABS) + (destcol % HARDTABS);
else
i = destcol;
/* j is cost to move locally without homing. */
if (destcol >= outcol) { /* if motion is to the right */
j = destcol / HARDTABS - outcol / HARDTABS;
if (__GT && j)
j += destcol % HARDTABS;
else
j = destcol - outcol;
} else
/* leftward motion only works if we can backspace. */
if (outcol - destcol <= i)
/* Cheaper to backspace. */
i = j = outcol - destcol;
else
/* Impossibly expensive. */
j = i + 1;
/* k is the absolute value of vertical distance. */
k = outline - destline;
if (k < 0)
k = -k;
j += k;
/* Decision. We may not have a choice if no up. */
if (i + destline < j || (!cursor_up && destline < outline)) {
/*
* Cheaper to home. Do it now and pretend it's a
* regular local motion.
*/
tputs(cursor_home, 0, plodput);
outcol = outline = 0;
} else
if (cursor_to_ll) {
/*
* Quickly consider homing down and moving from
* there. Assume cost of ll is 2.
*/
k = (LINES - 1) - destline;
if (i + k + 2 < j && (k <= 0 || cursor_up)) {
tputs(cursor_to_ll, 0, plodput);
outcol = 0;
outline = LINES - 1;
}
}
} else
/* No home and no up means it's impossible. */
if (!cursor_up && destline < outline)
return (-1);
if (__GT)
i = destcol % HARDTABS + destcol / HARDTABS;
else
i = destcol;
#ifdef notdef
if (back_tab && outcol > destcol &&
(j = (((outcol + 7) & ~7) - destcol - 1) >> 3)) {
j *= (k = strlen(back_tab));
if ((k += (destcol & 7)) > 4)
j += 8 - (destcol & 7);
else
j += k;
} else
#endif
j = outcol - destcol;
/*
* If we will later need a \n which will turn into a \r\n by the
* system or the terminal, then don't bother to try to \r.
*/
if ((__NONL || !__pfast) && outline < destline)
goto dontcr;
/*
* If the terminal will do a \r\n and there isn't room for it, then
* we can't afford a \r.
*/
if (!carriage_return && outline >= destline)
goto dontcr;
/*
* If it will be cheaper, or if we can't back up, then send a return
* preliminarily.
*/
if (j > i + 1 || outcol > destcol) {
/*
* BUG: this doesn't take the (possibly long) length of cr
* into account.
*/
if (carriage_return)
tputs(carriage_return, 0, plodput);
else
plodput('\r');
if (!carriage_return) {
if (cursor_down)
tputs(cursor_down, 0, plodput);
else
plodput('\n');
outline++;
}
outcol = 0;
}
dontcr:while (outline < destline) {
outline++;
if (cursor_down)
tputs(cursor_down, 0, plodput);
else
plodput('\n');
if (plodcnt < 0)
goto out;
if (__NONL || __pfast == 0)
outcol = 0;
}
if (back_tab)
k = (int) strlen(back_tab);
while (outcol > destcol) {
if (plodcnt < 0)
goto out;
#ifdef notdef
if (back_tab && outcol - destcol > k + 4) {
tputs(back_tab, 0, plodput);
outcol--;
outcol &= ~7;
continue;
}
#endif
outcol--;
if (cursor_left)
tputs(cursor_left, 0, plodput);
else
plodput('\b');
}
while (outline > destline) {
outline--;
tputs(cursor_up, 0, plodput);
if (plodcnt < 0)
goto out;
}
if (__GT && destcol - outcol > 1) {
for (;;) {
i = tabcol(outcol, HARDTABS);
if (i > destcol)
break;
if (tab)
tputs(tab, 0, plodput);
else
plodput('\t');
outcol = i;
}
if (destcol - outcol > 4 && i < COLS) {
if (tab)
tputs(tab, 0, plodput);
else
plodput('\t');
outcol = i;
while (outcol > destcol) {
outcol--;
if (cursor_left)
tputs(cursor_left, 0, plodput);
else
plodput('\b');
}
}
}
while (outcol < destcol) {
/*
* Move one char to the right. We don't use nd space because
* it's better to just print the char we are moving over.
*/
if (in_refresh)
if (plodflg) /* Avoid a complex calculation. */
plodcnt--;
else {
#ifndef HAVE_WCHAR
i = curscr->alines[outline]->line[outcol].ch
& __CHARTEXT;
if (curscr->alines[outline]->line[outcol].attr
== curscr->wattr)
__cputchar(i);
#else
if ((curscr->alines[outline]->line[outcol].attr
& WA_ATTRIBUTES)
== curscr->wattr) {
switch (WCOL(curscr->alines[outline]->line[outcol])) {
case 1:
__cputwchar(curscr->alines[outline]->line[outcol].ch);
__cursesi_putnsp(curscr->alines[outline]->line[outcol].nsp,
outline,
outcol);
#ifdef DEBUG
__CTRACE(__CTRACE_OUTPUT,
"plod: (%d,%d)WCOL(%d), "
"putwchar(%x)\n",
outline, outcol,
WCOL(curscr->alines[outline]->line[outcol]),
curscr->alines[outline]->line[outcol].ch);
#endif /* DEBUG */
/*FALLTHROUGH*/
case 0:
break;
default:
goto nondes;
}
}
#endif /* HAVE_WCHAR */
else
goto nondes;
}
else
nondes: if (cursor_right)
tputs(cursor_right, 0, plodput);
else
plodput(' ');
outcol++;
if (plodcnt < 0)
goto out;
}
out: if (plodflg) {
outcol = soutcol;
outline = soutline;
}
#ifdef DEBUG
__CTRACE(__CTRACE_OUTPUT, "plod: returns %d\n", plodcnt);
#endif /* DEBUG */
return (plodcnt);
}
/*
* Return the column number that results from being in column col and
* hitting a tab, where tabs are set every ts columns. Work right for
* the case where col > COLS, even if ts does not divide COLS.
*/
static int
tabcol(col, ts)
int col, ts;
{
int offset;
if (col >= COLS) {
offset = COLS * (col / COLS);
col -= offset;
} else
offset = 0;
return (col + ts - (col % ts) + offset);
}

120
lib/libcurses/ctrace.c Normal file
View file

@ -0,0 +1,120 @@
/* $NetBSD: ctrace.c,v 1.20 2009/01/17 15:25:36 christos 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/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)ctrace.c 8.2 (Berkeley) 10/5/93";
#else
__RCSID("$NetBSD: ctrace.c,v 1.20 2009/01/17 15:25:36 christos Exp $");
#endif
#endif /* not lint */
#ifdef DEBUG
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <string.h>
#include "curses.h"
#include "curses_private.h"
static FILE *tracefp = NULL; /* Curses debugging file descriptor. */
static int tracemask; /* Areas of trace output we want. */
static int init_done = 0;
void
__CTRACE_init()
{
char *tf, *tm;
tm = getenv("CURSES_TRACE_MASK");
if (tm == NULL)
tracemask = __CTRACE_ALL;
else {
tracemask = (int) strtol(tm, NULL, 0);
}
if (tracemask < 0)
tracemask = (0 - tracemask) ^ __CTRACE_ALL;
if (tracemask == 0)
return;
tf = getenv("CURSES_TRACE_FILE");
if ((tf != NULL) && !strcmp( tf, "<none>"))
tf = NULL;
if (tf != NULL)
tracefp = fopen(tf, "w");
init_done = 1;
__CTRACE(__CTRACE_ALL, "Trace mask: 0x%08x\n", tracemask);
}
void
__CTRACE(int area, const char *fmt,...)
{
struct timeval tv;
static int seencr = 1;
va_list ap;
if (!init_done)
__CTRACE_init();
if (tracefp == NULL || !(tracemask & area)) {
return;
}
gettimeofday(&tv, NULL);
if (seencr && (tracemask & __CTRACE_TSTAMP)) {
gettimeofday(&tv, NULL);
(void) fprintf(tracefp, "%llu.%06lu: ",
(long long)tv.tv_sec, (long)tv.tv_usec);
}
va_start(ap, fmt);
(void) vfprintf(tracefp, fmt, ap);
seencr = (strchr(fmt, '\n') != NULL);
va_end(ap);
(void) fflush(tracefp);
}
#else
/* this kills the empty translation unit message from lint... */
void
__cursesi_make_lint_shut_up_if_debug_not_defined(void);
void
__cursesi_make_lint_shut_up_if_debug_not_defined(void)
{
return;
}
#endif

65
lib/libcurses/cur_hash.c Normal file
View file

@ -0,0 +1,65 @@
/* $NetBSD: cur_hash.c,v 1.12 2005/02/18 22:16:27 dsl 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/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)cur_hash.c 8.1 (Berkeley) 6/4/93";
#else
__RCSID("$NetBSD: cur_hash.c,v 1.12 2005/02/18 22:16:27 dsl Exp $");
#endif
#endif /* not lint */
#include <sys/types.h>
#include "curses.h"
#include "curses_private.h"
/*
* __hash_more() is "hashpjw" from the Dragon Book, Aho, Sethi & Ullman, p.436.
*/
u_int
__hash_more(const void *v_s, size_t len, u_int h)
{
u_int g;
size_t i = 0;
const char *s = v_s;
while (i < len) {
h = (h << 4) + s[i];
if ((g = h & 0xf0000000) != 0) {
h = h ^ (g >> 24);
h = h ^ g;
}
i++;
}
return h;
}

View file

@ -1,25 +1,105 @@
#include <curses.h>
#include <termcap.h>
/* $NetBSD: curs_set.c,v 1.9 2010/02/03 15:34:40 roy Exp $ */
extern char *vi, *ve, *vs;
/*-
* Copyright (c) 1998-2000 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.
*
*
*/
/* Sets cursor visibility to unvisible=0; normal visible=1 or very good
* visible=2.
*/
void curs_set(visibility)
int visibility;
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: curs_set.c,v 1.9 2010/02/03 15:34:40 roy Exp $");
#endif /* not lint */
#include "curses.h"
#include "curses_private.h"
/*
* curs_set --
* Set the visibility of the cursor, 0 means invisible, 1 means normal
* visibility and 2 means high visibility. Return the previous
* visibility iff the terminal supports the new visibility otherwise
* return ERR.
*/
int
curs_set(int visibility)
{
switch (visibility) {
case 0:
if (vi) tputs(vi, 1, outc);
break;
case 1:
if (ve) tputs(ve, 1, outc);
break;
case 2:
if (vs)
tputs(vs, 1, outc);
else if (ve)
tputs(ve, 1, outc);
}
int old_one;
old_one = _cursesi_screen->old_mode;
switch (visibility) {
case 0: /* invisible */
if (cursor_invisible != NULL) {
#ifdef DEBUG
__CTRACE(__CTRACE_MISC,
"curs_set: invisible\n");
#endif
_cursesi_screen->old_mode = 0;
tputs(cursor_invisible, 0, __cputchar);
return old_one;
}
break;
case 1: /* normal */
if (cursor_normal != NULL) {
#ifdef DEBUG
__CTRACE(__CTRACE_MISC, "curs_set: normal\n");
#endif
_cursesi_screen->old_mode = 1;
tputs(cursor_normal, 0, __cputchar);
return old_one;
}
break;
case 2: /* high visibility */
if (cursor_visible != NULL) {
#ifdef DEBUG
__CTRACE(__CTRACE_MISC,
"curs_set: high vis\n");
#endif
_cursesi_screen->old_mode = 2;
tputs(cursor_visible, 0, __cputchar);
return old_one;
}
break;
default:
break;
}
return ERR;
}
/*
* __restore_cursor_vis --
* Restore the old cursor visibility.
*/
void
__restore_cursor_vis(void)
{
curs_set(_cursesi_screen->old_mode);
}

338
lib/libcurses/curses.3 Normal file
View file

@ -0,0 +1,338 @@
.\" $NetBSD: curses.3,v 1.61 2010/12/09 13:26:27 njoly Exp $
.\"
.\" Copyright (c) 1985, 1991, 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.
.\"
.\" @(#)curses.3 8.1 (Berkeley) 6/4/93
.\"
.Dd July 6, 2009
.Dt CURSES 3
.Os
.Sh NAME
.Nm curses
.Nd screen functions with
.Dq optimal
cursor motion
.Sh LIBRARY
.Lb libcurses
.Sh SYNOPSIS
.Nm cc
.Op Ar flags
.Ar files
.Fl lcurses
.Op Ar libraries
.Sh DESCRIPTION
These routines give the user a method of updating screens with reasonable
optimization.
They keep an image of the current screen,
and the user sets up an image of a new one.
Then the
.Fn refresh
tells the routines to make the current screen look like the new one.
In order to initialize the routines, the routine
.Fn initscr
must be called before any of the other routines that deal with windows and
screens are used.
The routine
.Fn endwin
should be called before exiting.
The routine
.Fn start_color
must be called before any of the other routines that deal with color are used.
.Sh FUNCTIONS
.Bl -column "subwin(win,lines,cols,begin_y,begin_x)"
.It Sy "Function Name" Ta Sy "Manual Page Name"
.It addch Ta Xr curses_addch 3
.It addchnstr Ta Xr curses_addchstr 3
.It addchstr Ta Xr curses_addchstr 3
.It addnstr Ta Xr curses_addstr 3
.It addstr Ta Xr curses_addstr 3
.It assume_default_colors Ta Xr curses_default_colors 3
.It attr_get Ta Xr curses_attributes 3
.It attr_off Ta Xr curses_attributes 3
.It attr_on Ta Xr curses_attributes 3
.It attr_set Ta Xr curses_attributes 3
.It attroff Ta Xr curses_attributes 3
.It attron Ta Xr curses_attributes 3
.It attrset Ta Xr curses_attributes 3
.It beep Ta Xr curses_tty 3
.It bkgd Ta Xr curses_background 3
.It bkgdset Ta Xr curses_background 3
.It border Ta Xr curses_border 3
.It box Ta Xr curses_border 3
.It can_change_color Ta Xr curses_color 3
.It cbreak Ta Xr curses_tty 3
.It chgat Ta Xr curses_chgat 3
.It clear Ta Xr curses_clear 3
.It clearok Ta Xr curses_clear 3
.It clrtobot Ta Xr curses_clear 3
.It clrtoeol Ta Xr curses_clear 3
.It color_content Ta Xr curses_color 3
.It color_set Ta Xr curses_attributes 3
.It copywin Ta Xr curses_window 3
.It curs_set Ta Xr curses_tty 3
.It def_prog_mode Ta Xr curses_tty 3
.It def_shell_mode Ta Xr curses_tty 3
.It define_key Ta Xr curses_input 3
.It delay_output Ta Xr curses_tty 3
.It delch Ta Xr curses_delch 3
.It deleteln Ta Xr curses_deleteln 3
.It delscreen Ta Xr curses_screen 3
.It delwin Ta Xr curses_window 3
.It derwin Ta Xr curses_window 3
.It doupdate Ta Xr curses_refresh 3
.It dupwin Ta Xr curses_window 3
.It echo Ta Xr curses_tty 3
.It endwin Ta Xr curses_screen 3
.It erase Ta Xr curses_clear 3
.It erasechar Ta Xr curses_tty 3
.It flash Ta Xr curses_tty 3
.It flushinp Ta Xr curses_tty 3
.It flushok Ta Xr curses_refresh 3
.It fullname Ta Xr curses_termcap 3
.It getattrs Ta Xr curses_attributes 3
.It getbegx Ta Xr curses_cursor 3
.It getbegy Ta Xr curses_cursor 3
.It getbkgd Ta Xr curses_background 3
.It getcap Ta Xr curses_termcap 3
.It getch Ta Xr curses_input 3
.It getcurx Ta Xr curses_cursor 3
.It getcury Ta Xr curses_cursor 3
.It getmaxx Ta Xr curses_cursor 3
.It getmaxy Ta Xr curses_cursor 3
.It getnstr Ta Xr curses_input 3
.It getparx Ta Xr curses_cursor 3
.It getpary Ta Xr curses_cursor 3
.It getparyx Ta Xr curses_cursor 3
.It getstr Ta Xr curses_input 3
.It gettmode Ta Xr curses_tty 3
.It getwin Ta Xr curses_fileio 3
.It getyx Ta Xr curses_cursor 3
.It has_colors Ta Xr curses_color 3
.It has_ic Ta Xr curses_tty 3
.It has_il Ta Xr curses_tty 3
.It hline Ta Xr curses_line 3
.It idcok Ta Xr curses_tty 3
.It idlok Ta Xr curses_tty 3
.It inch Ta Xr curses_inch 3
.It inchnstr Ta Xr curses_inch 3
.It inchstr Ta Xr curses_inch 3
.It init_color Ta Xr curses_color 3
.It init_pair Ta Xr curses_color 3
.It initscr Ta Xr curses_screen 3
.It innstr Ta Xr curses_inch 3
.It insch Ta Xr curses_insertch 3
.It insdelln Ta Xr curses_insdelln 3
.It insertln Ta Xr curses_insertln 3
.It instr Ta Xr curses_inch 3
.It intrflush Ta Xr curses_tty 3
.It is_linetouched Ta Xr curses_touch 3
.It is_wintouched Ta Xr curses_touch 3
.It isendwin Ta Xr curses_screen 3
.It keyname Ta Xr curses_keyname 3
.It keyok Ta Xr curses_input 3
.It keypad Ta Xr curses_input 3
.It killchar Ta Xr curses_tty 3
.It leaveok Ta Xr curses_tty 3
.It longname Ta Xr curses_termcap 3
.It meta Ta Xr curses_tty 3
.It move Ta Xr curses_cursor 3
.It mvaddch Ta Xr curses_addch 3
.It mvaddchnstr Ta Xr curses_addchstr 3
.It mvaddchstr Ta Xr curses_addchstr 3
.It mvaddnstr Ta Xr curses_addstr 3
.It mvaddstr Ta Xr curses_addstr 3
.It mvchgat Ta Xr curses_chgat 3
.It mvcur Ta Xr curses_cursor 3
.It mvderwin Ta Xr curses_window 3
.It mvgetnstr Ta Xr curses_input 3
.It mvgetstr Ta Xr curses_input 3
.It mvhline Ta Xr curses_line 3
.It mvinchstr Ta Xr curses_inch 3
.It mvinchnstr Ta Xr curses_inch 3
.It mvprintw Ta Xr curses_print 3
.It mvscanw Ta Xr curses_scanw 3
.It mvvline Ta Xr curses_line 3
.It mvwaddch Ta Xr curses_addch 3
.It mvwaddchnstr Ta Xr curses_addchstr 3
.It mvwaddchstr Ta Xr curses_addchstr 3
.It mvwaddnstr Ta Xr curses_addstr 3
.It mvwaddstr Ta Xr curses_addstr 3
.It mvwchgat Ta Xr curses_chgat 3
.It mvwgetnstr Ta Xr curses_input 3
.It mvwgetstr Ta Xr curses_input 3
.It mvwhline Ta Xr curses_line 3
.It mvwinchstr Ta Xr curses_inch 3
.It mvwinchnstr Ta Xr curses_inch 3
.It mvwprintw Ta Xr curses_print 3
.It mvwscanw Ta Xr curses_scanw 3
.It mvwvline Ta Xr curses_line 3
.It napms Ta Xr curses_tty 3
.It newpad Ta Xr curses_pad 3
.It newterm Ta Xr curses_screen 3
.It newwin Ta Xr curses_window 3
.It \&nl Ta Xr curses_tty 3
.It nocbreak Ta Xr curses_tty 3
.It nodelay Ta Xr curses_input 3
.It noecho Ta Xr curses_tty 3
.It nonl Ta Xr curses_tty 3
.It noqiflush Ta Xr curses_tty 3
.It noraw Ta Xr curses_tty 3
.It notimeout Ta Xr curses_input 3
.It overlay Ta Xr curses_window 3
.It overwrite Ta Xr curses_window 3
.It pair_content Ta Xr curses_color 3
.It pnoutrefresh Ta Xr curses_pad 3
.It prefresh Ta Xr curses_pad 3
.It printw Ta Xr curses_print 3
.It putwin Ta Xr curses_fileio 3
.It qiflush Ta Xr curses_tty 3
.It raw Ta Xr curses_tty 3
.It redrawwin Ta Xr curses_touch 3
.It refresh Ta Xr curses_refresh 3
.It reset_prog_mode Ta Xr curses_tty 3
.It reset_shell_mode Ta Xr curses_tty 3
.It resetty Ta Xr curses_tty 3
.It resizeterm Ta Xr curses_screen 3
.It savetty Ta Xr curses_tty 3
.It scanw Ta Xr curses_scanw 3
.It scrl Ta Xr curses_scroll 3
.It scroll Ta Xr curses_scroll 3
.It scrollok Ta Xr curses_scroll 3
.It set_term Ta Xr curses_screen 3
.It setscrreg Ta Xr curses_scroll 3
.It setterm Ta Xr curses_screen 3
.It standend Ta Xr curses_standout 3
.It standout Ta Xr curses_standout 3
.It start_color Ta Xr curses_color 3
.It subpad Ta Xr curses_pad 3
.It subwin Ta Xr curses_window 3
.It termattrs Ta Xr curses_attributes 3
.It timeout Ta Xr curses_input 3
.It touchline Ta Xr curses_touch 3
.It touchoverlap Ta Xr curses_touch 3
.It touchwin Ta Xr curses_touch 3
.It unctrl Ta Xr curses_print 3
.It underend Ta Xr curses_underscore 3
.It underscore Ta Xr curses_underscore 3
.It ungetch Ta Xr curses_input 3
.It untouchwin Ta Xr curses_touch 3
.It use_default_colors Ta Xr curses_default_colors 3
.It vline Ta Xr curses_line 3
.It waddch Ta Xr curses_addch 3
.It waddchnstr Ta Xr curses_addchstr 3
.It waddchstr Ta Xr curses_addchstr 3
.It waddnstr Ta Xr curses_addstr 3
.It waddstr Ta Xr curses_addstr 3
.It wattr_get Ta Xr curses_attributes 3
.It wattr_off Ta Xr curses_attributes 3
.It wattr_on Ta Xr curses_attributes 3
.It wattr_set Ta Xr curses_attributes 3
.It wattroff Ta Xr curses_attributes 3
.It wattron Ta Xr curses_attributes 3
.It wattrset Ta Xr curses_attributes 3
.It wbkgd Ta Xr curses_background 3
.It wbkgdset Ta Xr curses_background 3
.It wborder Ta Xr curses_border 3
.It wchgat Ta Xr curses_chgat 3
.It wclear Ta Xr curses_clear 3
.It wclrtobot Ta Xr curses_clear 3
.It wclrtoeol Ta Xr curses_clear 3
.It wcolor_set Ta Xr curses_attributes 3
.It wdelch Ta Xr curses_delch 3
.It wdeleteln Ta Xr curses_deleteln 3
.It werase Ta Xr curses_clear 3
.It wgetch Ta Xr curses_input 3
.It wgetnstr Ta Xr curses_input 3
.It wgetstr Ta Xr curses_input 3
.It whline Ta Xr curses_line 3
.It winch Ta Xr curses_inch 3
.It winchnstr Ta Xr curses_inch 3
.It winchstr Ta Xr curses_inch 3
.It winnstr Ta Xr curses_inch 3
.It winsch Ta Xr curses_insertch 3
.It winsdelln Ta Xr curses_insdelln 3
.It winsertln Ta Xr curses_insertln 3
.It winstr Ta Xr curses_inch 3
.It wmove Ta Xr curses_cursor 3
.It wnoutrefresh Ta Xr curses_refresh 3
.It wprintw Ta Xr curses_print 3
.It wredrawln Ta Xr curses_touch 3
.It wrefresh Ta Xr curses_refresh 3
.It wresize Ta Xr curses_window 3
.It wscanw Ta Xr curses_scanw 3
.It wscrl Ta Xr curses_scroll 3
.It wsetscrreg Ta Xr curses_scroll 3
.It wstandend Ta Xr curses_standout 3
.It wstandout Ta Xr curses_standout 3
.It wtimeout Ta Xr curses_input 3
.It wtouchln Ta Xr curses_touch 3
.It wunderend Ta Xr curses_underscore 3
.It wunderscore Ta Xr curses_underscore 3
.It wvline Ta Xr curses_line 3
.El
.Sh ENVIRONMENT
.Bl -tag -width CURSES_TRACE_MASK
.It COLUMNS
The number of columns in the terminal if set.
This is usually automatically configured by querying the kernel.
.It CURSES_TRACE_MASK
An integer mask that enables specific debugging traces.
Enabled only in the debug build of curses.
.It CURSES_TRACE_FILE
A file where to output debugging information.
Enabled only in the debug build of curses.
.It ESCDELAY
The maximum delay in milliseconds between characters in multi-character
keystrokes (such are arrow keys) where the adjacent characters are considered
part of the same multi-character sequence.
The default is 300 milliseconds.
.It LINES
The number of lines in the terminal if set.
is usually automatically configured by querying the kernel.
.It TERM
The terminal type of the current terminal.
.El
.Sh SEE ALSO
.Xr ioctl 2 ,
.Xr getenv 3 ,
.Xr tty 4 ,
.Xr termcap 5
.Rs
.%T Screen Updating and Cursor Movement Optimization: A Library Package
.%A Ken Arnold
.Re
.Sh STANDARDS
The
.Nx
Curses library complies with the X/Open Curses specification, part of the
Single Unix Specification.
.Sh HISTORY
The Curses package appeared in
.Bx 4.0 .
.Sh AUTHORS
.An Ken Arnold

160
lib/libcurses/curses.c Normal file
View file

@ -0,0 +1,160 @@
/* $NetBSD: curses.c,v 1.24 2010/02/03 15:34:40 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 <sys/cdefs.h>
#include <stdlib.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#)curses.c 8.3 (Berkeley) 5/4/94";
#else
__RCSID("$NetBSD: curses.c,v 1.24 2010/02/03 15:34:40 roy Exp $");
#endif
#endif /* not lint */
#include "curses.h"
#include "curses_private.h"
/* Private. */
int __echoit = 1; /* If stty indicates ECHO. */
int __pfast;
int __rawmode = 0; /* If stty indicates RAW mode. */
int __noqch = 0;
/* If terminal doesn't have
* insert/delete line capabilities
* for quick change on refresh.
*/
char __CA;
/*
* Public.
*
* XXX
* UPPERCASE isn't used by libcurses, and is left for backward
* compatibility only.
*/
WINDOW *curscr; /* Current screen. */
WINDOW *stdscr; /* Standard screen. */
WINDOW *__virtscr; /* Virtual screen (for doupdate()). */
SCREEN *_cursesi_screen; /* the current screen we are using */
int COLS; /* Columns on the screen. */
int LINES; /* Lines on the screen. */
int COLORS; /* Maximum colors on the screen */
int COLOR_PAIRS = 0; /* Maximum color pairs on the screen */
int My_term = 0; /* Use Def_term regardless. */
const char *Def_term = "unknown"; /* Default terminal type. */
char __GT; /* Gtty indicates tabs. */
char __NONL; /* Term can't hack LF doing a CR. */
char __UPPERCASE; /* Terminal is uppercase only. */
#ifdef HAVE_WCHAR
/*
* Copy the non-spacing character list (src_nsp) to the given character,
* allocate or free storage as required.
*/
int
_cursesi_copy_nsp(nschar_t *src_nsp, struct __ldata *ch)
{
nschar_t *np, *tnp, *pnp;
pnp = NULL;
np = src_nsp;
if (np) {
tnp = ch->nsp;
while (np) {
if (tnp) {
tnp->ch = np->ch;
pnp = tnp;
tnp = tnp->next;
} else {
tnp = (nschar_t *)malloc(sizeof(nschar_t));
if (!tnp)
return ERR;
tnp->ch = np->ch;
pnp->next = tnp;
tnp->next = NULL;
pnp = tnp;
tnp = NULL;
}
np = np->next;
}
np = tnp;
if (np) {
pnp->next = NULL;
__cursesi_free_nsp(np);
}
} else {
if (ch->nsp) {
__cursesi_free_nsp(ch->nsp);
ch->nsp = NULL;
}
}
return OK;
}
/*
* Free the storage associated with a non-spacing character - traverse the
* linked list until all storage is done.
*/
void
__cursesi_free_nsp(nschar_t *inp)
{
nschar_t *tnp, *np;
np = inp;
if (np) {
while (np) {
tnp = np->next;
free(np);
np = tnp;
}
}
}
/*
* Traverse all the cells in the given window free'ing the non-spacing
* character storage.
*/
void
__cursesi_win_free_nsp(WINDOW *win)
{
int i, j;
__LDATA *sp;
for (i = 0; i < win->maxy; i++) {
for (sp = win->alines[i]->line, j = 0; j < win->maxx;
j++, sp++) {
__cursesi_free_nsp(sp->nsp);
}
}
}
#endif

933
lib/libcurses/curses.h Normal file
View file

@ -0,0 +1,933 @@
/* $NetBSD: curses.h,v 1.101 2010/12/16 17:42:28 wiz 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.
*
* @(#)curses.h 8.5 (Berkeley) 4/29/95
*
* Modified by Ruibiao Qiu <ruibiao@arl.wustl.edu,ruibiao@gmail.com> 2005
* to add wide-character support
* - Add complex character structure (cchar_t)
* - Add definitions of wide-character routines
* - Add KEY_CODE_YES
*/
#ifndef _CURSES_H_
#define _CURSES_H_
#include <sys/types.h>
#include <sys/cdefs.h>
#include <wchar.h>
#include <stdio.h>
#include <stdbool.h>
/*
* attr_t must be the same size as wchar_t (see <wchar.h>) to avoid padding
* in __LDATA.
*/
typedef wchar_t chtype;
typedef wchar_t attr_t;
#if !defined(HAVE_WCHAR) && !defined(DISABLE_WCHAR)
#define HAVE_WCHAR 1
#endif
#ifdef HAVE_WCHAR
/*
* The complex character structure required by the X/Open reference and used
* in * functions such as in_wchstr(). It includes a string of up to 8 wide
* characters and its length, an attribute, and a color-pair.
*/
#define CURSES_CCHAR_MAX 8
#define CCHARW_MAX 5
typedef struct {
attr_t attributes; /* character attributes */
unsigned elements; /* number of wide char in
vals[] */
wchar_t vals[CURSES_CCHAR_MAX]; /* wide chars including
non-spacing */
} cchar_t;
#else
typedef chtype cchar_t;
#endif /* HAVE_WCHAR */
#ifndef TRUE
#define TRUE (/*CONSTCOND*/1)
#endif
#ifndef FALSE
#define FALSE (/*CONSTCOND*/0)
#endif
#ifndef _CURSES_PRIVATE
#define _puts(s) tputs(s, 0, __cputchar)
#define _putchar(c) __cputchar(c)
/* Old-style terminal modes access. */
#define crmode() cbreak()
#define nocrmode() nocbreak()
#endif /* _CURSES_PRIVATE */
/* symbols for values returned by getch in keypad mode */
#define KEY_MIN 0x101 /* minimum extended key value */
#define KEY_BREAK 0x101 /* break key */
#define KEY_DOWN 0x102 /* down arrow */
#define KEY_UP 0x103 /* up arrow */
#define KEY_LEFT 0x104 /* left arrow */
#define KEY_RIGHT 0x105 /* right arrow*/
#define KEY_HOME 0x106 /* home key */
#define KEY_BACKSPACE 0x107 /* Backspace */
/* First function key (block of 64 follow) */
#define KEY_F0 0x108
/* Function defining other function key values*/
#define KEY_F(n) (KEY_F0+(n))
#define KEY_DL 0x148 /* Delete Line */
#define KEY_IL 0x149 /* Insert Line*/
#define KEY_DC 0x14A /* Delete Character */
#define KEY_IC 0x14B /* Insert Character */
#define KEY_EIC 0x14C /* Exit Insert Char mode */
#define KEY_CLEAR 0x14D /* Clear screen */
#define KEY_EOS 0x14E /* Clear to end of screen */
#define KEY_EOL 0x14F /* Clear to end of line */
#define KEY_SF 0x150 /* Scroll one line forward */
#define KEY_SR 0x151 /* Scroll one line back */
#define KEY_NPAGE 0x152 /* Next Page */
#define KEY_PPAGE 0x153 /* Prev Page */
#define KEY_STAB 0x154 /* Set Tab */
#define KEY_CTAB 0x155 /* Clear Tab */
#define KEY_CATAB 0x156 /* Clear All Tabs */
#define KEY_ENTER 0x157 /* Enter or Send */
#define KEY_SRESET 0x158 /* Soft Reset */
#define KEY_RESET 0x159 /* Hard Reset */
#define KEY_PRINT 0x15A /* Print */
#define KEY_LL 0x15B /* Home Down */
/*
* "Keypad" keys arranged like this:
*
* A1 up A3
* left B2 right
* C1 down C3
*
*/
#define KEY_A1 0x15C /* Keypad upper left */
#define KEY_A3 0x15D /* Keypad upper right */
#define KEY_B2 0x15E /* Keypad centre key */
#define KEY_C1 0x15F /* Keypad lower left */
#define KEY_C3 0x160 /* Keypad lower right */
#define KEY_BTAB 0x161 /* Back Tab */
#define KEY_BEG 0x162 /* Begin key */
#define KEY_CANCEL 0x163 /* Cancel key */
#define KEY_CLOSE 0x164 /* Close Key */
#define KEY_COMMAND 0x165 /* Command Key */
#define KEY_COPY 0x166 /* Copy key */
#define KEY_CREATE 0x167 /* Create key */
#define KEY_END 0x168 /* End key */
#define KEY_EXIT 0x169 /* Exit key */
#define KEY_FIND 0x16A /* Find key */
#define KEY_HELP 0x16B /* Help key */
#define KEY_MARK 0x16C /* Mark key */
#define KEY_MESSAGE 0x16D /* Message key */
#define KEY_MOVE 0x16E /* Move key */
#define KEY_NEXT 0x16F /* Next Object key */
#define KEY_OPEN 0x170 /* Open key */
#define KEY_OPTIONS 0x171 /* Options key */
#define KEY_PREVIOUS 0x172 /* Previous Object key */
#define KEY_REDO 0x173 /* Redo key */
#define KEY_REFERENCE 0x174 /* Ref Key */
#define KEY_REFRESH 0x175 /* Refresh key */
#define KEY_REPLACE 0x176 /* Replace key */
#define KEY_RESTART 0x177 /* Restart key */
#define KEY_RESUME 0x178 /* Resume key */
#define KEY_SAVE 0x179 /* Save key */
#define KEY_SBEG 0x17A /* Shift begin key */
#define KEY_SCANCEL 0x17B /* Shift Cancel key */
#define KEY_SCOMMAND 0x17C /* Shift Command key */
#define KEY_SCOPY 0x17D /* Shift Copy key */
#define KEY_SCREATE 0x17E /* Shift Create key */
#define KEY_SDC 0x17F /* Shift Delete Character */
#define KEY_SDL 0x180 /* Shift Delete Line */
#define KEY_SELECT 0x181 /* Select key */
#define KEY_SEND 0x182 /* Send key */
#define KEY_SEOL 0x183 /* Shift Clear Line key */
#define KEY_SEXIT 0x184 /* Shift Exit key */
#define KEY_SFIND 0x185 /* Shift Find key */
#define KEY_SHELP 0x186 /* Shift Help key */
#define KEY_SHOME 0x187 /* Shift Home key */
#define KEY_SIC 0x188 /* Shift Input key */
#define KEY_SLEFT 0x189 /* Shift Left Arrow key */
#define KEY_SMESSAGE 0x18A /* Shift Message key */
#define KEY_SMOVE 0x18B /* Shift Move key */
#define KEY_SNEXT 0x18C /* Shift Next key */
#define KEY_SOPTIONS 0x18D /* Shift Options key */
#define KEY_SPREVIOUS 0x18E /* Shift Previous key */
#define KEY_SPRINT 0x18F /* Shift Print key */
#define KEY_SREDO 0x190 /* Shift Redo key */
#define KEY_SREPLACE 0x191 /* Shift Replace key */
#define KEY_SRIGHT 0x192 /* Shift Right Arrow key */
#define KEY_SRSUME 0x193 /* Shift Resume key */
#define KEY_SSAVE 0x194 /* Shift Save key */
#define KEY_SSUSPEND 0x195 /* Shift Suspend key */
#define KEY_SUNDO 0x196 /* Shift Undo key */
#define KEY_SUSPEND 0x197 /* Suspend key */
#define KEY_UNDO 0x198 /* Undo key */
#define KEY_MOUSE 0x199 /* Mouse event has occurred */
#define KEY_RESIZE 0x200 /* Resize event has occurred */
#define KEY_MAX 0x240 /* maximum extended key value */
#define KEY_CODE_YES 0x241 /* A function key pressed */
#include <unctrl.h>
/*
* A window an array of __LINE structures pointed to by the 'lines' pointer.
* A line is an array of __LDATA structures pointed to by the 'line' pointer.
*/
/*
* Definitions for characters and attributes in __LDATA
*/
#define __CHARTEXT 0x000000ff /* bits for 8-bit characters */
#define __NORMAL 0x00000000 /* Added characters are normal. */
#define __STANDOUT 0x00000100 /* Added characters are standout. */
#define __UNDERSCORE 0x00000200 /* Added characters are underscored. */
#define __REVERSE 0x00000400 /* Added characters are reverse
video. */
#define __BLINK 0x00000800 /* Added characters are blinking. */
#define __DIM 0x00001000 /* Added characters are dim. */
#define __BOLD 0x00002000 /* Added characters are bold. */
#define __BLANK 0x00004000 /* Added characters are blanked. */
#define __PROTECT 0x00008000 /* Added characters are protected. */
#define __ALTCHARSET 0x00010000 /* Added characters are ACS */
#define __COLOR 0x03fe0000 /* Color bits */
#define __ATTRIBUTES 0x03ffff00 /* All 8-bit attribute bits */
#ifdef HAVE_WCHAR
#define __ACS_IS_WACS 0x04000000 /* internal: use wacs table for ACS char */
#endif
typedef struct __ldata __LDATA;
typedef struct __line __LINE;
typedef struct __window WINDOW;
typedef struct __screen SCREEN;
/*
* Attribute definitions
*/
#define A_NORMAL __NORMAL
#define A_STANDOUT __STANDOUT
#define A_UNDERLINE __UNDERSCORE
#define A_REVERSE __REVERSE
#define A_BLINK __BLINK
#define A_DIM __DIM
#define A_BOLD __BOLD
#define A_BLANK __BLANK
#define A_INVIS __BLANK
#define A_PROTECT __PROTECT
#define A_ALTCHARSET __ALTCHARSET
#define A_ATTRIBUTES __ATTRIBUTES
#define A_CHARTEXT __CHARTEXT
#define A_COLOR __COLOR
#ifdef HAVE_WCHAR
#define WA_ATTRIBUTES 0x03ffffff /* Wide character attributes mask */
#define WA_STANDOUT __STANDOUT /* Best highlighting mode */
#define WA_UNDERLINE __UNDERSCORE /* Underlining */
#define WA_REVERSE __REVERSE /* Reverse video */
#define WA_BLINK __BLINK /* Blinking */
#define WA_DIM __DIM /* Half bright */
#define WA_BOLD __BOLD /* Extra bright or bold */
#define WA_INVIS __BLANK /* Invisible */
#define WA_PROTECT __PROTECT /* Protected */
#define WA_ALTCHARSET __ALTCHARSET /* Alternate character set */
#define WA_LOW 0x00000002 /* Low highlight */
#define WA_TOP 0x00000004 /* Top highlight */
#define WA_HORIZONTAL 0x00000008 /* Horizontal highlight */
#define WA_VERTICAL 0x00000010 /* Vertical highlight */
#define WA_LEFT 0x00000020 /* Left highlight */
#define WA_RIGHT 0x00000040 /* Right highlight */
#endif /* HAVE_WCHAR */
/*
* Alternate character set definitions
*/
#define NUM_ACS 128
extern chtype _acs_char[NUM_ACS];
#ifdef __cplusplus
#define __UC_CAST(a) static_cast<unsigned char>(a)
#else
#define __UC_CAST(a) (unsigned char)(a)
#endif
/* Standard definitions */
#define ACS_RARROW _acs_char[__UC_CAST('+')]
#define ACS_LARROW _acs_char[__UC_CAST(',')]
#define ACS_UARROW _acs_char[__UC_CAST('-')]
#define ACS_DARROW _acs_char[__UC_CAST('.')]
#define ACS_BLOCK _acs_char[__UC_CAST('0')]
#define ACS_DIAMOND _acs_char[__UC_CAST('`')]
#define ACS_CKBOARD _acs_char[__UC_CAST('a')]
#define ACS_DEGREE _acs_char[__UC_CAST('f')]
#define ACS_PLMINUS _acs_char[__UC_CAST('g')]
#define ACS_BOARD _acs_char[__UC_CAST('h')]
#define ACS_LANTERN _acs_char[__UC_CAST('i')]
#define ACS_LRCORNER _acs_char[__UC_CAST('j')]
#define ACS_URCORNER _acs_char[__UC_CAST('k')]
#define ACS_ULCORNER _acs_char[__UC_CAST('l')]
#define ACS_LLCORNER _acs_char[__UC_CAST('m')]
#define ACS_PLUS _acs_char[__UC_CAST('n')]
#define ACS_HLINE _acs_char[__UC_CAST('q')]
#define ACS_S1 _acs_char[__UC_CAST('o')]
#define ACS_S9 _acs_char[__UC_CAST('s')]
#define ACS_LTEE _acs_char[__UC_CAST('t')]
#define ACS_RTEE _acs_char[__UC_CAST('u')]
#define ACS_BTEE _acs_char[__UC_CAST('v')]
#define ACS_TTEE _acs_char[__UC_CAST('w')]
#define ACS_VLINE _acs_char[__UC_CAST('x')]
#define ACS_BULLET _acs_char[__UC_CAST('~')]
/* Extensions */
#define ACS_S3 _acs_char[__UC_CAST('p')]
#define ACS_S7 _acs_char[__UC_CAST('r')]
#define ACS_LEQUAL _acs_char[__UC_CAST('y')]
#define ACS_GEQUAL _acs_char[__UC_CAST('z')]
#define ACS_PI _acs_char[__UC_CAST('{')]
#define ACS_NEQUAL _acs_char[__UC_CAST('|')]
#define ACS_STERLING _acs_char[__UC_CAST('}')]
#ifdef HAVE_WCHAR
extern cchar_t _wacs_char[NUM_ACS];
#define WACS_RARROW (&_wacs_char[(unsigned char)'+'])
#define WACS_LARROW (&_wacs_char[(unsigned char)','])
#define WACS_UARROW (&_wacs_char[(unsigned char)'-'])
#define WACS_DARROW (&_wacs_char[(unsigned char)'.'])
#define WACS_BLOCK (&_wacs_char[(unsigned char)'0'])
#define WACS_DIAMOND (&_wacs_char[(unsigned char)'`'])
#define WACS_CKBOARD (&_wacs_char[(unsigned char)'a'])
#define WACS_DEGREE (&_wacs_char[(unsigned char)'f'])
#define WACS_PLMINUS (&_wacs_char[(unsigned char)'g'])
#define WACS_BOARD (&_wacs_char[(unsigned char)'h'])
#define WACS_LANTERN (&_wacs_char[(unsigned char)'i'])
#define WACS_LRCORNER (&_wacs_char[(unsigned char)'j'])
#define WACS_URCORNER (&_wacs_char[(unsigned char)'k'])
#define WACS_ULCORNER (&_wacs_char[(unsigned char)'l'])
#define WACS_LLCORNER (&_wacs_char[(unsigned char)'m'])
#define WACS_PLUS (&_wacs_char[(unsigned char)'n'])
#define WACS_HLINE (&_wacs_char[(unsigned char)'q'])
#define WACS_S1 (&_wacs_char[(unsigned char)'o'])
#define WACS_S9 (&_wacs_char[(unsigned char)'s'])
#define WACS_LTEE (&_wacs_char[(unsigned char)'t'])
#define WACS_RTEE (&_wacs_char[(unsigned char)'u'])
#define WACS_BTEE (&_wacs_char[(unsigned char)'v'])
#define WACS_TTEE (&_wacs_char[(unsigned char)'w'])
#define WACS_VLINE (&_wacs_char[(unsigned char)'x'])
#define WACS_BULLET (&_wacs_char[(unsigned char)'~'])
#define WACS_S3 (&_wacs_char[(unsigned char)'p'])
#define WACS_S7 (&_wacs_char[(unsigned char)'r'])
#define WACS_LEQUAL (&_wacs_char[(unsigned char)'y'])
#define WACS_GEQUAL (&_wacs_char[(unsigned char)'z'])
#define WACS_PI (&_wacs_char[(unsigned char)'{'])
#define WACS_NEQUAL (&_wacs_char[(unsigned char)'|'])
#define WACS_STERLING (&_wacs_char[(unsigned char)'}'])
#endif /* HAVE_WCHAR */
/* System V compatibility */
#define ACS_SBBS ACS_LRCORNER
#define ACS_BBSS ACS_URCORNER
#define ACS_BSSB ACS_ULCORNER
#define ACS_SSBB ACS_LLCORNER
#define ACS_SSSS ACS_PLUS
#define ACS_BSBS ACS_HLINE
#define ACS_SSSB ACS_LTEE
#define ACS_SBSS ACS_RTEE
#define ACS_SSBS ACS_BTEE
#define ACS_BSSS ACS_TTEE
#define ACS_SBSB ACS_VLINE
#define _acs_map _acs_char
/*
* Color definitions (ANSI color numbers)
*/
#define COLOR_BLACK 0x00
#define COLOR_RED 0x01
#define COLOR_GREEN 0x02
#define COLOR_YELLOW 0x03
#define COLOR_BLUE 0x04
#define COLOR_MAGENTA 0x05
#define COLOR_CYAN 0x06
#define COLOR_WHITE 0x07
#ifdef __cplusplus
#define __UINT32_CAST(a) static_cast<u_int32_t>(a)
#else
#define __UINT32_CAST(a) (u_int32_t)(a)
#endif
#define COLOR_PAIR(n) (((__UINT32_CAST(n)) << 17) & A_COLOR)
#define PAIR_NUMBER(n) (((__UINT32_CAST(n)) & A_COLOR) >> 17)
/* Curses external declarations. */
extern WINDOW *curscr; /* Current screen. */
extern WINDOW *stdscr; /* Standard screen. */
extern int __tcaction; /* If terminal hardware set. */
extern int COLS; /* Columns on the screen. */
extern int LINES; /* Lines on the screen. */
extern int COLORS; /* Max colors on the screen. */
extern int COLOR_PAIRS; /* Max color pairs on the screen. */
extern int ESCDELAY; /* Delay between keys in esc seq's. */
#ifndef OK
#define ERR (-1) /* Error return. */
#define OK (0) /* Success return. */
#endif
/*
* The following have, traditionally, been macros but X/Open say they
* need to be functions. Keep the old macros for debugging.
*/
#ifdef _CURSES_USE_MACROS
/* Standard screen pseudo functions. */
#define addbytes(s, n) __waddbytes(stdscr, s, n, 0)
#define addch(ch) waddch(stdscr, ch)
#define addchnstr(s) waddchnstr(stdscr, s, n)
#define addchstr(s) waddchnstr(stdscr, s, -1)
#define addnstr(s, n) waddnstr(stdscr, s, n)
#define addstr(s) waddnstr(stdscr, s, -1)
#define attr_get(a, p, o) wattr_get(stdscr, a, p, o)
#define attr_off(a, o) wattr_off(stdscr, a, o)
#define attr_on(a, o) wattr_on(stdscr, a, o)
#define attr_set(a, p, o) wattr_set(stdscr, a, p, o)
#define attroff(attr) wattroff(stdscr, attr)
#define attron(attr) wattron(stdscr, attr)
#define attrset(attr) wattrset(stdscr, attr)
#define bkgd(ch) wbkgd(stdscr, ch)
#define bkgdset(ch) wbkgdset(stdscr, ch)
#define border(l, r, t, b, tl, tr, bl, br) \
wborder(stdscr, l, r, t, b, tl, tr, bl, br)
#define clear() wclear(stdscr)
#define clrtobot() wclrtobot(stdscr)
#define clrtoeol() wclrtoeol(stdscr)
#define color_set(c, o) wcolor_set(stdscr, c, o)
#define delch() wdelch(stdscr)
#define deleteln() wdeleteln(stdscr)
#define echochar(c) wechochar(stdscr, c)
#define erase() werase(stdscr)
#define getch() wgetch(stdscr)
#define getnstr(s, n) wgetnstr(stdscr, s, n)
#define getstr(s) wgetstr(stdscr, s)
#define inch() winch(stdscr)
#define inchnstr(c) winchnstr(stdscr, c)
#define inchstr(c) winchstr(stdscr, c)
#define innstr(s, n) winnstr(stdscr, s, n)
#define insch(ch) winsch(stdscr, ch)
#define insdelln(n) winsdelln(stdscr, n)
#define insertln() winsertln(stdscr)
#define instr(s) winstr(stdscr, s)
#define move(y, x) wmove(stdscr, y, x)
#define refresh() wrefresh(stdscr)
#define scrl(n) wscrl(stdscr, n)
#define setscrreg(t, b) wsetscrreg(stdscr, t, b)
#define standend() wstandend(stdscr)
#define standout() wstandout(stdscr)
#define timeout(delay) wtimeout(stdscr, delay)
#define underscore() wunderscore(stdscr)
#define underend() wunderend(stdscr)
#define waddbytes(w, s, n) __waddbytes(w, s, n, 0)
#define waddstr(w, s) waddnstr(w, s, -1)
/* Standard screen plus movement pseudo functions. */
#define mvaddbytes(y, x, s, n) mvwaddbytes(stdscr, y, x, s, n)
#define mvaddch(y, x, ch) mvwaddch(stdscr, y, x, ch)
#define mvaddchnstr(y, x, s, n) mvwaddchnstr(stdscr, y, x, s, n)
#define mvaddchstr(y, x, s) mvwaddchstr(stdscr, y, x, s)
#define mvaddnstr(y, x, s, n) mvwaddnstr(stdscr, y, x, s, n)
#define mvaddstr(y, x, s) mvwaddstr(stdscr, y, x, s)
#define mvdelch(y, x) mvwdelch(stdscr, y, x)
#define mvgetch(y, x) mvwgetch(stdscr, y, x)
#define mvgetnstr(y, x, s) mvwgetnstr(stdscr, y, x, s, n)
#define mvgetstr(y, x, s) mvwgetstr(stdscr, y, x, s)
#define mvinch(y, x) mvwinch(stdscr, y, x)
#define mvinchnstr(y, x, c, n) mvwinchnstr(stdscr, y, x, c, n)
#define mvinchstr(y, x, c) mvwinchstr(stdscr, y, x, c)
#define mvinnstr(y, x, s, n) mvwinnstr(stdscr, y, x, s, n)
#define mvinsch(y, x, c) mvwinsch(stdscr, y, x, c)
#define mvinstr(y, x, s) mvwinstr(stdscr, y, x, s)
#define mvwaddbytes(w, y, x, s, n) \
(wmove(w, y, x) == ERR ? ERR : __waddbytes(w, s, n, 0))
#define mvwaddch(w, y, x, ch) \
(wmove(w, y, x) == ERR ? ERR : waddch(w, ch))
#define mvwaddchnstr(w, y, x, s, n) \
(wmove(w, y, x) == ERR ? ERR : waddchnstr(w, s, n))
#define mvwaddchstr(w, y, x, s) \
(wmove(w, y, x) == ERR ? ERR : waddchnstr(w, s, -1))
#define mvwaddnstr(w, y, x, s, n) \
(wmove(w, y, x) == ERR ? ERR : waddnstr(w, s, n))
#define mvwaddstr(w, y, x, s) \
(wmove(w, y, x) == ERR ? ERR : waddnstr(w, s, -1))
#define mvwdelch(w, y, x) \
(wmove(w, y, x) == ERR ? ERR : wdelch(w))
#define mvwgetch(w, y, x) \
(wmove(w, y, x) == ERR ? ERR : wgetch(w))
#define mvwgetnstr(w, y, x, s, n) \
(wmove(w, y, x) == ERR ? ERR : wgetnstr(w, s, n))
#define mvwgetstr(w, y, x, s) \
(wmove(w, y, x) == ERR ? ERR : wgetstr(w, s))
#define mvwinch(w, y, x) \
(wmove(w, y, x) == ERR ? ERR : winch(w))
#define mvwinchnstr(w, y, x, c, n) \
(wmove(w, y, x) == ERR ? ERR : winchnstr(w, c, n))
#define mvwinchstr(w, y, x, s) \
(wmove(w, y, x) == ERR ? ERR : winchstr(w, c))
#define mvwinnstr(w, y, x, s, n) \
(wmove(w, y, x) == ERR ? ERR : winnstr(w, s, n))
#define mvwinsch(w, y, x, c) \
(wmove(w, y, x) == ERR ? ERR : winsch(w, c))
#define mvwinstr(w, y, x, s) \
(wmove(w, y, x) == ERR ? ERR : winstr(w, s))
/* Miscellaneous. */
#define noqiflush() intrflush(stdscr, FALSE)
#define qiflush() intrflush(stdscr, TRUE)
#else
/* Use functions not macros... */
__BEGIN_DECLS
int addbytes(const char *, int);
int addch(chtype);
int addchnstr(const chtype *, int);
int addchstr(const chtype *);
int addnstr(const char *, int);
int addstr(const char *);
int attr_get(attr_t *, short *, void *);
int attr_off(attr_t, void *);
int attr_on(attr_t, void *);
int attr_set(attr_t, short, void *);
int attroff(int);
int attron(int);
int attrset(int);
int bkgd(chtype);
void bkgdset(chtype);
int border(chtype, chtype, chtype, chtype,
chtype, chtype, chtype, chtype);
int clear(void);
int clrtobot(void);
int clrtoeol(void);
int color_set(short, void *);
int delch(void);
int deleteln(void);
int echochar(const chtype);
int erase(void);
int getch(void);
int getnstr(char *, int);
int getstr(char *);
chtype inch(void);
int inchnstr(chtype *, int);
int inchstr(chtype *);
int innstr(char *, int);
int insch(chtype);
int insdelln(int);
int insertln(void);
int instr(char *);
int move(int, int);
int refresh(void);
int scrl(int);
int setscrreg(int, int);
int standend(void);
int standout(void);
void timeout(int);
int underscore(void);
int underend(void);
int waddbytes(WINDOW *, const char *, int);
int waddstr(WINDOW *, const char *);
/* Standard screen plus movement functions. */
int mvaddbytes(int, int, const char *, int);
int mvaddch(int, int, chtype);
int mvaddchnstr(int, int, const chtype *, int);
int mvaddchstr(int, int, const chtype *);
int mvaddnstr(int, int, const char *, int);
int mvaddstr(int, int, const char *);
int mvdelch(int, int);
int mvgetch(int, int);
int mvgetnstr(int, int, char *, int);
int mvgetstr(int, int, char *);
chtype mvinch(int, int);
int mvinchnstr(int, int, chtype *, int);
int mvinchstr(int, int, chtype *);
int mvinnstr(int, int, char *, int);
int mvinsch(int, int, chtype);
int mvinstr(int, int, char *);
int mvwaddbytes(WINDOW *, int, int, const char *, int);
int mvwaddch(WINDOW *, int, int, chtype);
int mvwaddchnstr(WINDOW *, int, int, const chtype *, int);
int mvwaddchstr(WINDOW *, int, int, const chtype *);
int mvwaddnstr(WINDOW *, int, int, const char *, int);
int mvwaddstr(WINDOW *, int, int, const char *);
int mvwdelch(WINDOW *, int, int);
int mvwgetch(WINDOW *, int, int);
int mvwgetnstr(WINDOW *, int, int, char *, int);
int mvwgetstr(WINDOW *, int, int, char *);
chtype mvwinch(WINDOW *, int, int);
int mvwinsch(WINDOW *, int, int, chtype);
__END_DECLS
#endif /* _CURSES_USE_MACROS */
#define getyx(w, y, x) (y) = getcury(w), (x) = getcurx(w)
#define getbegyx(w, y, x) (y) = getbegy(w), (x) = getbegx(w)
#define getmaxyx(w, y, x) (y) = getmaxy(w), (x) = getmaxx(w)
#define getparyx(w, y, x) (y) = getpary(w), (x) = getparx(w)
/* Public function prototypes. */
__BEGIN_DECLS
int assume_default_colors(short, short);
int baudrate(void);
int beep(void);
int box(WINDOW *, chtype, chtype);
bool can_change_color(void);
int cbreak(void);
int clearok(WINDOW *, bool);
int color_content(short, short *, short *, short *);
int copywin(const WINDOW *, WINDOW *, int, int, int, int, int, int, int);
int curs_set(int);
int def_prog_mode(void);
int def_shell_mode(void);
int define_key(char *, int);
int delay_output(int);
void delscreen(SCREEN *);
int delwin(WINDOW *);
WINDOW *derwin(WINDOW *, int, int, int, int);
WINDOW *dupwin(WINDOW *);
int doupdate(void);
int echo(void);
int endwin(void);
char erasechar(void);
int flash(void);
int flushinp(void);
int flushok(WINDOW *, bool);
char *fullname(const char *, char *);
chtype getattrs(WINDOW *);
chtype getbkgd(WINDOW *);
char *getcap(char *);
int getcury(WINDOW *);
int getcurx(WINDOW *);
int getbegy(WINDOW *);
int getbegx(WINDOW *);
int getmaxy(WINDOW *);
int getmaxx(WINDOW *);
int getpary(WINDOW *);
int getparx(WINDOW *);
int gettmode(void);
WINDOW *getwin(FILE *);
int halfdelay(int);
bool has_colors(void);
bool has_ic(void);
bool has_il(void);
int hline(chtype, int);
int idcok(WINDOW *, bool);
int idlok(WINDOW *, bool);
int init_color(short, short, short, short);
int init_pair(short, short, short);
WINDOW *initscr(void);
int intrflush(WINDOW *, bool);
bool isendwin(void);
bool is_linetouched(WINDOW *, int);
bool is_wintouched(WINDOW *);
int keyok(int, bool);
int keypad(WINDOW *, bool);
char *keyname(int);
char killchar(void);
int leaveok(WINDOW *, bool);
char *longname(void);
int meta(WINDOW *, bool);
int mvcur(int, int, int, int);
int mvderwin(WINDOW *, int, int);
int mvhline(int, int, chtype, int);
int mvprintw(int, int, const char *, ...) __printflike(3, 4);
int mvscanw(int, int, const char *, ...) __scanflike(3, 4);
int mvvline(int, int, chtype, int);
int mvwhline(WINDOW *, int, int, chtype, int);
int mvwvline(WINDOW *, int, int, chtype, int);
int mvwin(WINDOW *, int, int);
int mvwinchnstr(WINDOW *, int, int, chtype *, int);
int mvwinchstr(WINDOW *, int, int, chtype *);
int mvwinnstr(WINDOW *, int, int, char *, int);
int mvwinstr(WINDOW *, int, int, char *);
int mvwprintw(WINDOW *, int, int, const char *, ...) __printflike(4, 5);
int mvwscanw(WINDOW *, int, int, const char *, ...) __scanflike(4, 5);
int napms(int);
WINDOW *newpad(int, int);
SCREEN *newterm(char *, FILE *, FILE *);
WINDOW *newwin(int, int, int, int);
int nl(void);
attr_t no_color_attributes(void);
int nocbreak(void);
int nodelay(WINDOW *, bool);
int noecho(void);
int nonl(void);
void noqiflush(void);
int noraw(void);
int notimeout(WINDOW *, bool);
int overlay(const WINDOW *, WINDOW *);
int overwrite(const WINDOW *, WINDOW *);
int pair_content(short, short *, short *);
int pechochar(WINDOW *, const chtype);
int pnoutrefresh(WINDOW *, int, int, int, int, int, int);
int prefresh(WINDOW *, int, int, int, int, int, int);
int printw(const char *, ...) __printflike(1, 2);
int putwin(WINDOW *, FILE *);
void qiflush(void);
int raw(void);
int redrawwin(WINDOW *);
int reset_prog_mode(void);
int reset_shell_mode(void);
int resetty(void);
int resizeterm(int, int);
int savetty(void);
int scanw(const char *, ...) __scanflike(1, 2);
int scroll(WINDOW *);
int scrollok(WINDOW *, bool);
int setterm(char *);
SCREEN *set_term(SCREEN *);
int start_color(void);
WINDOW *subpad(WINDOW *, int, int, int, int);
WINDOW *subwin(WINDOW *, int, int, int, int);
chtype termattrs(void);
attr_t term_attrs(void);
int touchline(WINDOW *, int, int);
int touchoverlap(WINDOW *, WINDOW *);
int touchwin(WINDOW *);
int ungetch(int);
int untouchwin(WINDOW *);
int use_default_colors(void);
int vline(chtype, int);
int vw_printw(WINDOW *, const char *, _BSD_VA_LIST_) __printflike(2, 0);
int vw_scanw(WINDOW *, const char *, _BSD_VA_LIST_) __scanflike(2, 0);
int vwprintw(WINDOW *, const char *, _BSD_VA_LIST_) __printflike(2, 0);
int vwscanw(WINDOW *, const char *, _BSD_VA_LIST_) __scanflike(2, 0);
int waddch(WINDOW *, chtype);
int waddchnstr(WINDOW *, const chtype *, int);
int waddchstr(WINDOW *, const chtype *);
int waddnstr(WINDOW *, const char *, int);
int wattr_get(WINDOW *, attr_t *, short *, void *);
int wattr_off(WINDOW *, attr_t, void *);
int wattr_on(WINDOW *, attr_t, void *);
int wattr_set(WINDOW *, attr_t, short, void *);
int wattroff(WINDOW *, int);
int wattron(WINDOW *, int);
int wattrset(WINDOW *, int);
int wbkgd(WINDOW *, chtype);
void wbkgdset(WINDOW *, chtype);
int wborder(WINDOW *, chtype, chtype, chtype, chtype, chtype, chtype,
chtype, chtype);
int wclear(WINDOW *);
int wclrtobot(WINDOW *);
int wclrtoeol(WINDOW *);
int wcolor_set(WINDOW *, short, void *);
void wcursyncup(WINDOW *);
int wdelch(WINDOW *);
int wdeleteln(WINDOW *);
int wechochar(WINDOW *, const chtype);
int werase(WINDOW *);
int wgetch(WINDOW *);
int wgetnstr(WINDOW *, char *, int);
int wgetstr(WINDOW *, char *);
int whline(WINDOW *, chtype, int);
chtype winch(WINDOW *);
int winchnstr(WINDOW *, chtype *, int);
int winchstr(WINDOW *, chtype *);
int winnstr(WINDOW *, char *, int);
int winsch(WINDOW *, chtype);
int winsdelln(WINDOW *, int);
int winsertln(WINDOW *);
int winstr(WINDOW *, char *);
int wmove(WINDOW *, int, int);
int wnoutrefresh(WINDOW *);
int wprintw(WINDOW *, const char *, ...) __printflike(2, 3);
int wredrawln(WINDOW *, int, int);
int wrefresh(WINDOW *);
int wresize(WINDOW *, int, int);
int wscanw(WINDOW *, const char *, ...) __scanflike(2, 3);
int wscrl(WINDOW *, int);
int wsetscrreg(WINDOW *, int, int);
int wstandend(WINDOW *);
int wstandout(WINDOW *);
void wsyncdown(WINDOW *);
void wsyncup(WINDOW *);
void wtimeout(WINDOW *, int);
int wtouchln(WINDOW *, int, int, int);
int wunderend(WINDOW *);
int wunderscore(WINDOW *);
int wvline(WINDOW *, chtype, int);
int insnstr(const char *, int);
int insstr(const char *);
int mvinsnstr(int, int, const char *, int);
int mvinsstr(int, int, const char *);
int mvwinsnstr(WINDOW *, int, int, const char *, int);
int mvwinsstr(WINDOW *, int, int, const char *);
int winsnstr(WINDOW *, const char *, int);
int winsstr(WINDOW *, const char *);
int chgat(int, attr_t, short, const void *);
int wchgat(WINDOW *, int, attr_t, short, const void *);
int mvchgat(int, int, int, attr_t, short, const void *);
int mvwchgat(WINDOW *, int, int, int, attr_t, short, const void *);
/* wide-character support routines */
/* return ERR when HAVE_WCHAR is not defined */
/* add */
int add_wch(const cchar_t *);
int wadd_wch(WINDOW *, const cchar_t *);
int mvadd_wch(int, int, const cchar_t *);
int mvwadd_wch(WINDOW *, int, int, const cchar_t *);
int add_wchnstr(const cchar_t *, int);
int add_wchstr(const cchar_t *);
int wadd_wchnstr(WINDOW *, const cchar_t *, int);
int wadd_wchstr(WINDOW *, const cchar_t *);
int mvadd_wchnstr(int, int, const cchar_t *, int);
int mvadd_wchstr(int, int, const cchar_t *);
int mvwadd_wchnstr(WINDOW *, int, int, const cchar_t *, int);
int mvwadd_wchstr(WINDOW *, int, int, const cchar_t *);
int addnwstr(const wchar_t *, int);
int addwstr(const wchar_t *);
int mvaddnwstr(int, int x, const wchar_t *, int);
int mvaddwstr(int, int x, const wchar_t *);
int mvwaddnwstr(WINDOW *, int, int, const wchar_t *, int);
int mvwaddwstr(WINDOW *, int, int, const wchar_t *);
int waddnwstr(WINDOW *, const wchar_t *, int);
int waddwstr(WINDOW *, const wchar_t *);
int echo_wchar(const cchar_t *);
int wecho_wchar(WINDOW *, const cchar_t *);
int pecho_wchar(WINDOW *, const cchar_t *);
/* insert */
int ins_wch(const cchar_t *);
int wins_wch(WINDOW *, const cchar_t *);
int mvins_wch(int, int, const cchar_t *);
int mvwins_wch(WINDOW *, int, int, const cchar_t *);
int ins_nwstr(const wchar_t *, int);
int ins_wstr(const wchar_t *);
int mvins_nwstr(int, int, const wchar_t *, int);
int mvins_wstr(int, int, const wchar_t *);
int mvwins_nwstr(WINDOW *, int, int, const wchar_t *, int);
int mvwins_wstr(WINDOW *, int, int, const wchar_t *);
int wins_nwstr(WINDOW *, const wchar_t *, int);
int wins_wstr(WINDOW *, const wchar_t *);
/* input */
int get_wch(wint_t *);
int unget_wch(const wchar_t);
int mvget_wch(int, int, wint_t *);
int mvwget_wch(WINDOW *, int, int, wint_t *);
int wget_wch(WINDOW *, wint_t *);
int getn_wstr(wchar_t *, int);
int get_wstr(wchar_t *);
int mvgetn_wstr(int, int, wchar_t *, int);
int mvget_wstr(int, int, wchar_t *);
int mvwgetn_wstr(WINDOW *, int, int, wchar_t *, int);
int mvwget_wstr(WINDOW *, int, int, wchar_t *);
int wgetn_wstr(WINDOW *, wchar_t *, int);
int wget_wstr(WINDOW *, wchar_t *);
int in_wch(cchar_t *);
int mvin_wch(int, int, cchar_t *);
int mvwin_wch(WINDOW *, int, int, cchar_t *);
int win_wch(WINDOW *, cchar_t *);
int in_wchnstr(cchar_t *, int);
int in_wchstr(cchar_t *);
int mvin_wchnstr(int, int, cchar_t *, int);
int mvin_wchstr(int, int, cchar_t *);
int mvwin_wchnstr(WINDOW *, int, int, cchar_t *, int);
int mvwin_wchstr(WINDOW *, int, int, cchar_t *);
int win_wchnstr(WINDOW *, cchar_t *, int);
int win_wchstr(WINDOW *, cchar_t *);
int innwstr(wchar_t *, int);
int inwstr(wchar_t *);
int mvinnwstr(int, int, wchar_t *, int);
int mvinwstr(int, int, wchar_t *);
int mvwinnwstr(WINDOW *, int, int, wchar_t *, int);
int mvwinwstr(WINDOW *, int, int, wchar_t *);
int winnwstr(WINDOW *, wchar_t *, int);
int winwstr(WINDOW *, wchar_t *);
/* cchar handlgin */
int setcchar(cchar_t *, const wchar_t *, const attr_t, short, const void *);
int getcchar(const cchar_t *, wchar_t *, attr_t *, short *, void *);
/* misc */
char *key_name( wchar_t );
int border_set(const cchar_t *, const cchar_t *, const cchar_t *,
const cchar_t *, const cchar_t *, const cchar_t *,
const cchar_t *, const cchar_t *);
int wborder_set(WINDOW *, const cchar_t *, const cchar_t *,
const cchar_t *, const cchar_t *, const cchar_t *,
const cchar_t *, const cchar_t *, const cchar_t *);
int box_set(WINDOW *, const cchar_t *, const cchar_t *);
int erasewchar(wchar_t *);
int killwchar(wchar_t *);
int hline_set(const cchar_t *, int);
int mvhline_set(int, int, const cchar_t *, int);
int mvvline_set(int, int, const cchar_t *, int);
int mvwhline_set(WINDOW *, int, int, const cchar_t *, int);
int mvwvline_set(WINDOW *, int, int, const cchar_t *, int);
int vline_set(const cchar_t *, int);
int whline_set(WINDOW *, const cchar_t *, int);
int wvline_set(WINDOW *, const cchar_t *, int);
int bkgrnd(const cchar_t *);
void bkgrndset(const cchar_t *);
int getbkgrnd(cchar_t *);
int wbkgrnd(WINDOW *, const cchar_t *);
void wbkgrndset(WINDOW *, const cchar_t *);
int wgetbkgrnd(WINDOW *, cchar_t *);
/* Private functions that are needed for user programs prototypes. */
int __cputchar(int);
int __waddbytes(WINDOW *, const char *, int, attr_t);
#ifdef HAVE_WCHAR
int __cputwchar( wchar_t );
#endif /* HAVE_WCHAR */
__END_DECLS
#endif /* !_CURSES_H_ */

View file

@ -0,0 +1,187 @@
.\" $NetBSD: curses_addch.3,v 1.8 2007/07/15 21:37:55 wiz Exp $
.\"
.\" Copyright (c) 2002
.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au)
.\"
.\" This code is 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. 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. 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.
.\"
.\"
.Dd July 11, 2007
.Dt CURSES_ADDCH 3
.Os
.Sh NAME
.Nm curses_addch ,
.Nm addch ,
.Nm waddch ,
.Nm mvaddch ,
.Nm mvwaddch
.Nd curses add characters to windows routines
.Sh LIBRARY
.Lb libcurses
.Sh SYNOPSIS
.In curses.h
.Ft int
.Fn addch "chtype ch"
.Ft int
.Fn waddch "WINDOW *win" "chtype ch"
.Ft int
.Fn mvaddch "int y" "int x" "chtype ch"
.Ft int
.Fn mvwaddch "WINDOW *win" "int y" "int x" "chtype ch"
.Sh DESCRIPTION
These functions add characters to
.Dv stdscr
or to the specified window.
.Pp
The
.Fn addch
function adds the character given in
.Fa ch
to
.Dv stdscr
at the current cursor position and advances the current cursor position by one.
Any character attributes set in
.Fa ch
will be merged with the background attributes currently set on
.Dv stdscr .
.Pp
The
.Fn waddch
function is the same as the
.Fn addch
function, excepting that the character is added to the window specified by
.Fa win .
.Pp
The
.Fn mvaddch
and
.Fn mvwaddch
functions are the same as the
.Fn addch
and
.Fn waddch
functions, respectively, excepting that
.Fn wmove
is called to move the cursor to the position specified by
.Fa y ,
.Fa x
before the character is added to the window.
.Ss LINE DRAWING CHARACTERS
Some terminals support the display of line drawing and graphics characters.
These characters can be added using their defined names, as shown in the
table below.
Where the terminal does not support a specific character, the default
(non-graphics) character is displayed instead.
.Bl -column -offset indent ".Sy System V Name" ".Sy Default"
.It Sy "Name" Ta Sy "Default" Ta Sy "Description"
.It ACS_RARROW Ta \*[Gt] Ta "Arrow pointing right"
.It ACS_LARROW Ta \*[Lt] Ta "Arrow pointing left"
.It ACS_UARROW Ta ^ Ta "Arrow pointing up"
.It ACS_DARROW Ta v Ta "Arrow pointing down"
.It ACS_BLOCK Ta # Ta "Solid square block"
.It ACS_DIAMOND Ta + Ta "Diamond"
.It ACS_CKBOARD Ta : Ta "Checker board (stipple)"
.It ACS_DEGREE Ta ' Ta "Degree symbol"
.It ACS_PLMINUS Ta # Ta "Plus/minus"
.It ACS_BOARD Ta # Ta "Board of squares"
.It ACS_LANTERN Ta # Ta "Lantern symbol"
.It ACS_LRCORNER Ta + Ta "Lower right-hand corner"
.It ACS_URCORNER Ta + Ta "Upper right-hand corner"
.It ACS_ULCORNER Ta + Ta "Upper left-hand corner"
.It ACS_LLCORNER Ta + Ta "Lower left-hand corner"
.It ACS_PLUS Ta + Ta "Plus"
.It ACS_HLINE Ta - Ta "Horizontal line"
.It ACS_S1 Ta - Ta "Scan line 1"
.It ACS_S9 Ta - Ta "Scan line 9"
.It ACS_LTEE Ta + Ta "Left tee"
.It ACS_RTEE Ta + Ta "Right tee"
.It ACS_BTEE Ta + Ta "Bottom tee"
.It ACS_TTEE Ta + Ta "Top tee"
.It ACS_VLINE Ta | Ta "Vertical line"
.It ACS_BULLET Ta o Ta "Bullet"
.El
.Pp
The following additional,
.Em ncurses
compatible, characters are also supported.
.Bl -column -offset indent ".Sy System V Name" ".Sy Default"
.It Sy "Name" Ta Sy "Default" Ta Sy "Description"
.It ACS_S3 Ta - Ta "Scan line 3"
.It ACS_S7 Ta - Ta "Scan line 7"
.It ACS_LEQUAL Ta \*[Lt] Ta "Less than or equal to"
.It ACS_GEQUAL Ta \*[Gt] Ta "Greater than or equal to"
.It ACS_PI Ta * Ta "Pi symbol"
.It ACS_NEQUAL Ta ! Ta "Not equal to"
.It ACS_STERLING Ta f Ta "Sterling symbol"
.El
.Pp
For compatibility with some
.Em System V
implementations, the following definitions are also supported.
.Bl -column -offset indent ".Sy System V Name" ".Sy Default"
.It Sy "System V Name" Ta Sy "NetBSD Curses Name"
.It ACS_SBBS Ta ACS_LRCORNER
.It ACS_BBSS Ta ACS_URCORNER
.It ACS_BSSB Ta ACS_ULCORNER
.It ACS_SSBB Ta ACS_LLCORNER
.It ACS_SSSS Ta ACS_PLUS
.It ACS_BSBS Ta ACS_HLINE
.It ACS_SSSB Ta ACS_LTEE
.It ACS_SBSS Ta ACS_RTEE
.It ACS_SSBS Ta ACS_BTEE
.It ACS_BSSS Ta ACS_TTEE
.It ACS_SBSB Ta ACS_VLINE
.El
.Sh RETURN VALUES
Functions returning pointers will return
.Dv NULL
if an error is detected.
The functions that return an int will return one of the following
values:
.Pp
.Bl -tag -width ERR -compact
.It Er OK
The function completed successfully.
.It Er ERR
An error occurred in the function.
.El
.Sh SEE ALSO
.Xr curses_addchstr 3 ,
.Xr curses_addstr 3 ,
.Xr curses_attributes 3 ,
.Xr curses_cursor 3 ,
.Xr curses_delch 3 ,
.Xr curses_inch 3 ,
.Xr curses_insertch 3
.Sh STANDARDS
The
.Nx
Curses library complies with the X/Open Curses specification, part of the
Single Unix Specification.
.Sh HISTORY
The Curses package appeared in
.Bx 4.0 .

View file

@ -0,0 +1,155 @@
.\" $NetBSD: curses_addchstr.3,v 1.3 2008/04/30 13:10:51 martin Exp $
.\"
.\" Copyright (c) 2003
.\" Douwe Kiela (virtus@wanadoo.nl)
.\" 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.
.\"
.\"
.Dd May 21, 2003
.Dt CURSES_ADDCHSTR 3
.Os
.Sh NAME
.Nm curses_addchstr ,
.Nm addchstr ,
.Nm waddchstr ,
.Nm addchnstr ,
.Nm waddchnstr ,
.Nm mvaddchstr ,
.Nm mvwaddchstr ,
.Nm mvaddchnstr ,
.Nm mvwaddchnstr
.Nd curses add character strings to windows routines
.Sh LIBRARY
.Lb libcurses
.Sh SYNOPSIS
.In curses.h
.Ft int
.Fn addchstr "const chtype *chstr"
.Ft int
.Fn waddchstr "WINDOW *win" "const chtype *chstr"
.Ft int
.Fn mvaddchstr "int y" "int x" "const chtype *chstr"
.Ft int
.Fn mvwaddchstr "WINDOW *win" "int y" "int x" "const chtype *chstr"
.Ft int
.Fn addchnstr "const chtype *chstr" "int n"
.Ft int
.Fn waddchnstr "WINDOW *win" "const chtype *chstr" "int n"
.Ft int
.Fn mvaddchnstr "int y" "int x" "const chtype *chstr" "int n"
.Ft int
.Fn mvwaddchnstr "WINDOW *win" "int y" "int x" "const chtype *chstr" "int n"
.Sh DESCRIPTION
These functions add character strings and attributes to
.Dv stdscr
or to the specified window.
.Pp
The
.Fn addchstr
function will add the characters and their attributes passed in
.Fa chstr
to
.Dv stdscr
starting at the current cursor position.
Any character attributes set in
.Fa chstr
will be merged with the background attributes currently set on
.Dv stdscr .
The
.Fn waddstr
function does the same as
.Fn addchstr
but adds the string to the window specified by
.Fn win .
.Pp
The
.Fn addchnstr
function will add the contents of
.Fa string
to
.Dv stdscr
but will limit the number of characters added to be, at most,
.Fa n .
If
.Fa n
is \-1 then
.Fa addchnstr
will add the number of characters contained in the null terminated string
.Fa chstr .
Any character attributes set in
.Fa chstr
will be merged with the background attributes currently set on
.Dv stdscr .
.Pp
The
.Fn waddchnstr
function does the same as
.Fa addchnstr
but adds the string to the window specified by
.Fa win .
.Pp
The functions
.Fn mvaddchstr ,
.Fn mwaddchnstr ,
.Fn mvwaddchstr
and
.Fn mvwaddchnstr
are the same as the functions
.Fn addchstr ,
.Fn waddchstr ,
.Fn waddchstr
and
.Fn waddchnstr ,
respectively, except that
.Fn wmove
is called to move the cursor to the position specified by
.Fa y ,
.Fa x
before the string is added to the window.
.Sh RETURN VALUES
The functions will return one of the following values:
.Pp
.Bl -tag -width ERR -compact
.It Er OK
The function completed successfully.
.It Er ERR
An error occurred in the function.
.El
.Sh SEE ALSO
.Xr curses_addch 3 ,
.Xr curses_addstr 3 ,
.Xr curses_attributes 3 ,
.Xr curses_cursor 3 ,
.Xr curses_inch 3
.Sh STANDARDS
The
.Nx
Curses library complies with the X/Open Curses specification, part of the
Single Unix Specification.
.Sh HISTORY
These functions first appeared in
.Nx 2.0 .

View file

@ -0,0 +1,159 @@
.\" $NetBSD: curses_addstr.3,v 1.4 2003/05/21 21:22:15 jdc Exp $
.\"
.\" Copyright (c) 2002
.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au)
.\"
.\" This code is 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. 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. 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.
.\"
.\"
.Dd May 21, 2003
.Dt CURSES_ADDSTR 3
.Os
.Sh NAME
.Nm curses_addstr ,
.Nm addstr ,
.Nm waddstr ,
.Nm addnstr ,
.Nm waddnstr ,
.Nm mvaddstr ,
.Nm mvwaddstr ,
.Nm mvaddnstr ,
.Nm mvwaddnstr
.Nd curses add character strings to windows routines
.Sh LIBRARY
.Lb libcurses
.Sh SYNOPSIS
.In curses.h
.Ft int
.Fn addstr "const char *string"
.Ft int
.Fn waddstr "WINDOW *win" "const char *string"
.Ft int
.Fn mvaddstr "int y" "int x" "const char *string"
.Ft int
.Fn mvwaddstr "WINDOW *win" "int y" "int x" "const char *string"
.Ft int
.Fn addnstr "const char *string" "int len"
.Ft int
.Fn waddnstr "WINDOW *win" "const char *string" "int len"
.Ft int
.Fn mvaddnstr "int y" "int x" "const char *string" "int len"
.Ft int
.Fn mvwaddnstr "WINDOW *win" "int y" "int x" "const char *string" "int len"
.Sh DESCRIPTION
These functions add character strings to
.Dv stdscr
or to the specified window.
.Pp
The
.Fn addstr
function
will add the characters passed in
.Fa string
to
.Dv stdscr
starting at the current cursor position.
Any background attributes currently set on
.Dv stdscr
will be applied to the added character.
The
.Fn waddstr
function does the same as
.Fn addstr
but adds the string to the window specified by
.Fn win .
.Pp
The
.Fn addnstr
function will add the contents of
.Fa string
to
.Dv stdscr
but will limit the number of characters added to be, at most,
.Fa len .
If
.Fa len
is \-1 then
.Fa addnstr
will add the number of characters contained in the null terminated string
.Fa string .
Any background attributes currently set on
.Dv stdscr
will be applied to the added character.
The
.Fn waddnstr
function
does the same as
.Fa addnstr
but adds the string to the window specified by
.Fa win .
.Pp
The functions
.Fn mvaddstr ,
.Fn mwaddnstr ,
.Fn mvwaddstr
and
.Fn mvwaddnstr
are the same as the functions
.Fn addstr ,
.Fn waddstr ,
.Fn waddstr
and
.Fn waddnstr ,
respectively, excepting that
.Fn wmove
is called to move the cursor to the position specified by
.Fa y ,
.Fa x
before the string is added to the window.
.Sh RETURN VALUES
Functions returning pointers will return
.Dv NULL
if an error is detected.
The functions that return an int will return one of the following
values:
.Pp
.Bl -tag -width ERR -compact
.It Er OK
The function completed successfully.
.It Er ERR
An error occurred in the function.
.El
.Sh SEE ALSO
.Xr curses_addch 3 ,
.Xr curses_addchstr 3 ,
.Xr curses_attributes 3 ,
.Xr curses_cursor 3 ,
.Xr curses_inch 3
.Sh STANDARDS
The
.Nx
Curses library complies with the X/Open Curses specification, part of the
Single Unix Specification.
.Sh HISTORY
The Curses package appeared in
.Bx 4.0 .

View file

@ -0,0 +1,342 @@
.\" $NetBSD: curses_attributes.3,v 1.8 2008/04/30 13:10:51 martin Exp $
.\" Copyright (c) 2002 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.
.\"
.Dd March 14, 2008
.Dt CURSES_ATTRIBUTES 3
.Os
.Sh NAME
.Nm curses_attributes ,
.Nm attron ,
.Nm attroff ,
.Nm attrset ,
.Nm color_set ,
.Nm getattrs ,
.Nm termattrs ,
.Nm wattron ,
.Nm wattroff ,
.Nm wattrset ,
.Nm wcolor_set ,
.Nm attr_on ,
.Nm attr_off ,
.Nm attr_set ,
.Nm attr_get ,
.Nm term_attrs ,
.Nm wattr_on ,
.Nm wattr_off ,
.Nm wattr_set ,
.Nm wattr_get
.Nd curses general attribute manipulation routines
.Sh LIBRARY
.Lb libcurses
.Sh SYNOPSIS
.In curses.h
.Ft int
.Fn attron "int attr"
.Ft int
.Fn attroff "int attr"
.Ft int
.Fn attrset "int attr"
.Ft int
.Fn color_set "short pair" "void *opt"
.Ft chtype
.Fn getattrs "WINDOW *win"
.Ft chtype
.Fn termattrs "void"
.Ft int
.Fn wcolor_set "WINDOW *win" "short pair" "void *opt"
.Ft int
.Fn wattron "WINDOW * win" "int attr"
.Ft int
.Fn wattroff "WINDOW * win" "int attr"
.Ft int
.Fn wattrset "WINDOW * win" "int attr"
.Ft int
.Fn attr_on "attr_t attr" "void *opt"
.Ft int
.Fn attr_off "attr_t attr" "void *opt"
.Ft int
.Fn attr_set "attr_t attr" "short pair" "void *opt"
.Ft int
.Fn attr_get "attr_t *attr" "short *pair" "void *opt"
.Ft attr_t
.Fn term_attrs "void"
.Ft int
.Fn wattr_on "WINDOW *win" "attr_t attr" "void *opt"
.Ft int
.Fn wattr_off "WINDOW *win" "attr_t attr" "void *opt"
.Ft int
.Fn wattr_set "WINDOW *win" "attr_t attr" "short pair" "void *opt"
.Ft int
.Fn wattr_get "WINDOW *win" "attr_t *attr" "short *pair" "void *opt"
.Sh DESCRIPTION
These functions manipulate attributes on
.Dv stdscr
or on the specified window.
The attributes that can be manipulated are:
.Pp
.Bl -tag -width "COLOR_PAIR(n)" -compact -offset indent
.It A_NORMAL
no special attributes are applied
.It A_STANDOUT
characters are displayed in standout mode
.It A_UNDERLINE
characters are displayed underlined
.It A_REVERSE
characters are displayed in inverse video
.It A_BLINK
characters blink
.It A_DIM
characters are displayed at a lower intensity
.It A_BOLD
characters are displayed at a higher intensity
.It A_INVIS
characters are added invisibly
.It A_PROTECT
characters are protected from modification
.It A_ALTCHARSET
characters are displayed using the alternate character set (ACS)
.It COLOR_PAIR(n)
characters are displayed using color pair n.
.El
.Pp
The
.Fn attron
function turns on the attributes specified in
.Fa attr
on
.Dv stdscr ,
while the
.Fn attroff
function turns off the attributes specified in
.Fa attr
on
.Dv stdscr .
.Pp
The function
.Fn attrset
sets the attributes of
.Dv stdscr
to those specified in
.Fa attr ,
turning off any others.
To turn off all the attributes (including color and alternate character set),
use
.Fn attrset A_NORMAL .
.Pp
Multiple attributes can be manipulated by combining the attributes
using a logical
.Em OR .
For example,
.Fn attron "A_REVERSE | A_BOLD"
will turn on both inverse video and higher intensity.
.Pp
The function
.Fn color_set
sets the color pair attribute to the pair specified in
.Fa pair .
.Pp
The function
.Fn getattrs
returns the attributes that are currently applied to window specified by
.Fa win .
.Pp
The function
.Fn termattrs
returns the logical
.Em OR
of attributes that can be applied to the screen.
.Pp
The functions
.Fn wattron ,
.Fn wattroff ,
.Fn wattrset ,
and
.Fn wcolor_set
are equivalent to
.Fn attron ,
.Fn attroff
.Fn attrset ,
and
.Fn color_set
respectively, excepting that the attributes are applied to the window
specified by
.Fa win .
.Pp
The following functions additionally manipulate wide attributes on
.Dv stdscr
or on the specified window.
The additional wide attributes that can be manipulated are:
.Pp
.Bl -tag -width "COLOR_PAIR(n)" -compact -offset indent
.It WA_STANDOUT
characters are displayed in standout mode
.It WA_UNDERLINE
characters are displayed underlined
.It WA_REVERSE
characters are displayed in inverse video
.It WA_BLINK
characters blink
.It WA_DIM
characters are displayed at a lower intensity
.It WA_BOLD
characters are displayed at a higher intensity
.It WA_INVIS
characters are added invisibly
.It WA_PROTECT
characters are protected from modification
.It WA_ALTCHARSET
characters are displayed using the alternate character set (ACS)
.It WA_LOW
characters are displayed with low highlight
.It WA_TOP
characters are displayed with top highlight
.It WA_HORIZONTAL
characters are displayed with horizontal highlight
.It WA_VERTICAL
characters are displayed with vertical highlight
.It WA_LEFT
characters are displayed with left highlight
.It WA_RIGHT
characters are displayed with right highlight
.El
.Pp
The
.Fn attr_on
function turns on the wide attributes specified in
.Fa attr
on
.Dv stdscr ,
while the
.Fn attr_off
function turns off the wide attributes specified in
.Fa attr
on
.Dv stdscr .
.Pp
The function
.Fn attr_set
sets the wide attributes of
.Dv stdscr
to those specified in
.Fa attr
and
.Fa pair ,
turning off any others.
Note that a color pair specified in
.Fa pair
will override any color pair specified in
.Fa attr .
.Pp
The function
.Fn attr_get
sets
.Fa attr
to the wide attributes and
.Fa pair
to the color pair currently applied to
.Dv stdscr .
Either of
.Fa attr
and
.Fa pair
can be
.Dv NULL ,
if the relevant value is of no interest.
.Pp
The function
.Fn term_attrs
returns the logical
.Em OR
of wide attributes that can be applied to the screen.
.Pp
The functions
.Fn wattr_on ,
.Fn wattr_off
and
.Fn wattr_set
are equivalent to
.Fn attr_on ,
.Fn attr_off
and
.Fn attr_set
respectively, excepting that the character is added to the window specified by
.Fa win .
.Pp
The function
.Fn wattr_get
is equivalent to
.Fn attr_get ,
excepting that the wide attributes and color pair currently applied to
.Fa win
are set.
.Pp
The following constants can be used to extract the components of a
.Dv chtype :
.Pp
.Bl -tag -width "COLOR_PAIR(n)" -compact -offset indent
.It A_ATTRIBUTES
bit-mask containing attributes part
.It A_CHARTEXT
bit-mask containing character part
.It A_COLOR
bit-mask containing color-pair part
.El
.Sh RETURN VALUES
These functions return OK on success and ERR on failure.
.Sh SEE ALSO
.Xr curses_addch 3 ,
.Xr curses_addchstr 3 ,
.Xr curses_addstr 3 ,
.Xr curses_background 3 ,
.Xr curses_color 3 ,
.Xr curses_insertch 3 ,
.Xr curses_standout 3 ,
.Xr curses_underscore 3
.Sh NOTES
The
.Fa opt
argument is not currently used but is reserved for a future version of the
specification.
.Sh STANDARDS
The
.Nx
Curses library complies with the X/Open Curses specification, part of the
Single Unix Specification.
.Pp
The
.Fn getattrs
function
is a
.Nx
extension.
.Sh HISTORY
These functions first appeared in
.Nx 1.5 .
.Sh BUGS
Some terminals do not support characters with both color and other attributes
set.
In this case, the other attribute is displayed instead of the color attribute.

View file

@ -0,0 +1,124 @@
.\" $NetBSD: curses_background.3,v 1.6 2008/04/30 13:10:51 martin Exp $
.\" Copyright (c) 2002 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.
.\"
.Dd January 15, 2006
.Dt CURSES_BACKGROUND 3
.Os
.Sh NAME
.Nm curses_background ,
.Nm bkgd ,
.Nm bkgdset ,
.Nm getbkgd ,
.Nm wbkgd ,
.Nm wbkgdset
.Nd curses attribute manipulation routines
.Sh LIBRARY
.Lb libcurses
.Sh SYNOPSIS
.In curses.h
.Ft int
.Fn bkgd chtype
.Ft int
.Fn bkgdset chtype
.Ft chtype
.Fn getbkgd "WINDOW *"
.Ft int
.Fn wbkgd chtype
.Ft int
.Fn wbkgdset chtype
.Sh DESCRIPTION
These functions manipulate the background attributes on
.Dv stdscr
or on the specified window.
.Pp
The function
.Fn wbkgdset win ch
sets the background attributes of the specified window
.Fa win
to
.Fa ch .
.Pp
When the background attributes are set on a window, characters are added to
the window with the logical
.Em OR
of the background attributes and the character's attributes.
If both the background attribute and the character attribute contain color,
the color of the character attribute is rendered.
If the background attribute contains a non-space character, then this
character is added where the foreground character is a space character.
.Pp
Note that subwindows created from
.Fa win
inherit the background attributes of
.Fa win .
.Pp
The function
.Fn wbkgd win ch
sets the background attributes of the specified window
.Fa win
to
.Fa ch
and also sets the rendition of every character position on that window,
as if the characters had been newly added to
.Fa win .
The rendition of characters on subwindows of
.Fa win
is also set to
.Fa ch .
.Pp
The functions
.Fn bkgdset ch
and
.Fn bkgd ch
are equivalent to
.Fn wbkgdset stdscr ch
and
.Fn wbkgd stdscr ch ,
respectively.
.Pp
The function
.Fn getbkgd win
returns the background attributes for the window
.Fa win .
.Sh RETURN VALUES
The functions
.Fn wbkgdset
and
.Fn wbkgd
return OK on success and ERR on failure.
.Sh SEE ALSO
.Xr curses_attributes 3 ,
.Xr curses_color 3 ,
.Xr curses_window 3
.Sh STANDARDS
The
.Nx
Curses library complies with the X/Open Curses specification, part of the
Single Unix Specification.
.Sh HISTORY
These functions first appeared in
.Nx 1.6 .

View file

@ -0,0 +1,159 @@
.\" $NetBSD: curses_border.3,v 1.4 2004/03/16 19:20:20 snj Exp $
.\"
.\" Copyright (c) 2002
.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au)
.\"
.\" This code is 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. 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. 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.
.\"
.\"
.Dd August 12, 2002
.Dt CURSES_BORDER 3
.Os
.Sh NAME
.Nm curses_border ,
.Nm border ,
.Nm box ,
.Nm wborder
.Nd curses border drawing routines
.Sh LIBRARY
.Lb libcurses
.Sh SYNOPSIS
.In curses.h
.Ft int
.Fo border
.Fa "chtype ls"
.Fa "chtype rs"
.Fa "chtype ts"
.Fa "chtype bs"
.Fa "chtype tl"
.Fa "chtype tr"
.Fa "chtype bl"
.Fa "chtype br"
.Fc
.Ft int
.Fn box "WINDOW *win" "chtype vertical" "chtype horizontal"
.Ft int
.Fo wborder
.Fa "WINDOW *win"
.Fa "chtype ls"
.Fa "chtype rs"
.Fa "chtype ts"
.Fa "chtype bs"
.Fa "chtype tl"
.Fa "chtype tr"
.Fa "chtype bl"
.Fa "chtype br"
.Fc
.Sh DESCRIPTION
These functions draw borders around
.Dv stdscr
or around the specified window.
.Pp
The
.Fn border
function draws a border around
.Dv stdscr
using the characters given as arguments to the function.
The
.Fa ls ,
.Fa rs ,
.Fa ts
and
.Fa bs
are the characters used to draw the left, right, top and bottom sides,
respectively.
The
.Fa tl ,
.Fa tr ,
.Fa bl
and
.Fa br
are the characters used to draw the top-left, top-right, bottom-left
and bottom-right corners, respectively.
If any of the characters have a text portion that is 0 then a default
alternate character set character is used for that character.
Note that even though the text portion of the argument is 0, the argument
can still be used to specify the attributes for that portion of the border.
The following table shows the default characters for each argument:
.Pp
.Bl -column "ls" -offset indent
.It ls ACS_VLINE
.It rs ACS_VLINE
.It ts ACS_HLINE
.It bs ACS_HLINE
.It tl ACS_ULCORNER
.It tr ACS_URCORNER
.It bl ACS_LLCORNER
.It br ACS_LRCORNER
.El
.Pp
.Fn wborder
is the same as
.Fn border
excepting that the border is drawn around the specified window.
.Pp
The
.Fn box
command draws a box around the window given in
.Fa win
using the
.Fa vertical
character for the vertical lines and the
.Fa horizontal
character for the horizontal lines.
The corner characters of this box will be the defaults as described for
.Fn border
above.
Passing characters with text portion that is 0 to
.Fn box
will result in the same defaults as those for
.Fn border
as described above.
.Sh RETURN VALUES
Functions returning pointers will return
.Dv NULL
if an error is detected.
The functions that return an int will return one of the following
values:
.Pp
.Bl -tag -width ERR -compact
.It Er OK
The function completed successfully.
.It Er ERR
An error occurred in the function.
.El
.Sh SEE ALSO
.Xr curses_attributes 3 ,
.Xr curses_line 3
.Sh STANDARDS
The
.Nx
Curses library complies with the X/Open Curses specification, part of the
Single Unix Specification.
.Sh HISTORY
The Curses package appeared in
.Bx 4.0 .

View file

@ -0,0 +1,119 @@
.\" $NetBSD: curses_chgat.3,v 1.4 2009/07/12 23:14:06 wiz 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.
.\"
.Dd July 6, 2009
.Dt CURSES_CHGAT 3
.Os
.Sh NAME
.Nm chgat ,
.Nm wchgat ,
.Nm mvchgat ,
.Nm mvwchgat
.Nd curses on-screen attribute manipulation routines
.Sh LIBRARY
.Lb libcurses
.Sh SYNOPSIS
.In curses.h
.Ft int
.Fn chgat "int n" "attr_t attr" "short color" "const void *opts"
.Ft int
.Fn wchgat "WINDOW *win" "int n" "attr_t attr" "short color" \
"const void *opts"
.Ft int
.Fn mvchgat "int y" "int x" "int n" "attr_t attr" "short color" \
"const void *opts"
.Ft int
.Fn mvwchgat "WINDOW *win" "int y" "int x" "int n" "attr_t attr" \
"short color" "const void *opts"
.Sh DESCRIPTION
These functions modify the attributes of the drawn content on stdscr or
on the specified window.
.Pp
The
.Fn chgat
function sets the attributes of the next
.Fa n
characters to
.Fa attr
and the color pair to
.Fa color .
If
.Fa n
is negative or larger than the reminder of the line, it gets truncated.
.Pp
The
.Fn wchgat
is the same as the
.Fn chgat
function, excepting that the attributes are changed in the window specified by
.Fa win .
.Pp
The
.Fn mvchgat
and
.Fn mvwchgat
functions are the same as the
.Fn chgat
and
.Fn wchgat
functions, respectively, excepting that they operate from the position
specified by
.Fa y ,
.Fa x .
.Pp
These functions do not perform wrapping.
They do not update the cursor position.
.Sh RETURN VALUES
The functions that return an int will return one of the following
values:
.Pp
.Bl -tag -width ERR -compact
.It Er OK
The function completed successfully.
.It Er ERR
An error occurred in the function.
.El
.Sh SEE ALSO
.Xr curses_attributes 3
.Sh STANDARDS
The
.Fn chgat ,
.Fn wchgat ,
.Fn mvchgat ,
and
.Fn mvwchgat
functions conform to
.St -xcurses4.2 .
.Sh HISTORY
The Curses package appeared in
.Bx 4.0 .
Support for the
.Fn chgat
family was added in
.Nx 6.0 .

View file

@ -0,0 +1,141 @@
.\" $NetBSD: curses_clear.3,v 1.3 2003/04/16 13:35:00 wiz Exp $
.\"
.\" Copyright (c) 2002
.\" Brett Lymn (blymn@NetBSD.org, brett_lymn@yahoo.com.au)
.\"
.\" This code is 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. 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. 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.
.\"
.\"
.Dd August 12, 2002
.Dt CURSES_CLEAR 3
.Os
.Sh NAME
.Nm curses_clear ,
.Nm clear ,
.Nm wclear ,
.Nm clearok ,
.Nm clrtobot ,
.Nm clrtoeol ,
.Nm erase ,
.Nm werase ,
.Nm wclrtobot ,
.Nm wclrtoeol
.Nd curses clear window routines
.Sh LIBRARY
.Lb libcurses
.Sh SYNOPSIS
.In curses.h
.Ft int
.Fn clear "void"
.Ft int
.Fn clearok "WINDOW *win" "bool flag"
.Ft int
.Fn clrtobot "void"
.Ft int
.Fn clrtoeol "void"
.Ft int
.Fn erase "void"
.Ft int
.Fn wclear "WINDOW *win"
.Ft int
.Fn werase "WINDOW *win"
.Ft int
.Fn wclrtobot "WINDOW *win"
.Ft int
.Fn wclrtoeol "WINDOW *win"
.Sh DESCRIPTION
These functions clear all or part of
.Dv stdscr
or of the specified window.
.Pp
The
.Fn clear
and
.Fn erase
functions erase all characters on
.Dv stdscr .
.Fn wclear
and
.Fn werase
perform the same function as
.Fn clear
and
.Fn erase ,
respectively, excepting that the specified window is cleared.
.Pp
By setting
.Fa flag
to
.Dv TRUE ,
the
.Fn clearok
function is used to force the next call to
.Fn wrefresh
to clear and completely redraw the window given in
.Fa win .
.Pp
The function
.Fn clrtobot
will clear
.Dv stdscr
from the current row to the bottom of the screen.
.Fn clrtoeol
will clear
.Dv stdscr
from the current column position to the end of the line.
.Fn wclrtobot
and
.Fn wclrtoeol
are the same as
.Fn clrtobot
and
.Fn clrtoeol ,
respectively, excepting the window specified is operated on instead of
.Dv stdscr .
.Sh RETURN VALUES
Functions returning pointers will return
.Dv NULL
if an error is detected.
The functions that return an int will return one of the following
values:
.Pp
.Bl -tag -width ERR -compact
.It Er OK
The function completed successfully.
.It Er ERR
An error occurred in the function.
.El
.Sh SEE ALSO
.Xr curses_refresh 3
.Sh STANDARDS
The
.Nx
Curses library complies with the X/Open Curses specification, part of the
Single Unix Specification.
.Sh HISTORY
The Curses package appeared in
.Bx 4.0 .

View file

@ -0,0 +1,232 @@
.\" $NetBSD: curses_color.3,v 1.12 2009/07/22 16:57:14 roy Exp $
.\" Copyright (c) 2002 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.
.\"
.Dd July 20, 2009
.Dt CURSES_COLOR 3
.Os
.Sh NAME
.Nm curses_color ,
.Nm has_colors ,
.Nm can_change_color ,
.Nm start_color ,
.Nm init_pair ,
.Nm pair_content ,
.Nm COLOR_PAIR ,
.Nm PAIR_NUMBER ,
.Nm init_color ,
.Nm color_content ,
.Nm no_color_attributes
.Nd curses color manipulation routines
.Sh LIBRARY
.Lb libcurses
.Sh SYNOPSIS
.In curses.h
.Ft bool
.Fn has_colors void
.Ft bool
.Fn can_change_color void
.Ft int
.Fn start_color void
.Ft int
.Fn init_pair "short pair" "short fore" "short back"
.Ft int
.Fn pair_content "short pair" "short *fore" "short *back"
.Ft int
.Fn COLOR_PAIR "int n"
.Ft int
.Fn PAIR_NUMBER "int val"
.Ft int
.Fn init_color "short color" "short red" "short green" "short blue"
.Ft int
.Fn color_content "short color" "short *red" "short *green" "short *blue"
.Ft attr_t
.Fn no_color_attributes void
.Pp
.Va extern int COLOR_PAIRS ;
.Pp
.Va extern int COLORS ;
.Sh DESCRIPTION
These functions manipulate color on terminals that support color attributes.
.Pp
The function
.Fn has_colors
indicates whether a terminal is capable of displaying color attributes.
It returns
.Dv TRUE
if the terminal is capable of displaying color attributes and
.Dv FALSE
otherwise.
.Pp
The function
.Fn can_change_color
indicates whether a terminal is capable of redefining colors.
It returns
.Dv TRUE
if colors can be redefined and
.Dv FALSE
if they can not.
.Pp
The function
.Fn start_color
initializes the curses color support on a terminal.
It must be called before any color manipulation functions are called on that
terminal.
The function initializes the eight basic colors (black, red, green, yellow,
blue, magenta, cyan and white) that are specified using the color macros
(such as
.Dv COLOR_BLACK )
defined in
.Em \*[Lt]curses.h\*[Gt] .
.Fn start_color
also initializes the global external variables
.Va COLORS
and
.Va COLOR_PAIRS .
.Va COLORS
defines the number of colors that the terminal supports and
.Va COLOR_PAIRS
defines the number of color-pairs that the terminal supports.
These color-pairs are initialized to white foreground on black background.
.Fn start_color
sets the colors on the terminal to the curses defaults of white
foreground on black background unless the functions
.Fn assume_default_colors
or
.Fn use_default_colors
have been called previously.
.Pp
The function
.Fn init_pair pair fore back
sets foreground color
.Fa fore
and background color
.Fa back
for color-pair number
.Fa pair .
The valid range for the color-pair
.Fa pair
is from 1 to
.Va COLOR_PAIRS
\&- 1
and the valid range for the colors is any number less than
.Va COLORS .
Specifying a negative number will set that color to the default foreground
or background color.
The 8 initial colors are defined as:
.Bl -tag -width "COLOR_MAGENTA" -compact -offset indent
.It COLOR_BLACK
.It COLOR_RED
.It COLOR_GREEN
.It COLOR_YELLOW
.It COLOR_BLUE
.It COLOR_MAGENTA
.It COLOR_CYAN
.It COLOR_WHITE
.El
Color-pair 0 is used as the default color pair, so changing this will
have no effect.
Use the function
.Fn assume_default_colors
to change the default colors.
.Pp
The function
.Fn pair_content pair *fore *back
stores the foreground and background color numbers of color-pair
.Fa pair
in the variables
.Fa fore
and
.Fa back ,
respectively.
.Pp
The macro
.Fn COLOR_PAIR n
gives the attribute value of color-pair number
.Fa n .
This is the value that is used to set the attribute of a character to this
color-pair.
For example,
.Dl attrset(COLOR_PAIR(2))
will display characters using color-pair 2.
.Pp
The macro
.Fn PAIR_NUMBER val
gives the color-pair number associated with the attribute value
.Fa val .
.Pp
The function
.Fn init_color color red green blue
sets the red, green and blue intensity components of color
.Fa color
to the values
.Fa red ,
.Fa green
and
.Fa blue ,
respectively.
The minimum intensity value is 0 and the maximum intensity value is 1000.
.Pp
The function
.Fn color_content color *red *green *blue
stores the red, green and blue intensity components of color
.Fa color
in the variables
.Fa red ,
.Fa green ,
and
.Fa blue ,
respectively.
.Pp
The function
.Fn no_color_attributes
returns those attributes that a terminal is unable to combine with color.
.Sh RETURN VALUES
The functions
.Fn start_color ,
.Fn init_pair ,
.Fn pair_content ,
.Fn init_color
and
.Fn color_content
return OK on success and ERR on failure.
.Sh SEE ALSO
.Xr curses_attributes 3 ,
.Xr curses_background 3 ,
.Xr curses_default_colors 3
.Sh STANDARDS
The
.Nx
Curses library complies with the X/Open Curses specification, part of the
Single Unix Specification.
.Pp
The function
.Fn no_color_attributes
and the use of negative color numbers
are extensions to the X/Open Curses specification.
.Sh HISTORY
These functions first appeared in
.Nx 1.5 .

Some files were not shown because too many files have changed in this diff Show more