1
/* @(#)tvgets.c 19.1 (ES0-DMD) 02/25/03 13:58:14 */
2
/*===========================================================================
3
Copyright (C) 1995 European Southern Observatory (ESO)
5
This program is free software; you can redistribute it and/or
6
modify it under the terms of the GNU General Public License as
7
published by the Free Software Foundation; either version 2 of
8
the License, or (at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public
16
License along with this program; if not, write to the Free
17
Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
20
Corresponding concerning ESO-MIDAS should be addressed as follows:
21
Internet e-mail: midas@eso.org
22
Postal address: European Southern Observatory
23
Data Management Division
24
Karl-Schwarzschild-Strasse 2
25
D 85748 Garching bei Muenchen
27
===========================================================================*/
29
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
32
.IDENTIFICATION tvgets.c
33
.AUTHOR Francois Ochsenbein [ESO-IPG]
35
.KEYWORDS On-line input editing
36
.ENVIRONMENT TermWindows
37
.COMMENTS This module contains routines to perform command input,
41
This module is only there to be able to use on-line editiing
42
facilities without any window. Unlike tw\_gets functions,
43
commands are not stacked, and the memory is limited to
46
The default actions of control characters are defined as TW\_cc\_default
47
in {\tt twparam.h}, with choices UNIX-like, VMS-like or a third
48
set. The action of each control character may be modified with the
49
tv\_setcc(control\_character, action) (DefineControl) function.
51
The characters that stop output may be defined via the tv\_stopin
56
.VERSION 3.0 14-Apr-1988: Creation for MIDAS usage.
57
.VERSION 3.1 05-Oct-1988: Modifications for MIDAS: Command Stacking allowed.
58
.VERSION 3.2 21-Feb-1990: Suppress all warnings
60
-----------------------------------------------------------------------*/
62
#define DEBUG 0 /* For debugging */
64
#define PM_LEVEL LEVEL_TV
67
#define TW_STRUCT 0 /* Do not use window Structures */
68
#define TW_MACROS 0 /* Don't use Windows Macros */
71
MID_EXTERN TERM *terms ;
74
# define ENTER_DEBUG(x) ENTER(x)
75
# define EXIT_DEBUG(x) EXIT(x)
76
# define TERMTEST if(!terms->version) tv_gopen();\
79
# define TERMTEST if(!terms->version) tv_gopen()
80
# define ENTER_DEBUG(x)
81
# define EXIT_DEBUG(x) return(x)
84
#define FINISH goto FIN
86
MID_STATIC unsigned int f = 0; /* Flags to communicate */
87
MID_STATIC unsigned int f0= Echo|Stacking;/* Flags to communicate */
88
static int J; /* Column width */
89
static int init_pos; /* Where is the cursor at beginning */
91
MID_STATIC char *stop_list = (char *)0;
92
MID_STATIC int stop_len = 0;
96
#define Special 0x0200
100
/* Stored Commands as a static structure */
102
static unsigned char command_buffer[1600] = {0,0,0,0};
104
static COMMAND command = {
105
MASK('\r'), /* Which controls exit */
106
0, /* Which arrow keys exit */
107
0, /* Which special keys exit */
110
sizeof(command_buffer),
119
static COMMAND *c = &command;
120
static short command_number;
121
static int command_len;
126
/*==========================================================================
128
*==========================================================================*/
129
static int o1(ch, len)
131
.PURPOSE Optimized output of 1 character.
132
.RETURNS 0 / 1 (number of chars output on Screen)
133
.REMARKS Complete string rewritten if in InsertMode.
135
char *ch; /* IN: Character to output */
136
int len; /* IN: Length of input */
143
if_not(f&Echo) EXIT_DEBUG(0);
147
state_buffer = tv_buffer(1); /* To output only at end */
148
status = WriteBinary(p, 1);
151
if ( f & Imode) /* Continuation to write */
154
SetPosition(GetPosition() - len);
157
tv_buffer(state_buffer); /* Output everything */
159
/* Check if the Screen scrolled; modify accordingly init_pos */
160
init_pos = GetPosition() - (p - p_start);
165
/*======================================================================
167
*======================================================================*/
168
static int mv1(direction, max_move)
170
.PURPOSE Optimized cursor mouvement of 1 place in the specified
171
direction: up, down, right, left or home.
172
.RETURNS The actual displacement in bytes.
173
.REMARKS Move is limited...
175
int direction; /* IN: The direction of the displacement */
176
int max_move; /* IN: Maximal right / down displacement in bytes */
186
{ case _LEFT_: new_pos -= 1; break;
187
case _RIGHT_: new_pos += MIN(max_move, 1); break;
188
case _UP_: new_pos -= J; break;
189
case _DOWN_: new_pos += MIN(max_move, J); break;
190
default: new_pos = init_pos;
193
if (new_pos < init_pos) new_pos = init_pos;
194
SetPosition(new_pos);
196
EXIT_DEBUG(new_pos - pos);
199
/*======================================================================
201
*======================================================================*/
202
static int dc(str, nd, len)
204
.PURPOSE Delete characters at left of cursor.
208
char *str; /* IN: The new string */
209
int nd; /* IN: Number of bytes to delete */
210
int len; /* IN: Length of text */
212
int pos, nb, state_buffer;
213
static char blanks[] = " ";
218
state_buffer = tv_buffer(1); /* To output only at end */
219
pos = GetPosition() - nd;
222
if (len) WriteBinary(str, len);
223
for (nb = nd; nb > 0; nb -= sizeof(blanks)-1)
224
WriteBinary(blanks, MIN(nb, sizeof(blanks)-1));
227
tv_buffer(state_buffer); /* Output everything */
232
/*======================================================================
234
*======================================================================*/
235
static int show(str, in, len)
237
.PURPOSE Redisplay the string (in, len) in place of the current command,
239
.RETURNS Length of string
242
char *str; /* OUT: copied string */
243
char *in; /* IN: string to display */
244
int len; /* IN: Length of in */
248
l = MIN (len, command_len);
250
SetPosition(init_pos);
253
/* Check if the Screen scrolled; modify accordingly init_pos */
254
init_pos = GetPosition() - l;
259
/*==========================================================================*/
260
static int zm(direction)
262
.PURPOSE Move in the command stack according to the specified direction.
263
.RETURNS OK / NOK (at the top or bottom of the stack)
266
int direction; /* IN: _UP_, _DOWN_ or _HOME_ (last command) */
272
{ case _UP_: /* Towards the beginning of the stack */
273
if (c->pointed_no <= c->first_no)
274
{ c->pointed_no = c->first_no - 1;
279
(c->pointed)--; /* Index of suffix length */
280
(c->pointed) -= (1 + *(c->text + c->pointed));
282
case _DOWN_: /* Towards the bottom of the stack */
283
if (c->pointed_no >= c->last_no)
284
{ c->pointed_no = c->last_no + 1;
285
c->pointed = c->used;
289
(c->pointed) += (2 + *(c->text + c->pointed));
291
default: /* The last issued command */
292
if (c->last_no < c->first_no)
297
c->pointed_no = c->last_no;
298
c->pointed = (c->used) - 1;
299
(c->pointed) -= (1 + *(c->text + c->pointed));
308
/*==========================================================================
310
*==========================================================================*/
311
static int zadd(str, nbytes, opt)
313
.PURPOSE Insert into the command stack the string str.
314
.RETURNS OK / NOK (not enough space)
317
char *str; /* IN: The string to insert */
318
int nbytes; /* IN: Length of the str string */
319
int opt; /* IN: Option 1 to add effectively / 2 only if\
320
differs from previous */
325
TRACE_ED_STR2("Command = ",str,nbytes);
329
if (nbytes < 0) FINISH;
330
if (c->size == 0) FINISH;
332
/* Check it it's the same command as previous one */
334
if ((opt == 2) && zm(_HOME_)) /* Get last command */
335
{ p = (char *)(c->text + c->pointed);
336
if ((*(p++) == nbytes) && (oscomp(p, str, nbytes) == 0))
342
u = c->used + nbytes + 2; /* Used bytes after addition */
345
while (u > c->size) /* Look if stack must be compressed */
346
{ l = *(c->text + i) + 2; /* Length of command */
351
if (u < 2) /* Not enough space ... */
357
{ l = c->used - i; /* Length to copy */
358
c->used = 2 + oscopy((char *)(c->text+2), (char *)(c->text + i), l);
361
c->pointed = c->used;
363
p = (char *)(c->text + c->used);
364
*(p++) = nbytes; /* Prefix length */
365
p += oscopy((char *)p, (char *)str, nbytes);
367
*(p++) = nbytes; /* Suffix length */
369
if (opt) /* Modify only if required */
370
{ c->used = (unsigned char *)p - (c->text);
372
(c->pointed_no) = c->last_no;
381
/*==========================================================================
383
*==========================================================================*/
384
int tv_stopin(type, list)
386
.PURPOSE Define the list of Characters that stop the Input:
387
Control Characters, Arrows, Keypad, Function Keys.
389
.REMARKS For type _STANDARD_ or _ARROW_, list gives the ASCII equivalence,
390
e.g. A for Control A, U for the Up Key.
391
For a void string (""), all stopping characters are removed;
392
a string starting with + means "add to existing list",
393
with - "delete from existing list".
394
The * acts as the wild character, e.g. "*-" means "delete all".
395
By default, only the \r (Carriage-Return) stops the input.
397
int type; /* IN: _STANDARD_ , _ARROW_, _KEYPAD_, _PF_ or _FK_ */
398
char *list; /* IN: The characters that may be used to terminate; \
399
the * is used as a wild character \
408
if_not(list) EXIT(NOK);
410
wild = (*p == '+' ? 1 : (*p == '-' ? -1 : 0));
414
if_not(wild) c->exit_ar = 0;
416
{ switch(tolower(*p))
417
{ case 'u': i = MASK(_UP_); break;
418
case 'd': i = MASK(_DOWN_); break;
419
case 'l': case 'b': i = MASK(_LEFT_); break;
420
case 'r': case 'f': i = MASK(_RIGHT_); break;
421
default : i = MASK(_HOME_); break;
422
case '*': i = 0xff; break;;
423
case '+': wild = 1; continue;
424
case '-': wild = -1; continue;
426
if (wild<0) c->exit_ar &= ~i;
427
else c->exit_ar |= i;
431
case _KEYPAD_: case _PF_: case _FK_:
433
if (*p == '*') wild = 1;
434
if (wild) c->exit_pf &= ~i;
435
if (wild > 0) c->exit_pf |= i;
438
default: /* Control Characters */
439
if_not(wild) c->exit_cc = MASK('\r');
442
{ case '+': wild = 1; continue;
443
case '-': wild = -1; continue;
444
case '*': i = (unsigned int)0xffffffff; break;
445
default: i = MASK(Control_(*p)); break;
447
if (wild<0) c->exit_cc &= ~i;
448
else c->exit_cc |= i;
456
/*==========================================================================
458
*==========================================================================*/
459
int tv_get1(str, nbytes, stop1)
461
.PURPOSE Get a command string from terminal, made of up to (nbytes-1)
462
characters, but stop if one of the characters
463
in stop1 was hit as the {\em first} input.
464
.RETURNS _EOF_ / 0 / _STANDARD_ / _ARROW_ / _KEYPAD_ / _FK_ / _PF_
467
char *str; /* MOD: The buffer to get the input */
468
int nbytes; /* IN: Length of the input buffer */
469
char *stop1; /* IN: List of characters to stop */
476
stop_len = strlen(stop1);
477
status = tv_mods(str, nbytes, 0);
483
/*==========================================================================
485
*==========================================================================*/
486
int tv_getp(str, nbytes)
488
.PURPOSE Get a password (no echo)
489
.RETURNS _EOF_ / 0 / _STANDARD_ / _ARROW_ / _KEYPAD_ / _FK_ / _PF_
492
char *str; /* MOD: The buffer to get the input */
493
int nbytes; /* IN: Length of the input buffer */
500
status = tv_mods(str, nbytes, 0);
501
f0 = Echo | Stacking;
506
/*==========================================================================
508
*==========================================================================*/
509
int tv_mods(str, nbytes, linput)
511
.PURPOSE Display a template command, and get a command string
512
from terminal, made of up to (nbytes-1)
513
characters, and echo.
514
The input stops when the one of the characters
515
specified by tv_stopin is hit (the Carriage Return only by default).
517
{\em Note that} keypad characters are considered as normal chars,
518
unless {\tt tv\_stopin(w, \_KEYPAD\_,"*")} was called.
520
.RETURNS OK or _STANDARD_, EOF, NOK, _KEYPAD_, _PF_, _FK_ with the
524
\item OK or \_STANDARD\_: a $<$Carriage\_Return$>$ or $<$Enter$>$
525
terminates the input;
526
this last character is not reported to the string,
527
but {\em is replaced by the EOS character.}
530
\item the size of the input string is 1 character or less
532
\item a control / arrow / keypad / PK / Function character was typed
533
at the terminal, which is {\em not the
535
the returned string contains the previous characters
536
(\ie before the stopping char), and a next call to
537
the function will return the control character.
539
\item EOF: the EOF (Control\_Z or Control\_D, depending on initialization)
540
char was typed as the
541
{\em first} input character; the output string contains only
543
{\em Note that the EOF character not typed as the first char
545
\item \_KEYPAD\_: a keypad key is the
546
{\em first} input character and the Keypad is enabled
547
via a previous call to {\tt tv\_stopin(w, \_KEYPAD\_, "*")};
548
the output string contains the equivalence keypad.
549
If the Keypad is enabled via {\em tv\_stopin}, and a Keypad
550
was hit after normal ASCII characters, the function returns NOK.
551
Note that keypad keys are translated if the keypad is not enabled.
552
\item \_PF\_: a PF key is the
553
{\em first} input character if PF keys were previously enabled
554
via {\tt tv\_stopin(w, \_PF\_, "*")}.
555
\item \_FK\_: a Function is the
556
{\em first} input character if Function keys were previously enabled
557
via {\tt tv\_stopin(w, \_FK\_, "*")}.
562
char *str; /* MOD: The buffer to get the input */
563
int nbytes; /* IN: Length of the input buffer */
564
int linput; /* IN: Length of template string */
566
register char *p; /* Current position in str */
567
char *pw, *p_end; /* pw is last valid char in str */
574
f = f0, f0 = Echo | Stacking;
576
if (nbytes < 2) EXIT(NOK); /* Buffer too small */
578
TERMTEST; /* Open Terminal if not yet done */
582
command_len = nbytes - 1;
583
p_end = p + command_len;
585
init_pos = GetPosition(); /* Keep first initial data */
586
J = terms->dim[1]; /* Column width */
588
if (linput) TRACE_STR2(str, linput);
591
/* Echo template string, and position cursor to End of Template */
594
{ i = MIN(linput, p_end - p_start);
595
WriteBinary(p_start, i);
599
/* Initialize the Stack of Commands */
601
c->pointed = c->used;
602
c->pointed_no = c->last_no + 1;
603
command_number = c->pointed_no;
606
/* ============ Loop on the input char ======== */
610
if (f & NoMore) /* Too long string... */
618
TRACE_ED_STR2("Total string is: ",str, pw-str);
619
TRACE_ED_STR2("Present string is: ",str, p-str);
620
TRACE_ED_STR2("Just read : ",&ch, 1);
621
TRACE_ED_I (" ... of type: ",type);
624
if ( type == NOK) /* Bad Escape Sequence... */
629
if (f & Raw) type = _STANDARD_;
632
{ case EOF: f |= (Stop|Special);
635
case _PF_: case _FK_:
636
if (c->exit_pf & MASK(type))
642
if (c->exit_ar & MASK(ch))
643
{ f |= (Stop|Special);
646
switch(ch) /* Execute the Cursor Movements */
649
p += mv1(ch, pw - p); /* Maximal Displacement is pw-p */
652
SetPosition(init_pos), p = p_start;
656
/* Copy retrieved command, and edit it */
657
if_not(f&Echo) continue;
658
if (c->pointed_no == command_number)
659
/* Save what has been typed */
660
zadd(str, pw-str, 0);
661
zm(ch); /* Move in Stack */
664
l = show(p_start, (char *)(c->text + i + 1), l);
670
if (c->exit_pf & MASK(_KEYPAD_))
671
{ f |= (Stop|Special);
674
type = _STANDARD_; /* Keypad chars are considered as normal */
678
/* --- Here Only if it's an ASCII character ---- */
680
if ((isprint(ch)) || (f&Raw))
683
{ if ( (pw) >= p_end) f |= NoMore;
684
else oscopy ( p+1, p, pw++ - p);
686
else /* Replace Mode */
687
{ if (pw <= p) pw = p+1;
688
if (pw > p_end) pw--, f |= NoMore;
690
if (f & NoMore) /* Too long string... */
693
o1(p, pw-p); /* Echo the character...*/
695
if (stop_len) /* Check first byte */
696
{ if (oscloc(stop_list, stop_len, ch) < stop_len)
700
if(ch == EOS) continue;
705
/*==============================================*/
706
/* --- Here only if it's a Control Char */
707
/*==============================================*/
709
if (ch == '\r') /* Normal End */
714
i = *(unsigned char *)(&ch);
715
if (i > 32) /* Delete char */
718
if (c->exit_cc & MASK(i)) /* Exit on Control */
719
{ f |= (Stop|Special);
724
{ default: Bell(); /* Just ignore... */
727
case TW_cc_RAW: f |= Raw;
730
case TW_cc_REFR: /* Refresh Screen */
731
SetPosition(init_pos);
733
WriteBinary(p_start, pw-p_start);
734
SetPosition(init_pos + (p-p_start));
737
case TW_cc_HELP: /* Go first to end of text, show help,
738
* and reissue text */
739
SetPosition(init_pos + (pw - p_start));
741
WriteBinary(p_start, pw-p_start);
742
init_pos = GetPosition() - (pw - p_start);
743
SetPosition(init_pos + (p - p_start));
746
case TW_cc_MODE: f ^= Imode; /* Change mode */
747
continue; /* Imode flag done at loop top */
749
case TW_cc_NW: /* Move to next word */
750
p += oscscan(p, pw-p, _SPACE_, main_ascii);
751
p += oscspan(p, pw-p, _SPACE_, main_ascii);
752
SetPosition(init_pos + (p-p_start));
755
case TW_cc_EOL: /* Move cursor to end */
756
SetPosition(init_pos + (pw - p_start));
760
case TW_cc_DELC: /* Delete Char */
761
if (p == p_start) continue;
763
oscopy(p, p+1, pw-p);
767
case TW_cc_DELL: /* Clear Line */
769
SetPosition(init_pos);
773
case TW_cc_DELE: /* Delete to the right */
778
case TW_cc_DELW: /* Delete Previous Word */
779
if (p == p_start) continue;
780
i = oscbspan(p_start, p-p_start, _SPACE_, main_ascii);
781
i = oscbscan(p_start, i+1, _SPACE_, main_ascii);
782
i = (p-p_start) - (i+1); /* Number of chars to delete */
783
oscopy(p-i, p, pw-p);
790
p = pw, l = p - p_start; /* Final Length of String */
791
SetPosition(init_pos + l); /* Where the cursor must be */
793
/* Add the string to command stack */
795
if ( (type <= _STANDARD_) && (l > 0) && (f&Stacking))
799
{ if (pw == str) /* Was First Input Character */
801
else tv_push(type, ch), type = NOK;
812
/*==========================================================================
814
*==========================================================================*/
815
int tv_kmods(flag,str, nbytes, linput)
817
.PURPOSE Display a template command, and get a command string
818
from terminal, made of up to (nbytes-1)
819
characters, and echo.
820
The input stops when the one of the characters
821
specified by tv_stopin is hit (the Carriage Return only by default).
823
{\em Note that} keypad characters are considered as normal chars,
824
unless {\tt tv\_stopin(w, \_KEYPAD\_,"*")} was called.
826
.RETURNS OK or _STANDARD_, EOF, NOK, _KEYPAD_, _PF_, _FK_ with the
830
\item OK or \_STANDARD\_: a $<$Carriage\_Return$>$ or $<$Enter$>$
831
terminates the input;
832
this last character is not reported to the string,
833
but {\em is replaced by the EOS character.}
836
\item the size of the input string is 1 character or less
838
\item a control / arrow / keypad / PK / Function character was typed
839
at the terminal, which is {\em not the
841
the returned string contains the previous characters
842
(\ie before the stopping char), and a next call to
843
the function will return the control character.
845
\item EOF: the EOF (Control\_Z or Control\_D, depending on initialization)
846
char was typed as the
847
{\em first} input character; the output string contains only
849
{\em Note that the EOF character not typed as the first char
851
\item \_KEYPAD\_: a keypad key is the
852
{\em first} input character and the Keypad is enabled
853
via a previous call to {\tt tv\_stopin(w, \_KEYPAD\_, "*")};
854
the output string contains the equivalence keypad.
855
If the Keypad is enabled via {\em tv\_stopin}, and a Keypad
856
was hit after normal ASCII characters, the function returns NOK.
857
Note that keypad keys are translated if the keypad is not enabled.
858
\item \_PF\_: a PF key is the
859
{\em first} input character if PF keys were previously enabled
860
via {\tt tv\_stopin(w, \_PF\_, "*")}.
861
\item \_FK\_: a Function is the
862
{\em first} input character if Function keys were previously enabled
863
via {\tt tv\_stopin(w, \_FK\_, "*")}.
868
int flag; /* IN: 1 or 0 for Insert or Change mode */
869
char *str; /* MOD: The buffer to get the input */
870
int nbytes; /* IN: Length of the input buffer */
871
int linput; /* IN: Length of template string */
873
register char *p; /* Current position in str */
874
char *pw, *p_end; /* pw is last valid char in str */
881
f = f0, f0 = Echo | Stacking;
883
if (nbytes < 2) EXIT(NOK); /* Buffer too small */
885
TERMTEST; /* Open Terminal if not yet done */
889
command_len = nbytes - 1;
890
p_end = p + command_len;
892
init_pos = GetPosition(); /* Keep first initial data */
893
J = terms->dim[1]; /* Column width */
895
if (linput) TRACE_STR2(str, linput);
898
/* Echo template string, and position cursor to End of Template */
901
{ i = MIN(linput, p_end - p_start);
902
WriteBinary(p_start, i);
906
/* Initialize the Stack of Commands */
908
c->pointed = c->used;
909
c->pointed_no = c->last_no + 1;
910
command_number = c->pointed_no;
912
if (flag == 1) f ^= Imode; /* Change mode */
914
/* ============ Loop on the input char ======== */
918
if (f & NoMore) /* Too long string... */
926
TRACE_ED_STR2("Total string is: ",str, pw-str);
927
TRACE_ED_STR2("Present string is: ",str, p-str);
928
TRACE_ED_STR2("Just read : ",&ch, 1);
929
TRACE_ED_I (" ... of type: ",type);
932
if ( type == NOK) /* Bad Escape Sequence... */
937
if (f & Raw) type = _STANDARD_;
940
{ case EOF: f |= (Stop|Special);
943
case _PF_: case _FK_:
944
if (c->exit_pf & MASK(type))
950
if (c->exit_ar & MASK(ch))
951
{ f |= (Stop|Special);
954
switch(ch) /* Execute the Cursor Movements */
957
p += mv1(ch, pw - p); /* Maximal Displacement is pw-p */
960
SetPosition(init_pos), p = p_start;
964
/* Copy retrieved command, and edit it */
965
if_not(f&Echo) continue;
966
if (c->pointed_no == command_number)
967
/* Save what has been typed */
968
zadd(str, pw-str, 0);
969
zm(ch); /* Move in Stack */
972
l = show(p_start, (char *)(c->text + i + 1), l);
978
if (c->exit_pf & MASK(_KEYPAD_))
979
{ f |= (Stop|Special);
982
type = _STANDARD_; /* Keypad chars are considered as normal */
986
/* --- Here Only if it's an ASCII character ---- */
988
if ((isprint(ch)) || (f&Raw))
991
{ if ( (pw) >= p_end) f |= NoMore;
992
else oscopy ( p+1, p, pw++ - p);
994
else /* Replace Mode */
995
{ if (pw <= p) pw = p+1;
996
if (pw > p_end) pw--, f |= NoMore;
998
if (f & NoMore) /* Too long string... */
1001
o1(p, pw-p); /* Echo the character...*/
1003
if (stop_len) /* Check first byte */
1004
{ if (oscloc(stop_list, stop_len, ch) < stop_len)
1008
if(ch == EOS) continue;
1013
/*==============================================*/
1014
/* --- Here only if it's a Control Char */
1015
/*==============================================*/
1017
if (ch == '\r') /* Normal End */
1022
i = *(unsigned char *)(&ch);
1023
if (i > 32) /* Delete char */
1026
if (c->exit_cc & MASK(i)) /* Exit on Control */
1027
{ f |= (Stop|Special);
1031
switch(terms->tc[i])
1032
{ default: Bell(); /* Just ignore... */
1035
case TW_cc_RAW: f |= Raw;
1038
case TW_cc_REFR: /* Refresh Screen */
1039
SetPosition(init_pos);
1041
WriteBinary(p_start, pw-p_start);
1042
SetPosition(init_pos + (p-p_start));
1045
case TW_cc_HELP: /* Go first to end of text, show help,
1046
* and reissue text */
1047
SetPosition(init_pos + (pw - p_start));
1049
WriteBinary(p_start, pw-p_start);
1050
init_pos = GetPosition() - (pw - p_start);
1051
SetPosition(init_pos + (p - p_start));
1054
case TW_cc_MODE: f ^= Imode; /* Change mode */
1055
continue; /* Imode flag done at loop top */
1057
case TW_cc_NW: /* Move to next word */
1058
p += oscscan(p, pw-p, _SPACE_, main_ascii);
1059
p += oscspan(p, pw-p, _SPACE_, main_ascii);
1060
SetPosition(init_pos + (p-p_start));
1063
case TW_cc_EOL: /* Move cursor to end */
1064
SetPosition(init_pos + (pw - p_start));
1068
case TW_cc_DELC: /* Delete Char */
1069
if (p == p_start) continue;
1071
oscopy(p, p+1, pw-p);
1075
case TW_cc_DELL: /* Clear Line */
1076
p = p_start, pw = p;
1077
SetPosition(init_pos);
1081
case TW_cc_DELE: /* Delete to the right */
1086
case TW_cc_DELW: /* Delete Previous Word */
1087
if (p == p_start) continue;
1088
i = oscbspan(p_start, p-p_start, _SPACE_, main_ascii);
1089
i = oscbscan(p_start, i+1, _SPACE_, main_ascii);
1090
i = (p-p_start) - (i+1); /* Number of chars to delete */
1091
oscopy(p-i, p, pw-p);
1098
p = pw, l = p - p_start; /* Final Length of String */
1099
SetPosition(init_pos + l); /* Where the cursor must be */
1101
/* Add the string to command stack */
1103
if ( (type <= _STANDARD_) && (l > 0) && (f&Stacking))
1107
{ if (pw == str) /* Was First Input Character */
1109
else tv_push(type, ch), type = NOK;