|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1980 Regents of the University of California. ! 3: * All rights reserved. The Berkeley software License Agreement ! 4: * specifies the terms and conditions for redistribution. ! 5: */ ! 6: ! 7: #ifndef lint ! 8: static char sccsid[] = "@(#)newwin.c 5.1 (Berkeley) 6/7/85"; ! 9: #endif not lint ! 10: ! 11: /* ! 12: * allocate space for and set up defaults for a new window ! 13: * ! 14: */ ! 15: ! 16: # include "curses.ext" ! 17: ! 18: char *malloc(); ! 19: ! 20: # define SMALLOC (short *) malloc ! 21: ! 22: static WINDOW *makenew(); ! 23: ! 24: # undef nl /* don't need it here, and it interferes */ ! 25: ! 26: WINDOW * ! 27: newwin(num_lines, num_cols, begy, begx) ! 28: int num_lines, num_cols, begy, begx; ! 29: { ! 30: reg WINDOW *win; ! 31: reg char *sp; ! 32: reg int i, by, bx, nl, nc; ! 33: reg int j; ! 34: ! 35: by = begy; ! 36: bx = begx; ! 37: nl = num_lines; ! 38: nc = num_cols; ! 39: ! 40: if (nl == 0) ! 41: nl = LINES - by; ! 42: if (nc == 0) ! 43: nc = COLS - bx; ! 44: if ((win = makenew(nl, nc, by, bx)) == NULL) ! 45: return ERR; ! 46: if ((win->_firstch = SMALLOC(nl * sizeof win->_firstch[0])) == NULL) { ! 47: free(win->_y); ! 48: free(win); ! 49: return NULL; ! 50: } ! 51: if ((win->_lastch = SMALLOC(nl * sizeof win->_lastch[0])) == NULL) { ! 52: free(win->_y); ! 53: free(win->_firstch); ! 54: free(win); ! 55: return NULL; ! 56: } ! 57: win->_nextp = win; ! 58: for (i = 0; i < nl; i++) { ! 59: win->_firstch[i] = _NOCHANGE; ! 60: win->_lastch[i] = _NOCHANGE; ! 61: } ! 62: for (i = 0; i < nl; i++) ! 63: if ((win->_y[i] = malloc(nc * sizeof win->_y[0])) == NULL) { ! 64: for (j = 0; j < i; j++) ! 65: free(win->_y[j]); ! 66: free(win->_firstch); ! 67: free(win->_lastch); ! 68: free(win->_y); ! 69: free(win); ! 70: return ERR; ! 71: } ! 72: else ! 73: for (sp = win->_y[i]; sp < win->_y[i] + nc; ) ! 74: *sp++ = ' '; ! 75: win->_ch_off = 0; ! 76: # ifdef DEBUG ! 77: fprintf(outf, "NEWWIN: win->_ch_off = %d\n", win->_ch_off); ! 78: # endif ! 79: return win; ! 80: } ! 81: ! 82: WINDOW * ! 83: subwin(orig, num_lines, num_cols, begy, begx) ! 84: reg WINDOW *orig; ! 85: int num_lines, num_cols, begy, begx; ! 86: { ! 87: reg int i; ! 88: reg WINDOW *win; ! 89: reg int by, bx, nl, nc; ! 90: ! 91: by = begy; ! 92: bx = begx; ! 93: nl = num_lines; ! 94: nc = num_cols; ! 95: ! 96: /* ! 97: * make sure window fits inside the original one ! 98: */ ! 99: # ifdef DEBUG ! 100: fprintf(outf, "SUBWIN(%0.2o, %d, %d, %d, %d)\n", orig, nl, nc, by, bx); ! 101: # endif ! 102: if (by < orig->_begy || bx < orig->_begx ! 103: || by + nl > orig->_maxy + orig->_begy ! 104: || bx + nc > orig->_maxx + orig->_begx) ! 105: return ERR; ! 106: if (nl == 0) ! 107: nl = orig->_maxy + orig->_begy - by; ! 108: if (nc == 0) ! 109: nc = orig->_maxx + orig->_begx - bx; ! 110: if ((win = makenew(nl, nc, by, bx)) == NULL) ! 111: return ERR; ! 112: win->_nextp = orig->_nextp; ! 113: orig->_nextp = win; ! 114: win->_orig = orig; ! 115: _set_subwin_(orig, win); ! 116: return win; ! 117: } ! 118: ! 119: /* ! 120: * this code is shared with mvwin() ! 121: */ ! 122: _set_subwin_(orig, win) ! 123: register WINDOW *orig, *win; ! 124: { ! 125: register int i, j, k; ! 126: ! 127: j = win->_begy - orig->_begy; ! 128: k = win->_begx - orig->_begx; ! 129: win->_ch_off = k; ! 130: # ifdef DEBUG ! 131: fprintf(outf, "_SET_SUBWIN_: win->_ch_off = %d\n", win->_ch_off); ! 132: # endif ! 133: win->_firstch = &orig->_firstch[j]; ! 134: win->_lastch = &orig->_lastch[j]; ! 135: for (i = 0; i < win->_maxy; i++, j++) ! 136: win->_y[i] = &orig->_y[j][k]; ! 137: ! 138: } ! 139: ! 140: /* ! 141: * This routine sets up a window buffer and returns a pointer to it. ! 142: */ ! 143: static WINDOW * ! 144: makenew(num_lines, num_cols, begy, begx) ! 145: int num_lines, num_cols, begy, begx; { ! 146: ! 147: reg int i; ! 148: reg WINDOW *win; ! 149: reg int by, bx, nl, nc; ! 150: ! 151: by = begy; ! 152: bx = begx; ! 153: nl = num_lines; ! 154: nc = num_cols; ! 155: ! 156: # ifdef DEBUG ! 157: fprintf(outf, "MAKENEW(%d, %d, %d, %d)\n", nl, nc, by, bx); ! 158: # endif ! 159: if ((win = (WINDOW *) malloc(sizeof *win)) == NULL) ! 160: return NULL; ! 161: # ifdef DEBUG ! 162: fprintf(outf, "MAKENEW: nl = %d\n", nl); ! 163: # endif ! 164: if ((win->_y = (char **) malloc(nl * sizeof win->_y[0])) == NULL) { ! 165: free(win); ! 166: return NULL; ! 167: } ! 168: # ifdef DEBUG ! 169: fprintf(outf, "MAKENEW: nc = %d\n", nc); ! 170: # endif ! 171: win->_cury = win->_curx = 0; ! 172: win->_clear = FALSE; ! 173: win->_maxy = nl; ! 174: win->_maxx = nc; ! 175: win->_begy = by; ! 176: win->_begx = bx; ! 177: win->_flags = 0; ! 178: win->_scroll = win->_leave = FALSE; ! 179: _swflags_(win); ! 180: # ifdef DEBUG ! 181: fprintf(outf, "MAKENEW: win->_clear = %d\n", win->_clear); ! 182: fprintf(outf, "MAKENEW: win->_leave = %d\n", win->_leave); ! 183: fprintf(outf, "MAKENEW: win->_scroll = %d\n", win->_scroll); ! 184: fprintf(outf, "MAKENEW: win->_flags = %0.2o\n", win->_flags); ! 185: fprintf(outf, "MAKENEW: win->_maxy = %d\n", win->_maxy); ! 186: fprintf(outf, "MAKENEW: win->_maxx = %d\n", win->_maxx); ! 187: fprintf(outf, "MAKENEW: win->_begy = %d\n", win->_begy); ! 188: fprintf(outf, "MAKENEW: win->_begx = %d\n", win->_begx); ! 189: # endif ! 190: return win; ! 191: } ! 192: ! 193: _swflags_(win) ! 194: register WINDOW *win; ! 195: { ! 196: win->_flags &= ~(_ENDLINE|_FULLLINE|_FULLWIN|_SCROLLWIN); ! 197: if (win->_begx + win->_maxx == COLS) { ! 198: win->_flags |= _ENDLINE; ! 199: if (win->_begx == 0) { ! 200: if (AL && DL) ! 201: win->_flags |= _FULLLINE; ! 202: if (win->_maxy == LINES && win->_begy == 0) ! 203: win->_flags |= _FULLWIN; ! 204: } ! 205: if (win->_begy + win->_maxy == LINES) ! 206: win->_flags |= _SCROLLWIN; ! 207: } ! 208: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.