| 1 |
/* @(#)tvindel.c 19.1 (ES0-DMD) 02/25/03 13:58:15 */ |
| 2 |
/*=========================================================================== |
| 3 |
Copyright (C) 1995 European Southern Observatory (ESO) |
| 4 |
|
| 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. |
| 9 |
|
| 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. |
| 14 |
|
| 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, |
| 18 |
MA 02139, USA. |
| 19 |
|
| 20 |
Corresponding concerning ESO-MIDAS should be addressed as follows: |
| 21 |
Internet e-mail: [email protected] |
| 22 |
Postal address: European Southern Observatory |
| 23 |
Data Management Division |
| 24 |
Karl-Schwarzschild-Strasse 2 |
| 25 |
D 85748 Garching bei Muenchen |
| 26 |
GERMANY |
| 27 |
===========================================================================*/ |
| 28 |
|
| 29 |
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 30 |
|
| 31 |
.TYPE Module |
| 32 |
.IDENTIFICATION tvindel.c |
| 33 |
.AUTHOR Francois Ochsenbein [ESO-IPG] |
| 34 |
.LANGUAGE C |
| 35 |
.KEYWORDS Terminal Independant i/o Package. |
| 36 |
.ENVIRONMENT TermWindows |
| 37 |
.COMMENTS This module includes functions to insert or delete lines |
| 38 |
and characters. |
| 39 |
In the Minimal Implementation, these routines are not used. |
| 40 |
\begin{TeX} |
| 41 |
Used Capabilities: |
| 42 |
$$\begin{tabular}{|lp{30em}|} \hline |
| 43 |
{\tt al} & Add a new (blank) line, pushing all lines below it down.\\ |
| 44 |
{\tt dl} & Delete the current line, moving all lines below it up \\ |
| 45 |
{\tt dc} & Delete the current char, moving all chars to the left \\ |
| 46 |
{\tt ei} & Exit Insert Mode. \\ |
| 47 |
{\tt ic} & Insert one blank, moving all chars to the right \\ |
| 48 |
{\tt im} & Enter Insert Mode. \\ |
| 49 |
\hline |
| 50 |
\end{tabular}$$ |
| 51 |
\end{TeX} |
| 52 |
.VERSION 1.0 12-Aug-1986: Creation |
| 53 |
.VERSION 2.0 03-Dec-1986 New terminal-independant graphic characters |
| 54 |
with output buffering version. |
| 55 |
.VERSION 2.1 11-Jun-1987 Version '2' of TermWindows. |
| 56 |
.VERSION 2.2 23-Jun-1987 Adapted to UNIX and Minimal Implementation. |
| 57 |
.VERSION 3.0 20-Mar-1988 Version '3' of TermWindows. |
| 58 |
----------------------------------------------------------------------------*/ |
| 59 |
|
| 60 |
#define DEBUG 0 /* Debugging only */ |
| 61 |
|
| 62 |
#define PM_LEVEL LEVEL_TV |
| 63 |
|
| 64 |
#define TW_MACROS 0 /* Don't use TermWindows Macros */ |
| 65 |
#define TW_import 0 |
| 66 |
#define TW_STRUCT 0 /* Do not use window Structures */ |
| 67 |
#include <twset.h> |
| 68 |
|
| 69 |
#define SEND(p) tv_send(p,1) |
| 70 |
|
| 71 |
#if DEBUG |
| 72 |
# define TERMTEST if(!terms->version) tv_gopen();\ |
| 73 |
tv_ed(terms) |
| 74 |
#else |
| 75 |
# define TERMTEST if(!terms->version) tv_gopen() |
| 76 |
#endif |
| 77 |
|
| 78 |
#define ENTER_TV(x) static int state_buffer; \ |
| 79 |
ENTER(x); TERMTEST; \ |
| 80 |
state_buffer = tv_buffer(TRUE); |
| 81 |
#define EXIT_TV(f) FIN: \ |
| 82 |
tv_buffer(state_buffer); \ |
| 83 |
EXIT(f) |
| 84 |
|
| 85 |
#if DEBUG |
| 86 |
static char ch=EOS; |
| 87 |
static int type=0; |
| 88 |
#endif |
| 89 |
|
| 90 |
/* Macros just to improve readibility */ |
| 91 |
#define oldl old_pos[0] |
| 92 |
#define oldc old_pos[1] |
| 93 |
#define curl (terms->pos[0]) |
| 94 |
#define curc (terms->pos[1]) |
| 95 |
#define diml (terms->dim[0]) |
| 96 |
#define dimc (terms->dim[1]) |
| 97 |
#define BUFS (terms->bufs) |
| 98 |
|
| 99 |
|
| 100 |
#if (TW_LEVEL >= 2) |
| 101 |
MONITOR (ZTINDEL); |
| 102 |
MID_EXTERN TERM *terms; |
| 103 |
#endif |
| 104 |
|
| 105 |
/*====================================================================== |
| 106 |
* tv_dc |
| 107 |
*======================================================================*/ |
| 108 |
/* ARGSUSED */ |
| 109 |
int tv_dc(nchars) |
| 110 |
/*+++ |
| 111 |
.PURPOSE Delete n chars, starting at the cursor position, and moving |
| 112 |
characters to the left. |
| 113 |
.RETURNS OK / NOK (impossible) |
| 114 |
.REMARKS A negative number of times asks to delete chars at the left of |
| 115 |
the cursor. Returns always NOK in the Minimal Implementation. |
| 116 |
---*/ |
| 117 |
int nchars; /* IN: Number of chars to delete */ |
| 118 |
{ |
| 119 |
#if (TW_LEVEL < 2) |
| 120 |
return(NOK); |
| 121 |
#else |
| 122 |
int n; |
| 123 |
char *p; |
| 124 |
|
| 125 |
ENTER_TV("tv_dc"); |
| 126 |
|
| 127 |
status = OK; |
| 128 |
|
| 129 |
if (nchars == 0) FINISH; |
| 130 |
|
| 131 |
p = SearchCap("dc"); |
| 132 |
if (!p) |
| 133 |
{ status = NOK; |
| 134 |
FINISH; |
| 135 |
} |
| 136 |
|
| 137 |
if (nchars < 0) tv_goto(curl, curc+nchars); |
| 138 |
n = ABSOLUTE(nchars); |
| 139 |
|
| 140 |
status = tv_send(p,n); |
| 141 |
|
| 142 |
EXIT_TV(status); |
| 143 |
#endif |
| 144 |
} |
| 145 |
|
| 146 |
/*========================================================================== |
| 147 |
* tv_dl |
| 148 |
*==========================================================================*/ |
| 149 |
/* ARGSUSED */ |
| 150 |
int tv_dl(lines) |
| 151 |
/*+++++++++ |
| 152 |
.PURPOSE Delete lines (moving up lines below), inluding the running |
| 153 |
line. |
| 154 |
.RETURNS OK, or NOK (capability does not exist) |
| 155 |
.REMARKS On return, the cursor is at the beginning of the line. |
| 156 |
If lines<0, lines on top of the current are deleted. |
| 157 |
Returns always NOK in the Minimal Implementation. |
| 158 |
-----------*/ |
| 159 |
int lines; /* IN: Number of lines to delete */ |
| 160 |
{ |
| 161 |
#if (TW_LEVEL < 2) |
| 162 |
return(NOK); |
| 163 |
#else |
| 164 |
short int old_pos[2]; |
| 165 |
char *p; |
| 166 |
int n; |
| 167 |
|
| 168 |
ENTER_TV("tv_dl"); |
| 169 |
|
| 170 |
status = OK; |
| 171 |
|
| 172 |
if (lines < 0) |
| 173 |
{ tv_goto(curl+lines, 0); |
| 174 |
n = -lines; |
| 175 |
} |
| 176 |
else |
| 177 |
{ tv_goto(curl, 0); |
| 178 |
n = lines; |
| 179 |
} |
| 180 |
|
| 181 |
if (lines == 0) FINISH; |
| 182 |
|
| 183 |
p = SearchCap("dl"); |
| 184 |
if (p) |
| 185 |
{ status = tv_send(p,n); |
| 186 |
FINISH; |
| 187 |
} |
| 188 |
|
| 189 |
/* Delete Line does not exist --- |
| 190 |
* Try to use the scrolling */ |
| 191 |
|
| 192 |
status = tv_sr(curl, diml-1) ; |
| 193 |
if (status == OK) |
| 194 |
{ tv_where(old_pos); |
| 195 |
tv_goto(diml-1,0); |
| 196 |
curl -= n; /* In fact, the cursor did not move */ |
| 197 |
tv_mvc(_DOWN_,n); |
| 198 |
tv_sr(0, diml-1); |
| 199 |
} |
| 200 |
|
| 201 |
status = tv_goto(oldl, 0); |
| 202 |
|
| 203 |
EXIT_TV(status); |
| 204 |
#endif |
| 205 |
} |
| 206 |
|
| 207 |
/*====================================================================== |
| 208 |
* tv_ic |
| 209 |
*======================================================================*/ |
| 210 |
/* ARGSUSED */ |
| 211 |
int tv_ic(nchars) |
| 212 |
/*+++ |
| 213 |
.PURPOSE Insert n blanks at the cursor position, moving existing characters |
| 214 |
to the right. |
| 215 |
.RETURNS OK / NOK (impossible) |
| 216 |
.REMARKS A negative number of times asks to insert chars at the left of |
| 217 |
the cursor. |
| 218 |
Returns always NOK in the Minimal Implementation. |
| 219 |
---*/ |
| 220 |
int nchars; /* IN: Number of blanks to insert */ |
| 221 |
{ |
| 222 |
#if (TW_LEVEL < 2) |
| 223 |
return(NOK); |
| 224 |
#else |
| 225 |
int n; |
| 226 |
char *p; |
| 227 |
|
| 228 |
ENTER_TV("tv_ic"); |
| 229 |
|
| 230 |
status = OK; |
| 231 |
|
| 232 |
if (nchars == 0) FINISH; |
| 233 |
|
| 234 |
if (nchars < 0) status = tv_goto(curl, curc+nchars); |
| 235 |
n = ABSOLUTE(nchars); |
| 236 |
n = MIN(n, terms->buf_size); |
| 237 |
|
| 238 |
p = SearchCap("ic"); |
| 239 |
if (!p) |
| 240 |
{ status = tv_imode(1); /* Try to use Insert Mode */ |
| 241 |
if (status == NOK) FINISH; |
| 242 |
oscfill(BUFS,n,' '); |
| 243 |
tv_write(BUFS,n); |
| 244 |
status = tv_imode(0); |
| 245 |
} |
| 246 |
|
| 247 |
if (status == OK) status = tv_send(p,n); |
| 248 |
|
| 249 |
EXIT_TV(status); |
| 250 |
#endif |
| 251 |
} |
| 252 |
|
| 253 |
/*========================================================================== |
| 254 |
* tv_il |
| 255 |
*==========================================================================*/ |
| 256 |
/* ARGSUSED */ |
| 257 |
int tv_il(lines) |
| 258 |
/*++++++++++++++ |
| 259 |
.PURPOSE Insert blank lines (moving down lines below) from the |
| 260 |
cursor position inclusive. |
| 261 |
.RETURNS OK, or NOK (capability does not exist) |
| 262 |
.REMARKS On return, the cursor is at the beginning of the current (blank) line. |
| 263 |
If lines<0, lines are inserted on top of the current line. |
| 264 |
Returns always NOK in the Minimal Implementation. |
| 265 |
---------------*/ |
| 266 |
int lines; /* IN: Number of blank lines to insert */ |
| 267 |
{ |
| 268 |
#if (TW_LEVEL < 2) |
| 269 |
return(NOK); |
| 270 |
#else |
| 271 |
short int old_pos[2]; |
| 272 |
char *p; |
| 273 |
int n; |
| 274 |
|
| 275 |
ENTER_TV("tv_il"); |
| 276 |
|
| 277 |
status = OK; |
| 278 |
|
| 279 |
if (lines < 0) |
| 280 |
{ tv_goto(curl+lines, 0); |
| 281 |
n = -lines; |
| 282 |
} |
| 283 |
else |
| 284 |
{ tv_goto(curl, 0); |
| 285 |
n = lines; |
| 286 |
} |
| 287 |
|
| 288 |
if (lines == 0) FINISH; |
| 289 |
|
| 290 |
p = SearchCap("al"); |
| 291 |
if (p) |
| 292 |
{ status = tv_send(p,n); |
| 293 |
FINISH; |
| 294 |
} |
| 295 |
|
| 296 |
/* Insert Line does not exist --- |
| 297 |
* Try to use the scrolling */ |
| 298 |
|
| 299 |
#if DEBUG |
| 300 |
tv_getc(&ch,&type); |
| 301 |
#endif |
| 302 |
status = tv_sr(curl, diml-1) ; |
| 303 |
if (status == OK) |
| 304 |
{ tv_where(old_pos); /* The cursor is at top of subscreen */ |
| 305 |
#if DEBUG |
| 306 |
tv_getc(&ch,&type); |
| 307 |
#endif |
| 308 |
if ((status = tv_mvc(_UP_, n)) != OK) FINISH; |
| 309 |
#if DEBUG |
| 310 |
tv_getc(&ch,&type); |
| 311 |
#endif |
| 312 |
status = tv_sr(0, diml-1); |
| 313 |
} |
| 314 |
|
| 315 |
if (status == OK) status = tv_goto(oldl,0); |
| 316 |
|
| 317 |
EXIT_TV(status); |
| 318 |
#endif |
| 319 |
} |
| 320 |
|
| 321 |
/*====================================================================== |
| 322 |
* tv_imode |
| 323 |
*======================================================================*/ |
| 324 |
/* ARGSUSED */ |
| 325 |
int tv_imode(k) |
| 326 |
/*+++ |
| 327 |
.PURPOSE Enter/Exit Insert Mode (displayed chars will push existing chars to |
| 328 |
the right of the cursor) |
| 329 |
.RETURNS OK / NOK (impossible) |
| 330 |
.REMARKS Displaying a new line will stop the Insert Mode. |
| 331 |
(see tv_nl). |
| 332 |
Returns always NOK in the Minimal Implementation. |
| 333 |
---*/ |
| 334 |
int k; /* IN: 0 to exit, non-zero to enter */ |
| 335 |
{ |
| 336 |
#if (TW_LEVEL < 2) |
| 337 |
return(NOK); |
| 338 |
#else |
| 339 |
register char *p; |
| 340 |
|
| 341 |
ENTER_TV("tv_imode"); |
| 342 |
|
| 343 |
status = OK; |
| 344 |
|
| 345 |
if (k) /* Trying to enable ... */ |
| 346 |
{ if (terms->flags & TERM_IMODE) FINISH; |
| 347 |
p = SearchCap("im"); |
| 348 |
if (p) terms->flags |= TERM_IMODE; |
| 349 |
} |
| 350 |
else |
| 351 |
{ if (!(terms->flags & TERM_IMODE)) FINISH; |
| 352 |
p = SearchCap("ei"); |
| 353 |
if (p) terms->flags &= (~TERM_IMODE); |
| 354 |
} |
| 355 |
|
| 356 |
if (!p) status = NOK; |
| 357 |
if (status == OK) status = tv_send(p,1); |
| 358 |
|
| 359 |
EXIT_TV(status); |
| 360 |
#endif |
| 361 |
} |
| 362 |
|
| 363 |
/*====================================================================== |
| 364 |
* tv_iwrite |
| 365 |
*======================================================================*/ |
| 366 |
/* ARGSUSED */ |
| 367 |
int tv_iwrite(str,len) |
| 368 |
/*+++ |
| 369 |
.PURPOSE Insert a text at the cursor position, pushing |
| 370 |
existing chars to the right. |
| 371 |
.RETURNS OK / NOK (impossible) |
| 372 |
.REMARKS Displaying a new line will stop the Insert Mode. |
| 373 |
(see tv_nl). |
| 374 |
Returns always NOK in the Minimal Implementation. |
| 375 |
---*/ |
| 376 |
char *str; /* IN: Text to display */ |
| 377 |
int len; /* IN: Length of text */ |
| 378 |
{ |
| 379 |
#if (TW_LEVEL < 2) |
| 380 |
return(NOK); |
| 381 |
#else |
| 382 |
register char *p; |
| 383 |
|
| 384 |
ENTER_TV("tv_imode"); |
| 385 |
|
| 386 |
status = OK; |
| 387 |
|
| 388 |
if (!(terms->flags & TERM_IMODE)) /* Enter Insert Mode */ |
| 389 |
{ if ( (status = tv_imode(1)) == NOK) FINISH; |
| 390 |
} |
| 391 |
|
| 392 |
status = tv_write(str,len); |
| 393 |
|
| 394 |
tv_imode(0); |
| 395 |
|
| 396 |
EXIT_TV(status); |
| 397 |
#endif |
| 398 |
} |