~ubuntu-branches/ubuntu/quantal/splitvt/quantal

« back to all changes in this revision

Viewing changes to .pc/old.changes.patch/videomem.c

  • Committer: Bazaar Package Importer
  • Author(s): Mònica Ramírez Arceda
  • Date: 2011-02-13 00:21:26 UTC
  • Revision ID: james.westby@ubuntu.com-20110213002126-dl9ggx3zwvpu0awj
Tags: 1.6.6-8
* Adopt the package. (Closes: #489450)
* Switch to quilt format: add old.changes.patch.
* Tidy up debian/copyright: organize it in sections, add copyright
  notice, add GPL version and add myself as a Debian mantainer.
* Manpage:
  - Change - by \- to use minus sign instead of hyphen in manpage 
    (fix.man.minus.sign.patch).
  - Add .TB macro (fix.man.macro.not.defined.patch).
* Override lintian warning (setgid-binary): splitvt needs write 
  access to /var/run/utmp file.
* Add debian/install, debian/docs, debian/examples and
  debian/splitvt.manpages in order to minimize debian/rules.
* Update debian/rules to use overrides of dh_*.
* Delete Homepage field in debian/control and debian/watch: 
  upstream site doesn't exist any more.
* Bump to Standards-Version 3.9.1. No changes required.
* Add Vcs-Git, Vcs-Browser fields in debian/control.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
/* This file holds the functions for manipulating video memory */
 
3
 
 
4
#include        <stdio.h>
 
5
#include        <stdlib.h>
 
6
#include        "video.h"
 
7
#include        "terminal.h"
 
8
 
 
9
/* This function returns a pointer to a video memory area of ints.
 
10
   Integers are used to encode both the characters and the flags.
 
11
   If this function fails, it should be a fatal error.  Allocated
 
12
   memory is not freed if the function fails.
 
13
 */
 
14
 
 
15
int **alloc_video(rows, cols)
 
16
int rows;
 
17
int cols;
 
18
{
 
19
        int **videomem;
 
20
        int i, j;
 
21
 
 
22
        /* Allocate row pointers */
 
23
        if ( (videomem=(int **)malloc(rows*sizeof(int *))) == NULL )
 
24
                return(NULL);
 
25
 
 
26
        /* Allocate the columns for each row */
 
27
        for ( i=0; i<rows; ++i ) {
 
28
                if ( (videomem[i]=(int *)malloc(cols*sizeof(int))) == NULL )
 
29
                        return(NULL);
 
30
                for ( j=0; j<cols; ++j )
 
31
                        videomem[i][j]=0;
 
32
        }
 
33
        return(videomem);
 
34
}
 
35
 
 
36
/* This function copies an existing window to a new buffer, 
 
37
   truncating lines if necessary, and translates the cursor position  */
 
38
void copy_video(win, newarea, rows, cols, newcursor)
 
39
window *win;
 
40
int **newarea;
 
41
int rows;
 
42
int cols;
 
43
position *newcursor;
 
44
{
 
45
        int i, j, ni, nj;
 
46
 
 
47
        /* Copy from the bottom up... */
 
48
        newcursor->x=0;
 
49
        for ( i=win->rows, ni=rows; i && ni; --i, --ni ) {
 
50
                if ( win->cursor.x == i ) {
 
51
                        if ( (newcursor->x=(i+rows-win->rows)) < 1 )
 
52
                                newcursor->x=1;
 
53
                }
 
54
                for ( j=0, nj=0; (j<win->cols) && (nj<cols); ++j, ++nj )
 
55
                        newarea[ni-1][nj]=win->videomem[i-1][j];
 
56
        }
 
57
        if ( ! newcursor->x )   /* We never reached the old cursor */
 
58
                newcursor->x=1;
 
59
        newcursor->y=(win->cursor.y > cols ? cols : win->cursor.y);
 
60
}
 
61
 
 
62
/* This function adds a character to the video memory at the cursor position */
 
63
void add_video(win, c)
 
64
window *win;
 
65
char c;
 
66
{
 
67
        win->videomem[win->cursor.x - 1][win->cursor.y - 1] = (int)c;
 
68
        win->videomem[win->cursor.x - 1][win->cursor.y - 1] |= 
 
69
                                                (((int)win->textattr)<<8);
 
70
}
 
71
 
 
72
/* This function returns a character from video at a specific position */
 
73
int get_video(win, x, y)
 
74
window *win;
 
75
int x, y;
 
76
{
 
77
        return(win->videomem[x-1][y-1]);
 
78
}
 
79
 
 
80
/* This function sets a character position in video memory */
 
81
void put_video(c, win, x, y)
 
82
int c;
 
83
window *win;
 
84
int x, y;
 
85
{
 
86
        win->videomem[x-1][y-1]=c;
 
87
}
 
88
 
 
89
/* This function returns the array index of the end of the specified line
 
90
   in the specified window.  lineno should start as 1 for the first line.
 
91
*/
 
92
static int video_eol(win, lineno)
 
93
window *win;
 
94
int lineno;
 
95
{
 
96
        int eol=(-1), j;
 
97
 
 
98
        for ( j=0; j<win->cols; ++j ) {
 
99
                if ( (win->videomem[lineno-1][j]&0xFF) != 0 )
 
100
                        eol=j;
 
101
        }
 
102
        ++eol;
 
103
        return(eol);
 
104
}
 
105
 
 
106
/* This function copies a specified section of video memory to a buffer */
 
107
/* x1 is the first line, x2 is the second line, y1 is the y on the first
 
108
   line, and y2 is the y on the last line.
 
109
*/
 
110
void getsel_video(win, buf, maxlen, x1, x2, y1, y2)
 
111
window *win;
 
112
char *buf;
 
113
int maxlen;
 
114
int x1, x2;
 
115
int y1, y2;
 
116
{
 
117
        int l=0, i, j, eol, eos;
 
118
 
 
119
        --maxlen;       /* Account for trailing null */
 
120
        for ( i=(x1-1); (i<x2 && l<maxlen); ++i ) {
 
121
                eol=video_eol(win, i+1);
 
122
                if ( i == (x1-1) ) {
 
123
                        j=(y1-1);
 
124
                        eos=eol;
 
125
                } else
 
126
                        j=0;
 
127
                if ( i == (x2-1) )
 
128
                        eos=((y2-1) < eol ? (y2-1) : eol);
 
129
                for ( ; j<eos; ++j ) {
 
130
                        if ( (win->videomem[i][j]&0xFF) == '\0' )
 
131
                                *(buf++) = ' ';
 
132
                        else
 
133
                                *(buf++) = (win->videomem[i][j]&0xFF);
 
134
                        ++l;
 
135
                }
 
136
                if ( l<maxlen && j >= eol ) {
 
137
                        *(buf++) = '\r';
 
138
                        ++l;
 
139
                }
 
140
        }
 
141
        *buf='\0';
 
142
        return;
 
143
}
 
144
 
 
145
/* This function clears the SELECTED bit in a whole window */
 
146
void clrsel_video(win)
 
147
window *win;
 
148
{
 
149
        int i, j;
 
150
 
 
151
        for ( i=0; i<win->rows; ++i ) {
 
152
                for ( j=0; j<win->cols; ++j ) {
 
153
                        if ( ((win->videomem[i][j]>>8)&SELECTED) == SELECTED )
 
154
                                win->videomem[i][j] &= ~(SELECTED<<8);
 
155
                }
 
156
        }
 
157
}
 
158
 
 
159
/* This function erases a specified section of video memory */
 
160
void erase_video(win, x1, x2, y1, y2)
 
161
window *win;
 
162
int x1, x2;
 
163
int y1, y2;
 
164
{
 
165
        int i, j;
 
166
 
 
167
        for ( i=(x1-1); i<x2; ++i ) {
 
168
                for ( j=(y1-1); j<y2; ++j )
 
169
                        win->videomem[i][j] = 0;
 
170
        }
 
171
        return;
 
172
}
 
173
 
 
174
/* This function "scrolls" video memory forward */
 
175
void scroll_video(win, numlines)
 
176
window *win;
 
177
int numlines;
 
178
{
 
179
        int i, n, *tmp;
 
180
 
 
181
        /* Don't scroll memory if cursor is outside of scroll region */
 
182
        if ( win->cursor.x > win->scr_lower )
 
183
                return;
 
184
 
 
185
        /* Otherwise, scroll away! */
 
186
        for ( i=0; i<numlines; ++i ) {
 
187
                /* Clear out the line that has been scrolled off the edge */
 
188
                tmp=win->videomem[win->scr_upper-1];
 
189
                for ( n=0; n<win->cols; ++n )
 
190
                        tmp[n]=0;
 
191
 
 
192
                /* Now perform the scroll */
 
193
                for ( n=(win->scr_upper-1); n<(win->scr_lower-1); ++n )
 
194
                        win->videomem[n]=win->videomem[n+1];
 
195
                win->videomem[n]=tmp;
 
196
        }
 
197
        /* That's it! */
 
198
        return;
 
199
}
 
200
 
 
201
/* This function "scrolls" video memory backward */
 
202
void revscroll_video(win, numlines)
 
203
window *win;
 
204
int numlines;
 
205
{
 
206
        int i, n, *tmp;
 
207
 
 
208
        /* Don't scroll memory if cursor is outside of scroll region */
 
209
        if ( win->cursor.x < win->scr_upper )
 
210
                return;
 
211
 
 
212
        /* Otherwise, scroll away! */
 
213
        for ( i=0; i<numlines; ++i ) {
 
214
                /* Clear out the line that has been scrolled off the edge */
 
215
                tmp=win->videomem[win->scr_lower-1];
 
216
                for ( n=0; n<win->cols; ++n )
 
217
                        tmp[n]=0;
 
218
 
 
219
                /* Now perform the scroll */
 
220
                for ( n=(win->scr_lower-1); n>(win->scr_upper-1); --n )
 
221
                        win->videomem[n]=win->videomem[n-1];
 
222
                win->videomem[n]=tmp;
 
223
        }
 
224
        /* That's it! */
 
225
        return;
 
226
}
 
227
 
 
228
/* This function inserts nulls in a line, shifting everything right */
 
229
void rshift_video(win, numcols)
 
230
window *win;
 
231
int numcols;
 
232
{
 
233
        int i;
 
234
 
 
235
        for ( i=(win->cols-1); i > (win->cursor.y-1); --i ) {
 
236
                if ( (i-numcols) >= 0 )
 
237
                        win->videomem[win->cursor.x-1][i] = 
 
238
                                win->videomem[win->cursor.x-1][i-numcols];
 
239
                else
 
240
                        win->videomem[win->cursor.x-1][i] = 0;
 
241
        }
 
242
}
 
243
 
 
244
int check_attr(pixel, lastattr, currattr)
 
245
int pixel;
 
246
int lastattr;
 
247
unsigned char *currattr;
 
248
{
 
249
        unsigned char simplepixel, lastpixel;
 
250
        unsigned char change;
 
251
        unsigned char selected, reversed;
 
252
 
 
253
        /* Set the simplepixel REVERSE bit if SELECTED ^ REVERSE */
 
254
        simplepixel = ((pixel>>8)&(~SELECTED)&(~REVERSE));
 
255
        selected = ( ((pixel>>8)&(~SELECTED)) ? 1 : 0 );
 
256
        reversed = ( ((pixel>>8)&(~REVERSE)) ? 1 : 0 );
 
257
        if ( selected ^ reversed )
 
258
                simplepixel |= REVERSE;
 
259
 
 
260
        /* Set the lastpixel REVERSE bit if SELECTED ^ REVERSE */
 
261
        lastpixel = ((lastattr>>8)&(~SELECTED)&(~REVERSE));
 
262
        selected = ( ((lastattr>>8)&(~SELECTED)) ? 1 : 0 );
 
263
        reversed = ( ((lastattr>>8)&(~REVERSE)) ? 1 : 0 );
 
264
        if ( selected ^ reversed )
 
265
                lastpixel |= REVERSE;
 
266
 
 
267
        /* Thanks to Dan Dorough for the XOR code */
 
268
checkchange:
 
269
        change = (lastpixel ^ simplepixel);
 
270
        if ( change ) {
 
271
                if ( change&REVERSE ) {
 
272
                        if ( (*currattr)&REVERSE ) {
 
273
#define GOTO_HACK       /* vt_reverse(0) doesn't work on xterms :-( */
 
274
#ifdef GOTO_HACK        /* This goto hack resets all current attributes */
 
275
                                vt_resetattr();
 
276
                                *currattr &= ~REVERSE;
 
277
                                simplepixel=0;
 
278
                                lastpixel &= (~REVERSE);
 
279
                                goto checkchange;
 
280
#else /* ideal code */
 
281
                                vt_reverse(0);
 
282
                                *currattr &= ~REVERSE;
 
283
#endif
 
284
                        } else {
 
285
                                vt_reverse(1);
 
286
                                *currattr |= REVERSE;
 
287
                        }
 
288
                }
 
289
                if ( change&BOLD ) {
 
290
                        if ( (*currattr)&BOLD ) {
 
291
                                vt_bold(0);
 
292
                                *currattr &= ~BOLD;
 
293
                        } else {
 
294
                                vt_bold(1);
 
295
                                *currattr |= BOLD;
 
296
                        }
 
297
                }
 
298
                if ( change&UNDERLINE ) {
 
299
                        if ( (*currattr)&UNDERLINE ) {
 
300
                                vt_underline(0);
 
301
                                *currattr &= ~UNDERLINE;
 
302
                        } else {
 
303
                                vt_underline(1);
 
304
                                *currattr |= UNDERLINE;
 
305
                        }
 
306
                }
 
307
                if ( change&BLINK ) {
 
308
                        if ( (*currattr)&BLINK ) {
 
309
                                vt_blink(0);
 
310
                                *currattr &= ~BLINK;
 
311
                        } else {
 
312
                                vt_blink(1);
 
313
                                *currattr |= BLINK;
 
314
                        }
 
315
                }
 
316
        }
 
317
        return(pixel);
 
318
}
 
319
 
 
320
void paint_video(win)
 
321
window *win;
 
322
{
 
323
        unsigned char change, on=NORMAL;
 
324
        int i, j, oldattr=0;
 
325
 
 
326
        vt_setscroll(0,0);
 
327
        vt_resetattr();
 
328
        vt_goto(1+win->row_offset, 1);
 
329
        for ( i=0; i<win->rows; ++i ) {
 
330
                for ( j=0; j<win->cols; ++j ) {
 
331
                        if ( win->videomem[i][j]&0xFF ) {
 
332
                                oldattr=check_attr(win->videomem[i][j],
 
333
                                                                oldattr, &on);
 
334
                                printf("%c", (win->videomem[i][j]&0xFF));
 
335
                        } else {
 
336
                                oldattr=0;
 
337
                                if ( on != NORMAL ) {
 
338
                                        vt_resetattr();
 
339
                                        on=NORMAL;
 
340
                                }
 
341
                                printf(" ");
 
342
                        }
 
343
                }
 
344
                printf("\r");
 
345
                vt_down(1);             /* This shouldn't cause scroll */
 
346
        }
 
347
        vt_setscroll(win->scr_upper+win->row_offset, 
 
348
                                        win->scr_lower+win->row_offset);
 
349
        vt_goto(win->cursor.x+win->row_offset, win->cursor.y);
 
350
        vt_update();
 
351
}