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

« back to all changes in this revision

Viewing changes to prim/tw3/libsrc/tvindel.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 tvindel.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 insert or delete lines
 
37
                and characters.
 
38
                In the Minimal Implementation, these routines are not used.
 
39
\begin{TeX}
 
40
Used Capabilities:
 
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.                                    \\
 
48
\hline
 
49
\end{tabular}$$
 
50
\end{TeX}
 
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.
 
57
 
 
58
 090831         last modif
 
59
----------------------------------------------------------------------------*/
 
60
 
 
61
#define DEBUG           0               /* Debugging only       */
 
62
 
 
63
#define PM_LEVEL        LEVEL_TV
 
64
 
 
65
#define TW_MACROS       0               /* Don't use TermWindows Macros */
 
66
#define TW_import       0       
 
67
#define TW_STRUCT       0       /* Do not use window Structures         */
 
68
#include <twset.h>
 
69
 
 
70
MID_EXTERN TERM *terms;         
 
71
 
 
72
#define         SEND(p)         tv_send(p,1)
 
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 ENTER_TV(x)     static int      state_buffer;                   \
 
82
                        ENTER(x);       TERMTEST;                       \
 
83
                        state_buffer  = tv_buffer(TRUE);        
 
84
#define EXIT_TV(f)      FIN:                                            \
 
85
                        tv_buffer(state_buffer);                        \
 
86
                        EXIT(f)
 
87
 
 
88
#if DEBUG
 
89
        static  char ch=EOS;
 
90
        static int type=0;
 
91
#endif
 
92
 
 
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)
 
101
 
 
102
 
 
103
        /* MONITOR (ZTINDEL); */
 
104
 
 
105
/*======================================================================
 
106
 *                      tv_dc
 
107
 *======================================================================*/
 
108
int tv_dc(nchars)
 
109
/*+++
 
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.
 
115
---*/
 
116
        int nchars;     /* IN: Number of chars to delete                */
 
117
{
 
118
#if (TW_LEVEL < 2)
 
119
  return(NOK);
 
120
#else
 
121
        int     n;
 
122
        char    *p;
 
123
 
 
124
  ENTER_TV("tv_dc");
 
125
 
 
126
  status = OK;
 
127
 
 
128
  if (nchars == 0)      FINISH;
 
129
 
 
130
  p = SearchCap("dc");
 
131
  if (!p)
 
132
  {     status = NOK;
 
133
        FINISH;
 
134
  }
 
135
 
 
136
  if (nchars < 0)       tv_goto(curl, curc+nchars);
 
137
  n = ABSOLUTE(nchars);  
 
138
 
 
139
  status = tv_send(p,n);
 
140
 
 
141
  EXIT_TV(status);
 
142
#endif
 
143
}
 
144
 
 
145
/*==========================================================================
 
146
 *                      tv_dl
 
147
 *==========================================================================*/
 
148
int     tv_dl(lines)
 
149
/*+++++++++
 
150
.PURPOSE Delete lines (moving up lines below), inluding the running
 
151
        line.
 
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.
 
156
-----------*/
 
157
        int lines;              /* IN: Number of lines to delete        */
 
158
{       
 
159
#if (TW_LEVEL < 2)
 
160
  return(NOK);
 
161
#else
 
162
        short int old_pos[2];
 
163
        char    *p;
 
164
        int     n;
 
165
 
 
166
  ENTER_TV("tv_dl");
 
167
 
 
168
  status = OK;
 
169
 
 
170
  if (lines < 0) 
 
171
  {     tv_goto(curl+lines, 0);
 
172
        n = -lines;
 
173
  }
 
174
  else  
 
175
  {     tv_goto(curl, 0);
 
176
        n = lines;
 
177
  }
 
178
 
 
179
  if (lines == 0)       FINISH;
 
180
 
 
181
  p = SearchCap("dl");
 
182
  if (p)
 
183
  {     status = tv_send(p,n);
 
184
        FINISH;
 
185
  }
 
186
 
 
187
        /* Delete Line does not exist ---
 
188
         * Try to use the scrolling             */
 
189
 
 
190
  status = tv_sr(curl,  diml-1) ;
 
191
  if (status == OK)
 
192
  {     tv_where(old_pos);
 
193
        tv_goto(diml-1,0);
 
194
        curl -= n;              /* In fact, the cursor did not move     */
 
195
        tv_mvc(_DOWN_,n);
 
196
        tv_sr(0, diml-1);
 
197
  }
 
198
 
 
199
  status = tv_goto(oldl, 0);    
 
200
 
 
201
  EXIT_TV(status);
 
202
#endif
 
203
}
 
204
 
 
205
/*======================================================================
 
206
 *                      tv_ic
 
207
 *======================================================================*/
 
208
int tv_ic(nchars)
 
209
/*+++
 
210
.PURPOSE Insert n blanks at the cursor position, moving existing characters
 
211
        to the right.
 
212
.RETURNS OK / NOK (impossible)
 
213
.REMARKS A negative number of times asks to insert chars at the left of
 
214
        the cursor.
 
215
        Returns always NOK in the Minimal Implementation.
 
216
---*/
 
217
        int nchars;     /* IN: Number of blanks to insert       */
 
218
{
 
219
#if (TW_LEVEL < 2)
 
220
  return(NOK);
 
221
#else
 
222
        int     n;
 
223
        char    *p;
 
224
 
 
225
  ENTER_TV("tv_ic");
 
226
 
 
227
  status = OK;
 
228
 
 
229
  if (nchars == 0)      FINISH;
 
230
 
 
231
  if (nchars < 0)       status = tv_goto(curl, curc+nchars);
 
232
  n = ABSOLUTE(nchars);  
 
233
  n = MIN(n, terms->buf_size);
 
234
 
 
235
  p = SearchCap("ic");
 
236
  if (!p)       
 
237
  {     status = tv_imode(1);   /* Try to use Insert Mode */
 
238
        if (status == NOK)      FINISH;
 
239
        oscfill(BUFS,n,' ');
 
240
        tv_write(BUFS,n);
 
241
        status = tv_imode(0);
 
242
  }
 
243
 
 
244
  if (status == OK)     status = tv_send(p,n);
 
245
 
 
246
  EXIT_TV(status);
 
247
#endif
 
248
}
 
249
 
 
250
/*==========================================================================
 
251
 *                      tv_il
 
252
 *==========================================================================*/
 
253
int     tv_il(lines)
 
254
/*++++++++++++++
 
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.
 
261
---------------*/
 
262
        int lines;              /* IN: Number of blank lines to insert  */
 
263
{
 
264
#if (TW_LEVEL < 2)
 
265
  return(NOK);
 
266
#else
 
267
        short int old_pos[2];
 
268
        char    *p;
 
269
        int     n;
 
270
 
 
271
  ENTER_TV("tv_il");
 
272
 
 
273
  status = OK;
 
274
 
 
275
  if (lines < 0) 
 
276
  {     tv_goto(curl+lines, 0);
 
277
        n = -lines;
 
278
  }
 
279
  else  
 
280
  {     tv_goto(curl, 0);
 
281
        n = lines;
 
282
  }
 
283
 
 
284
  if (lines == 0)       FINISH;
 
285
 
 
286
  p = SearchCap("al");
 
287
  if (p)        
 
288
  {     status = tv_send(p,n);
 
289
        FINISH;
 
290
  }
 
291
 
 
292
        /* Insert Line does not exist ---
 
293
         * Try to use the scrolling             */
 
294
 
 
295
#if DEBUG
 
296
        tv_getc(&ch,&type);
 
297
#endif
 
298
  status = tv_sr(curl,  diml-1) ;
 
299
  if (status == OK)
 
300
  {     tv_where(old_pos);      /* The cursor is at top of subscreen    */
 
301
#if DEBUG
 
302
        tv_getc(&ch,&type);
 
303
#endif
 
304
        if ((status = tv_mvc(_UP_, n)) != OK)   FINISH;
 
305
#if DEBUG
 
306
        tv_getc(&ch,&type);
 
307
#endif
 
308
        status = tv_sr(0, diml-1);
 
309
  }
 
310
 
 
311
  if (status == OK)     status = tv_goto(oldl,0);       
 
312
 
 
313
  EXIT_TV(status);
 
314
#endif
 
315
}
 
316
 
 
317
/*======================================================================
 
318
 *                      tv_imode
 
319
 *======================================================================*/
 
320
int tv_imode(k)
 
321
/*+++
 
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.
 
326
        (see tv_nl).
 
327
        Returns always NOK in the Minimal Implementation.
 
328
---*/
 
329
        int k;          /* IN: 0 to exit, non-zero to enter     */
 
330
{
 
331
#if (TW_LEVEL < 2)
 
332
  return(NOK);
 
333
#else
 
334
        register char *p;
 
335
 
 
336
  ENTER_TV("tv_imode");
 
337
 
 
338
  status = OK;
 
339
 
 
340
  if (k)                /* Trying to enable ...         */
 
341
  {     if (terms->flags & TERM_IMODE)          FINISH;
 
342
        p = SearchCap("im");
 
343
        if (p)  terms->flags |= TERM_IMODE;
 
344
  }
 
345
  else
 
346
  {     if (!(terms->flags & TERM_IMODE))       FINISH;
 
347
        p = SearchCap("ei");
 
348
        if (p)  terms->flags &= (~TERM_IMODE);
 
349
  }
 
350
 
 
351
  if (!p)               status = NOK;
 
352
  if (status == OK)     status = tv_send(p,1);
 
353
 
 
354
  EXIT_TV(status);
 
355
#endif
 
356
}
 
357
 
 
358
/*======================================================================
 
359
 *                      tv_iwrite
 
360
 *======================================================================*/
 
361
int tv_iwrite(str,len)
 
362
/*+++
 
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.
 
367
        (see tv_nl).
 
368
        Returns always NOK in the Minimal Implementation.
 
369
---*/
 
370
        char *str;      /* IN: Text to display          */
 
371
        int len;        /* IN: Length of text           */
 
372
{
 
373
#if (TW_LEVEL < 2)
 
374
  return(NOK);
 
375
#else
 
376
        register char *p;
 
377
 
 
378
  ENTER_TV("tv_imode");
 
379
 
 
380
  status = OK;
 
381
 
 
382
  if (!(terms->flags & TERM_IMODE))     /* Enter Insert Mode    */
 
383
  {     if ( (status = tv_imode(1)) == NOK)     FINISH;
 
384
  }
 
385
  
 
386
  status = tv_write(str,len);
 
387
 
 
388
  tv_imode(0);
 
389
 
 
390
  EXIT_TV(status);
 
391
#endif
 
392
}