1
/*===========================================================================
2
Copyright (C) 1986-2009 European Southern Observatory (ESO)
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; either version 2 of
7
the License, or (at your option) any later version.
9
This program is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU General Public License for more details.
14
You should have received a copy of the GNU General Public
15
License along with this program; if not, write to the Free
16
Software Foundation, Inc., 675 Massachusetss Ave, Cambridge,
19
Corresponding concerning ESO-MIDAS should be addressed as follows:
20
Internet e-mail: midas@eso.org
21
Postal address: European Southern Observatory
22
Data Management Division
23
Karl-Schwarzschild-Strasse 2
24
D 85748 Garching bei Muenchen
26
===========================================================================*/
28
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
.IDENTIFICATION tvindel.c
32
.AUTHOR Francois Ochsenbein [ESO-IPG]
34
.KEYWORDS Terminal Independant i/o Package.
35
.ENVIRONMENT TermWindows
36
.COMMENTS This module includes functions to insert or delete lines
38
In the Minimal Implementation, these routines are not used.
41
$$\begin{tabular}{|lp{30em}|} \hline
42
{\tt al} & Add a new (blank) line, pushing all lines below it down.\\
43
{\tt dl} & Delete the current line, moving all lines below it up \\
44
{\tt dc} & Delete the current char, moving all chars to the left \\
45
{\tt ei} & Exit Insert Mode. \\
46
{\tt ic} & Insert one blank, moving all chars to the right \\
47
{\tt im} & Enter Insert Mode. \\
51
.VERSION 1.0 12-Aug-1986: Creation
52
.VERSION 2.0 03-Dec-1986 New terminal-independant graphic characters
53
with output buffering version.
54
.VERSION 2.1 11-Jun-1987 Version '2' of TermWindows.
55
.VERSION 2.2 23-Jun-1987 Adapted to UNIX and Minimal Implementation.
56
.VERSION 3.0 20-Mar-1988 Version '3' of TermWindows.
59
----------------------------------------------------------------------------*/
61
#define DEBUG 0 /* Debugging only */
63
#define PM_LEVEL LEVEL_TV
65
#define TW_MACROS 0 /* Don't use TermWindows Macros */
67
#define TW_STRUCT 0 /* Do not use window Structures */
70
MID_EXTERN TERM *terms;
72
#define SEND(p) tv_send(p,1)
75
# define TERMTEST if(!terms->version) tv_gopen();\
78
# define TERMTEST if(!terms->version) tv_gopen()
81
#define ENTER_TV(x) static int state_buffer; \
83
state_buffer = tv_buffer(TRUE);
84
#define EXIT_TV(f) FIN: \
85
tv_buffer(state_buffer); \
93
/* Macros just to improve readibility */
94
#define oldl old_pos[0]
95
#define oldc old_pos[1]
96
#define curl (terms->pos[0])
97
#define curc (terms->pos[1])
98
#define diml (terms->dim[0])
99
#define dimc (terms->dim[1])
100
#define BUFS (terms->bufs)
103
/* MONITOR (ZTINDEL); */
105
/*======================================================================
107
*======================================================================*/
110
.PURPOSE Delete n chars, starting at the cursor position, and moving
111
characters to the left.
112
.RETURNS OK / NOK (impossible)
113
.REMARKS A negative number of times asks to delete chars at the left of
114
the cursor. Returns always NOK in the Minimal Implementation.
116
int nchars; /* IN: Number of chars to delete */
128
if (nchars == 0) FINISH;
136
if (nchars < 0) tv_goto(curl, curc+nchars);
137
n = ABSOLUTE(nchars);
139
status = tv_send(p,n);
145
/*==========================================================================
147
*==========================================================================*/
150
.PURPOSE Delete lines (moving up lines below), inluding the running
152
.RETURNS OK, or NOK (capability does not exist)
153
.REMARKS On return, the cursor is at the beginning of the line.
154
If lines<0, lines on top of the current are deleted.
155
Returns always NOK in the Minimal Implementation.
157
int lines; /* IN: Number of lines to delete */
162
short int old_pos[2];
171
{ tv_goto(curl+lines, 0);
179
if (lines == 0) FINISH;
183
{ status = tv_send(p,n);
187
/* Delete Line does not exist ---
188
* Try to use the scrolling */
190
status = tv_sr(curl, diml-1) ;
194
curl -= n; /* In fact, the cursor did not move */
199
status = tv_goto(oldl, 0);
205
/*======================================================================
207
*======================================================================*/
210
.PURPOSE Insert n blanks at the cursor position, moving existing characters
212
.RETURNS OK / NOK (impossible)
213
.REMARKS A negative number of times asks to insert chars at the left of
215
Returns always NOK in the Minimal Implementation.
217
int nchars; /* IN: Number of blanks to insert */
229
if (nchars == 0) FINISH;
231
if (nchars < 0) status = tv_goto(curl, curc+nchars);
232
n = ABSOLUTE(nchars);
233
n = MIN(n, terms->buf_size);
237
{ status = tv_imode(1); /* Try to use Insert Mode */
238
if (status == NOK) FINISH;
241
status = tv_imode(0);
244
if (status == OK) status = tv_send(p,n);
250
/*==========================================================================
252
*==========================================================================*/
255
.PURPOSE Insert blank lines (moving down lines below) from the
256
cursor position inclusive.
257
.RETURNS OK, or NOK (capability does not exist)
258
.REMARKS On return, the cursor is at the beginning of the current (blank) line.
259
If lines<0, lines are inserted on top of the current line.
260
Returns always NOK in the Minimal Implementation.
262
int lines; /* IN: Number of blank lines to insert */
267
short int old_pos[2];
276
{ tv_goto(curl+lines, 0);
284
if (lines == 0) FINISH;
288
{ status = tv_send(p,n);
292
/* Insert Line does not exist ---
293
* Try to use the scrolling */
298
status = tv_sr(curl, diml-1) ;
300
{ tv_where(old_pos); /* The cursor is at top of subscreen */
304
if ((status = tv_mvc(_UP_, n)) != OK) FINISH;
308
status = tv_sr(0, diml-1);
311
if (status == OK) status = tv_goto(oldl,0);
317
/*======================================================================
319
*======================================================================*/
322
.PURPOSE Enter/Exit Insert Mode (displayed chars will push existing chars to
323
the right of the cursor)
324
.RETURNS OK / NOK (impossible)
325
.REMARKS Displaying a new line will stop the Insert Mode.
327
Returns always NOK in the Minimal Implementation.
329
int k; /* IN: 0 to exit, non-zero to enter */
336
ENTER_TV("tv_imode");
340
if (k) /* Trying to enable ... */
341
{ if (terms->flags & TERM_IMODE) FINISH;
343
if (p) terms->flags |= TERM_IMODE;
346
{ if (!(terms->flags & TERM_IMODE)) FINISH;
348
if (p) terms->flags &= (~TERM_IMODE);
351
if (!p) status = NOK;
352
if (status == OK) status = tv_send(p,1);
358
/*======================================================================
360
*======================================================================*/
361
int tv_iwrite(str,len)
363
.PURPOSE Insert a text at the cursor position, pushing
364
existing chars to the right.
365
.RETURNS OK / NOK (impossible)
366
.REMARKS Displaying a new line will stop the Insert Mode.
368
Returns always NOK in the Minimal Implementation.
370
char *str; /* IN: Text to display */
371
int len; /* IN: Length of text */
378
ENTER_TV("tv_imode");
382
if (!(terms->flags & TERM_IMODE)) /* Enter Insert Mode */
383
{ if ( (status = tv_imode(1)) == NOK) FINISH;
386
status = tv_write(str,len);