Changeset b917098 in mainline
- Timestamp:
- 2006-06-02T16:33:42Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a805c24
- Parents:
- b1f51f0
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
libc/generic/io/stream.c
rb1f51f0 rb917098 40 40 #include <console.h> 41 41 #include <unistd.h> 42 #include <async.h> 42 43 43 44 #define FDS 32 … … 47 48 preadfn_t r; 48 49 void * param; 50 int phone; 49 51 } stream_t; 50 52 51 int console_phone = -1; 52 53 stream_t streams[FDS] = {{0, 0, 0}}; 53 static int console_phone = -1; 54 static stream_t streams[FDS] = {{0, 0, 0, -1}}; 54 55 55 56 static ssize_t write_stderr(void *param, const void *buf, size_t count) … … 64 65 65 66 while (i < count) { 66 if ( ipc_call_sync_2(console_phone, CONSOLE_GETCHAR, 0, 0, &r0, &r1) < 0) {67 if (sync_send_2(streams[0].phone, CONSOLE_GETCHAR, 0, 0, &r0, &r1) < 0) { 67 68 return -1; 68 69 } … … 78 79 79 80 for (i = 0; i < count; i++) 80 send_call( console_phone, CONSOLE_PUTCHAR, ((const char *)buf)[i]);81 send_call(streams[1].phone, CONSOLE_PUTCHAR, ((const char *)buf)[i]); 81 82 82 83 return count; … … 99 100 stream.r = read_stdin; 100 101 stream.param = 0; 102 stream.phone = console_phone; 103 101 104 return stream; 102 105 } … … 106 109 stream_t stream; 107 110 int res; 108 111 109 112 if (console_phone < 0) { 110 113 while ((console_phone = ipc_connect_me_to(PHONE_NS, SERVICE_CONSOLE, 0)) < 0) { … … 139 142 140 143 if (!strcmp(fname, "stdout")) { 141 //streams[c].w = write_stdout;142 //return c;143 144 streams[c] = open_stdout(); 144 145 return c; … … 172 173 } 173 174 175 int get_fd_phone(int fd) 176 { 177 if (fd >= FDS || fd < 0) 178 return -1; 179 return streams[fd].phone; 180 } -
libc/include/io/stream.h
rb1f51f0 rb917098 38 38 39 39 fd_t open(const char *fname, int flags); 40 int get_fd_phone(int fd); -
tetris/screen.c
rb1f51f0 rb917098 40 40 */ 41 41 42 #include <sys/ioctl.h>43 44 42 #include <err.h> 45 //#include <setjmp.h>46 //#include <signal.h>47 43 #include <stdio.h> 48 44 #include <stdlib.h> 49 45 #include <string.h> 50 #include <term.h>51 #include <termios.h>52 46 #include <unistd.h> 47 #include <io/stream.h> 53 48 54 49 #include "screen.h" … … 135 130 #define moveto(r, c) putpad(tgoto(CMstr, c, r)) 136 131 132 static int con_phone; 133 137 134 /* 138 135 * Set up from termcap. … … 141 138 scr_init(void) 142 139 { 143 static int bsflag, xsflag, sgnum; 144 #ifdef unneeded 145 static int ncflag; 146 #endif 147 char *term, *fill; 148 static struct tcninfo { /* termcap numeric and flag info */ 149 char tcname[3]; 150 int *tcaddr; 151 } tcflags[] = { 152 {"bs", &bsflag}, 153 {"ms", &MSflag}, 154 #ifdef unneeded 155 {"nc", &ncflag}, 156 #endif 157 {"xs", &xsflag}, 158 { {0}, NULL} 159 }, tcnums[] = { 160 {"co", &COnum}, 161 {"li", &LInum}, 162 {"sg", &sgnum}, 163 { {0}, NULL} 164 }; 165 166 if ((term = getenv("TERM")) == NULL) 167 stop("you must set the TERM environment variable"); 168 if (tgetent(tbuf, term) <= 0) 169 stop("cannot find your termcap"); 170 fill = combuf; 171 { 172 struct tcsinfo *p; 173 174 for (p = tcstrings; p->tcaddr; p++) 175 *p->tcaddr = tgetstr(p->tcname, &fill); 176 } 177 if (classic) 178 SOstr = SEstr = NULL; 179 { 180 struct tcninfo *p; 181 182 for (p = tcflags; p->tcaddr; p++) 183 *p->tcaddr = tgetflag(p->tcname); 184 for (p = tcnums; p->tcaddr; p++) 185 *p->tcaddr = tgetnum(p->tcname); 186 } 187 if (bsflag) 188 BC = "\b"; 189 else if (BC == NULL && bcstr != NULL) 190 BC = bcstr; 191 if (CLstr == NULL) 192 stop("cannot clear screen"); 193 if (CMstr == NULL || UP == NULL || BC == NULL) 194 stop("cannot do random cursor positioning via tgoto()"); 195 PC = pcstr ? *pcstr : 0; 196 if (sgnum > 0 || xsflag) 197 SOstr = SEstr = NULL; 198 #ifdef unneeded 199 if (ncflag) 200 CRstr = NULL; 201 else if (CRstr == NULL) 202 CRstr = "\r"; 203 #endif 204 } 205 206 /* this foolery is needed to modify tty state `atomically' */ 207 //static jmp_buf scr_onstop; 208 209 /* static void */ 210 /* stopset(int sig) */ 211 /* { */ 212 /* sigset_t sigset; */ 213 214 /* (void) signal(sig, SIG_DFL); */ 215 /* (void) kill(getpid(), sig); */ 216 /* sigemptyset(&sigset); */ 217 /* sigaddset(&sigset, sig); */ 218 /* (void) sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *)0); */ 219 /* longjmp(scr_onstop, 1); */ 220 /* } */ 140 con_phone = get_fd_phone(1); 141 } 142 221 143 222 144 static void 223 145 scr_stop(int sig) 224 146 { 225 // sigset_t sigset;226 147 227 148 scr_end(); 228 /* (void) kill(getpid(), sig); */229 /* sigemptyset(&sigset); */230 /* sigaddset(&sigset, sig); */231 /* (void) sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *)0); */232 149 scr_set(); 233 150 scr_msg(key_msg, 1); … … 242 159 struct winsize ws; 243 160 struct termios newtt; 244 // sigset_t sigset, osigset;245 161 void (*ttou)(int); 246 162 247 /* sigemptyset(&sigset); */248 /* sigaddset(&sigset, SIGTSTP); */249 /* sigaddset(&sigset, SIGTTOU); */250 /* (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */251 /* if ((tstp = signal(SIGTSTP, stopset)) == SIG_IGN) */252 /* (void) signal(SIGTSTP, SIG_IGN); */253 /* if ((ttou = signal(SIGTTOU, stopset)) == SIG_IGN) */254 /* (void) signal(SIGTTOU, SIG_IGN); */255 /* /\* */256 /* * At last, we are ready to modify the tty state. If */257 /* * we stop while at it, stopset() above will longjmp back */258 /* * to the setjmp here and we will start over. */259 /* *\/ */260 /* (void) setjmp(scr_onstop); */261 /* (void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); */262 163 Rows = 0, Cols = 0; 263 164 if (ioctl(0, TIOCGWINSZ, &ws) == 0) { … … 284 185 if (tcsetattr(0, TCSADRAIN, &newtt) < 0) 285 186 stop("tcsetattr() fails"); 286 /* (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */287 187 288 188 /* … … 292 192 if (TIstr) 293 193 putstr(TIstr); /* termcap(5) says this is not padded */ 294 /* if (tstp != SIG_IGN) */295 /* (void) signal(SIGTSTP, scr_stop); */296 /* if (ttou != SIG_IGN) */297 /* (void) signal(SIGTTOU, ttou); */298 194 299 195 isset = 1; 300 // (void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); 196 301 197 scr_clear(); 302 198 } … … 308 204 scr_end(void) 309 205 { 310 // sigset_t sigset, osigset;311 312 /* sigemptyset(&sigset); */313 /* sigaddset(&sigset, SIGTSTP); */314 /* sigaddset(&sigset, SIGTTOU); */315 /* (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */316 /* move cursor to last line */317 if (LLstr)318 putstr(LLstr); /* termcap(5) says this is not padded */319 else320 moveto(Rows - 1, 0);321 /* exit screen mode */322 if (TEstr)323 putstr(TEstr); /* termcap(5) says this is not padded */324 // (void) fflush(stdout);325 (void) tcsetattr(0, TCSADRAIN, &oldtt);326 isset = 0;327 /* restore signals */328 /* (void) signal(SIGTSTP, tstp); */329 /* (void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0); */330 206 } 331 207 … … 366 242 regcell so, cur_so = 0; 367 243 int i, ccol, j; 368 // sigset_t sigset, osigset;369 244 static const struct shape *lastshape; 370 371 /* sigemptyset(&sigset); */372 /* sigaddset(&sigset, SIGTSTP); */373 /* (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */374 245 375 246 /* always leave cursor after last displayed point */
Note:
See TracChangeset
for help on using the changeset viewer.