|
|
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 the above copyright notice and this paragraph are ! 7: * duplicated in all such forms and that any documentation, ! 8: * advertising materials, and other materials related to such ! 9: * distribution and use acknowledge that the software was developed ! 10: * by the University of California, Berkeley. The name of the ! 11: * University may not be used to endorse or promote products derived ! 12: * from this software without specific prior written permission. ! 13: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 14: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 15: * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 16: */ ! 17: ! 18: #ifndef COHERENT ! 19: #ifndef lint ! 20: static uchar sccsid[] = "@(#)newwin.c 5.3 (Berkeley) 6/30/88"; ! 21: #endif /* not lint */ ! 22: #endif /* not COHERENT */ ! 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 uchar *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 NULL; ! 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: touchwin(win); ! 72: for (i = 0; i < nl; i++) ! 73: if ((win->_y[i] = malloc(nc * sizeof win->_y[0])) == NULL) { ! 74: for (j = 0; j < i; j++) ! 75: free(win->_y[j]); ! 76: free(win->_firstch); ! 77: free(win->_lastch); ! 78: free(win->_y); ! 79: free(win); ! 80: return NULL; ! 81: } ! 82: else ! 83: for (sp = win->_y[i]; sp < win->_y[i] + nc; ) ! 84: *sp++ = ' '; ! 85: win->_ch_off = 0; ! 86: # ifdef DEBUG ! 87: fprintf(outf, "NEWWIN: win->_ch_off = %d\n", win->_ch_off); ! 88: # endif ! 89: return win; ! 90: } ! 91: ! 92: WINDOW * ! 93: subwin(orig, num_lines, num_cols, begy, begx) ! 94: reg WINDOW *orig; ! 95: int num_lines, num_cols, begy, begx; ! 96: { ! 97: reg WINDOW *win; ! 98: reg int by, bx, nl, nc; ! 99: ! 100: by = begy; ! 101: bx = begx; ! 102: nl = num_lines; ! 103: nc = num_cols; ! 104: ! 105: /* ! 106: * make sure window fits inside the original one ! 107: */ ! 108: # ifdef DEBUG ! 109: fprintf(outf, "SUBWIN(%0.2o, %d, %d, %d, %d)\n", orig, nl, nc, by, bx); ! 110: # endif ! 111: if (by < orig->_begy || bx < orig->_begx ! 112: || by + nl > orig->_maxy + orig->_begy ! 113: || bx + nc > orig->_maxx + orig->_begx) ! 114: return NULL; ! 115: if (nl == 0) ! 116: nl = orig->_maxy + orig->_begy - by; ! 117: if (nc == 0) ! 118: nc = orig->_maxx + orig->_begx - bx; ! 119: if ((win = makenew(nl, nc, by, bx)) == NULL) ! 120: return NULL; ! 121: win->_nextp = orig->_nextp; ! 122: orig->_nextp = win; ! 123: win->_orig = orig; ! 124: _set_subwin_(orig, win); ! 125: return win; ! 126: } ! 127: ! 128: /* ! 129: * this code is shared with mvwin() ! 130: */ ! 131: _set_subwin_(orig, win) ! 132: register WINDOW *orig, *win; ! 133: { ! 134: register int i, j, k; ! 135: ! 136: j = win->_begy - orig->_begy; ! 137: k = win->_begx - orig->_begx; ! 138: win->_ch_off = k; ! 139: # ifdef DEBUG ! 140: fprintf(outf, "_SET_SUBWIN_: win->_ch_off = %d\n", win->_ch_off); ! 141: # endif ! 142: win->_firstch = &orig->_firstch[j]; ! 143: win->_lastch = &orig->_lastch[j]; ! 144: for (i = 0; i < win->_maxy; i++, j++) ! 145: win->_y[i] = &orig->_y[j][k]; ! 146: ! 147: } ! 148: ! 149: /* ! 150: * This routine sets up a window buffer and returns a pointer to it. ! 151: */ ! 152: static WINDOW * ! 153: makenew(num_lines, num_cols, begy, begx) ! 154: int num_lines, num_cols, begy, begx; { ! 155: ! 156: reg WINDOW *win; ! 157: reg int by, bx, nl, nc; ! 158: ! 159: by = begy; ! 160: bx = begx; ! 161: nl = num_lines; ! 162: nc = num_cols; ! 163: ! 164: # ifdef DEBUG ! 165: fprintf(outf, "MAKENEW(%d, %d, %d, %d)\n", nl, nc, by, bx); ! 166: # endif ! 167: if ((win = (WINDOW *) malloc(sizeof *win)) == NULL) ! 168: return NULL; ! 169: # ifdef DEBUG ! 170: fprintf(outf, "MAKENEW: nl = %d\n", nl); ! 171: # endif ! 172: if ((win->_y = (uchar **) malloc(nl * sizeof win->_y[0])) == NULL) { ! 173: free(win); ! 174: return NULL; ! 175: } ! 176: # ifdef DEBUG ! 177: fprintf(outf, "MAKENEW: nc = %d\n", nc); ! 178: # endif ! 179: win->_cury = win->_curx = 0; ! 180: win->_clear = FALSE; ! 181: win->_maxy = nl; ! 182: win->_maxx = nc; ! 183: win->_begy = by; ! 184: win->_begx = bx; ! 185: win->_flags = 0; ! 186: win->_scroll = win->_leave = FALSE; ! 187: _swflags_(win); ! 188: # ifdef DEBUG ! 189: fprintf(outf, "MAKENEW: win->_clear = %d\n", win->_clear); ! 190: fprintf(outf, "MAKENEW: win->_leave = %d\n", win->_leave); ! 191: fprintf(outf, "MAKENEW: win->_scroll = %d\n", win->_scroll); ! 192: fprintf(outf, "MAKENEW: win->_flags = %0.2o\n", win->_flags); ! 193: fprintf(outf, "MAKENEW: win->_maxy = %d\n", win->_maxy); ! 194: fprintf(outf, "MAKENEW: win->_maxx = %d\n", win->_maxx); ! 195: fprintf(outf, "MAKENEW: win->_begy = %d\n", win->_begy); ! 196: fprintf(outf, "MAKENEW: win->_begx = %d\n", win->_begx); ! 197: # endif ! 198: return win; ! 199: } ! 200: ! 201: _swflags_(win) ! 202: register WINDOW *win; ! 203: { ! 204: win->_flags &= ~(_ENDLINE|_FULLLINE|_FULLWIN|_SCROLLWIN); ! 205: if (win->_begx + win->_maxx == COLS) { ! 206: win->_flags |= _ENDLINE; ! 207: if (win->_begx == 0) { ! 208: if (AL && DL) ! 209: win->_flags |= _FULLLINE; ! 210: if (win->_maxy == LINES && win->_begy == 0) ! 211: win->_flags |= _FULLWIN; ! 212: } ! 213: if (win->_begy + win->_maxy == LINES) ! 214: win->_flags |= _SCROLLWIN; ! 215: } ! 216: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.