1 /*$Header: /p/tcsh/cvsroot/tcsh/win32/nt.screen.c,v 1.14 2006/03/14 01:22:57 mitr Exp $*/
3 * ed.screen.c: Editor/termcap-curses interface
6 * Copyright (c) 1980, 1991 The Regents of the University of California.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 /* #define DEBUG_LITERAL */
44 * IMPORTANT NOTE: these routines are allowed to look at the current screen
45 * and the current possition assuming that it is correct. If this is not
46 * true, then the update will be WRONG! This is (should be) a valid
52 extern int nt_getsize(int*,int*,int*);
53 extern int nt_ClearEOL( void) ;
54 extern void NT_ClearEOD( void) ;
55 extern void NT_ClearScreen(void) ;
56 extern void NT_VisibleBell(void);
57 extern void NT_WrapHorizontal(void);
59 static int GetSize(int *lins, int *cols);
61 int DisplayWindowHSize;
70 int T_ActualWindowSize;
72 static void ReBufferDisplay (void);
80 xprintf(CGETS(7, 1, "\n\tYou're using a Windows console.\n"));
92 nt_getsize(&lins,&cols,&DisplayWindowHSize);
97 for (bufp = b; *bufp != NULL; bufp++)
98 xfree((ptr_t) * bufp);
104 for (bufp = b; *bufp != NULL; bufp++)
105 xfree((ptr_t) * bufp);
110 TermV = (INBUFSIZE * 4) / TermH + 1;/*FIXBUF*/
111 b = (Char **) xmalloc((size_t) (sizeof(*b) * (TermV + 1)));
112 for (i = 0; i < TermV; i++)
113 b[i] = (Char *) xmalloc((size_t) (sizeof(*b[i]) * (TermH + 1)));
116 b = (Char **) xmalloc((size_t) (sizeof(*b) * (TermV + 1)));
117 for (i = 0; i < TermV; i++)
118 b[i] = (Char *) xmalloc((size_t) (sizeof(*b[i]) * (TermH + 1)));
124 SetTC(char *what, char *how)
128 nt_getsize(&li,&co,&win);
129 if (!lstrcmp(what,"li")) {
132 }else if(!lstrcmp(what,"co")) { //set window, not buffer size
136 stderror(ERR_SYSTEM, "SetTC","Sorry, this function is not supported");
144 * Print the termcap string out with variable substitution
150 char cv[BUFSIZE];/*FIXBUF*/
151 int verbose = 0, silent = 0;
152 static char *fmts = "%s\n", *fmtd = "%d\n";
158 v = glob_all_or_error(v);
160 cleanup_push(globbed, blk_cleanup);
162 if (!v || !*v || *v[0] == '\0')
164 if (v[0][0] == '-') {
173 stderror(ERR_NAME | ERR_TCUSAGE);
178 if (!*v || *v[0] == '\0')
180 (void) StringCbCopy(cv,sizeof(cv), short2str(*v));
184 if(!lstrcmp(cv,"rows") || !lstrcmp(cv,"lines") ) {
185 xprintf(fmtd,T_Lines);
188 else if(!lstrcmp(cv,"cols") ) {
189 xprintf(fmtd,T_ActualWindowSize);
192 else if(!lstrcmp(cv,"buffer") ) {
193 xprintf(fmtd,T_Cols);
197 stderror(ERR_SYSTEM, "EchoTC","Sorry, this function is not supported");
200 cleanup_until(globbed);
212 DefaultArrowKeys(void)
218 SetArrowKeys(const CStr *name, XmapVal *fun, int type)
220 UNREFERENCED_PARAMETER(name);
221 UNREFERENCED_PARAMETER(fun);
222 UNREFERENCED_PARAMETER(type);
227 IsArrowKey(Char *name)
229 UNREFERENCED_PARAMETER(name);
234 ClearArrowKeys(const CStr *name)
236 UNREFERENCED_PARAMETER(name);
241 PrintArrowKeys(const CStr *name)
243 UNREFERENCED_PARAMETER(name);
254 #define GoodStr(ignore) 1
256 SetAttributes(Char atr)
261 /* PWP 6-27-88 -- if the tty driver thinks that we can tab, we ask termcap */
268 /* move to line <where> (first line == 0) as efficiently as possible; */
270 MoveToLine(int where)
274 if (where == CursorV)
279 xprintf("MoveToLine: where is ridiculous: %d\r\n", where);
281 #endif /* DEBUG_SCREEN */
285 del = where - CursorV;
287 NT_MoveToLineOrChar(del, 1);
289 CursorV = where; /* now where is here */
292 /* move to character position (where) as efficiently as possible */
294 MoveToChar(int where)
296 if (where == CursorH)
299 if (where >= TermH) {
301 xprintf("MoveToChar: where is riduculous: %d\r\n", where);
303 #endif /* DEBUG_SCREEN */
307 if (!where) { /* if where is first column */
308 //(void) putraw('\r'); /* do a CR */
309 NT_MoveToLineOrChar(where, 0);
315 NT_MoveToLineOrChar(where, 0);
316 CursorH = where; /* now where is here */
320 so_write(register Char *cp, register int n)
323 return; /* catch bugs */
333 for (d = litptr + (*cp++ & ~LITERAL) * LIT_FACTOR; *d;
338 (void) putraw(*cp++);
342 if (CursorH >= TermH) { /* wrap? */
348 else if(CursorH >= DisplayWindowHSize) {
350 NT_MoveToLineOrChar(CursorH,0);
356 DeleteChars(int num) /* deletes <num> characters */
363 xprintf(CGETS(7, 16, "ERROR: cannot delete\r\n"));
364 #endif /* DEBUG_EDIT */
371 xprintf(CGETS(7, 17, "DeletChars: num is riduculous: %d\r\n"), num);
373 #endif /* DEBUG_SCREEN */
379 /* Puts terminal in insert character mode, or inserts num characters in the
382 Insert_write(register Char *cp, register int num)
384 UNREFERENCED_PARAMETER(cp);
390 xprintf(CGETS(7, 18, "ERROR: cannot insert\r\n"));
391 #endif /* DEBUG_EDIT */
398 xprintf(CGETS(7, 19, "StartInsert: num is riduculous: %d\r\n"), num);
400 #endif /* DEBUG_SCREEN */
407 /* clear to end of line. There are num characters to clear */
421 { /* clear the whole screen and home */
429 { /* produce a sound */
431 if (adrof(STRnobeep))
434 if (adrof(STRvisiblebell))
435 NT_VisibleBell(); /* visible bell */
437 MessageBeep(MB_ICONQUESTION);
442 { /* clear to the bottom of the screen */
452 nt_getsize(&lins,&cols,&DisplayWindowHSize);
458 T_ActualWindowSize = DisplayWindowHSize;
459 T_Margin = MARGIN_AUTO;
471 * Return the new window size in lines and cols, and
472 * true if the size was changed.
475 GetSize(int *lins, int *cols)
484 nt_getsize(lins,cols,&DisplayWindowHSize);
486 // compare the actual visible window size,but return the console buffer size
487 // this is seriously demented.
488 ret = (T_Lines != *lins || T_ActualWindowSize != DisplayWindowHSize);
492 T_ActualWindowSize = DisplayWindowHSize;
497 ChangeSize(int lins, int cols)
501 // here we're setting the window size, not the buffer size.
503 nt_set_size(lins,cols);
505 rc = GetSize(&lins,&cols);
508 ReBufferDisplay(); /* re-make display buffers */
512 PutPlusOne(Char c, int width)
516 while (width > 1 && CursorH + width > DisplayWindowHSize)
518 if ((c & LITERAL) != 0) {
520 for (d = litptr + (c & ~LITERAL) * LIT_FACTOR; *d; d++)
526 Display[CursorV][CursorH++] = (Char) c;
528 Display[CursorV][CursorH++] = CHAR_DBWIDTH;
530 if (CursorH >= TermH) { /* if we must overflow */
536 else if(CursorH >= DisplayWindowHSize) {
537 NT_MoveToLineOrChar(CursorH,0);