1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright (c) 1995, by Sun Microsystems, Inc. 24 * All rights reserved. 25 */ 26 27 /* 28 * getwin.c 29 * 30 * XCurses Library 31 * 32 * Copyright 1990, 1995 by Mortice Kern Systems Inc. All rights reserved. 33 * 34 */ 35 36 #if M_RCSID 37 #ifndef lint 38 static char rcsID[] = "$Header: /rd/src/libc/xcurses/rcs/getwin.c 1.2 1995/06/12 17:48:38 ant Exp $"; 39 #endif 40 #endif 41 42 #include <private.h> 43 #include <limits.h> 44 45 static int 46 get_cc(w, mbs, fp) 47 WINDOW *w; 48 char *mbs; 49 FILE *fp; 50 { 51 short co; 52 attr_t at; 53 int i, n, y, x; 54 55 if (fscanf(fp, "%d,%d,%hx,%hd,", &y, &x, &at, &co) < 4) 56 return 0; 57 58 if (fscanf(fp, "%[^\n]%n ", mbs, &n) < 1) 59 return 0; 60 61 if (wattr_set(w, at, co, (void *) 0) == ERR) 62 return 0; 63 64 if (mvwaddstr(w, y, x, mbs) == ERR) 65 return 0; 66 67 (void) wstandend(w); 68 69 return n; 70 } 71 72 WINDOW * 73 getwin(fp) 74 FILE *fp; 75 { 76 char *mbs; 77 WINDOW *w; 78 short flags; 79 int by, bx, my, mx; 80 81 #ifdef M_CURSES_TRACE 82 __m_trace("getwin(%p)", fp); 83 #endif 84 85 /* Get window dimensions and location to create a new window. */ 86 if (fscanf(fp, "MAX=%d,%d BEG=%d,%d ", &my, &mx, &by, &bx) < 4) 87 goto error1; 88 89 if ((mbs = (char *) malloc((size_t) (LINE_MAX+1))) == (char *) 0) 90 goto error1; 91 92 if ((w = newwin(my, mx, by, bx)) == (WINDOW *) 0) 93 goto error2; 94 95 /* Read other window attributes. */ 96 by = fscanf( 97 fp, "SCROLL=%hd,%hd VMIN=%hd VTIME=%hd FLAGS=%hx FG=%hx,%hd ", 98 &w->_top, &w->_bottom, &w->_vmin, &w->_vtime, &flags, 99 &w->_fg._at, &w->_fg._co 100 ); 101 if (by < 7) 102 goto error3; 103 104 w->_flags &= ~W_CONFIG_MASK; 105 w->_flags |= flags; 106 107 by = fscanf( fp, "BG=%hx,%hd,%[^\n] ", &w->_bg._at, &w->_bg._co, mbs); 108 if (by < 3) 109 goto error3; 110 111 while (get_cc(w, mbs, fp)) 112 ; 113 114 if (fscanf(fp, "CUR=%hd,%hd", &w->_cury, &w->_curx) < 2) 115 goto error3; 116 117 free(mbs); 118 119 return __m_return_pointer("getwin", w); 120 error3: 121 (void) delwin(w); 122 error2: 123 free(mbs); 124 error1: 125 rewind(fp); 126 127 return __m_return_pointer("getwin", (WINDOW *) 0); 128 } 129 130 static int 131 put_cc(w, y, x, mbs, len, fp) 132 WINDOW *w; 133 int y, x; 134 char *mbs; 135 int len; 136 FILE *fp; 137 { 138 int i; 139 short co; 140 attr_t at; 141 142 at = w->_line[y][x]._at; 143 co = w->_line[y][x]._co; 144 145 /* Write first character as a multibyte string. */ 146 (void) __m_cc_mbs(&w->_line[y][x], mbs, len); 147 148 /* Write additional characters with same colour and attributes. */ 149 for (i = x;;) { 150 i = __m_cc_next(w, y, i); 151 if (w->_maxx <= i) 152 break; 153 if (w->_line[y][i]._at != at || w->_line[y][i]._co != co) 154 break; 155 (void) __m_cc_mbs(&w->_line[y][i], mbs, 0); 156 } 157 158 /* Terminate string. */ 159 (void) __m_cc_mbs((const cchar_t *) 0, (char *) 0, 0); 160 161 (void) fprintf(fp, "%d,%d,%#x,%d,%s\n", y, x, at, co, mbs); 162 163 /* Return index of next unprocessed column. */ 164 return i; 165 } 166 167 int 168 putwin(w, fp) 169 WINDOW *w; 170 FILE *fp; 171 { 172 char *mbs; 173 int y, x, mbs_len; 174 175 #ifdef M_CURSES_TRACE 176 __m_trace("putwin(%p, %p)", w, fp); 177 #endif 178 179 mbs_len = columns * M_CCHAR_MAX * MB_LEN_MAX * sizeof *mbs + 1; 180 if ((mbs = (char *) malloc((size_t) mbs_len)) == (char *) 0) 181 return __m_return_code("putwin", ERR); 182 183 (void) fprintf( 184 fp, "MAX=%d,%d\nBEG=%d,%d\nSCROLL=%d,%d\n", 185 w->_maxy, w->_maxx, w->_begy, w->_begx, w->_top, w->_bottom 186 ); 187 (void) fprintf( 188 fp, "VMIN=%d\nVTIME=%d\nFLAGS=%#x\nFG=%#x,%d\n", 189 w->_vmin, w->_vtime, w->_flags & W_CONFIG_MASK, 190 w->_fg._at, w->_fg._co 191 ); 192 193 (void) __m_cc_mbs(&w->_bg, mbs, mbs_len); 194 (void) __m_cc_mbs((const cchar_t *) 0, (char *) 0, 0); 195 (void) fprintf(fp, "BG=%#x,%d,%s\n", w->_bg._at, w->_bg._co, mbs); 196 197 for (y = 0; y < w->_maxy; ++y) { 198 for (x = 0; x < w->_maxx; ) 199 x = put_cc(w, y, x, mbs, mbs_len, fp); 200 } 201 202 (void) fprintf(fp, "CUR=%d,%d\n", w->_curx, w->_cury); 203 204 free(mbs); 205 206 return __m_return_code("putwin", OK); 207 } 208 209