Changeset b917098 in mainline for tetris/screen.c


Ignore:
Timestamp:
2006-06-02T16:33:42Z (19 years ago)
Author:
Ondrej Palkovsky <ondrap@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a805c24
Parents:
b1f51f0
Message:

Slowly porting tetris screen… not yet done.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tetris/screen.c

    rb1f51f0 rb917098  
    4040 */
    4141
    42 #include <sys/ioctl.h>
    43 
    4442#include <err.h>
    45 //#include <setjmp.h>
    46 //#include <signal.h>
    4743#include <stdio.h>
    4844#include <stdlib.h>
    4945#include <string.h>
    50 #include <term.h>
    51 #include <termios.h>
    5246#include <unistd.h>
     47#include <io/stream.h>
    5348
    5449#include "screen.h"
     
    135130#define moveto(r, c)    putpad(tgoto(CMstr, c, r))
    136131
     132static int con_phone;
     133
    137134/*
    138135 * Set up from termcap.
     
    141138scr_init(void)
    142139{
    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
    221143
    222144static void
    223145scr_stop(int sig)
    224146{
    225 //      sigset_t sigset;
    226147
    227148        scr_end();
    228 /*      (void) kill(getpid(), sig); */
    229 /*      sigemptyset(&sigset); */
    230 /*      sigaddset(&sigset, sig); */
    231 /*      (void) sigprocmask(SIG_UNBLOCK, &sigset, (sigset_t *)0); */
    232149        scr_set();
    233150        scr_msg(key_msg, 1);
     
    242159        struct winsize ws;
    243160        struct termios newtt;
    244 //      sigset_t sigset, osigset;
    245161        void (*ttou)(int);
    246162
    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); */
    262163        Rows = 0, Cols = 0;
    263164        if (ioctl(0, TIOCGWINSZ, &ws) == 0) {
     
    284185        if (tcsetattr(0, TCSADRAIN, &newtt) < 0)
    285186                stop("tcsetattr() fails");
    286 /*      (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */
    287187
    288188        /*
     
    292192        if (TIstr)
    293193                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); */
    298194
    299195        isset = 1;
    300 //      (void) sigprocmask(SIG_SETMASK, &osigset, (sigset_t *)0);
     196
    301197        scr_clear();
    302198}
     
    308204scr_end(void)
    309205{
    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         else
    320                 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); */
    330206}
    331207
     
    366242        regcell so, cur_so = 0;
    367243        int i, ccol, j;
    368 //      sigset_t sigset, osigset;
    369244        static const struct shape *lastshape;
    370 
    371 /*      sigemptyset(&sigset); */
    372 /*      sigaddset(&sigset, SIGTSTP); */
    373 /*      (void) sigprocmask(SIG_BLOCK, &sigset, &osigset); */
    374245
    375246        /* always leave cursor after last displayed point */
Note: See TracChangeset for help on using the changeset viewer.