16.05.2015 Views

Working with the Unix OS

Working with the Unix OS

Working with the Unix OS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

C Libraries<br />

int attrset (chtype attrs) turns on requested attributes<br />

int attroff (chtype attrs) turns off requested attributes<br />

A_BLINK A_BOLD A_ALT A_DIM A_REVERSE A_STANDOUT A_UNDERLINE<br />

int beep()<br />

rings terminal bell<br />

Input Options:<br />

int echo()<br />

int noecho()<br />

int cbreak()<br />

int nocbreak()<br />

break for each character line at a time processing<br />

Output:<br />

Curses assumes stdin and stdout are connected to a terminal.<br />

Once initscr() is called, curses takes over terminal control.<br />

If endwin() is missing, may need to type "stty sane" and terminated <strong>with</strong> ^J.<br />

#include <br />

#include <br />

exit(register int code){<br />

/* flush and close o<strong>the</strong>r output streams */<br />

endwin();<br />

fflush(stdout), fflush(stderr);<br />

exit(code);<br />

/* exit must not return */<br />

}<br />

main()<br />

{<br />

initscr();<br />

signal (SIGINT, exit);<br />

...<br />

return 0;<br />

}<br />

WINDOW *win; /* declare a variable */<br />

initscr (); /* initialise screen */<br />

win=newwin(int lines, int columns, int begin_y, int begin_x);<br />

/* open window */<br />

wprintw(WINDOW *win, char *format); /*printf in window*/<br />

wmove(WINDOW *win, int y, int x); /* set current position */<br />

wclear(WINDOW *win); /* clear window */<br />

delwin(WINDOW *win); /* delete window */<br />

endwin(); /* end window modes */<br />

/* show: - display file page at time - example for curses */<br />

#include <br />

#include <br />

main(int argc, char *argv[])<br />

{<br />

FILE *fd;<br />

char linebuf[BUFSIZ];<br />

int line;<br />

void done(), perror(), exit();<br />

if (argc != 2)<br />

{<br />

fprintf(stderr, "usage: %s file\n", argv[0]);<br />

exit(1);<br />

77

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!