1/*- 2 * Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 *
| 1/*- 2 * Copyright (c) 2008-2009 Ed Schouten <ed@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 *
|
26 * $FreeBSD: head/sys/teken/teken_demo.c 196786 2009-09-03 16:31:11Z ed $
| 26 * $FreeBSD: head/sys/teken/teken_demo.c 197115 2009-09-12 10:34:34Z ed $
|
27 */ 28 29#include <sys/ioctl.h> 30 31#include <assert.h> 32#include <errno.h> 33#include <inttypes.h> 34#include <locale.h> 35#include <stdio.h> 36#include <stdlib.h> 37#include <unistd.h> 38 39#include <ncurses.h> 40#if defined(__FreeBSD__) 41#include <libutil.h> 42#elif defined(__linux__) 43#include <pty.h> 44#else 45#include <util.h> 46#endif 47 48#include "teken.h" 49 50static tf_bell_t test_bell; 51static tf_cursor_t test_cursor; 52static tf_putchar_t test_putchar; 53static tf_fill_t test_fill; 54static tf_copy_t test_copy; 55static tf_param_t test_param; 56static tf_respond_t test_respond; 57 58static teken_funcs_t tf = { 59 .tf_bell = test_bell, 60 .tf_cursor = test_cursor, 61 .tf_putchar = test_putchar, 62 .tf_fill = test_fill, 63 .tf_copy = test_copy, 64 .tf_param = test_param, 65 .tf_respond = test_respond, 66}; 67 68struct pixel { 69 teken_char_t c; 70 teken_attr_t a; 71}; 72 73#define NCOLS 80 74#ifdef TEKEN_XTERM 75#define NROWS 24 76#else /* !TEKEN_XTERM */ 77#define NROWS 25 78#endif /* TEKEN_XTERM */ 79struct pixel buffer[NCOLS][NROWS]; 80 81static int ptfd; 82 83static void 84printchar(const teken_pos_t *p) 85{ 86 int y, x, attr = 0; 87 struct pixel *px; 88 char str[5] = { 0 }; 89 90 assert(p->tp_row < NROWS); 91 assert(p->tp_col < NCOLS); 92 93 getyx(stdscr, y, x); 94 95 px = &buffer[p->tp_col][p->tp_row]; 96 97 /* Convert Unicode to UTF-8. */
| 27 */ 28 29#include <sys/ioctl.h> 30 31#include <assert.h> 32#include <errno.h> 33#include <inttypes.h> 34#include <locale.h> 35#include <stdio.h> 36#include <stdlib.h> 37#include <unistd.h> 38 39#include <ncurses.h> 40#if defined(__FreeBSD__) 41#include <libutil.h> 42#elif defined(__linux__) 43#include <pty.h> 44#else 45#include <util.h> 46#endif 47 48#include "teken.h" 49 50static tf_bell_t test_bell; 51static tf_cursor_t test_cursor; 52static tf_putchar_t test_putchar; 53static tf_fill_t test_fill; 54static tf_copy_t test_copy; 55static tf_param_t test_param; 56static tf_respond_t test_respond; 57 58static teken_funcs_t tf = { 59 .tf_bell = test_bell, 60 .tf_cursor = test_cursor, 61 .tf_putchar = test_putchar, 62 .tf_fill = test_fill, 63 .tf_copy = test_copy, 64 .tf_param = test_param, 65 .tf_respond = test_respond, 66}; 67 68struct pixel { 69 teken_char_t c; 70 teken_attr_t a; 71}; 72 73#define NCOLS 80 74#ifdef TEKEN_XTERM 75#define NROWS 24 76#else /* !TEKEN_XTERM */ 77#define NROWS 25 78#endif /* TEKEN_XTERM */ 79struct pixel buffer[NCOLS][NROWS]; 80 81static int ptfd; 82 83static void 84printchar(const teken_pos_t *p) 85{ 86 int y, x, attr = 0; 87 struct pixel *px; 88 char str[5] = { 0 }; 89 90 assert(p->tp_row < NROWS); 91 assert(p->tp_col < NCOLS); 92 93 getyx(stdscr, y, x); 94 95 px = &buffer[p->tp_col][p->tp_row]; 96 97 /* Convert Unicode to UTF-8. */
|
98#ifdef TEKEN_UTF8
| |
99 if (px->c < 0x80) { 100 str[0] = px->c; 101 } else if (px->c < 0x800) { 102 str[0] = 0xc0 | (px->c >> 6); 103 str[1] = 0x80 | (px->c & 0x3f); 104 } else if (px->c < 0x10000) { 105 str[0] = 0xe0 | (px->c >> 12); 106 str[1] = 0x80 | ((px->c >> 6) & 0x3f); 107 str[2] = 0x80 | (px->c & 0x3f); 108 } else { 109 str[0] = 0xf0 | (px->c >> 18); 110 str[1] = 0x80 | ((px->c >> 12) & 0x3f); 111 str[2] = 0x80 | ((px->c >> 6) & 0x3f); 112 str[3] = 0x80 | (px->c & 0x3f); 113 }
| 98 if (px->c < 0x80) { 99 str[0] = px->c; 100 } else if (px->c < 0x800) { 101 str[0] = 0xc0 | (px->c >> 6); 102 str[1] = 0x80 | (px->c & 0x3f); 103 } else if (px->c < 0x10000) { 104 str[0] = 0xe0 | (px->c >> 12); 105 str[1] = 0x80 | ((px->c >> 6) & 0x3f); 106 str[2] = 0x80 | (px->c & 0x3f); 107 } else { 108 str[0] = 0xf0 | (px->c >> 18); 109 str[1] = 0x80 | ((px->c >> 12) & 0x3f); 110 str[2] = 0x80 | ((px->c >> 6) & 0x3f); 111 str[3] = 0x80 | (px->c & 0x3f); 112 }
|
114#else /* !TEKEN_UTF8 */ 115 str[0] = px->c; 116#endif /* TEKEN_UTF8 */
| |
117 118 if (px->a.ta_format & TF_BOLD) 119 attr |= A_BOLD; 120 if (px->a.ta_format & TF_UNDERLINE) 121 attr |= A_UNDERLINE; 122 if (px->a.ta_format & TF_BLINK) 123 attr |= A_BLINK; 124 if (px->a.ta_format & TF_REVERSE) 125 attr |= A_REVERSE; 126 127 bkgdset(attr | COLOR_PAIR(px->a.ta_fgcolor + 8 * px->a.ta_bgcolor)); 128 mvaddstr(p->tp_row, p->tp_col, str); 129 130 move(y, x); 131} 132 133static void 134test_bell(void *s __unused) 135{ 136 137 beep(); 138} 139 140static void 141test_cursor(void *s __unused, const teken_pos_t *p) 142{ 143 144 move(p->tp_row, p->tp_col); 145} 146 147static void 148test_putchar(void *s __unused, const teken_pos_t *p, teken_char_t c, 149 const teken_attr_t *a) 150{ 151 152 buffer[p->tp_col][p->tp_row].c = c; 153 buffer[p->tp_col][p->tp_row].a = *a; 154 printchar(p); 155} 156 157static void 158test_fill(void *s, const teken_rect_t *r, teken_char_t c, 159 const teken_attr_t *a) 160{ 161 teken_pos_t p; 162 163 /* Braindead implementation of fill() - just call putchar(). */ 164 for (p.tp_row = r->tr_begin.tp_row; p.tp_row < r->tr_end.tp_row; p.tp_row++) 165 for (p.tp_col = r->tr_begin.tp_col; p.tp_col < r->tr_end.tp_col; p.tp_col++) 166 test_putchar(s, &p, c, a); 167} 168 169static void 170test_copy(void *s __unused, const teken_rect_t *r, const teken_pos_t *p) 171{ 172 int nrow, ncol, x, y; /* Has to be signed - >= 0 comparison */ 173 teken_pos_t d; 174 175 /* 176 * Copying is a little tricky. We must make sure we do it in 177 * correct order, to make sure we don't overwrite our own data. 178 */ 179 180 nrow = r->tr_end.tp_row - r->tr_begin.tp_row; 181 ncol = r->tr_end.tp_col - r->tr_begin.tp_col; 182 183 if (p->tp_row < r->tr_begin.tp_row) { 184 /* Copy from top to bottom. */ 185 if (p->tp_col < r->tr_begin.tp_col) { 186 /* Copy from left to right. */ 187 for (y = 0; y < nrow; y++) { 188 d.tp_row = p->tp_row + y; 189 for (x = 0; x < ncol; x++) { 190 d.tp_col = p->tp_col + x; 191 buffer[d.tp_col][d.tp_row] = 192 buffer[r->tr_begin.tp_col + x][r->tr_begin.tp_row + y]; 193 printchar(&d); 194 } 195 } 196 } else { 197 /* Copy from right to left. */ 198 for (y = 0; y < nrow; y++) { 199 d.tp_row = p->tp_row + y; 200 for (x = ncol - 1; x >= 0; x--) { 201 d.tp_col = p->tp_col + x; 202 buffer[d.tp_col][d.tp_row] = 203 buffer[r->tr_begin.tp_col + x][r->tr_begin.tp_row + y]; 204 printchar(&d); 205 } 206 } 207 } 208 } else { 209 /* Copy from bottom to top. */ 210 if (p->tp_col < r->tr_begin.tp_col) { 211 /* Copy from left to right. */ 212 for (y = nrow - 1; y >= 0; y--) { 213 d.tp_row = p->tp_row + y; 214 for (x = 0; x < ncol; x++) { 215 d.tp_col = p->tp_col + x; 216 buffer[d.tp_col][d.tp_row] = 217 buffer[r->tr_begin.tp_col + x][r->tr_begin.tp_row + y]; 218 printchar(&d); 219 } 220 } 221 } else { 222 /* Copy from right to left. */ 223 for (y = nrow - 1; y >= 0; y--) { 224 d.tp_row = p->tp_row + y; 225 for (x = ncol - 1; x >= 0; x--) { 226 d.tp_col = p->tp_col + x; 227 buffer[d.tp_col][d.tp_row] = 228 buffer[r->tr_begin.tp_col + x][r->tr_begin.tp_row + y]; 229 printchar(&d); 230 } 231 } 232 } 233 } 234} 235 236static void 237test_param(void *s __unused, int cmd, unsigned int value) 238{ 239 240 switch (cmd) { 241 case TP_SHOWCURSOR: 242 curs_set(value); 243 break; 244 case TP_KEYPADAPP: 245 keypad(stdscr, value ? TRUE : FALSE); 246 break; 247 } 248} 249 250static void 251test_respond(void *s __unused, const void *buf, size_t len) 252{ 253 254 write(ptfd, buf, len); 255} 256 257static void 258redraw_border(void) 259{ 260 unsigned int i; 261 262 for (i = 0; i < NROWS; i++) 263 mvaddch(i, NCOLS, '|'); 264 for (i = 0; i < NCOLS; i++) 265 mvaddch(NROWS, i, '-'); 266 267 mvaddch(NROWS, NCOLS, '+'); 268} 269 270static void 271redraw_all(void) 272{ 273 teken_pos_t tp; 274 275 for (tp.tp_row = 0; tp.tp_row < NROWS; tp.tp_row++) 276 for (tp.tp_col = 0; tp.tp_col < NCOLS; tp.tp_col++) 277 printchar(&tp); 278 279 redraw_border(); 280} 281 282int 283main(int argc __unused, char *argv[] __unused) 284{ 285 struct winsize ws; 286 teken_t t; 287 teken_pos_t tp; 288 fd_set rfds; 289 char b[256]; 290 ssize_t bl; 291 const int ccolors[8] = { 292 COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW, 293 COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE 294 }; 295 int i, j; 296
| 113 114 if (px->a.ta_format & TF_BOLD) 115 attr |= A_BOLD; 116 if (px->a.ta_format & TF_UNDERLINE) 117 attr |= A_UNDERLINE; 118 if (px->a.ta_format & TF_BLINK) 119 attr |= A_BLINK; 120 if (px->a.ta_format & TF_REVERSE) 121 attr |= A_REVERSE; 122 123 bkgdset(attr | COLOR_PAIR(px->a.ta_fgcolor + 8 * px->a.ta_bgcolor)); 124 mvaddstr(p->tp_row, p->tp_col, str); 125 126 move(y, x); 127} 128 129static void 130test_bell(void *s __unused) 131{ 132 133 beep(); 134} 135 136static void 137test_cursor(void *s __unused, const teken_pos_t *p) 138{ 139 140 move(p->tp_row, p->tp_col); 141} 142 143static void 144test_putchar(void *s __unused, const teken_pos_t *p, teken_char_t c, 145 const teken_attr_t *a) 146{ 147 148 buffer[p->tp_col][p->tp_row].c = c; 149 buffer[p->tp_col][p->tp_row].a = *a; 150 printchar(p); 151} 152 153static void 154test_fill(void *s, const teken_rect_t *r, teken_char_t c, 155 const teken_attr_t *a) 156{ 157 teken_pos_t p; 158 159 /* Braindead implementation of fill() - just call putchar(). */ 160 for (p.tp_row = r->tr_begin.tp_row; p.tp_row < r->tr_end.tp_row; p.tp_row++) 161 for (p.tp_col = r->tr_begin.tp_col; p.tp_col < r->tr_end.tp_col; p.tp_col++) 162 test_putchar(s, &p, c, a); 163} 164 165static void 166test_copy(void *s __unused, const teken_rect_t *r, const teken_pos_t *p) 167{ 168 int nrow, ncol, x, y; /* Has to be signed - >= 0 comparison */ 169 teken_pos_t d; 170 171 /* 172 * Copying is a little tricky. We must make sure we do it in 173 * correct order, to make sure we don't overwrite our own data. 174 */ 175 176 nrow = r->tr_end.tp_row - r->tr_begin.tp_row; 177 ncol = r->tr_end.tp_col - r->tr_begin.tp_col; 178 179 if (p->tp_row < r->tr_begin.tp_row) { 180 /* Copy from top to bottom. */ 181 if (p->tp_col < r->tr_begin.tp_col) { 182 /* Copy from left to right. */ 183 for (y = 0; y < nrow; y++) { 184 d.tp_row = p->tp_row + y; 185 for (x = 0; x < ncol; x++) { 186 d.tp_col = p->tp_col + x; 187 buffer[d.tp_col][d.tp_row] = 188 buffer[r->tr_begin.tp_col + x][r->tr_begin.tp_row + y]; 189 printchar(&d); 190 } 191 } 192 } else { 193 /* Copy from right to left. */ 194 for (y = 0; y < nrow; y++) { 195 d.tp_row = p->tp_row + y; 196 for (x = ncol - 1; x >= 0; x--) { 197 d.tp_col = p->tp_col + x; 198 buffer[d.tp_col][d.tp_row] = 199 buffer[r->tr_begin.tp_col + x][r->tr_begin.tp_row + y]; 200 printchar(&d); 201 } 202 } 203 } 204 } else { 205 /* Copy from bottom to top. */ 206 if (p->tp_col < r->tr_begin.tp_col) { 207 /* Copy from left to right. */ 208 for (y = nrow - 1; y >= 0; y--) { 209 d.tp_row = p->tp_row + y; 210 for (x = 0; x < ncol; x++) { 211 d.tp_col = p->tp_col + x; 212 buffer[d.tp_col][d.tp_row] = 213 buffer[r->tr_begin.tp_col + x][r->tr_begin.tp_row + y]; 214 printchar(&d); 215 } 216 } 217 } else { 218 /* Copy from right to left. */ 219 for (y = nrow - 1; y >= 0; y--) { 220 d.tp_row = p->tp_row + y; 221 for (x = ncol - 1; x >= 0; x--) { 222 d.tp_col = p->tp_col + x; 223 buffer[d.tp_col][d.tp_row] = 224 buffer[r->tr_begin.tp_col + x][r->tr_begin.tp_row + y]; 225 printchar(&d); 226 } 227 } 228 } 229 } 230} 231 232static void 233test_param(void *s __unused, int cmd, unsigned int value) 234{ 235 236 switch (cmd) { 237 case TP_SHOWCURSOR: 238 curs_set(value); 239 break; 240 case TP_KEYPADAPP: 241 keypad(stdscr, value ? TRUE : FALSE); 242 break; 243 } 244} 245 246static void 247test_respond(void *s __unused, const void *buf, size_t len) 248{ 249 250 write(ptfd, buf, len); 251} 252 253static void 254redraw_border(void) 255{ 256 unsigned int i; 257 258 for (i = 0; i < NROWS; i++) 259 mvaddch(i, NCOLS, '|'); 260 for (i = 0; i < NCOLS; i++) 261 mvaddch(NROWS, i, '-'); 262 263 mvaddch(NROWS, NCOLS, '+'); 264} 265 266static void 267redraw_all(void) 268{ 269 teken_pos_t tp; 270 271 for (tp.tp_row = 0; tp.tp_row < NROWS; tp.tp_row++) 272 for (tp.tp_col = 0; tp.tp_col < NCOLS; tp.tp_col++) 273 printchar(&tp); 274 275 redraw_border(); 276} 277 278int 279main(int argc __unused, char *argv[] __unused) 280{ 281 struct winsize ws; 282 teken_t t; 283 teken_pos_t tp; 284 fd_set rfds; 285 char b[256]; 286 ssize_t bl; 287 const int ccolors[8] = { 288 COLOR_BLACK, COLOR_RED, COLOR_GREEN, COLOR_YELLOW, 289 COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE 290 }; 291 int i, j; 292
|
297#ifdef TEKEN_UTF8
| |
298 setlocale(LC_CTYPE, "UTF-8");
| 293 setlocale(LC_CTYPE, "UTF-8");
|
299#endif /* TEKEN_UTF8 */
| |
300 301 tp.tp_row = ws.ws_row = NROWS; 302 tp.tp_col = ws.ws_col = NCOLS; 303 304 switch (forkpty(&ptfd, NULL, NULL, &ws)) { 305 case -1: 306 perror("forkpty"); 307 exit(1); 308 case 0: 309#ifdef TEKEN_XTERM 310 setenv("TERM", "xterm", 1); 311#else /* !TEKEN_XTERM */ 312 setenv("TERM", "cons25", 1); 313#endif /* TEKEN_XTERM */
| 294 295 tp.tp_row = ws.ws_row = NROWS; 296 tp.tp_col = ws.ws_col = NCOLS; 297 298 switch (forkpty(&ptfd, NULL, NULL, &ws)) { 299 case -1: 300 perror("forkpty"); 301 exit(1); 302 case 0: 303#ifdef TEKEN_XTERM 304 setenv("TERM", "xterm", 1); 305#else /* !TEKEN_XTERM */ 306 setenv("TERM", "cons25", 1); 307#endif /* TEKEN_XTERM */
|
314#ifdef TEKEN_UTF8
| |
315 setenv("LC_CTYPE", "UTF-8", 0);
| 308 setenv("LC_CTYPE", "UTF-8", 0);
|
316#endif /* TEKEN_UTF8 */
| |
317 execlp("zsh", "-zsh", NULL); 318 execlp("bash", "-bash", NULL); 319 execlp("sh", "-sh", NULL); 320 _exit(1); 321 } 322 323 teken_init(&t, &tf, NULL); 324 teken_set_winsize(&t, &tp); 325 326 initscr(); 327 raw(); 328 start_color(); 329 for (i = 0; i < 8; i++) 330 for (j = 0; j < 8; j++) 331 init_pair(i + 8 * j, ccolors[i], ccolors[j]); 332 333 redraw_border(); 334 335 FD_ZERO(&rfds); 336 337 for (;;) { 338 FD_SET(STDIN_FILENO, &rfds); 339 FD_SET(ptfd, &rfds); 340 341 if (select(ptfd + 1, &rfds, NULL, NULL, NULL) < 0) { 342 if (errno == EINTR) { 343 redraw_all(); 344 refresh(); 345 continue; 346 } 347 break; 348 } 349 350 if (FD_ISSET(STDIN_FILENO, &rfds)) { 351 bl = read(STDIN_FILENO, b, sizeof b); 352 if (bl <= 0) 353 break; 354 write(ptfd, b, bl); 355 } 356 357 if (FD_ISSET(ptfd, &rfds)) { 358 bl = read(ptfd, b, sizeof b); 359 if (bl <= 0) 360 break; 361 teken_input(&t, b, bl); 362 refresh(); 363 } 364 } 365 366 endwin(); 367 368 return (0); 369}
| 309 execlp("zsh", "-zsh", NULL); 310 execlp("bash", "-bash", NULL); 311 execlp("sh", "-sh", NULL); 312 _exit(1); 313 } 314 315 teken_init(&t, &tf, NULL); 316 teken_set_winsize(&t, &tp); 317 318 initscr(); 319 raw(); 320 start_color(); 321 for (i = 0; i < 8; i++) 322 for (j = 0; j < 8; j++) 323 init_pair(i + 8 * j, ccolors[i], ccolors[j]); 324 325 redraw_border(); 326 327 FD_ZERO(&rfds); 328 329 for (;;) { 330 FD_SET(STDIN_FILENO, &rfds); 331 FD_SET(ptfd, &rfds); 332 333 if (select(ptfd + 1, &rfds, NULL, NULL, NULL) < 0) { 334 if (errno == EINTR) { 335 redraw_all(); 336 refresh(); 337 continue; 338 } 339 break; 340 } 341 342 if (FD_ISSET(STDIN_FILENO, &rfds)) { 343 bl = read(STDIN_FILENO, b, sizeof b); 344 if (bl <= 0) 345 break; 346 write(ptfd, b, bl); 347 } 348 349 if (FD_ISSET(ptfd, &rfds)) { 350 bl = read(ptfd, b, sizeof b); 351 if (bl <= 0) 352 break; 353 teken_input(&t, b, bl); 354 refresh(); 355 } 356 } 357 358 endwin(); 359 360 return (0); 361}
|