home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / vile-src.zip / vile-8.1 / msgs.c < prev    next >
C/C++ Source or Header  |  1998-04-28  |  3KB  |  168 lines

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