File: error.c

package info (click to toggle)
ytree 1.90-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 728 kB
  • ctags: 1,031
  • sloc: ansic: 13,987; makefile: 126
file content (180 lines) | stat: -rw-r--r-- 3,350 bytes parent folder | download | duplicates (9)
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/***************************************************************************
 *
 * $Header: /usr/local/cvsroot/utils/ytree/error.c,v 1.12 2003/06/06 19:47:26 werner Exp $
 *
 * Ausgabe von Fehlermeldungen
 *
 ***************************************************************************/


#include "ytree.h"




static void MapErrorWindow(char *header);
static void MapNoticeWindow(char *header);
static void UnmapErrorWindow(void);
static void PrintErrorLine(int y, char *str);
static void DisplayErrorMessage(char *msg);
static int  PrintErrorMessage(char *msg);



void Message(char *msg)
{
  MapErrorWindow( "E R R O R" );
  (void) PrintErrorMessage( msg );
}


void Notice(char *msg)
{
  MapNoticeWindow( "N O T I C E" );
  DisplayErrorMessage( msg );
  RefreshWindow( error_window );
  refresh();
}


void Warning(char *msg)
{
  MapErrorWindow( "W A R N I N G" );
  (void) PrintErrorMessage( msg );
}


void Error(char *msg, char *module, int line)
{
  char buffer[MESSAGE_LENGTH + 1];

  MapErrorWindow( "INTERNAL ERROR" );
  (void) sprintf( buffer, "%s*In Module \"%s\"*Line %d", 
		  msg, module, line
		);
  (void) PrintErrorMessage( buffer );
}





static void MapErrorWindow(char *header)
{
   werase( error_window );
   box( error_window, 0, 0 );

   PrintSpecialString( error_window, 
		       ERROR_WINDOW_HEIGHT - 3, 
		       0,
		       "6--------------------------------------7",
		       WINERR_COLOR
		     );
   wattrset( error_window, A_REVERSE | A_BLINK ); 
   MvWAddStr( error_window,
	      ERROR_WINDOW_HEIGHT - 2,
	      1,
	      "             PRESS ENTER              "
	    );
   wattrset( error_window, 0 );
   PrintErrorLine( 1, header );
}


static void MapNoticeWindow(char *header)
{
   werase( error_window );
   box( error_window, 0, 0 );

   PrintSpecialString( error_window, 
		       ERROR_WINDOW_HEIGHT - 3, 
		       0,
		       "6--------------------------------------7",
		       WINERR_COLOR
		     );
   wattrset( error_window, A_REVERSE | A_BLINK ); 
   MvWAddStr( error_window,
	      ERROR_WINDOW_HEIGHT - 2,
	      1,
	      "             PLEASE WAIT              "
	    );
   wattrset( error_window, 0 );
   PrintErrorLine( 1, header );
}


static void UnmapErrorWindow(void)
{
   werase( error_window );
   touchwin( stdscr );
   doupdate();
}


void UnmapNoticeWindow(void)
{
   werase( error_window );
   touchwin( stdscr );
   doupdate();
}



static void PrintErrorLine(int y, char *str)
{
  int l;

  l = strlen( str );

  MvWAddStr( error_window, y, (ERROR_WINDOW_WIDTH - l) >> 1, str );
}




static void DisplayErrorMessage(char *msg)
{
  int  y, i, j, count;
  char buffer[ERROR_WINDOW_WIDTH - 2 + 1];

  for(i=0, count=0; msg[i]; i++)
    if( msg[i] == '*' ) count++;

  if( count > 3 )      y = 2;
  else if( count > 1 ) y = 3;
  else                 y = 4;


  for( i=0,j=0; msg[i]; i++ )
  {
    if( msg[i] == '*' )
    {
      buffer[j] = '\0';
      PrintErrorLine( y++, buffer );
      j=0;
    }
    else
    {
      if( j < (int)((sizeof( buffer) - 1)) ) buffer[j++] = msg[i];
    }
  } 
  buffer[j] = '\0';
  PrintErrorLine( y, buffer );
}



static int PrintErrorMessage(char *msg)
{
  int c;
  
  DisplayErrorMessage( msg );
  beep();
  RefreshWindow( error_window );
  doupdate();
  c = wgetch(error_window);
  UnmapErrorWindow();
  touchwin( dir_window );
  return( c );
}