|
|
1.1 root 1: /*
2: * Copyright (c) 1981 Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms are permitted
6: * provided that: (1) source distributions retain this entire copyright
7: * notice and comment, and (2) distributions including binaries display
8: * the following acknowledgement: ``This product includes software
9: * developed by the University of California, Berkeley and its contributors''
10: * in the documentation or other materials provided with the distribution
11: * and in all advertising materials mentioning features or use of this
12: * software. Neither the name of the University nor the names of its
13: * contributors may be used to endorse or promote products derived
14: * from this software without specific prior written permission.
15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18: */
19:
20: #ifndef lint
21: static char sccsid[] = "@(#)newwin.c 5.4 (Berkeley) 6/1/90";
22: #endif /* not lint */
23:
24: /*
25: * allocate space for and set up defaults for a new window
26: *
27: */
28:
29: # include "curses.ext"
30:
31: char *malloc();
32:
33: # define SMALLOC (short *) malloc
34:
35: static WINDOW *makenew();
36:
37: # undef nl /* don't need it here, and it interferes */
38:
39: WINDOW *
40: newwin(num_lines, num_cols, begy, begx)
41: int num_lines, num_cols, begy, begx;
42: {
43: reg WINDOW *win;
44: reg char *sp;
45: reg int i, by, bx, nl, nc;
46: reg int j;
47:
48: by = begy;
49: bx = begx;
50: nl = num_lines;
51: nc = num_cols;
52:
53: if (nl == 0)
54: nl = LINES - by;
55: if (nc == 0)
56: nc = COLS - bx;
57: if ((win = makenew(nl, nc, by, bx)) == NULL)
58: return ERR;
59: if ((win->_firstch = SMALLOC(nl * sizeof win->_firstch[0])) == NULL) {
60: free(win->_y);
61: free(win);
62: return NULL;
63: }
64: if ((win->_lastch = SMALLOC(nl * sizeof win->_lastch[0])) == NULL) {
65: free(win->_y);
66: free(win->_firstch);
67: free(win);
68: return NULL;
69: }
70: win->_nextp = win;
71: for (i = 0; i < nl; i++) {
72: win->_firstch[i] = _NOCHANGE;
73: win->_lastch[i] = _NOCHANGE;
74: }
75: for (i = 0; i < nl; i++)
76: if ((win->_y[i] = malloc(nc * sizeof win->_y[0])) == NULL) {
77: for (j = 0; j < i; j++)
78: free(win->_y[j]);
79: free(win->_firstch);
80: free(win->_lastch);
81: free(win->_y);
82: free(win);
83: return ERR;
84: }
85: else
86: for (sp = win->_y[i]; sp < win->_y[i] + nc; )
87: *sp++ = ' ';
88: win->_ch_off = 0;
89: # ifdef DEBUG
90: fprintf(outf, "NEWWIN: win->_ch_off = %d\n", win->_ch_off);
91: # endif
92: return win;
93: }
94:
95: WINDOW *
96: subwin(orig, num_lines, num_cols, begy, begx)
97: reg WINDOW *orig;
98: int num_lines, num_cols, begy, begx;
99: {
100: reg int i;
101: reg WINDOW *win;
102: reg int by, bx, nl, nc;
103:
104: by = begy;
105: bx = begx;
106: nl = num_lines;
107: nc = num_cols;
108:
109: /*
110: * make sure window fits inside the original one
111: */
112: # ifdef DEBUG
113: fprintf(outf, "SUBWIN(%0.2o, %d, %d, %d, %d)\n", orig, nl, nc, by, bx);
114: # endif
115: if (by < orig->_begy || bx < orig->_begx
116: || by + nl > orig->_maxy + orig->_begy
117: || bx + nc > orig->_maxx + orig->_begx)
118: return ERR;
119: if (nl == 0)
120: nl = orig->_maxy + orig->_begy - by;
121: if (nc == 0)
122: nc = orig->_maxx + orig->_begx - bx;
123: if ((win = makenew(nl, nc, by, bx)) == NULL)
124: return ERR;
125: win->_nextp = orig->_nextp;
126: orig->_nextp = win;
127: win->_orig = orig;
128: _set_subwin_(orig, win);
129: return win;
130: }
131:
132: /*
133: * this code is shared with mvwin()
134: */
135: _set_subwin_(orig, win)
136: register WINDOW *orig, *win;
137: {
138: register int i, j, k;
139:
140: j = win->_begy - orig->_begy;
141: k = win->_begx - orig->_begx;
142: win->_ch_off = k;
143: # ifdef DEBUG
144: fprintf(outf, "_SET_SUBWIN_: win->_ch_off = %d\n", win->_ch_off);
145: # endif
146: win->_firstch = &orig->_firstch[j];
147: win->_lastch = &orig->_lastch[j];
148: for (i = 0; i < win->_maxy; i++, j++)
149: win->_y[i] = &orig->_y[j][k];
150:
151: }
152:
153: /*
154: * This routine sets up a window buffer and returns a pointer to it.
155: */
156: static WINDOW *
157: makenew(num_lines, num_cols, begy, begx)
158: int num_lines, num_cols, begy, begx; {
159:
160: reg int i;
161: reg WINDOW *win;
162: reg int by, bx, nl, nc;
163:
164: by = begy;
165: bx = begx;
166: nl = num_lines;
167: nc = num_cols;
168:
169: # ifdef DEBUG
170: fprintf(outf, "MAKENEW(%d, %d, %d, %d)\n", nl, nc, by, bx);
171: # endif
172: if ((win = (WINDOW *) malloc(sizeof *win)) == NULL)
173: return NULL;
174: # ifdef DEBUG
175: fprintf(outf, "MAKENEW: nl = %d\n", nl);
176: # endif
177: if ((win->_y = (char **) malloc(nl * sizeof win->_y[0])) == NULL) {
178: free(win);
179: return NULL;
180: }
181: # ifdef DEBUG
182: fprintf(outf, "MAKENEW: nc = %d\n", nc);
183: # endif
184: win->_cury = win->_curx = 0;
185: win->_clear = FALSE;
186: win->_maxy = nl;
187: win->_maxx = nc;
188: win->_begy = by;
189: win->_begx = bx;
190: win->_flags = 0;
191: win->_scroll = win->_leave = FALSE;
192: _swflags_(win);
193: # ifdef DEBUG
194: fprintf(outf, "MAKENEW: win->_clear = %d\n", win->_clear);
195: fprintf(outf, "MAKENEW: win->_leave = %d\n", win->_leave);
196: fprintf(outf, "MAKENEW: win->_scroll = %d\n", win->_scroll);
197: fprintf(outf, "MAKENEW: win->_flags = %0.2o\n", win->_flags);
198: fprintf(outf, "MAKENEW: win->_maxy = %d\n", win->_maxy);
199: fprintf(outf, "MAKENEW: win->_maxx = %d\n", win->_maxx);
200: fprintf(outf, "MAKENEW: win->_begy = %d\n", win->_begy);
201: fprintf(outf, "MAKENEW: win->_begx = %d\n", win->_begx);
202: # endif
203: return win;
204: }
205:
206: _swflags_(win)
207: register WINDOW *win;
208: {
209: win->_flags &= ~(_ENDLINE|_FULLLINE|_FULLWIN|_SCROLLWIN);
210: if (win->_begx + win->_maxx == COLS) {
211: win->_flags |= _ENDLINE;
212: if (win->_begx == 0) {
213: if (AL && DL)
214: win->_flags |= _FULLLINE;
215: if (win->_maxy == LINES && win->_begy == 0)
216: win->_flags |= _FULLWIN;
217: }
218: if (win->_begy + win->_maxy == LINES)
219: win->_flags |= _SCROLLWIN;
220: }
221: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.