home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / util / vim-2.0.lha / Vim-2.0 / src / message.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-15  |  3.4 KB  |  183 lines

  1. /* vi:ts=4:sw=4
  2.  *
  3.  * VIM - Vi IMproved
  4.  *
  5.  * Code Contributions By:    Bram Moolenaar            mool@oce.nl
  6.  *                            Tim Thompson            twitch!tjt
  7.  *                            Tony Andrews            onecom!wldrdg!tony 
  8.  *                            G. R. (Fred) Walter        watmath!watcgl!grwalter 
  9.  */
  10.  
  11. /*
  12.  * message.c: functions for displaying messages on the command line
  13.  */
  14.  
  15. #include "vim.h"
  16. #include "globals.h"
  17. #define MESSAGE
  18. #include "proto.h"
  19. #include "param.h"
  20.  
  21. static int msg_invert = FALSE;        /* message should be inverted */
  22.  
  23. /*
  24.  * msg(s) - displays the string 's' on the status line
  25.  */
  26.     void
  27. msg(s)
  28.     char           *s;
  29. {
  30.     if (Columns == 0)    /* terminal not initialized */
  31.     {
  32.         fprintf(stderr, s);
  33.         fflush(stderr);
  34.         return;
  35.     }
  36.  
  37.     start_msg();
  38.     if (msg_invert && T_TI)
  39.     {
  40.         outstr(T_TI);
  41.         char_count -= strlen(T_TI);
  42.     }
  43.     outtrans(s, -1);
  44.     if (msg_invert && T_TP)
  45.     {
  46.         outstr(T_TP);
  47.         msg_invert = FALSE;
  48.         char_count -= strlen(T_TP);
  49.     }
  50.     end_msg();
  51. }
  52.  
  53. #ifndef PROTO        /* automatic prototype generation does not understand this */
  54. /* VARARGS */
  55.     void
  56. smsg(s, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
  57.     char        *s;
  58.     long        a1, a2, a3, a4, a5, a6, a7, a8, a9, a10;
  59. {
  60.     sprintf(IObuff, s, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
  61.     msg(IObuff);
  62. }
  63. #endif
  64.  
  65. /*
  66.  * emsg() - display an error message
  67.  *
  68.  * Rings the bell, if appropriate, and calls message() to do the real work
  69.  */
  70.     void
  71. emsg(s)
  72.     char           *s;
  73. {
  74.     if (p_eb)
  75.         beep();                    /* also includes flush_buffers() */
  76.     else
  77.         flush_buffers(FALSE);    /* flush internal buffers */
  78.     msg_invert = TRUE;
  79.     msg(s);
  80.     if (char_count < sc_col)    /* if wait_return not called */
  81.         sleep(1);                /* give the user a chance to read the message */
  82. }
  83.  
  84.     void
  85. emsg2(s, a1)
  86.     char *s, *a1;
  87. {
  88.     sprintf(IObuff, s, a1);
  89.     emsg(IObuff);
  90. }
  91.  
  92. extern int global_busy, global_wait;    /* shared with csearch.c, cmdline.c */
  93.  
  94.     void
  95. wait_return(redraw)
  96.     int        redraw;
  97. {
  98.     u_char            c;
  99.     int                oldState;
  100.     int                tmpState;
  101.  
  102.         /* with the global command we only need one return at the end */
  103.     if (global_busy)
  104.     {
  105.         global_wait = 1;
  106.         starttermcap();
  107.         return;
  108.     }
  109.     oldState = State;
  110.     State = HITRETURN;
  111.     if (got_int)
  112.         outstrn("Interrupt: ");
  113.  
  114. #ifdef ORG_HITRETURN
  115.     outstrn("Press RETURN to continue");
  116.     do {
  117.         c = vgetc();
  118.     } while (strchr("\r\n: ", c) == NULL);
  119.     if (c == ':')                     /* this can vi too (but not always!) */
  120.         stuffcharReadbuff(c);
  121. #else
  122.     outstrn("Press RETURN or enter command to continue");
  123.     c = vgetc();
  124.     breakcheck();
  125.     if (strchr("\r\n ", c) == NULL)
  126.         stuffcharReadbuff(c);
  127. #endif
  128.  
  129.     if (!termcap_active)            /* start termcap before redrawing */
  130.         starttermcap();
  131.  
  132. /*
  133.  * If the window size changed set_winsize() will redraw the screen.
  134.  * Otherwise the screen is only redrawn if 'redraw' is set.
  135.  */
  136.     tmpState = State;
  137.     State = oldState;                /* restore State before set_winsize */
  138.     if (tmpState == SETWSIZE)        /* got resize event while in vgetc() */
  139.         set_winsize(0, 0, FALSE);
  140.     else if (redraw)
  141.         updateScreen(CLEAR);
  142.  
  143.     script_winsize_pp();
  144. }
  145.  
  146.     void
  147. start_msg()
  148. {
  149.     gotocmdline(TRUE, NUL);
  150.     char_count = 0;
  151. }
  152.  
  153.     void
  154. end_msg()
  155. {
  156.     /*
  157.      * if the string is larger than the window,
  158.      * or the ruler option is set and we run into it,
  159.      * we have to redraw the window.
  160.      * Do not do this if we are abandoning the file.
  161.      */
  162.     if (!exiting && char_count >= sc_col)
  163.     {
  164.         outchar('\n');
  165.         wait_return(TRUE);
  166.     }
  167.     else
  168.         flushbuf();
  169. }
  170.  
  171.     void
  172. check_msg()
  173. {
  174.     /*
  175.      * if the string is larger than the window,
  176.      * or the ruler option is set and we run into it,
  177.      * we have to redraw the window later.
  178.      */
  179.     if (char_count >= sc_col)
  180.         must_redraw = CLEAR;
  181.     cmdoffset = char_count / Columns;
  182. }
  183.