~ubuntu-branches/debian/jessie/eso-midas/jessie

« back to all changes in this revision

Viewing changes to prim/tw3/libsrc/tvcursor.c

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-okiwi1assxkkiz39
Tags: upstream-13.09pl1.2+dfsg
ImportĀ upstreamĀ versionĀ 13.09pl1.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*===========================================================================
 
2
  Copyright (C) 1986-2009 European Southern Observatory (ESO)
 
3
 
 
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.
 
8
 
 
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.
 
13
 
 
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, 
 
17
  MA 02139, USA.
 
18
 
 
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 
 
25
                        GERMANY
 
26
===========================================================================*/
 
27
 
 
28
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 
29
 
 
30
.TYPE           Module
 
31
.IDENTIFICATION tvcursor.c
 
32
.AUTHOR         Francois Ochsenbein [ESO-IPG]
 
33
.LANGUAGE       C
 
34
.KEYWORDS       Terminal Independant i/o Package.
 
35
.ENVIRONMENT    TermWindows
 
36
.COMMENTS       This module includes functions to define and perform
 
37
                scrolling, and cursor movements.
 
38
\begin{TeX}
 
39
Used Capabilities:
 
40
$$\begin{tabular}{|lp{30em}|}   \hline
 
41
{\tt cm}        & Move cursor to specified position     \\
 
42
{\tt ff}        & Form-feed                             \\
 
43
{\tt ho}        & Move cursor to home (\ie [0,0]) position\\
 
44
{\tt cs}        & Define a scrolling region     \\
 
45
{\tt sf}        & Scroll forwards (up)          \\
 
46
{\tt sr}        & Scroll reverse (down)         \\
 
47
\hline
 
48
\end{tabular}$$
 
49
\end{TeX}
 
50
.VERSION   1.0  07-Jul-1986:    Creation
 
51
.VERSION   1.1  23-Oct-1986     Flag the move to a newline, to ensure
 
52
                        that correct attributes are set even with HP's
 
53
                        (attributes end with end-of-line).
 
54
                        Take care of cursor move if a scrolling region 
 
55
                        exists: reset first the scrolling region.
 
56
                        (added tv_sr0 to do this)
 
57
 
 
58
.VERSION   1.2  26-Nov-1986     Remove bug in tv_sr0
 
59
 
 
60
.VERSION   2.0  03-Dec-1986     New terminal-independant graphic characters
 
61
                        with output buffering version.
 
62
.VERSION   2.1  11-Jun-1987     Version '2'. Improvements for hard terminals.
 
63
.VERSION   2.2  23-Jun-1987     Adapted to UNIX and Minimal Implementation.
 
64
.VERSION   2.3  04-Dec-1987     Save and Get Cursor also save Attribute
 
65
.VERSION   3.0  20-Mar-1988     Version '3' of TermWindows.
 
66
.VERSION   3.1  06-Oct-1989     Be sure that tv_sr0 RESETS the scrolling region.
 
67
.VERSION   3.2  23-May-1990     Hard terminals up movement does nothing...
 
68
 
 
69
 090831         last modif
 
70
----------------------------------------------------------------------------*/
 
71
 
 
72
#define DEBUG           0       /* For debugging only   */
 
73
 
 
74
#define PM_LEVEL        LEVEL_TV
 
75
 
 
76
#define TW_MACROS       0               /* Don't use TermWindows Macros */
 
77
#define TW_import       0       
 
78
#define TW_STRUCT       0       /* Do not use window Structures         */
 
79
#include <twset.h>
 
80
 
 
81
extern int tv_buffer(), tv_where(), tv_goto(), tv_out();
 
82
extern int tv_attr(), tv_mvc(), tv_open(), tv_sr0();
 
83
extern int tv_nl(), tv_send(), tv_imode(), tv_il(), tv_delay();
 
84
 
 
85
extern int tu_format();
 
86
 
 
87
extern int  pm_enter(), pm_iexit();
 
88
 
 
89
 
 
90
MID_EXTERN TERM *terms ;                
 
91
 
 
92
#define         SEND(p)         tv_send(p,1)
 
93
 
 
94
#if     DEBUG
 
95
#       define  TERMTEST        if(!terms->version) tv_gopen();\
 
96
                                tv_ed(terms)
 
97
#else
 
98
#       define  TERMTEST        if(!terms->version) tv_gopen()
 
99
#endif
 
100
 
 
101
#define FINISH          goto FIN
 
102
#define ENTER_TV(x)     static int      state_buffer;                   \
 
103
                        ENTER(x);       TERMTEST;                       \
 
104
                        state_buffer  = tv_buffer(1);   
 
105
#define EXIT_TV(f)      FIN:                                            \
 
106
                        tv_buffer(state_buffer);                        \
 
107
                        EXIT(f)
 
108
 
 
109
#if DEBUG
 
110
        MID_STATIC char ch=EOS;
 
111
        MID_STATIC int type=0;
 
112
#endif
 
113
 
 
114
                /* Macros just to improve readibility   */
 
115
#define         newl                    new_pos[0]
 
116
#define         newc                    new_pos[1]
 
117
#define         oldl                    old_pos[0]
 
118
#define         oldc                    old_pos[1]
 
119
#define         curl                    (terms->pos[0])
 
120
#define         curc                    (terms->pos[1])
 
121
#define         diml                    (terms->dim[0])
 
122
#define         dimc                    (terms->dim[1])
 
123
#define         BUFS                    (terms->bufs)
 
124
 
 
125
 
 
126
        MONITOR (ZTCURSOR);
 
127
 
 
128
/*==========================================================================
 
129
 *                      tv_cm(line, col)
 
130
 *==========================================================================*/
 
131
static int tv_cm(line, col)
 
132
/*+++
 
133
.PURPOSE Position the cursor using direct cursor addressing
 
134
.RETURNS OK / NOK (no direct addressing)
 
135
.REMARKS NO DELAY IS SENT HERE (for optimization).
 
136
        NO TEST on validy of line and col.
 
137
        *** For internal use ***. Not Traced.
 
138
------------------*/
 
139
        int     line;                   /* IN: Line number to move to */
 
140
        int     col;                    /* IN: Column number to move to */
 
141
{
 
142
        short int new_pos[2];
 
143
 
 
144
  newl = line;
 
145
  newc = col;
 
146
 
 
147
  status = tv_out(BUFS, tu_format(BUFS, terms->tt_cm, new_pos));
 
148
        /* tv_delay(terms->tt_cm); */
 
149
 
 
150
  return(status);
 
151
}
 
152
 
 
153
/*==========================================================================
 
154
 *                      tv_range
 
155
 *==========================================================================*/
 
156
int tv_range(coo, limits)
 
157
/*++++++++++++++
 
158
.PURPOSE Verify and updates the cursor position versus limits.
 
159
        Lines are numbered from 0 at the top of the screen; columns are
 
160
        numbered from 0 at the left margin of the screen. 
 
161
.RETURNS OK / NOK (cursor position modified)
 
162
.REMARKS Not traced.
 
163
----------------*/
 
164
        short int coo[2]; /* MOD: Cursor position (line, col) to verify */
 
165
        short int limits[2];    /* IN: Limits of the screen             */
 
166
{
 
167
        register int s;
 
168
 
 
169
  s = OK;
 
170
 
 
171
  if(coo[0] < 0) { coo[0] = 0; s = NOK;}
 
172
  if(coo[1] < 0) { coo[1] = 0; s = NOK;}
 
173
 
 
174
  if(coo[0] >= limits[0]) { coo[0] = limits[0]-1; s = NOK;}
 
175
  if(coo[1] >= limits[1]) { coo[1] = limits[1]-1; s = NOK;}
 
176
 
 
177
  return(s);
 
178
}
 
179
 
 
180
/*==========================================================================
 
181
 *                      tv_pos
 
182
 *==========================================================================*/
 
183
int tv_pos()
 
184
/*++++++++++++++
 
185
.PURPOSE Returns the cursor position, as a number of characters 
 
186
        from the top left.
 
187
.RETURNS Position, in range [0, lines*cols]
 
188
.REMARKS Not traced.
 
189
----------------*/
 
190
{
 
191
  return (terms->pos[0]*terms->dim[1] + terms->pos[1]);
 
192
}
 
193
 
 
194
/*==========================================================================
 
195
 *                      tv_cur()
 
196
 *==========================================================================*/
 
197
int     tv_cur(saved)
 
198
/*+++++++++++
 
199
.PURPOSE Restore the cursor position.
 
200
.RETURNS OK
 
201
.REMARKS 
 
202
-----------------------------------------------------------------------*/
 
203
        TVSAVE  *saved;         /* IN: Old position + attribute */
 
204
{
 
205
  ENTER_TV("tv_cur");
 
206
 
 
207
  status = tv_goto(saved->pos[0], saved->pos[1]);
 
208
  tv_attr(saved->attr);
 
209
  FINISH;
 
210
 
 
211
  EXIT_TV(status);
 
212
}
 
213
 
 
214
/*==========================================================================
 
215
 *                      tv_cus()
 
216
 *==========================================================================*/
 
217
int     tv_cus(saved)
 
218
/*++++++++++++++
 
219
.PURPOSE Save the current cursor position.
 
220
.RETURNS OK
 
221
.REMARKS Not traced.
 
222
---------------*/
 
223
        TVSAVE  *saved;         /* OUT: Current position + attribute */
 
224
{
 
225
  saved->pos[0] = terms->pos[0];
 
226
  saved->pos[1] = terms->pos[1];
 
227
  saved->attr   = terms->attr;
 
228
 
 
229
  return(OK);
 
230
}
 
231
 
 
232
/*==========================================================================
 
233
 *                      tv_agoto
 
234
 *==========================================================================*/
 
235
int tv_agoto(pos)
 
236
/*+++++++++++
 
237
.PURPOSE Position the cursor to a specified byte position.
 
238
        Position are numbered from 0 at the top left corner to N-1 at bottom
 
239
        right corner.
 
240
.RETURNS Actual position
 
241
.REMARKS 
 
242
------------*/
 
243
        int     pos;                    /* IN: Position to move to */
 
244
{
 
245
        int J, N, n;
 
246
 
 
247
  J = terms->dim[1];
 
248
  N = J * terms->dim[0];
 
249
  n = MAX(pos, 0);
 
250
  if (n >= N)   n = N-1;
 
251
  tv_goto(n/J, n%J);
 
252
  return(n);
 
253
}
 
254
  
 
255
/*==========================================================================
 
256
 *                      tv_goto
 
257
 *==========================================================================*/
 
258
int tv_goto(line, col)
 
259
/*+++++++++++
 
260
.PURPOSE Position the cursor to a specified line and column position on the screen.
 
261
        Lines are numbered from 0 at the top of the screen; columns are
 
262
        numbered from 0 at the left margin of the screen. 
 
263
        If full screen is not asked for, no test is performed on the
 
264
        validity of line and column.
 
265
.RETURNS OK / NOK (not possible, e.g. up on a hard terminal)
 
266
.REMARKS An attempt to position the cursor off the screen will place it 
 
267
        on an edge.
 
268
        NO DELAY IS SENT HERE. (for optimization)
 
269
------------*/
 
270
        int     line;                   /* IN: Line number to move to */
 
271
        int     col;                    /* IN: Column number to move to */
 
272
{
 
273
        short int new_pos[2];
 
274
        short int old_pos[2];
 
275
        register int n;
 
276
 
 
277
  ENTER_TV("tv_goto");
 
278
 
 
279
  status = OK;
 
280
  tv_where(old_pos);                    /* Save current position        */
 
281
  newl = line;
 
282
  newc = col;
 
283
  tv_range(new_pos, terms->dim);        /* Verify cursor within screen  */
 
284
 
 
285
#if     DEBUG
 
286
  TRACE_ED_I("Old       line ",oldl);
 
287
  TRACE_ED_I("      ... col  ",oldc);
 
288
  TRACE_ED_I("Moving to line ",line);
 
289
  TRACE_ED_I("      ... col  ",col);
 
290
#endif
 
291
 
 
292
        /* Optimize for move on the same line   */
 
293
 
 
294
  if (newl == oldl) 
 
295
  {     n = newc - oldc;                        /* Displacement */
 
296
        if ( n == 0 )           FINISH;         /* No move      */
 
297
        if ( (n > -3) && (n < 3) )
 
298
        {       status = tv_mvc(_RIGHT_, n);
 
299
                FINISH;
 
300
        }
 
301
  }
 
302
  else  terms->standout |= ChangedLine;
 
303
 
 
304
  if ( (newl < terms->scregion[0]) || (newl > terms->scregion[1]) )
 
305
        tv_sr0();                       /* Reset scrolling region */
 
306
 
 
307
 
 
308
        /* Optimize for a move to the left margin       */
 
309
  if (newc == 0 )
 
310
  {     if (oldl == newl)       
 
311
        {       status = tv_out("\r",1);
 
312
                curc = 0;
 
313
                FINISH;
 
314
        }
 
315
        if (newl == (oldl+1))   
 
316
        {       status = tv_nl();
 
317
                FINISH;
 
318
        }
 
319
  }
 
320
 
 
321
        /* Cursor addressing capability MUST exist in Minimal Implementation */
 
322
 
 
323
#if (TW_LEVEL == 0)
 
324
  status = tv_cm(newl, newc);
 
325
  curl = newl;
 
326
  curc = newc;
 
327
#else
 
328
  if (*terms->tt_cm)
 
329
  {     status = tv_cm(newl, newc);
 
330
        curl = newl;
 
331
        curc = newc;
 
332
        FINISH;
 
333
  }
 
334
 
 
335
        /* Unknown terminal: use right-left, up-down mouvements  ---
 
336
         * but Optimize for move on the same line to the right  */
 
337
 
 
338
  if (newl == oldl) 
 
339
  {     n = newc - oldc;                        /* Displacement */
 
340
        if ( n > 0 )    
 
341
        {       status = tv_mvc(_RIGHT_, n);
 
342
                FINISH;
 
343
        }
 
344
  }
 
345
 
 
346
  status = tv_out("\r",1);      /* Go first to left margin      */
 
347
  curc = 0;     oldc = 0;
 
348
 
 
349
  n = newl - oldl;              /* ... then move down ...       */
 
350
 
 
351
  while(n>0)    
 
352
  {     tv_nl();
 
353
        n--;
 
354
  }
 
355
                                /* ... move up if required...   */
 
356
  if(n)         status = tv_mvc(_UP_, -n);
 
357
                                /* ... finally, move right      */
 
358
  status = tv_mvc(_RIGHT_, newc);
 
359
#endif
 
360
 
 
361
  EXIT_TV(status);
 
362
}
 
363
 
 
364
/*======================================================================
 
365
 *                      tv_home
 
366
 *======================================================================*/
 
367
int tv_home()
 
368
/*+++
 
369
.PURPOSE Move the cursor to home position
 
370
.RETURNS OK
 
371
.REMARKS Minimal implementation: use goto(0,0)
 
372
---*/
 
373
{
 
374
#if (TW_LEVEL > 0)
 
375
        MID_REGISTER char *p;
 
376
#endif
 
377
 
 
378
  ENTER_TV("tv_home");
 
379
 
 
380
  if (terms->scregion[0])               /* Reset scrolling region */
 
381
        tv_sr0();               
 
382
 
 
383
#if (TW_LEVEL == 0)                     /* Minimal Implementation */
 
384
  status = tv_cm(0,0);
 
385
  curl = 0;     curc = 0;       
 
386
#else                                   /* --Full Implementation */
 
387
  /* Look if "ho" possibility exists    */
 
388
  p = SearchCap("ho");
 
389
  if (p)        
 
390
  {     status = SEND(p);
 
391
        curl = 0;
 
392
        curc = 0;
 
393
        FINISH;
 
394
  }
 
395
 
 
396
        /* If up movements not available,
 
397
           simply issue a newline
 
398
        */
 
399
 
 
400
  if(*terms->tt_ptr[_UP_] == 0) 
 
401
        tv_nl();
 
402
        
 
403
        /* Use up movements . Note that zt_mvc takes care of the
 
404
         * existance or not of up movements.                    */
 
405
 
 
406
  tv_out("\r",1);       /* Go first to left margin      */
 
407
  curc = 0;
 
408
  status = tv_mvc(_UP_, curl);
 
409
#endif
 
410
 
 
411
  EXIT_TV(status);
 
412
}
 
413
 
 
414
/*======================================================================
 
415
 *                      tv_mvc
 
416
 *======================================================================*/
 
417
int tv_mvc(direction,times)
 
418
/*+++
 
419
.PURPOSE Move the cursor n times in the specified direction: up, down,
 
420
        right, left or newline.
 
421
.RETURNS OK / NOK (not possible, e.g. up on a hard terminal)
 
422
.REMARKS A negative number of times asks for the opposite direction.
 
423
        If full screen is not asked for, no test on the number of
 
424
        of cursor mouvements is performed.
 
425
        --- Minimal Implementation: cursor movements ALWAYS exist.
 
426
---*/
 
427
        int direction;  /* IN: The direction of the displacement        */
 
428
        int times;      /* IN: Number of times to move  */
 
429
{
 
430
        short int old_pos[2];
 
431
        MID_RSTATIC short int step[2]   = {-1, 1};
 
432
        int     k, n, init_attr;
 
433
 
 
434
  ENTER_TV("tv_mvc");
 
435
 
 
436
#if DEBUG
 
437
  TRACE_ED_I("Moving to direction: ",direction);
 
438
  TRACE_ED_I("....          times: ",times);
 
439
#endif
 
440
 
 
441
  status = OK;
 
442
 
 
443
  if (times == 0)       FINISH;
 
444
 
 
445
  tv_where(old_pos);                            /* Save current position    */
 
446
  init_attr = terms->attr_init;
 
447
 
 
448
  tv_range(terms->pos, terms->dim);             /* Test the cursor position */
 
449
 
 
450
  k = direction >> 1;                           /* Lead to Horiz., Vert. or */
 
451
 
 
452
  switch(k)
 
453
  { case _VERTICAL_: 
 
454
        terms->standout |= ChangedLine;
 
455
    case _HORIZONTAL_: 
 
456
        n = times * step[direction & 1];
 
457
        terms->pos[k] += n;
 
458
        tv_range(terms->pos, terms->dim);
 
459
        if (k == _HORIZONTAL_)  n = curc - oldc;
 
460
        break;
 
461
    default:                                    /* _NEWLINE_ is assumed */
 
462
        if ( (n = times) < 0)   FINISH;
 
463
        while (--n>=0)          tv_nl(); 
 
464
        FINISH;
 
465
  }
 
466
  k <<= 1;                              /* Final Direction              */
 
467
  if (n < 0)            n = -n;
 
468
  else                  k++;
 
469
 
 
470
 
 
471
#if (TW_LEVEL > 0)                      /* ==> Full Implementation      */
 
472
  switch(k)     
 
473
  { case _UP_   :               /* New line for hard terminals: Nothing */
 
474
        if(*terms->tt_ptr[_UP_] == 0)
 
475
        {       /* tv_nl(); */
 
476
                status = NOK;
 
477
                FINISH;
 
478
        }
 
479
        break;
 
480
 
 
481
    case _DOWN_ :               /* Use newlines if cap' doesn't exist   */
 
482
        if (*terms->tt_ptr[_DOWN_] == 0)
 
483
        {       curl = oldl;
 
484
                curc = oldc;
 
485
                while (--n >= 0)        tv_nl();
 
486
                n = oldc;
 
487
                curc = n;       
 
488
                k = _RIGHT_;
 
489
        }               
 
490
        break;
 
491
 
 
492
    case _LEFT_ :               /* When capability doesn't exist, use \r
 
493
                                 * then move to the right               */
 
494
        if (*terms->tt_ptr[_LEFT_] == 0)
 
495
        {       tv_out("\r", 1);
 
496
                n = curc;               /* Blanks to move       */
 
497
                k = _RIGHT_;            /* Next op. is RIGHT    */
 
498
        }               
 
499
        else    break;          
 
500
 
 
501
    case _RIGHT_:               /* Test if blank is used --- if so, don't 
 
502
                                 * forget to use standard attribute !   */
 
503
        if (*(terms->tt_ptr[_RIGHT_] + 4) == ' ')
 
504
                init_attr = terms->attr, tv_attr((int)terms->attr_init);
 
505
        break;
 
506
  }
 
507
 
 
508
#endif
 
509
 
 
510
        /* Send n times the sequence    */
 
511
  status = tv_send(terms->tt_ptr[k], n);
 
512
 
 
513
  if (terms->attr_init != init_attr)    /* If blanks used for _RIGHT_ */
 
514
        tv_attr(init_attr);
 
515
 
 
516
  EXIT_TV(status);
 
517
}
 
518
 
 
519
/*==========================================================================
 
520
 *                      tv_nl
 
521
 *==========================================================================*/
 
522
int tv_nl()
 
523
/*+++++++++++++++
 
524
.PURPOSE New line, i.e. position the cursor to the beginning of the next line.
 
525
.RETURNS OK
 
526
.REMARKS The cursor position is at the beginning of the next line.
 
527
        The insert mode is switched off.
 
528
-----------*/
 
529
{
 
530
        register char *p;
 
531
        unsigned char old_attr;
 
532
 
 
533
  ENTER_TV("tv_nl");
 
534
 
 
535
  status = OK;
 
536
 
 
537
#if (TW_LEVEL > 0)
 
538
        /* First, switch off the insert mode if set     */
 
539
  tv_imode(0);
 
540
#endif
 
541
 
 
542
 
 
543
  curc = 0;                     /* The beginning of a line      */
 
544
  p = terms->tt_ptr[_NEWLINE_];
 
545
  old_attr = terms->attr;
 
546
  tv_attr(terms->attr_init);
 
547
 
 
548
  curl++;
 
549
  if (curl >= diml)             curl = diml -1;
 
550
  status = SEND(p);
 
551
  tv_attr(old_attr);
 
552
  FINISH;
 
553
 
 
554
  EXIT_TV(status); 
 
555
}
 
556
 
 
557
/*======================================================================
 
558
 *                      tv_scroll
 
559
 *======================================================================*/
 
560
int tv_scroll(direction, times)
 
561
/*+++
 
562
.PURPOSE Scroll n lines in the specified (_UP_ or _DOWN_) direction.
 
563
.RETURNS OK / NOK (always NOK in minimal implementation)
 
564
.REMARKS A negative number of times asks for the opposite direction. _UP_ 
 
565
        is the default. 
 
566
---*/
 
567
        int direction;  /* IN: The direction of the displacement        */
 
568
        int times;      /* IN: Number of lines to scroll                */
 
569
{
 
570
#if (TW_LEVEL == 0)     /* ===> Minimal Implementation                  */
 
571
  return(NOK);
 
572
#else                   /* ===> FULL    Implementation                  */
 
573
        int     dir, n;
 
574
        char    *p;
 
575
        TVSAVE  saved;
 
576
 
 
577
  ENTER_TV("tv_scroll");
 
578
 
 
579
#if DEBUG
 
580
        TRACE_ED_I("Scrolling lines: ",times);
 
581
        tv_getc(&ch,&type);
 
582
#endif
 
583
 
 
584
  status = OK;
 
585
  if (times == 0)       FINISH;
 
586
 
 
587
  dir = direction & 1;
 
588
  n = times;
 
589
  if (times  < 0)                       /* Change direction     */
 
590
  {     dir = 1^direction;      
 
591
        n   = -times;   
 
592
  }
 
593
  tv_cus(&saved);                       /* Save cursor position */
 
594
 
 
595
  /* If no scrolling capability exist: move 
 
596
        to top or bottom of screen, and use 
 
597
        - down mouvements to scroll up
 
598
        - insert lines to scroll down                           */
 
599
 
 
600
  if (dir == _DOWN_)    
 
601
  {     tv_home();
 
602
        p = "sr";
 
603
        p = SearchCap(p);
 
604
        if (p)  status = tv_send(p,n);
 
605
        else    status = tv_il(n);
 
606
  }
 
607
  else
 
608
  {     tv_goto(terms->dim[0]-1, 0);
 
609
        p = "sf";
 
610
        p = SearchCap(p);
 
611
        if (p)  status = tv_send(p,n);
 
612
        else    status = tv_send(terms->tt_ptr[_DOWN_], n);
 
613
  }
 
614
 
 
615
  tv_cur(&saved);                       /* Restore Cursor       */
 
616
 
 
617
  EXIT_TV(status);
 
618
#endif
 
619
}
 
620
 
 
621
/*==========================================================================
 
622
 *                      tv_sr
 
623
 *==========================================================================*/
 
624
int tv_sr(l1, l2)
 
625
/*+++++++++++++
 
626
.PURPOSE Defines a scrolling region on the terminal between
 
627
        lines l1 and l2.
 
628
        Lines are numbered from 0 at the top of the screen.
 
629
.RETURNS OK, or NOK (capability does not exist)
 
630
.REMARKS On return, the cursor is at the left margin within the
 
631
        scrolling region.
 
632
        It does not move if NOK is returned, or if the scrolling
 
633
        region did not change.
 
634
----------------*/
 
635
        int l1;         /* IN: Upper line of the scrolling region       */
 
636
        int l2;         /* IN: Lower line of the scrolling region       */
 
637
{
 
638
        register char *p;
 
639
        short int  scroll_lim[2];
 
640
 
 
641
  ENTER_TV("tv_sr");
 
642
 
 
643
  status = OK;
 
644
  p = SearchCap("cs");          /* Null pointer if terminal doesn't allow to
 
645
                                   define scrolling regions */
 
646
 
 
647
  if_not(p) 
 
648
  {     status = NOK;
 
649
        terms->scregion[0] = 0; terms->scregion[1] = diml-1;
 
650
        FINISH;
 
651
  }
 
652
 
 
653
  scroll_lim[0] = MIN(l1,l2);
 
654
  scroll_lim[1] = MAX(l1,l2);
 
655
  
 
656
  if(scroll_lim[0] < 0)         scroll_lim[0] = 0;
 
657
  if(scroll_lim[1] >= diml)     scroll_lim[1] = diml-1;
 
658
 
 
659
  if (  (terms->scregion[0] != scroll_lim[0]) ||
 
660
        (terms->scregion[1] != scroll_lim[1]) )                 
 
661
  {     
 
662
        if_not(status = tv_out(BUFS,tu_format(BUFS,p,scroll_lim)))
 
663
                        FINISH;
 
664
        if_not(status = tv_delay(p))    FINISH;
 
665
        terms->scregion[0] = scroll_lim[0];
 
666
        terms->scregion[1] = scroll_lim[1];
 
667
 
 
668
        if (curl < scroll_lim[0])       curl = scroll_lim[0];
 
669
        if (curl > scroll_lim[1])       curl = scroll_lim[1];
 
670
        curc = 0;
 
671
        if (*terms->tt_cm)  /* If cursor addressing exists, use it */
 
672
                        tv_cm(curl, 0);
 
673
  }
 
674
 
 
675
 
 
676
  EXIT_TV(status);
 
677
}
 
678
 
 
679
/*==========================================================================
 
680
 *                      tv_sr0
 
681
 *==========================================================================*/
 
682
int tv_sr0()
 
683
/*+++++++++++++++
 
684
.PURPOSE Redefines the complete screen as the scrolling region.
 
685
.RETURNS OK / NOK (no change in scrolling region)
 
686
.REMARKS On return, cursor is at home position if OK returned,
 
687
        and remains if NOK.
 
688
----------------*/
 
689
{
 
690
  ENTER_TV("tv_sr0");
 
691
 
 
692
        /* Set the current scrolling region to (0,0) to force
 
693
           a change in the tv_sr routine        */
 
694
          
 
695
  terms->scregion[0] = 0, terms->scregion[1] = 0;
 
696
 
 
697
  status = tv_sr(0, diml-1);
 
698
 
 
699
  FINISH;
 
700
  EXIT_TV(status);
 
701
}
 
702
 
 
703
/*==========================================================================
 
704
 *                      tv_where
 
705
 *==========================================================================*/
 
706
int tv_where(coo)
 
707
/*+++++++++++
 
708
.PURPOSE Returns the current cursor position.
 
709
.RETURNS OK
 
710
.REMARKS The position is adjusted within the screen limits.
 
711
        Not traced.
 
712
------------*/
 
713
        short int coo[2]; /* OUT: current position: line (0=top), col (0=left) */
 
714
{
 
715
  coo[0] = curl;
 
716
  coo[1] = curc;
 
717
  /*    if (terms->flags & TERM_am);
 
718
        else    tv_range(coo, terms->dim);
 
719
  */
 
720
  tv_range(coo, terms->dim);
 
721
  return(OK);
 
722
}
 
723