Annotation of sbbs/sbbs3/inkey.cpp, revision 1.1.1.1

1.1       root        1: /* inkey.cpp */
                      2: 
                      3: /* Synchronet single key input function (no wait) */
                      4: 
                      5: /* $Id: inkey.cpp,v 1.2 2000/12/11 23:21:11 rswindell Exp $ */
                      6: 
                      7: /****************************************************************************
                      8:  * @format.tab-size 4          (Plain Text/Source Code File Header)                    *
                      9:  * @format.use-tabs true       (see http://www.synchro.net/ptsc_hdr.html)              *
                     10:  *                                                                                                                                                     *
                     11:  * Copyright 2000 Rob Swindell - http://www.synchro.net/copyright.html         *
                     12:  *                                                                                                                                                     *
                     13:  * This program is free software; you can redistribute it and/or                       *
                     14:  * modify it under the terms of the GNU General Public License                         *
                     15:  * as published by the Free Software Foundation; either version 2                      *
                     16:  * of the License, or (at your option) any later version.                                      *
                     17:  * See the GNU General Public License for more details: gpl.txt or                     *
                     18:  * http://www.fsf.org/copyleft/gpl.html                                                                                *
                     19:  *                                                                                                                                                     *
                     20:  * Anonymous FTP access to the most recent released source is available at     *
                     21:  * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net     *
                     22:  *                                                                                                                                                     *
                     23:  * Anonymous CVS access to the development source and modification history     *
                     24:  * is available at cvs.synchro.net:/cvsroot/sbbs, example:                                     *
                     25:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs login                       *
                     26:  *     (just hit return, no password is necessary)                                                     *
                     27:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src                *
                     28:  *                                                                                                                                                     *
                     29:  * For Synchronet coding style and modification guidelines, see                                *
                     30:  * http://www.synchro.net/source.html                                                                          *
                     31:  *                                                                                                                                                     *
                     32:  * You are encouraged to submit any modifications (preferably in Unix diff     *
                     33:  * format) via e-mail to [email protected]                                                                      *
                     34:  *                                                                                                                                                     *
                     35:  * Note: If this box doesn't appear square, then you need to fix your tabs.    *
                     36:  ****************************************************************************/
                     37: 
                     38: #include "sbbs.h"
                     39: 
                     40: #define LAST_STAT_LINE 16
                     41: 
                     42: #define nosound()      
                     43: 
                     44: /****************************************************************************/
                     45: /* Returns character if a key has been hit remotely and responds                       */
                     46: /* Called from functions getkey, msgabort and main_sec                                         */
                     47: /****************************************************************************/
                     48: char sbbs_t::inkey(long mode)
                     49: {
                     50:        char    str[512];
                     51:        char    tmp[512];
                     52:        uchar   ch=0;
                     53:        uint    i,j;
                     54: 
                     55:     if(keybuftop!=keybufbot) {
                     56:         ch=keybuf[keybufbot++];
                     57:         if(keybufbot==KEY_BUFSIZE)
                     58:             keybufbot=0; 
                     59:        } else
                     60:                ch=incom();
                     61:        if(ch==0) {
                     62:                if(!(mode&K_GETSTR) || mode&K_LOWPRIO || cfg.node_misc&NM_LOWPRIO)
                     63:                        mswait(1);
                     64:                return(0);
                     65:        }
                     66: 
                     67:        if(cfg.node_misc&NM_7BITONLY
                     68:                && (!(sys_status&SS_USERON) || useron.misc&NO_EXASCII))
                     69:                ch&=0x7f; 
                     70: 
                     71:        timeout=time(NULL);
                     72:        if(ch==3) {  /* Ctrl-C Abort */
                     73:                sys_status|=SS_ABORT;
                     74:                if(mode&K_SPIN) /* back space once if on spinning cursor */
                     75:                        bputs("\b \b");
                     76:                return(0); }
                     77:        if(ch==26 && action!=NODE_PCHT) {        /* Ctrl-Z toggle raw input mode */
                     78:                if(mode&K_SPIN)
                     79:                        bputs("\b ");
                     80:                SAVELINE;
                     81:                attr(LIGHTGRAY);
                     82:                CRLF;
                     83:                bputs(text[RawMsgInputModeIsNow]);
                     84:                if(console&CON_RAW_IN)
                     85:                        bputs(text[OFF]);
                     86:                else
                     87:                        bputs(text[ON]);
                     88:                console^=CON_RAW_IN;
                     89:                CRLF;
                     90:                CRLF;
                     91:                RESTORELINE;
                     92:                lncntr=0;
                     93:                if(action!=NODE_MAIN && action!=NODE_XFER)
                     94:                        return(26);
                     95:                return(0); }
                     96:        if(console&CON_RAW_IN)   /* ignore ctrl-key commands if in raw mode */
                     97:                return(ch);
                     98: 
                     99:        if(ch<SP) {                             /* Control chars */
                    100:                if(ch==LF)                              /* ignore LF's in not in raw mode */
                    101:                        return(0);
                    102:                if(ch==15) {    /* Ctrl-O toggles pause temporarily */
                    103:                        useron.misc^=UPAUSE;
                    104:                        return(0); }
                    105:                if(ch==0x10) {  /* Ctrl-P Private node-node comm */
                    106:                        if(!(sys_status&SS_USERON))
                    107:                                return(0);                       /* keep from being recursive */
                    108:                        if(mode&K_SPIN)
                    109:                                bputs("\b ");
                    110:                        if(sys_status&SS_SPLITP) {
                    111: #if 0 /* screen size */
                    112:                                if((scrnbuf=(uchar*)MALLOC((24L*80L)*2L))==NULL) {
                    113:                                        errormsg(WHERE,ERR_ALLOC,nulstr,(24L*80L)*2L);
                    114:                                        return(CR); }
                    115:                                gettext(1,1,80,24,scrnbuf);
                    116:                                x=lclwx();
                    117:                                y=lclwy();
                    118:                                CLS; 
                    119: #endif
                    120:                        }
                    121:                        else {
                    122:                                SAVELINE;
                    123:                                attr(LIGHTGRAY);
                    124:                                CRLF; }
                    125:                        nodesync();     /* read any waiting messages */
                    126:                        nodemsg();              /* send a message */
                    127:                        SYNC;
                    128:                        if(sys_status&SS_SPLITP) {
                    129: #if 0 /* screen size */
                    130:                                lncntr=0;
                    131:                                CLS;
                    132:                                for(i=0;i<((24*80)-1)*2;i+=2) {
                    133:                                        if(scrnbuf[i+1]!=curatr)
                    134:                                                attr(scrnbuf[i+1]);
                    135:                                        outchar(scrnbuf[i]); }
                    136:                                FREE(scrnbuf);
                    137:                                GOTOXY(x,y); 
                    138: #endif
                    139:                        }
                    140:                        else {
                    141:                                CRLF;
                    142:                                RESTORELINE; }
                    143:                        lncntr=0;
                    144:                        return(0); }
                    145: 
                    146:                if(ch==21) { /* Ctrl-U Users online */
                    147:                        if(!(sys_status&SS_USERON))
                    148:                                return(0);
                    149:                        if(mode&K_SPIN)
                    150:                                bputs("\b ");
                    151:                        if(sys_status&SS_SPLITP) {
                    152: #if 0 /* screen size */
                    153:                                if((scrnbuf=(uchar*)MALLOC((24L*80L)*2L))==NULL) {
                    154:                                        errormsg(WHERE,ERR_ALLOC,nulstr,(24L*80L)*2L);
                    155:                                        return(CR); }
                    156:                                gettext(1,1,80,24,scrnbuf);
                    157:                                x=lclwx();
                    158:                                y=lclwy();
                    159:                                CLS; 
                    160: #endif
                    161:                        }
                    162:                        else {
                    163:                                SAVELINE;
                    164:                                attr(LIGHTGRAY);
                    165:                                CRLF; }
                    166:                        whos_online(true);      /* list users */
                    167:                        ASYNC;
                    168:                        if(sys_status&SS_SPLITP) {
                    169: #if 0 /* screen size */
                    170:                                CRLF;
                    171:                                nodesync();
                    172:                                pause();
                    173:                                CLS;
                    174:                                for(i=0;i<((24*80)-1)*2;i+=2) {
                    175:                                        if(scrnbuf[i+1]!=curatr)
                    176:                                                attr(scrnbuf[i+1]);
                    177:                                        outchar(scrnbuf[i]); }
                    178:                                FREE(scrnbuf);
                    179:                                GOTOXY(x,y); 
                    180: #endif
                    181:                        }
                    182:                        else {
                    183:                                CRLF;
                    184:                                RESTORELINE; }
                    185:                        lncntr=0;
                    186:                        return(0); }
                    187:                if(ch==20 && !(sys_status&SS_SPLITP)) { /* Ctrl-T Time information */
                    188:                        if(!(sys_status&SS_USERON))
                    189:                                return(0);
                    190:                        if(mode&K_SPIN)
                    191:                                bputs("\b ");
                    192:                        SAVELINE;
                    193:                        attr(LIGHTGRAY);
                    194:                        now=time(NULL);
                    195:                        bprintf(text[TiLogon],timestr(&logontime));
                    196:                        bprintf(text[TiNow],timestr(&now));
                    197:                        bprintf(text[TiTimeon]
                    198:                                ,sectostr(now-logontime,tmp));
                    199:                        bprintf(text[TiTimeLeft]
                    200:                                ,sectostr(timeleft,tmp));
                    201:                        SYNC;
                    202:                        RESTORELINE;
                    203:                        lncntr=0;
                    204:                        return(0); }
                    205:                if(ch==11 && !(sys_status&SS_SPLITP)) {  /*  Ctrl-k Control key menu */
                    206:                        if(!(sys_status&SS_USERON))
                    207:                                return(0);
                    208:                        if(mode&K_SPIN)
                    209:                                bputs("\b ");
                    210:                        SAVELINE;
                    211:                        attr(LIGHTGRAY);
                    212:                        lncntr=0;
                    213:                        bputs(text[ControlKeyMenu]);
                    214:                        ASYNC;
                    215:                        RESTORELINE;
                    216:                        lncntr=0;
                    217:                        return(0); }
                    218: 
                    219:                if(ch==ESC && console&CON_R_INPUT) {
                    220:                        if(mode&K_GETSTR)
                    221:                                i=60;   // 3 seconds in GETSTR mode
                    222:                        else
                    223:                                i=20;   // 1 second otherwise
                    224:                        for(;i && !rioctl(RXBC);i--)
                    225:                                mswait(50);
                    226:                        if(!i)          // timed-out waiting for '['
                    227:                                return(ESC);
                    228:                        ch=incom();
                    229:                        if(ch!='[') {
                    230:                                ungetkey(ESC);
                    231:                                ungetkey(ch);
                    232:                                return(0); }
                    233:                        i=j=0;
                    234:                        autoterm|=ANSI;                         /* <ESC>[x means they have ANSI */
                    235:                        if(!(useron.misc&ANSI) && useron.misc&AUTOTERM && sys_status&SS_USERON
                    236:                                && useron.number) {
                    237:                                useron.misc|=ANSI;
                    238:                                putuserrec(&cfg,useron.number,U_MISC,8,ultoa(useron.misc,str,16)); }
                    239:                        while(i<10 && j<30) {           /* up to 3 seconds */
                    240:                                if(rioctl(RXBC)) {
                    241:                                        ch=incom();
                    242:                                        if(ch!=';' && !isdigit(ch) && ch!='R') {    /* other ANSI */
                    243:                                                switch(ch) {
                    244:                                                        case 'A':
                    245:                                                                return(0x1e);   /* ctrl-^ (up arrow) */
                    246:                                                        case 'B':
                    247:                                                                return(LF);     /* ctrl-j (dn arrow) */
                    248:                                                        case 'C':
                    249:                                                                return(0x6);    /* ctrl-f (rt arrow) */
                    250:                                                        case 'D':
                    251:                                                                return(0x1d);   /* ctrl-] (lf arrow) */
                    252:                                                        case 'H':
                    253:                                                                return(0x2);    /* ctrl-b (beg line) */
                    254:                                                        case 'K':
                    255:                                                                return(0x5);    /* ctrl-e (end line) */
                    256:                                                        }
                    257:                                                ungetkey(ESC);
                    258:                                                ungetkey('[');
                    259:                                                for(j=0;j<i;j++)
                    260:                                                        ungetkey(str[j]);
                    261:                                                ungetkey(ch);
                    262:                                                return(0); }
                    263:                                        if(ch=='R') {       /* cursor position report */
                    264:                                                if(i && !(useron.rows)) {       /* auto-detect rows */
                    265:                                                        str[i]=0;
                    266:                                                        rows=atoi(str);
                    267:                                                        if(rows<5 || rows>99) rows=24; }
                    268:                                                return(0); }
                    269:                                        str[i++]=ch; }
                    270:                                else {
                    271:                                        mswait(100);
                    272:                                        j++; } }
                    273: 
                    274:                        ungetkey(ESC);          /* should only get here if time-out */
                    275:                        ungetkey('[');
                    276:                        for(j=0;j<i;j++)
                    277:                                ungetkey(str[j]);
                    278:                        return(0); }
                    279: 
                    280:                        }       /* end of control chars */
                    281: 
                    282:        return(ch);
                    283: }
                    284: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.