Commit f7de39bb by O'Reilly Media, Inc.

Initial commit

parents
## Example files for the title:
# Programming with curses, by John Strang
[![Programming with curses, by John Strang](http://akamaicovers.oreilly.com/images/9780937175026/cat.gif)](https://www.safaribooksonline.com/)
The following applies to example files from material published by O’Reilly Media, Inc. Content from other publishers may include different rules of usage. Please refer to any additional usage rights explained in the actual example files or refer to the publisher’s website.
O'Reilly books are here to help you get your job done. In general, you may use the code in O'Reilly books in your programs and documentation. You do not need to contact us for permission unless you're reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from our books does not require permission. Answering a question by citing our books and quoting example code does not require permission. On the other hand, selling or distributing a CD-ROM of examples from O'Reilly books does require permission. Incorporating a significant amount of example code from our books into your product's documentation does require permission.
We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN.
If you think your use of code examples falls outside fair use or the permission given here, feel free to contact us at <permissions@oreilly.com>.
Please note that the examples are not production code and have not been carefully testing. They are provided "as-is" and come with no warranty of any kind.
#include <curses.h>
#include <signal.h>
main()
{
void die();
/* if (startup() != ERR) startup unwritten */
/* init stdscr, curscr and terminal */
initscr();
/* call die() if get interrupt */
signal(SIGINT, die);
/* spreadsheet function defined later */
spreadsheet();
die();
}
void die()
{
/* ignore interrupts */
signal(SIGINT, SIG_IGN);
/* move cursor to lower left */
mvcur(0, COLS - 1, LINES - 1, 0);
/* make terminal the way it was */
endwin();
exit(0); /* exit normally */
}
#define VERSION 12
spreadsheet()
{
char filename[20];
intro(VERSION); /* print first screen */
/* initialize input modes */
initinput();
/* read in file, check password */
getfileandpw(filename);
/* create the fields for spreadsheet */
makefields();
/* makefields also calls driver */
}
/* intro() prints an initial screen */
intro(version)
int version;
{
int x1, x2, y;
/* make box around the screen */
box(stdscr, '*', '-');
move(1,2);
addstr("SHOWME Spreadsheet Program, version: ");
getyx(stdscr, y, x1);
printw("%d", version);
getyx(stdscr, y, x2);
while (x2++ - x1 < 6)
addch(' ');
addstr("1/1/86");
/* send stdscr to terminal */
refresh();
}
initinput() /* set up initial modes */
{
raw();
echo();
nonl();
}
getfileandpw(filename)
char *filename;
{
char passwd[6];
int i = 0;
mvaddstr(4,2, "What file do you want? ");
refresh();
while ((filename[i] = getch()) != '\r')
i++;
filename[i] = '\0';
mvaddstr(3,2, "Six character Password? ");
noecho();
refresh();
i = 0;
while (i < 6)
passwd[i++] = getch();
/* check password */
if (passwdok(passwd)) {
mvaddstr(4,26, "OK");
/* readinfile(filename); readinfile unwritten */
refresh();
}
else {
mvaddstr(4,26, "NO");
refresh();
die();
}
}
/* Dummy function so that example will run */
passwdok(passwd)
char *passwd;
{
return(1);
}
int _top, _left;
makefields()
{
WINDOW *worksp, *field[10][10];
int i, j;
extern int _left, _top;
worksp = subwin(stdscr, LINES - 2, COLS - 2, 1, 1);
/* create a sub-window to work in */
werase(worksp);
wmove(worksp, 1, 0);
waddstr(worksp, "\t0\t1\t2\t3\t4\t5\t6\t7");
wmove(worksp, 3, 0);
waddch(worksp, 'a');
mvwaddch(worksp, 5, 0, 'b');
mvwaddch(worksp, 7, 0, 'c');
mvwaddch(worksp, 9, 0, 'd');
mvwaddch(worksp, 11, 0, 'e');
mvwaddch(worksp, 13, 0, 'f');
mvwaddch(worksp, 15, 0, 'g');
mvwaddch(worksp, 17, 0, 'h');
mvwaddch(worksp, 19, 0, 'i');
mvwaddch(worksp, 21, 0, 'j');
wrefresh(worksp);
/* display border of workspace */
for (i = 0; i < 10; i++)
for (j = 0; j < 10; j++) {
field[i][j] = newwin(1, 7, 4+2*i, 7+8*j);
wprintw(field[i][j], "%d %d", i, j);
}
/* create fields to work in */
_left = 0; _top = 0;
reffields(field);
/* iodriver(worksp, field); iodriver unwritten */
}
/* reffields refreshes the fields currently
positioned in the workspace */
reffields(field)
WINDOW *field[10][10];
{
int i, j;
extern int _top, _left;
for (i = _top; i <= _top + 7; i++)
for (j = _left; j <= _left + 7; j++) {
touchwin(field[i][j]);
wrefresh(field[i][j]);
}
}
logo.png

2.37 KB

Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment