1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
/*
* msgs.c
*
* Support functions for "popup-msgs" mode.
* Written by T.E.Dickey for vile (august 1994).
*
* $Header: /usr/build/vile/vile/RCS/msgs.c,v 1.26 2004/12/06 01:13:12 tom Exp $
*/
#include "estruct.h"
#if OPT_POPUP_MSGS
#include "edef.h"
/*
* Create the message-buffer if it doesn't already exist
*/
static BUFFER *
create_msgs(void)
{
BUFFER *bp = bfind(MESSAGES_BufName, BFINVS);
if (valid_buffer(bp)) {
b_set_invisible(bp);
bp->b_active = TRUE;
}
return bp;
}
/*
* This is invoked as a wrapper for 'kbd_putc()'. It writes to the Messages
* scratch buffer, and also to the message line. If the Messages buffer isn't
* visible, it is automatically popped up when a new message line is begun.
* Since it's a scratch buffer, popping it down destroys it.
*/
void
msg_putc(int c)
{
BUFFER *savebp = curbp;
WINDOW *savewp = curwp;
MARK savemk;
int saverow = ttrow;
int savecol = ttcol;
register BUFFER *bp;
register WINDOW *wp;
if ((bp = create_msgs()) == 0)
return;
savemk = DOT;
beginDisplay();
/*
* Modify the current-buffer state as unobtrusively as possible (i.e.,
* don't modify the buffer order, and don't make the buffer visible if
* it isn't already!). To use the 'bputc()' logic, though, we've got
* to have a window, even if it's not real.
*/
curbp = bp;
if ((wp = bp2any_wp(bp)) == NULL) {
static WINDOW dummy;
wp = &dummy;
wp->w_bufp = bp;
}
curwp = wp;
DOT.l = lback(buf_head(bp));
DOT.o = llength(DOT.l);
/*
* Write into the [Messages]-buffer
*/
#if OPT_TRACE
if (c == '\n') {
static TBUFF *ss;
int len = (DOT.o > 0) ? DOT.o : 1;
if (tb_init(&ss, EOS) != 0
&& tb_bappend(&ss,
(DOT.o > 0) ? DOT.l->l_text : "?",
(size_t) len) != 0
&& tb_append(&ss, EOS) != 0) {
TRACE(("msg:%s\n",
visible_buff(tb_values(ss),
tb_length(ss) - 1, TRUE)));
}
}
#endif
if ((c != '\n') || (DOT.o > 0)) {
bputc(c);
b_clr_changed(bp);
}
/* Finally, restore the original current-buffer and write the character
* to the message line.
*/
curbp = savebp;
curwp = savewp;
if (savewp)
DOT = savemk;
movecursor(saverow, savecol);
if (c != '\n') {
if (sgarbf) {
mlsavec(c);
} else {
kbd_putc(c);
}
}
endofDisplay();
}
void
popup_msgs(void)
{
BUFFER *savebp = curbp;
WINDOW *savewp = curwp;
MARK savemk;
register BUFFER *bp;
WINDOW *wp;
if ((bp = create_msgs()) == 0)
return;
savemk = DOT;
if (!is_empty_buf(bp)) {
if ((curwp == 0) || sgarbf || global_g_val(GMDPOPUP_MSGS) == -TRUE) {
return; /* CAN'T popup yet */
}
if (popupbuff(bp) == FALSE) {
(void) zotbuf(bp);
return;
}
if ((wp = bp2any_wp(bp)) != NULL) {
make_local_w_val(wp, WMDNUMBER);
set_w_val(wp, WMDNUMBER, FALSE);
}
set_rdonly(bp, non_filename(), MDVIEW);
curbp = savebp;
curwp = savewp;
if (savewp)
DOT = savemk;
}
}
/*
* If no warning messages were encountered during startup, and the popup-msgs
* mode wasn't enabled, discard the informational messages that are there
* already.
*/
void
purge_msgs(void)
{
TRACE(("purge_msgs mode:%d, warnings:%d\n",
global_g_val(GMDPOPUP_MSGS), warnings));
if ((global_g_val(GMDPOPUP_MSGS) == -TRUE)
&& (warnings == 0)) {
BUFFER *bp = find_b_name(MESSAGES_BufName);
if (valid_buffer(bp)
&& bp->b_nwnd == 0) {
(void) zotbuf(bp);
}
set_global_g_val(GMDPOPUP_MSGS, FALSE);
}
}
#endif
|