| 1 |
/* @(#)tvclear.c 19.1 (ES0-DMD) 02/25/03 13:58:14 */ |
| 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 tvclear.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 clear functions. |
| 38 |
\begin{TeX} |
| 39 |
Used Capabilities: |
| 40 |
$$\begin{tabular}{|lp{30em}|} \hline |
| 41 |
{\tt cl=} & Clear whole screen (and cursor to home position) \\ |
| 42 |
{\tt cu=} & Clear Up (from top of screen to cursor inclusive) \\ |
| 43 |
{\tt cd=} & Clear Down (from cursor inclusive to bottom of screen)\\ |
| 44 |
{\tt ce=} & Clear from cursor to end of line \\ |
| 45 |
{\tt cs=} & Clear from start of line to cursor inclusive \\ |
| 46 |
\hline |
| 47 |
\end{tabular}$$ |
| 48 |
\end{TeX} |
| 49 |
.VERSION 1.0 07-Jul-1986: Creation |
| 50 |
.VERSION 1.1 12-Aug-1986: Clearing lines or screen also means stop insert mode. |
| 51 |
|
| 52 |
.VERSION 1.2 23-Oct-1986: Take care of possible existing scrolling region |
| 53 |
|
| 54 |
.VERSION 2.0 03-Dec-1986 New terminal-independant graphic characters |
| 55 |
with output buffering version. |
| 56 |
.VERSION 2.1 11-Jun-1987 Modify a bit for hard_copy terminals: |
| 57 |
Useless to clear characters!!! |
| 58 |
.VERSION 2.2 23-Jun-1987 Adapted to UNIX |
| 59 |
.VERSION 3.0 20-Mar-1988 Version '3' of TermWindows. |
| 60 |
----------------------------------------------------------------------------*/ |
| 61 |
|
| 62 |
#define DEBUG 0 /* Only for debugging */ |
| 63 |
|
| 64 |
#define PM_LEVEL LEVEL_TV |
| 65 |
|
| 66 |
#define TW_MACROS 0 /* Don't use TermWindows Macros */ |
| 67 |
#define TW_import 0 |
| 68 |
#define TW_STRUCT 0 /* Do not use window Structures */ |
| 69 |
#include <twset.h> |
| 70 |
|
| 71 |
MID_RSTATIC char clear_cap[] = "cucdcbce"; |
| 72 |
MID_STATIC short int old_pos[2] = {0,0}; |
| 73 |
|
| 74 |
#if DEBUG |
| 75 |
# define TERMTEST if(!terms->version) tv_gopen();\ |
| 76 |
tv_ed(terms) |
| 77 |
#else |
| 78 |
# define TERMTEST if(!terms->version) tv_gopen() |
| 79 |
#endif |
| 80 |
|
| 81 |
#define FIN_CURSOR goto RESET_CURSOR |
| 82 |
|
| 83 |
#define ENTER_TV(x) static int state_buffer; \ |
| 84 |
ENTER(x); TERMTEST; \ |
| 85 |
state_buffer = tv_buffer(TRUE); |
| 86 |
#define EXIT_TV(f) FIN: \ |
| 87 |
tv_buffer(state_buffer); \ |
| 88 |
EXIT(f) |
| 89 |
|
| 90 |
MID_EXTERN TERM *terms ; |
| 91 |
|
| 92 |
#define SEND(p) tv_send(p,1) |
| 93 |
|
| 94 |
/* Macros just to improve readibility */ |
| 95 |
|
| 96 |
#define oldl old_pos[0] |
| 97 |
#define oldc old_pos[1] |
| 98 |
#define curl (terms->pos[0]) |
| 99 |
#define curc (terms->pos[1]) |
| 100 |
#define diml (terms->dim[0]) |
| 101 |
#define dimc (terms->dim[1]) |
| 102 |
#define BUFS (terms->bufs) |
| 103 |
|
| 104 |
|
| 105 |
MONITOR (ZTCLEAR); |
| 106 |
|
| 107 |
/*========================================================================== |
| 108 |
* clear_h() |
| 109 |
*==========================================================================*/ |
| 110 |
static int clear_h(dir) |
| 111 |
/*++++++++++++++++++++++++ |
| 112 |
.DES Clear at left / right of cursor (inclusive) |
| 113 |
.RET OK / NOK |
| 114 |
.REM Not traced. Never called for hard-copy terminals. Cursor moves |
| 115 |
if blanks are sent. |
| 116 |
-----------------------*/ |
| 117 |
int dir; /* IN: Direction (left or right) */ |
| 118 |
{ |
| 119 |
register char *p; |
| 120 |
register int i, s; |
| 121 |
|
| 122 |
/* Use TermCapabilities when possible */ |
| 123 |
p = SearchCap(&clear_cap[dir*2]); |
| 124 |
if (p) return(SEND(p)); |
| 125 |
|
| 126 |
s = OK; |
| 127 |
if (dir == _LEFT_) |
| 128 |
{ tv_out("\r",1); |
| 129 |
i = curc + 1; |
| 130 |
curc = 0; |
| 131 |
} |
| 132 |
else i = dimc - curc; |
| 133 |
|
| 134 |
if (i > 0) |
| 135 |
{ oscfill(BUFS,i,' '); |
| 136 |
s = tv_line(BUFS, i); |
| 137 |
} |
| 138 |
|
| 139 |
return(s); |
| 140 |
} |
| 141 |
|
| 142 |
/*========================================================================== |
| 143 |
* tv_cc |
| 144 |
*==========================================================================*/ |
| 145 |
int tv_cc(nchar) |
| 146 |
/*+++++++++++ |
| 147 |
.DES Clear n chars from the cursor inclusive. |
| 148 |
.RET OK |
| 149 |
.REM The cursor position remains unchanged. Simply write blanks --- |
| 150 |
or do nothing for hard_copy terminals! |
| 151 |
If nchar<0, clear chars at the left of the cursor. |
| 152 |
----------*/ |
| 153 |
int nchar; /* IN: Number of chars to clear */ |
| 154 |
{ |
| 155 |
register int n; |
| 156 |
unsigned char old_attr; |
| 157 |
|
| 158 |
ENTER_TV("tv_cc"); |
| 159 |
|
| 160 |
TRACE_ED_I("Clearing chars: ", nchar); |
| 161 |
|
| 162 |
status = OK; |
| 163 |
if (nchar == 0) FINISH; |
| 164 |
if (terms->flags & TERM_hard) FINISH; |
| 165 |
|
| 166 |
tv_where(old_pos); |
| 167 |
old_attr = terms->attr; |
| 168 |
tv_attr(terms->attr_init); |
| 169 |
|
| 170 |
n = 0; /* Number of blanks to issue */ |
| 171 |
if (nchar < 0) |
| 172 |
{ if (oldc + nchar < 0) /* Optimize */ |
| 173 |
status = clear_h(_LEFT_); |
| 174 |
else tv_goto(oldl, oldc + nchar +1), n = -nchar; |
| 175 |
} |
| 176 |
else |
| 177 |
{ if (oldc + n >= dimc) /* Optimize */ |
| 178 |
status = clear_h(_RIGHT_); |
| 179 |
else n = nchar; |
| 180 |
} |
| 181 |
|
| 182 |
/* Can't clear with optimized TermCapabilities; |
| 183 |
* issue blanks. */ |
| 184 |
|
| 185 |
if (n) |
| 186 |
{ oscfill(BUFS,n,' '); |
| 187 |
status = tv_line(BUFS, n); |
| 188 |
} |
| 189 |
|
| 190 |
tv_goto(oldl,oldc); |
| 191 |
tv_attr(old_attr); |
| 192 |
|
| 193 |
EXIT_TV(status); |
| 194 |
} |
| 195 |
|
| 196 |
/*========================================================================== |
| 197 |
* tv_cl |
| 198 |
*==========================================================================*/ |
| 199 |
int tv_cl() |
| 200 |
/*+++++++++++++ |
| 201 |
.DES Clear the complete line; the cursor is moved to the left margin. |
| 202 |
.RET OK |
| 203 |
.REM |
| 204 |
--------------*/ |
| 205 |
{ |
| 206 |
unsigned char old_attr; |
| 207 |
|
| 208 |
ENTER_TV("tv_cl"); |
| 209 |
|
| 210 |
#if (TW_LEVEL > 0) |
| 211 |
status = OK; |
| 212 |
|
| 213 |
/* For hard-copy terminals, issue a new line */ |
| 214 |
|
| 215 |
if (terms->flags & TERM_hard) |
| 216 |
{ tv_nl(); |
| 217 |
curl--; /* ... but line unchanged */ |
| 218 |
FINISH; |
| 219 |
} |
| 220 |
#endif |
| 221 |
|
| 222 |
/* Simply go to line beginning, and clear it */ |
| 223 |
|
| 224 |
old_attr = terms->attr; |
| 225 |
tv_attr(terms->attr_init); |
| 226 |
tv_out("\r", 1); curc = 0; |
| 227 |
status = clear_h(_RIGHT_); |
| 228 |
tv_goto(curl,0); |
| 229 |
tv_attr(old_attr); |
| 230 |
|
| 231 |
EXIT_TV(status); |
| 232 |
} |
| 233 |
|
| 234 |
/*========================================================================== |
| 235 |
* tv_clear |
| 236 |
*==========================================================================*/ |
| 237 |
int tv_clear(direction) |
| 238 |
/*+++++++++++++++++ |
| 239 |
.DES Clear the terminal, according to the specified direction: |
| 240 |
\begin{TeX} |
| 241 |
\begin{itemize} |
| 242 |
\item \_UP\_ : from the top of the screen, to the cursor (inclusive). |
| 243 |
The cursor does not move. |
| 244 |
\item \_DOWN\_ : from the cursor (inclusive) to the end of the screen. |
| 245 |
The cursor does not move. |
| 246 |
\item \_LEFT\_ : from the left margin of the current line |
| 247 |
to the cursor (inclusive) . |
| 248 |
The cursor does not move. |
| 249 |
\item \_RIGHT\_ : from the cursor (inclusive) to the end of the line. |
| 250 |
The cursor does not move. |
| 251 |
\item \_WHOLE\_ : the complete screen (the cursor goes to home, \ie [0,0] |
| 252 |
position. |
| 253 |
\end{itemize} |
| 254 |
\end{TeX} |
| 255 |
.RET OK/NOK |
| 256 |
.REM Insert Mode turned off. For hard-copy terminals, only _WHOLE_ |
| 257 |
has some signification. |
| 258 |
-------------------*/ |
| 259 |
int direction; /* IN: Clearing direction _WHOLE_, _UP_, _DOWN_, etc */ |
| 260 |
{ |
| 261 |
register char *p; |
| 262 |
unsigned char old_attr; |
| 263 |
|
| 264 |
ENTER_TV("tv_clear"); |
| 265 |
|
| 266 |
status = OK; |
| 267 |
terms->flags &= (~TERM_IMODE); |
| 268 |
|
| 269 |
tv_where(old_pos); /* Save present position */ |
| 270 |
curc = oldc; /* For wrap (cursor passed right margin) */ |
| 271 |
old_attr = terms->attr; |
| 272 |
tv_attr(terms->attr_init); |
| 273 |
|
| 274 |
if ( (direction < 0) || (direction > 3) ) |
| 275 |
{ /* Whole screen is the default */ |
| 276 |
/* Reset the scrolling region to whole screen */ |
| 277 |
tv_sr0(); |
| 278 |
|
| 279 |
/* Look if "cl" cap exists (already stored in TERM) |
| 280 |
otherwise, simply put a new line */ |
| 281 |
|
| 282 |
p = terms->tt_clear; |
| 283 |
if (p) |
| 284 |
status = SEND(p); |
| 285 |
else status = tv_nl(); /* No cap: Simply go to newline ... */ |
| 286 |
|
| 287 |
oldc = 0; oldl = 0; /* New cursor position */ |
| 288 |
FIN_CURSOR; |
| 289 |
} |
| 290 |
|
| 291 |
if (terms->flags & TERM_hard) FINISH; |
| 292 |
|
| 293 |
|
| 294 |
/* Change the direction for optimisation */ |
| 295 |
|
| 296 |
switch(direction) |
| 297 |
{ case _UP_ : |
| 298 |
if (curl != 0) break; |
| 299 |
case _LEFT_ : /* Cont. _UP_ */ |
| 300 |
status = clear_h(_LEFT_); FIN_CURSOR; |
| 301 |
case _DOWN_ : |
| 302 |
if (curl != diml-1) break; |
| 303 |
case _RIGHT_: /* Cont. _DOWN_ */ |
| 304 |
status = clear_h(_RIGHT_); FIN_CURSOR; |
| 305 |
} |
| 306 |
|
| 307 |
/* Here only in case of _UP_/_DOWN_ clearing */ |
| 308 |
|
| 309 |
/* Test if a scrolling region exists --- Use tv_sr0 */ |
| 310 |
|
| 311 |
if ( (terms->scregion[0] != 0) || (terms->scregion[1] < diml-1) ) |
| 312 |
{ tv_sr0(); |
| 313 |
tv_goto(oldl, oldc); |
| 314 |
} |
| 315 |
|
| 316 |
/* Use TermCapabilities when possible */ |
| 317 |
p = SearchCap(&clear_cap[direction*2]); |
| 318 |
if (p) { status = SEND(p); FIN_CURSOR;} |
| 319 |
|
| 320 |
/* Simulate Clearing with blanks */ |
| 321 |
switch(direction) |
| 322 |
{ case _UP_: /* Clear from top left corner */ |
| 323 |
tv_home(); /* ... Cursor position is updated */ |
| 324 |
while (curl < oldl) |
| 325 |
{ clear_h(_RIGHT_); |
| 326 |
tv_nl(); |
| 327 |
} /* We are on original line... */ |
| 328 |
tv_goto(oldl, oldc); /* ... and continue with _LEFT_ */ |
| 329 |
status = clear_h(_LEFT_); |
| 330 |
break; |
| 331 |
|
| 332 |
case _DOWN_: /* `cd' capability doesn't exist */ |
| 333 |
status = clear_h(_RIGHT_); /* clear current line...*/ |
| 334 |
while (curl < diml-1) |
| 335 |
tv_nl(), clear_h(_RIGHT_); |
| 336 |
} |
| 337 |
|
| 338 |
RESET_CURSOR: |
| 339 |
tv_goto(oldl,oldc); |
| 340 |
tv_attr(old_attr); |
| 341 |
|
| 342 |
EXIT_TV(status); |
| 343 |
} |
| 344 |
|