|
|
1.1 root 1: /* inkey.cpp */
2:
3: /* Synchronet single key input function (no wait) */
4:
1.1.1.2 ! root 5: /* $Id: inkey.cpp,v 1.23 2003/10/24 21:46:55 rswindell Exp $ */
1.1 root 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: * *
1.1.1.2 ! root 11: * Copyright 2003 Rob Swindell - http://www.synchro.net/copyright.html *
1.1 root 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: /****************************************************************************/
1.1.1.2 ! root 48: char sbbs_t::inkey(long mode, unsigned long timeout)
1.1 root 49: {
50: uchar ch=0;
51:
52: if(keybuftop!=keybufbot) {
53: ch=keybuf[keybufbot++];
54: if(keybufbot==KEY_BUFSIZE)
55: keybufbot=0;
56: } else
1.1.1.2 ! root 57: ch=incom(timeout);
1.1 root 58: if(ch==0) {
1.1.1.2 ! root 59: // moved here from getkey() on AUG-29-2001
! 60: if(sys_status&SS_SYSPAGE)
! 61: sbbs_beep(sbbs_random(800),100);
! 62: #if 0
1.1 root 63: if(!(mode&K_GETSTR) || mode&K_LOWPRIO || cfg.node_misc&NM_LOWPRIO)
1.1.1.2 ! root 64: YIELD();
! 65: #endif
1.1 root 66: return(0);
67: }
68:
69: if(cfg.node_misc&NM_7BITONLY
70: && (!(sys_status&SS_USERON) || useron.misc&NO_EXASCII))
71: ch&=0x7f;
72:
73: timeout=time(NULL);
1.1.1.2 ! root 74:
! 75: /* Is this a control key */
! 76: if(ch<' ') {
! 77: if(cfg.ctrlkey_passthru&(1<<ch)) /* flagged as passthru? */
! 78: return(ch); /* do not handle here */
! 79: return(handle_ctrlkey(ch,mode));
! 80: }
! 81:
! 82: if(mode&K_UPPER)
! 83: ch=toupper(ch);
! 84:
! 85: return(ch);
! 86: }
! 87:
! 88: char sbbs_t::handle_ctrlkey(char ch, long mode)
! 89: {
! 90: char str[512];
! 91: char tmp[512];
! 92: uint i,j;
! 93:
! 94: if(ch==CTRL_C) { /* Ctrl-C Abort */
1.1 root 95: sys_status|=SS_ABORT;
96: if(mode&K_SPIN) /* back space once if on spinning cursor */
97: bputs("\b \b");
1.1.1.2 ! root 98: return(0);
! 99: }
! 100: if(ch==CTRL_Z && !(mode&K_MSG)
! 101: && action!=NODE_PCHT) { /* Ctrl-Z toggle raw input mode */
! 102: if(hotkey_inside>1) /* only allow so much recursion */
! 103: return(0);
! 104: hotkey_inside++;
1.1 root 105: if(mode&K_SPIN)
106: bputs("\b ");
107: SAVELINE;
108: attr(LIGHTGRAY);
109: CRLF;
110: bputs(text[RawMsgInputModeIsNow]);
111: if(console&CON_RAW_IN)
112: bputs(text[OFF]);
113: else
114: bputs(text[ON]);
115: console^=CON_RAW_IN;
116: CRLF;
117: CRLF;
118: RESTORELINE;
119: lncntr=0;
1.1.1.2 ! root 120: hotkey_inside--;
1.1 root 121: if(action!=NODE_MAIN && action!=NODE_XFER)
1.1.1.2 ! root 122: return(CTRL_Z);
! 123: return(0);
! 124: }
! 125:
1.1 root 126: if(console&CON_RAW_IN) /* ignore ctrl-key commands if in raw mode */
127: return(ch);
128:
1.1.1.2 ! root 129: if(ch==LF) /* ignore LF's if not in raw mode */
! 130: return(0);
! 131:
! 132: /* Global hot key event */
! 133: for(i=0;i<cfg.total_hotkeys;i++)
! 134: if(cfg.hotkey[i]->key==ch)
! 135: break;
! 136: if(i<cfg.total_hotkeys) {
! 137: if(hotkey_inside>1) /* only allow so much recursion */
1.1 root 138: return(0);
1.1.1.2 ! root 139: hotkey_inside++;
! 140: if(mode&K_SPIN)
! 141: bputs("\b ");
! 142: if(!(sys_status&SS_SPLITP)) {
! 143: SAVELINE;
! 144: attr(LIGHTGRAY);
! 145: CRLF;
! 146: }
! 147: external(cmdstr(cfg.hotkey[i]->cmd,nulstr,nulstr,NULL),0);
! 148: if(!(sys_status&SS_SPLITP)) {
! 149: CRLF;
! 150: RESTORELINE;
! 151: }
! 152: lncntr=0;
! 153: hotkey_inside--;
! 154: return(0);
! 155: }
! 156:
! 157: switch(ch) {
! 158: case CTRL_O: /* Ctrl-O toggles pause temporarily */
1.1 root 159: useron.misc^=UPAUSE;
1.1.1.2 ! root 160: return(0);
! 161: case CTRL_P: /* Ctrl-P Private node-node comm */
1.1 root 162: if(!(sys_status&SS_USERON))
163: return(0); /* keep from being recursive */
1.1.1.2 ! root 164: if(hotkey_inside>1) /* only allow so much recursion */
! 165: return(0);
! 166: hotkey_inside++;
1.1 root 167: if(mode&K_SPIN)
168: bputs("\b ");
1.1.1.2 ! root 169: if(!(sys_status&SS_SPLITP)) {
1.1 root 170: SAVELINE;
171: attr(LIGHTGRAY);
1.1.1.2 ! root 172: CRLF;
! 173: }
1.1 root 174: nodesync(); /* read any waiting messages */
175: nodemsg(); /* send a message */
176: SYNC;
1.1.1.2 ! root 177: if(!(sys_status&SS_SPLITP)) {
1.1 root 178: CRLF;
1.1.1.2 ! root 179: RESTORELINE;
! 180: }
1.1 root 181: lncntr=0;
1.1.1.2 ! root 182: hotkey_inside--;
! 183: return(0);
1.1 root 184:
1.1.1.2 ! root 185: case CTRL_U: /* Ctrl-U Users online */
! 186: /* needs recursion checking */
1.1 root 187: if(!(sys_status&SS_USERON))
188: return(0);
1.1.1.2 ! root 189: if(hotkey_inside>1) /* only allow so much recursion */
! 190: return(0);
! 191: hotkey_inside++;
1.1 root 192: if(mode&K_SPIN)
193: bputs("\b ");
1.1.1.2 ! root 194: if(!(sys_status&SS_SPLITP)) {
1.1 root 195: SAVELINE;
196: attr(LIGHTGRAY);
1.1.1.2 ! root 197: CRLF;
! 198: }
1.1 root 199: whos_online(true); /* list users */
200: ASYNC;
1.1.1.2 ! root 201: if(!(sys_status&SS_SPLITP)) {
1.1 root 202: CRLF;
1.1.1.2 ! root 203: RESTORELINE;
1.1 root 204: }
205: lncntr=0;
1.1.1.2 ! root 206: hotkey_inside--;
! 207: return(0);
! 208: case CTRL_T: /* Ctrl-T Time information */
! 209: if(sys_status&SS_SPLITP)
! 210: return(ch);
1.1 root 211: if(!(sys_status&SS_USERON))
212: return(0);
1.1.1.2 ! root 213: if(hotkey_inside>1) /* only allow so much recursion */
! 214: return(0);
! 215: hotkey_inside++;
1.1 root 216: if(mode&K_SPIN)
217: bputs("\b ");
218: SAVELINE;
219: attr(LIGHTGRAY);
220: now=time(NULL);
221: bprintf(text[TiLogon],timestr(&logontime));
222: bprintf(text[TiNow],timestr(&now));
223: bprintf(text[TiTimeon]
224: ,sectostr(now-logontime,tmp));
225: bprintf(text[TiTimeLeft]
226: ,sectostr(timeleft,tmp));
227: SYNC;
228: RESTORELINE;
229: lncntr=0;
1.1.1.2 ! root 230: hotkey_inside--;
! 231: return(0);
! 232: case CTRL_K: /* Ctrl-k Control key menu */
! 233: if(sys_status&SS_SPLITP)
! 234: return(ch);
1.1 root 235: if(!(sys_status&SS_USERON))
236: return(0);
1.1.1.2 ! root 237: if(hotkey_inside>1) /* only allow so much recursion */
! 238: return(0);
! 239: hotkey_inside++;
1.1 root 240: if(mode&K_SPIN)
241: bputs("\b ");
242: SAVELINE;
243: attr(LIGHTGRAY);
244: lncntr=0;
245: bputs(text[ControlKeyMenu]);
246: ASYNC;
247: RESTORELINE;
248: lncntr=0;
1.1.1.2 ! root 249: hotkey_inside--;
! 250: return(0);
! 251: case ESC:
! 252: i=incom(mode&K_GETSTR ? 3000:1000);
! 253: if(i==NOINP) // timed-out waiting for '['
1.1 root 254: return(ESC);
1.1.1.2 ! root 255: ch=i;
1.1 root 256: if(ch!='[') {
257: ungetkey(ESC);
258: ungetkey(ch);
1.1.1.2 ! root 259: return(0);
! 260: }
1.1 root 261: i=j=0;
262: autoterm|=ANSI; /* <ESC>[x means they have ANSI */
263: if(!(useron.misc&ANSI) && useron.misc&AUTOTERM && sys_status&SS_USERON
264: && useron.number) {
265: useron.misc|=ANSI;
1.1.1.2 ! root 266: putuserrec(&cfg,useron.number,U_MISC,8,ultoa(useron.misc,str,16));
! 267: }
1.1 root 268: while(i<10 && j<30) { /* up to 3 seconds */
1.1.1.2 ! root 269: ch=incom(100);
! 270: if(ch==(NOINP&0xff)) {
! 271: j++;
! 272: continue;
! 273: }
! 274: if(ch!=';' && !isdigit(ch) && ch!='R') { /* other ANSI */
! 275: switch(ch) {
! 276: case 'A':
! 277: return(0x1e); /* ctrl-^ (up arrow) */
! 278: case 'B':
! 279: return(LF); /* ctrl-j (dn arrow) */
! 280: case 'C':
! 281: return(CTRL_F); /* ctrl-f (rt arrow) */
! 282: case 'D':
! 283: return(0x1d); /* ctrl-] (lf arrow) */
! 284: case 'H': /* ANSI: home cursor */
! 285: return(CTRL_B); /* ctrl-b (beg line) */
! 286: case 'F': /* Xterm: cursor preceding line */
! 287: case 'K': /* ANSI: clear-to-end-of-line */
! 288: return(CTRL_E); /* ctrl-e (end line) */
! 289: }
! 290: ungetkey(ESC);
! 291: ungetkey('[');
! 292: for(j=0;j<i;j++)
! 293: ungetkey(str[j]);
! 294: ungetkey(ch);
! 295: return(0);
! 296: }
! 297: if(ch=='R') { /* cursor position report */
! 298: if(i && !(useron.rows)) { /* auto-detect rows */
! 299: str[i]=0;
! 300: rows=atoi(str);
! 301: lprintf(LOG_DEBUG,"Node %d ANSI cursor position report: %u rows"
! 302: ,cfg.node_num, rows);
! 303: if(rows<10 || rows>99) rows=24;
! 304: }
! 305: return(0);
! 306: }
! 307: str[i++]=ch;
! 308: }
1.1 root 309:
310: ungetkey(ESC); /* should only get here if time-out */
311: ungetkey('[');
312: for(j=0;j<i;j++)
313: ungetkey(str[j]);
1.1.1.2 ! root 314: return(0);
! 315: }
1.1 root 316: return(ch);
317: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.