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

« back to all changes in this revision

Viewing changes to prim/tw3/libsrc/twindel.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 twindel.c
 
32
.AUTHOR         Francois Ochsenbein [ESO-IPG]
 
33
.LANGUAGE       C
 
34
.KEYWORDS       Window Management
 
35
.ENVIRONMENT    TermWindows
 
36
.COMMENTS       This module includes functions to insert or delete lines/chars.
 
37
\begin{TeX}
 
38
\end{TeX}
 
39
.VERSION  1.0   29-Aug-1986:    Creation
 
40
 
 
41
.VERSION  2.0   03-Dec-1986     New terminal-independant graphic characters
 
42
                        with output buffering version.
 
43
.VERSION  2.1   29-Jun-1987     Version '2'
 
44
 
 
45
.VERSION 3.0    20-Mar-1988: Version '3'
 
46
 
 
47
 090901         last modif
 
48
----------------------------------------------------------------------------*/
 
49
 
 
50
#define DEBUG           0       /* Only for debugging   */
 
51
 
 
52
#define PM_LEVEL        LEVEL_TW
 
53
 
 
54
#define  TW_import      0       /* Do not use macro window definitions  */
 
55
#include <twset.h>
 
56
 
 
57
 
 
58
extern int tw_st(), tw_goto(), tw_chars(), tw_fill(), tw_r(), tw_copw();
 
59
extern int tv_buffer();
 
60
 
 
61
extern int pm_enter(), pm_iexit(), pm_ed_i();
 
62
 
 
63
 
 
64
 
 
65
MID_EXTERN      WINDOW *Screen;
 
66
 
 
67
#if     DEBUG
 
68
#define ed_level        3
 
69
#define ENTER_DEBUG(x)  ENTER(x)
 
70
#define EXIT_DEBUG(x)   EXIT(x)
 
71
#define DISPLAY(opt)    tw_ed(w,opt)
 
72
#else
 
73
#define DISPLAY(opt)
 
74
#define ENTER_DEBUG(x)  
 
75
#define EXIT_DEBUG(x)   return(x)
 
76
#endif
 
77
 
 
78
MID_STATIC int chars[2] = {0, 0};
 
79
static int J;
 
80
 
 
81
        MONITOR(TWINDEL);
 
82
 
 
83
 
 
84
/*======================================================================
 
85
 *                      tw_dc
 
86
 *======================================================================*/
 
87
int tw_dc(w, nchar)
 
88
/*+++
 
89
.PURPOSE Delete n chars on a specified window, pushing characters to the
 
90
        left.
 
91
.RETURNS OK / NOK (Not all characters deleted)
 
92
.REMARKS A negative number of times asks to delete chars at the left of
 
93
        the cursor ( the cursor moves in this case).
 
94
        The hardware `delete char' capability is not used.
 
95
        Deleting is limited witin markers.
 
96
---*/
 
97
        WINDOW  *w;             /* MOD: The window concerned    */
 
98
        int nchar;      /* IN: Number of chars to delete        */
 
99
{
 
100
        register int    n, d;
 
101
 
 
102
  ENTER_TWA("tw_dc");
 
103
 
 
104
  DISPLAY(0);
 
105
#if DEBUG
 
106
  TRACE_ED_STR2("Deleting Chars on Window: ", w->id, 8);
 
107
  TRACE_ED_I("Chars: ", nchar);
 
108
#endif
 
109
 
 
110
  n = nchar;
 
111
  tw_chars(w, chars);
 
112
 
 
113
  if (n < 0)
 
114
  {     n = -n;
 
115
        if (n > chars[0])       n = chars[0], status = NOK;
 
116
        w->pos -= n;
 
117
        tw_chars(w, chars);
 
118
  }
 
119
  else  if (n > chars[1])
 
120
        n = chars[1], status = NOK;
 
121
 
 
122
  if (n == 0)           Return;
 
123
 
 
124
        /* Copy the chars which are kept                */
 
125
 
 
126
  d = w->pos;
 
127
  d = tw_copw(w, d, w, d+n, chars[1] - n);
 
128
 
 
129
        /* Fill with blanks the rest of the line(s)     */
 
130
 
 
131
  tw_fill(w, d, n, w->attr_init);
 
132
 
 
133
  DISPLAY(0);
 
134
 
 
135
  EXIT_TWA(status);
 
136
}
 
137
 
 
138
/*==========================================================================
 
139
 *                      tw_dl
 
140
 *==========================================================================*/
 
141
int     tw_dl(w, lines)
 
142
/*+++
 
143
.PURPOSE Delete lines (moving up lines below) on a window,
 
144
        including the current line
 
145
.RETURNS OK / NOK (not all lines deleted)
 
146
.REMARKS On return, the cursor is at the beginning of the current line.
 
147
        If lines<0, lines on top of the current line are deleted.
 
148
---*/
 
149
        WINDOW  *w;     /* MOD: The window concerned                    */
 
150
        int lines;      /* IN: Upper line of the scrolling region       */
 
151
{
 
152
        int i, n, L;
 
153
 
 
154
  ENTER_TWA("tw_dl");
 
155
 
 
156
  TRACE_ED_I("Delete Lines: ", lines);
 
157
 
 
158
  n = lines, J = w->Nj, i = w->pos/J;
 
159
 
 
160
  if ( (i + n) < 0)             n = -i, status = NOK;
 
161
 
 
162
  if ( (i + n) >= w->Ni)        n = w->Ni - i, status = NOK;
 
163
 
 
164
  if (n == 0)           Return;
 
165
 
 
166
  if (n < 0)            i += n;
 
167
  w->pos = i * J;
 
168
  if (n == 0) FINISH;           /* The move to the line beginning is done */
 
169
 
 
170
  n = ABSOLUTE(n);              /* Number of deleted lines      */
 
171
 
 
172
        /* Update in Memory: First copy moved lines     */
 
173
 
 
174
  L = (w->Ni - n) * J - w->pos; /* Chars to copy        */
 
175
  L = tw_copw(w, w->pos, w, w->pos + n*J, L);
 
176
  DISPLAY(0);
 
177
 
 
178
        /* ... and clear bottom lines                   */
 
179
  tw_fill(w, L, n*J, w->attr_init);
 
180
 
 
181
  DISPLAY(0);
 
182
 
 
183
  EXIT_TWA(status);
 
184
}
 
185
 
 
186
/*==========================================================================
 
187
 *                      tw_il
 
188
 *==========================================================================*/
 
189
int     tw_il(w, lines)
 
190
/*+++
 
191
.PURPOSE Insert blank lines (moving down lines below) on a window.
 
192
.RETURNS OK
 
193
.REMARKS On return, the cursor is at the beginning of the current (blank) line.
 
194
        If lines<0, lines are inserted on top of the current line.
 
195
---*/
 
196
        WINDOW  *w;             /* MOD: The window concerned    */
 
197
        int lines;              /* IN: Upper line of the scrolling region       */
 
198
{
 
199
        int     i, n, L;
 
200
 
 
201
  ENTER_TWA("tw_il");
 
202
 
 
203
  TRACE_ED_I("Insert lines: ", lines);
 
204
 
 
205
  J = w->Nj, i = w->pos/J;
 
206
 
 
207
  if (lines < 0)        tw_goto(w, i + lines, 0), n = -lines;
 
208
  else                  tw_goto(w, i, 0), n = lines;
 
209
 
 
210
  if (n == 0)   Return;         /* The move to the line beginning is done */
 
211
 
 
212
  if ( (n + i) > w->Ni)         n = w->Ni - i;
 
213
 
 
214
        /* Update in Memory: First copy moved lines     */
 
215
 
 
216
  L = (w->Ni - n) * J - w->pos; /* Chars to copy        */
 
217
  tw_copw(w, w->pos + n*J, w, w->pos, L);
 
218
 
 
219
        /* ... and clear lines                          */
 
220
  tw_fill(w, w->pos, n*J, w->attr_init);
 
221
 
 
222
  DISPLAY(2);
 
223
 
 
224
  EXIT_TWA(status);
 
225
}
 
226