1: /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1984. */
   2: static char rcsid[] = "$Header: erro.c,v 2.5 85/08/22 16:02:02 timo Exp $";
   3: 
   4: /*
   5:  * B editor -- Handle error messages.
   6:  */
   7: 
   8: #include "b.h"
   9: #include "feat.h"
  10: #include "node.h"
  11: 
  12: 
  13: extern bool hushbaby;
  14: extern bool dflag;
  15: 
  16: string querepr();
  17: 
  18: extern int winheight; /* From scrn.c */
  19: extern int winstart; /* From scrn.c */
  20: extern int llength; /* From scrn.c */
  21: 
  22: #define SOBIT 0200 /* Interface with wind.c */
  23: 
  24: #define MAXMSG 1000
  25: 
  26: static char msgbuffer[MAXMSG];
  27: static bool ringbell;
  28: static int priority;
  29: 
  30: 
  31: /*
  32:  * Status line.  A combination of scroll bar, error message etc.
  33:  * Put the message on the screen and clear the buffers for next time.
  34:  * If there is no message, show status and copy buffer and recording mode.
  35:  */
  36: 
  37: Visible Procedure
  38: stsline(totlines, topline, scrlines, copybuffer, recording)
  39:     int totlines;
  40:     int topline;
  41:     int scrlines;
  42:     value copybuffer;
  43:     bool recording;
  44: {
  45:     register string bp;
  46: 
  47:     if (ringbell && !hushbaby)
  48:         trmbell();
  49:     if (msgbuffer[0]) {
  50:         msgbuffer[llength-1] = '\0'; /* Truncate */
  51:         if (ringbell) {
  52:             for (bp = msgbuffer; *bp; ++bp)
  53:                 *bp |= SOBIT;
  54:         }
  55:     }
  56:     else {
  57:         bp = msgbuffer;
  58: #ifdef SCROLLBAR
  59:         bp += addscrollbar(totlines, topline, scrlines);
  60: #endif SCROLLBAR
  61:         if (recording) {
  62:             strcpy(bp, "[Recording] ");
  63:             bp += (sizeof "[Recording] ") - 1;
  64:         }
  65:         if (copybuffer) {
  66: #ifdef SHOWBUF
  67:             sprintf(bp, "[Copy buffer: %.80s]",
  68:                 querepr(copybuffer));
  69:             while (*bp)
  70:                 ++bp;
  71:             if (bp >= msgbuffer+80)
  72:                 strcpy(msgbuffer+75, "...]");
  73: #else !SHOWBUF
  74:             strcpy(bp, "[Copy buffer]");
  75: #endif !SHOWBUF
  76:         }
  77:     }
  78:     trmputdata(winheight, winheight, 0, msgbuffer);
  79:     msgbuffer[0] = 0;
  80:     priority = 0;
  81:     ringbell = No;
  82: }
  83: 
  84: #ifdef SCROLLBAR
  85: 
  86: /*
  87:  * Paint a beautiful scroll bar so the user can see about what part of the
  88:  * unit is visible on the screen (considering logical lines).
  89:  */
  90: 
  91: Hidden int
  92: addscrollbar(totlines, topline, scrlines)
  93:     int totlines;
  94:     int topline;
  95:     int scrlines;
  96: {
  97:     int endline;
  98:     register int i;
  99: 
 100:     if (winstart > 0 || scrlines > totlines)
 101:         return 0; /* Nothing outside screen */
 102:     if (totlines <= 0)
 103:         totlines = 1; /* Don't want to divide by 0 */
 104:     topline = topline*winheight / totlines;
 105:     endline = topline + (scrlines*winheight + totlines-1) / totlines;
 106:     if (endline > winheight)
 107:         endline = winheight;
 108:     if (topline >= endline)
 109:         topline = endline-1;
 110:     for (i = 0; i < topline; ++i)
 111:         msgbuffer[i] = '-';
 112:     for (; i < endline; ++i)
 113:         msgbuffer[i] = '#';
 114:     for (; i < winheight; ++i)
 115:         msgbuffer[i] = '-';
 116:     msgbuffer[i++] = ' ';
 117:     msgbuffer[i] = '\0';
 118:     return i;
 119: }
 120: 
 121: #endif SCROLLBAR
 122: 
 123: /*
 124:  * Issue an error message.  These have highest priority.
 125:  * Once an error message is in the buffer, further error messages are ignored
 126:  * until it has been displayed.
 127:  */
 128: 
 129: /* VARARGS 1 */
 130: Visible Procedure
 131: error(fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
 132:     string fmt;
 133: {
 134:     ringbell = Yes;
 135:     if (fmt && priority < 3) {
 136:         priority = 3;
 137:         sprintf(msgbuffer, fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
 138:     }
 139: }
 140: 
 141: 
 142: /*
 143:  * Issue an informative message.  These have medium priority.
 144:  * Unlike error messages, the last such message is displayed.
 145:  */
 146: 
 147: /* VARARGS 1 */
 148: Visible Procedure
 149: message(fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
 150:     register string fmt;
 151: {
 152:     if (fmt && priority <= 2) {
 153:         priority = 2;
 154:         sprintf(msgbuffer, fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
 155:     }
 156: }
 157: 
 158: 
 159: /*
 160:  * Issue a debugging message.  These  have lowest priority and
 161:  * are not shown to ordinary users.
 162:  */
 163: 
 164: /* VARARGS1 */
 165: Visible Procedure
 166: debug(fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
 167:     string fmt;
 168: {
 169: #ifndef NDEBUG
 170:     if (fmt && priority <= 1) {
 171:         priority = 1;
 172:         sprintf(msgbuffer,
 173:             fmt, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
 174:     }
 175: #endif NDEBUG
 176: }
 177: 
 178: 
 179: /*
 180:  * Dump any error message still remaining to stderr.
 181:  */
 182: 
 183: Visible Procedure
 184: enderro()
 185: {
 186:     if (msgbuffer[0]) {
 187:         fprintf(stderr, "%s\n", msgbuffer);
 188:     }
 189:     msgbuffer[0] = 0;
 190:     priority = 0;
 191:     ringbell = No;
 192: }
 193: 
 194: 
 195: /*
 196:  * This #define causes "erro.h" to compile a table of error messages.
 197:  */
 198: 
 199: #define _ERROR(name, message) char name[] = message
 200: 
 201: #include "erro.h"

Defined functions

addscrollbar defined in line 91; used 1 times
  • in line 59
enderro defined in line 183; used 1 times
message defined in line 148; used 5 times
stsline defined in line 37; used 1 times

Defined variables

msgbuffer defined in line 26; used 19 times
priority defined in line 28; used 8 times
rcsid defined in line 2; never used
ringbell defined in line 27; used 5 times

Defined macros

MAXMSG defined in line 24; used 1 times
  • in line 26
SOBIT defined in line 22; used 1 times
  • in line 53
_ERROR defined in line 199; never used
Last modified: 1985-08-27
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1288
Valid CSS Valid XHTML 1.0 Strict