|
|
1.1 root 1: /*
2: * Copyright (c) 1989 Regents of the University of California.
3: * All rights reserved.
4: *
5: * This code is derived from software contributed to Berkeley by
6: * Edward Wang at The University of California, Berkeley.
7: *
8: * Redistribution and use in source and binary forms are permitted provided
9: * that: (1) source distributions retain this entire copyright notice and
10: * comment, and (2) distributions including binaries display the following
11: * acknowledgement: ``This product includes software developed by the
12: * University of California, Berkeley and its contributors'' in the
13: * documentation or other materials provided with the distribution and in
14: * all advertising materials mentioning features or use of this software.
15: * Neither the name of the University nor the names of its contributors may
16: * be used to endorse or promote products derived from this software without
17: * specific prior written permission.
18: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
19: * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
20: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21: */
22:
23: #ifndef lint
24: static char sccsid[] = "@(#)xx.c 3.6 (Berkeley) 6/6/90";
25: #endif /* not lint */
26:
27: #include "ww.h"
28: #include "xx.h"
29: #include "tt.h"
30:
31: xxinit()
32: {
33: if (ttinit() < 0)
34: return -1;
35: xxbufsize = tt.tt_nrow * tt.tt_ncol * 2;
36: /* ccinit may choose to change xxbufsize */
37: if (tt.tt_ntoken > 0 && ccinit() < 0)
38: return -1;
39: xxbuf = malloc((unsigned) xxbufsize * sizeof *xxbuf);
40: if (xxbuf == 0) {
41: wwerrno = WWE_NOMEM;
42: return -1;
43: }
44: xxbufp = xxbuf;
45: xxbufe = xxbuf + xxbufsize;
46: return 0;
47: }
48:
49: xxstart()
50: {
51: (*tt.tt_start)();
52: if (tt.tt_ntoken > 0)
53: ccstart();
54: xxreset(); /* might be a restart */
55: }
56:
57: xxend()
58: {
59: if (tt.tt_scroll_top != 0 || tt.tt_scroll_bot != tt.tt_nrow - 1)
60: /* tt.tt_setscroll is known to be defined */
61: (*tt.tt_setscroll)(0, tt.tt_nrow - 1);
62: if (tt.tt_modes)
63: (*tt.tt_setmodes)(0);
64: if (tt.tt_scroll_down)
65: (*tt.tt_scroll_down)(1);
66: (*tt.tt_move)(tt.tt_nrow - 1, 0);
67: if (tt.tt_ntoken > 0)
68: ccend();
69: (*tt.tt_end)();
70: (*tt.tt_flush)();
71: }
72:
73: struct xx *
74: xxalloc()
75: {
76: register struct xx *xp;
77:
78: if (xxbufp > xxbufe)
79: abort();
80: if ((xp = xx_freelist) == 0)
81: /* XXX can't deal with failure */
82: xp = (struct xx *) malloc((unsigned) sizeof *xp);
83: else
84: xx_freelist = xp->link;
85: if (xx_head == 0)
86: xx_head = xp;
87: else
88: xx_tail->link = xp;
89: xx_tail = xp;
90: xp->link = 0;
91: return xp;
92: }
93:
94: xxfree(xp)
95: register struct xx *xp;
96: {
97: xp->link = xx_freelist;
98: xx_freelist = xp;
99: }
100:
101: xxmove(row, col)
102: {
103: register struct xx *xp = xx_tail;
104:
105: if (xp == 0 || xp->cmd != xc_move) {
106: xp = xxalloc();
107: xp->cmd = xc_move;
108: }
109: xp->arg0 = row;
110: xp->arg1 = col;
111: }
112:
113: xxscroll(dir, top, bot)
114: {
115: register struct xx *xp = xx_tail;
116:
117: if (xp != 0 && xp->cmd == xc_scroll &&
118: xp->arg1 == top && xp->arg2 == bot &&
119: (xp->arg0 < 0 && dir < 0 || xp->arg0 > 0 && dir > 0)) {
120: xp->arg0 += dir;
121: return;
122: }
123: xp = xxalloc();
124: xp->cmd = xc_scroll;
125: xp->arg0 = dir;
126: xp->arg1 = top;
127: xp->arg2 = bot;
128: }
129:
130: xxinschar(row, col, c, m)
131: {
132: register struct xx *xp;
133:
134: xp = xxalloc();
135: xp->cmd = xc_inschar;
136: xp->arg0 = row;
137: xp->arg1 = col;
138: xp->arg2 = c;
139: xp->arg3 = m;
140: }
141:
142: xxinsspace(row, col)
143: {
144: register struct xx *xp = xx_tail;
145:
146: if (xp != 0 && xp->cmd == xc_insspace && xp->arg0 == row &&
147: col >= xp->arg1 && col <= xp->arg1 + xp->arg2) {
148: xp->arg2++;
149: return;
150: }
151: xp = xxalloc();
152: xp->cmd = xc_insspace;
153: xp->arg0 = row;
154: xp->arg1 = col;
155: xp->arg2 = 1;
156: }
157:
158: xxdelchar(row, col)
159: {
160: register struct xx *xp = xx_tail;
161:
162: if (xp != 0 && xp->cmd == xc_delchar &&
163: xp->arg0 == row && xp->arg1 == col) {
164: xp->arg2++;
165: return;
166: }
167: xp = xxalloc();
168: xp->cmd = xc_delchar;
169: xp->arg0 = row;
170: xp->arg1 = col;
171: xp->arg2 = 1;
172: }
173:
174: xxclear()
175: {
176: register struct xx *xp;
177:
178: xxreset();
179: xp = xxalloc();
180: xp->cmd = xc_clear;
181: }
182:
183: xxclreos(row, col)
184: {
185: register struct xx *xp = xxalloc();
186:
187: xp->cmd = xc_clreos;
188: xp->arg0 = row;
189: xp->arg1 = col;
190: }
191:
192: xxclreol(row, col)
193: {
194: register struct xx *xp = xxalloc();
195:
196: xp->cmd = xc_clreol;
197: xp->arg0 = row;
198: xp->arg1 = col;
199: }
200:
201: xxwrite(row, col, p, n, m)
202: char *p;
203: {
204: register struct xx *xp;
205:
206: if (xxbufp + n + 1 > xxbufe)
207: xxflush(0);
208: xp = xxalloc();
209: xp->cmd = xc_write;
210: xp->arg0 = row;
211: xp->arg1 = col;
212: xp->arg2 = n;
213: xp->arg3 = m;
214: xp->buf = xxbufp;
215: bcopy(p, xxbufp, n);
216: xxbufp += n;
217: *xxbufp++ = char_sep;
218: }
219:
220: xxreset()
221: {
222: register struct xx *xp, *xq;
223:
224: for (xp = xx_head; xp != 0; xp = xq) {
225: xq = xp->link;
226: xxfree(xp);
227: }
228: xx_tail = xx_head = 0;
229: xxbufp = xxbuf;
230: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.