tt_availmodes
[unix-history] / usr / src / usr.bin / window / wwlabel.c
CommitLineData
e7fe89d1 1#ifndef lint
861cd1ed 2static char *sccsid = "@(#)wwlabel.c 3.3 83/08/16";
e7fe89d1
EW
3#endif
4
5#include "ww.h"
6
85af59e4
EW
7/*
8 * Label window w on f,
9 * at 1 line above w and 'where' columns from it's left edge.
10 * Gross, but it works.
11 */
12wwlabel(w, f, where, l, mode)
0896e17e 13struct ww *w;
85af59e4
EW
14struct ww *f;
15char *l;
e7fe89d1 16{
85af59e4
EW
17 int i;
18 register j;
d439a752 19 register char *p;
85af59e4
EW
20 register char *win;
21 register union ww_char *buf;
22 register union ww_char *ns;
0896e17e 23 register char *fmap;
861cd1ed 24 char *touched;
e7fe89d1 25
85af59e4 26 if ((i = w->ww_w.t - 1 - f->ww_w.t) < 0)
d439a752 27 return -1;
85af59e4
EW
28 j = w->ww_w.l + where;
29 j = MAX(j, f->ww_w.l);
30 win = &f->ww_win[i][j - f->ww_w.l];
31 buf = &f->ww_buf[w->ww_scroll + i][j - f->ww_w.l];
32 i += f->ww_w.t;
33 ns = &wwns[i][j];
34 fmap = &wwfmap[i][j];
861cd1ed 35 touched = &wwtouched[i];
85af59e4
EW
36 j = MIN(w->ww_w.r, f->ww_w.r) - j;
37
38 for (; j > 0 && *l;)
0896e17e 39 for (p = unctrl(*l++); j > 0 && *p; j--) {
85af59e4 40 /* can't label if not already framed */
0896e17e 41 if (*win & WWM_GLS) {
85af59e4
EW
42 p++;
43 buf++;
44 ns++;
45 win++;
0896e17e 46 fmap++;
85af59e4
EW
47 } else if (*win & WWM_COV) {
48 buf++->c_w = mode << WWC_MSHIFT | *p++;
0896e17e 49 *fmap++ |= WWF_LABEL;
85af59e4
EW
50 ns++;
51 win++;
0896e17e 52 } else {
861cd1ed 53 *touched = 1;
85af59e4
EW
54 ns++->c_w = (buf++->c_w
55 = mode << WWC_MSHIFT | *p++)
56 ^ *win++ << WWC_MSHIFT;
0896e17e
EW
57 *fmap++ |= WWF_LABEL;
58 }
85af59e4
EW
59 }
60
61 return 0;
e7fe89d1 62}