errwin.icl 19.6 KB
Newer Older
Diederik van Arkel's avatar
Diederik van Arkel committed
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
implementation module errwin

//*********************************************************************************
// Original Clean Library Software Module
// Written for Clean version  : 1.3.3
// Written for I/O version    : 1.2
// Author                     : Diederik van Arkel
// Date                       :
// Last Modified by           :
// Date                       :
// Copyright                  : 1999 Hilt - High Level Software Tools B.V.
//                            : University of Nijmegen
// e-mail                     : clean@cs.kun.nl or rinus@hilt.nl
//*********************************************************************************
// It is allowed to modify this module for your own purposes but it is NOT allowed
// to (re)distribute the code or the modified code in ANY form without written
// permission.
//*********************************************************************************

import StdBool, StdFunc, StdMisc, StdChar, StdArray
import StdPSt, StdWindow, StdControlClass, StdControlReceiver, StdMenuElement
import StdClipboard, colourclip, StdPathname
import FilteredListBox

import morecontrols, colorpickcontrol, ioutil

from IDE import OpenModule	,Selection,Modulename,Position,ColumnNr,LineNr
from IdeState import General, getErrInfo, setErrInfo, ErrorInfo, MenuIds, getMenuIds, ErrPrefs
from IdeState import SearchMenuIds, PLMMessage, PLMReply, MIn, EditMenuLS
from EdClient import lineSelection

//from dodebug import trace_n`
trace_n _ f :== f

/*
ADD:
- error type selection...
- sort by error type...
- find...
- copy...

Means we should really build a custom window for this...
*/

sr_find_err :: !Bool !*(PSt *General) -> *PSt *General
sr_find_err forward ps
	# (errinfo,ps)	= getErrInfo ps
	= exec_next_filtered forward errinfo.infoId fifi ps
where
	fifi errmsg ps
		| not_empty = OpenModule path (lineSelection (inc lnr)) ps
		= ps
	where
		(path,lnr)	= ParseErrorMsg errmsg
		not_empty	= path <> EmptyPathname

//--- Error window handling

isErr Error = True
isErr _ = False
isWrn Warning = True
isWrn _ = False
isInf Info = True
isInf _ = False

countnums [] nums = nums
countnums [Error:ts] (e,w,i)	= countnums ts (inc e,w,i)
countnums [Warning:ts] (e,w,i)	= countnums ts (e,inc w,i)
countnums [Info:ts] (e,w,i)		= countnums ts (e,w,inc i)

checkWindowExistence id io
	# (st,io)	= getWindowsStack io
	= (isMember id st,io)

updateErrorWindow :: !([String]) !*(PSt *General) -> *PSt *General;
updateErrorWindow [] ps = ps	// or should we always show it?
updateErrorWindow messages ps
	#! (errinfo,ps)	= getErrInfo ps
	#! (isOpen,ps)	= accPIO (checkWindowExistence errinfo.errorId) ps
	#! ps			= case isOpen of
						True	-> ps
						_		-> err_open errinfo ps
	#! ps			= appendFilteredListBoxItems errinfo.infoId messages ps
	#! types		= map TypeErrorMsg messages
	#! (numerr,numwrn,numinf)
					= countnums types (errinfo.err_count,errinfo.wrn_count,errinfo.inf_count)
	# err			= (errinfo.err_countId,toString numerr)
	# wrn			= (errinfo.wrn_countId,toString numwrn)
	# inf			= (errinfo.inf_countId,toString numinf)
	#! cts			= case (numerr==errinfo.err_count,numwrn==errinfo.wrn_count,numinf==errinfo.inf_count) of
						(False,False,False)	-> [err,wrn,inf]
						(False,False,True)	-> [err,wrn]
						(False,True,False)	-> [err,inf]
						(False,True,True)	-> [err]
						(True,False,False)	-> [wrn,inf]
						(True,False,True)	-> [wrn]
						(True,True,False)	-> [inf]
						(True,True,True)	-> []
	#! ps			= appPIO (setControlTexts cts) ps
	#! errinfo		= {errinfo & err_count = numerr, wrn_count = numwrn, inf_count = numinf}
	#! ps			= setErrInfo errinfo ps
	= trace_n ("Warnings",numwrn) ps

err_open :: !(ErrorInfo (PSt *General)) !*(PSt *General) -> *PSt *General
err_open errinfo ps
	#! (menuIds=:{searchIds},ps)	= getMenuIds ps
	#! (inf_size,ps)				= controlSize (infobar errinfo) True Nothing Nothing Nothing ps
	# (elb)							= FilteredListBoxControl [] [] errinfo.infoId
					[ ControlOuterSize errinfo.err_size
					, ControlResize (err_resize inf_size.Size.h)
					, ControlPen
						[ PenColour errinfo.err_forg
						, PenBack errinfo.err_back
						, PenFont errinfo.err_font
						]
					, ControlPos (Fix,OffsetVector {zero & vy = inf_size.Size.h})
					, (flbMouse fifi)
					, (flbKeyboard fifi)
					]
	#! (win_size,ps)				= controlSize elb True Nothing Nothing Nothing ps
	#! wdef							= Window "Errors & Warnings"
					( infobar errinfo :+: elb
					)
					[ WindowId errinfo.errorId
					, WindowClose (noLS(err_close` o ew_deactivate))
					, WindowPos (LeftTop,OffsetVector errinfo.err_offset)
					, WindowViewSize win_size
					, WindowInitActive errinfo.infoId.fcontrolId
					, WindowPen [PenBack LightGrey]
					, WindowActivate (noLS ew_activate)
					, WindowDeactivate (noLS ew_deactivate)
					]
	#! ldef							= (errinfo.err,errinfo.wrn,errinfo.inf)
	#! (err,ps)						= openWindow ldef wdef ps
	| err == NoError
		# ps = appPIO (enableMenuElements [searchIds.nextIds!!1]) ps
		= setFilter errinfo.infoId (makeFilter errinfo.err errinfo.wrn errinfo.inf) ps
	= ps
where
	fifi errmsg ps
		| not_empty = OpenModule path (lineSelection (inc lnr)) ps
		= ps
	where
		(path,lnr)	= ParseErrorMsg errmsg
		not_empty	= path <> EmptyPathname

	infobar {err,err_buttonId,err_count,err_countId,wrn,wrn_buttonId,wrn_count,wrn_countId,inf,inf_buttonId,inf_count,inf_countId}
		= LayoutControl
			(	errButton err err_buttonId
			:+: errCount err_count err_countId
			:+: wrnButton wrn wrn_buttonId
			:+: wrnCount wrn_count wrn_countId
			:+: infButton inf inf_buttonId
			:+: infCount inf_count inf_countId
			)
			[ ControlResize inf_resize
			, ControlPos (Fix,zero)
			]
	wrnButton button buttonId
		= CheckControl [("Warnings:",Nothing,toMark button,wrnFun)] (Rows 1)
			[ControlId buttonId
			]
	wrnCount count countId
//		= EditControl (toString count) (ContentWidth "8888") 1
//			[ ControlSelectState Unable
		= TextControl (toString count)
			[ ControlWidth (ContentWidth "8888")
			, ControlId countId
			]
	errButton button buttonId
		= CheckControl [("Errors:",Nothing,toMark button,errFun)] (Rows 1)
			[ControlId buttonId
			]
	errCount count countId
//		= EditControl (toString count) (ContentWidth "8888") 1
//			[ ControlSelectState Unable
		= TextControl (toString count)
			[ ControlWidth (ContentWidth "8888")
			, ControlId countId
			]
	infButton button buttonId
		= CheckControl [("Info:",Nothing,toMark button,infFun)] (Rows 1)
			[ControlId buttonId
			]
	infCount count countId
//		= EditControl (toString count) (ContentWidth "8888") 1
//			[ ControlSelectState Unable
		= TextControl (toString count)
			[ ControlWidth (ContentWidth "8888")
			, ControlId countId
			]
	wrnFun ((err,wrn,inf),ps)
		# wrn = not wrn
		# (ei,ps) = getErrInfo ps
		# ps = setErrInfo {ei & wrn = wrn} ps
		# ps = setFilter ei.infoId (makeFilter err wrn inf) ps
		= ((err,wrn,inf),ps)
	errFun ((err,wrn,inf),ps)
		# err = not err
		# (ei,ps) = getErrInfo ps
		# ps = setErrInfo {ei & err = err} ps
		# ps = setFilter ei.infoId (makeFilter err wrn inf) ps
		= ((err,wrn,inf),ps)
	infFun ((err,wrn,inf),ps)
		# inf = not inf
		# (ei,ps) = getErrInfo ps
		# ps = setErrInfo {ei & inf = inf} ps
		# ps = setFilter ei.infoId (makeFilter err wrn inf) ps
		= ((err,wrn,inf),ps)
	makeFilter err wrn inf str
		# msg = TypeErrorMsg str
		| isErr msg && not err = False
		| isWrn msg && not wrn = False
		| isInf msg && not inf = False
		= True
	err_resize ih oc ow nw
		= {w = nw.w, h = nw.Size.h - ih}
	inf_resize oc ow nw
		= {oc & w = nw.w}

ew_activate ps
	# ({mn_cut,mn_cpy,mn_pst,mn_clr,mg_edt,searchIds},ps=:{io})
			= getMenuIds ps
	// disable Edit menu stuff
	# io = disableMenuElements [mn_cut,mn_cpy,mn_pst,mn_clr:mg_edt] io
	// disable Search menu stuff
	# io = disableMenuElements searchIds.findIds io
	# io = disableMenuElements searchIds.gotoIds io
	= {ps & io = io}

ew_deactivate ps
	# ({mn_cut,mn_cpy,mn_pst,mn_clr,mg_edt,searchIds},ps=:{io})
			= getMenuIds ps
	// enable Edit menu stuff
	# io = enableMenuElements [mn_cut,mn_cpy,mn_pst,mn_clr:mg_edt] io
	// enable Search menu stuff
	# io = enableMenuElements searchIds.findIds io
	# io = enableMenuElements searchIds.gotoIds io
	= {ps & io = io}

err_close` ps
	# (errinf,ps)		= getErrInfo ps
	= err_close errinf ps

err_close :: !(ErrorInfo (PSt *General)) !*(PSt *General) -> *PSt *General
err_close errinf ps
	# (errinf,ps)		= err_close_info errinf ps
	# ({searchIds},ps)	= getMenuIds ps
	# ps				= appPIO (disableMenuElements [searchIds.nextIds!!1]) ps
	= setErrInfo errinf ps

ew_safe_close			:: !*(PSt *General) -> *PSt *General
ew_safe_close ps
	# (win,ps)		= accPIO getActiveWindow ps
	# (errInf,ps)	= getErrInfo ps
	| isNothing win
		= err_close errInf ps
	# win			= fromJust win
	| win == errInf.errorId
		# ps		= ew_deactivate ps
		= err_close errInf ps
	= err_close errInf ps

ew_maybe_close :: !Id !*(PSt *General) -> (Bool,*PSt *General)
ew_maybe_close win ps
	# (errInf,ps) = getErrInfo ps
	| win == errInf.errorId
		# ps				= ew_deactivate ps
		# ps = err_close errInf ps
		= (True,ps)
	= (False,ps)

err_close_info :: (ErrorInfo .a) *(PSt .b) -> ((ErrorInfo .a),*PSt .b)
err_close_info errinfo ps
	# (err_pos,ps)		= accPIO (getWindowPos errinfo.errorId) ps
	# (wdef,ps)			= accPIO (getWindow errinfo.errorId) ps
	# wdef				= fromJust wdef
	# (ok,err_siz)		= getControlOuterSize errinfo.infoId.fcontrolId wdef
	# errinfo			= if (isNothing err_pos || not ok) errinfo {errinfo & err_offset = fromJust err_pos, err_size = err_siz}
	# errinfo			= {errinfo & err_count = 0, wrn_count = 0, inf_count = 0}
	# ps				= closeWindow errinfo.errorId ps
	= (errinfo,ps)

// error window options

:: EWO =
	{ fn	:: !String		// font name
	, fs	:: !Int			// font size
	, fc	:: !Colour		// foreground colour
	, bc	:: !Colour		// background colour
	, cur	:: !EWO_LS
	}

:: EWO_LS = TXT | BCK

instance == EWO_LS
where
	(==) TXT TXT = True
	(==) BCK BCK = True
	(==) _ _ = False


err_options :: !*(PSt *General) -> *PSt *General;
err_options ps
    # (dialogId,ps)	= openId ps
    # (okId,ps)		= openId ps
    # (cancelId,ps)	= openId ps
	# (fcid,ps)		= openId  ps
	# (bcid,ps)		= openId  ps
	# (rgbid,ps)	= openRGBId ps
	# (fontNames, ps) = accPIO (accScreenPicture getFontNames) ps
	// no fixed width filtering for error-window...!
	# fontSizes		= [7,8,9,10,11,12]
	# (errinf,ps)	= getErrInfo ps
	# font			= errinf.err_font
	# fdef			= getFontDef font
	# inifn			= fdef.fName
	# inifs			= fdef.fSize
	# inifc			= errinf.err_forg
	# inibc			= errinf.err_back
	# (lsid,ps)		= openRId ps
	# inistate		= {fn = inifn, fs = inifs, fc = inifc, bc = inibc, cur = TXT}
    # controls		=
    	(LayoutControl 
		(	FontNameSizeControl inifn inifs fontNames fontSizes fontfun sizefun [ left ]
		:+:	RGBColourPickControl` rgbid inifc fcid (Just (Left, zero))
		) []

		:+: LayoutControl
		(	TextControl "Text:" [ left , ControlWidth (ContentWidth "Background: ")]
		:+: ColourBoxControl` (toRGBColour inifc) fcid (mfilter,mfun rgbid lsid fcid bcid TXT) Nothing
		:+: TextControl "Background:" [ left, ControlWidth (ContentWidth "Background: ")]
		:+: ColourBoxControl` (toRGBColour inibc) bcid (mfilter,mfun rgbid lsid fcid bcid BCK) Nothing
		) []
		
	   	:+:	ButtonControl "Ok"
  			[ ControlId okId
  			, ControlFunction (okFun rgbid lsid dialogId) 
  			, ControlPos (Right, zero)
  			, ControlWidth (ContentWidth "Cancel")
  			]
    	:+:	ButtonControl "Cancel"
  			[ ControlPos (LeftOfPrev, zero) 
  			, ControlFunction (cancelFun inistate dialogId)
  			, ControlId cancelId
  			] 
		:+: ButtonControl "Apply"
			[ ControlPos (LeftOfPrev,zero)
			, ControlFunction (applyFun rgbid lsid)
			]
  		:+: ButtonControl "Paste"
  			[ ControlPos (LeftOfPrev,zero)
  			, ControlFunction (pasteFun rgbid fcid bcid)
  			]
  		:+: ButtonControl "Copy"
  			[ ControlPos (LeftOfPrev,zero)
  			, ControlFunction (copyFun rgbid)
  			]

  		:+: Receiver lsid lsfun []
		)
	# dialog		=
		Dialog "Error Window..." controls 
  		[ WindowId		dialogId 
  		, WindowOk		okId
  		, WindowCancel	cancelId
  		, WindowClose	(cancelFun inistate dialogId)
		, WindowInit	(setBoxCol fcid bcid)
  		]
	# (_,ps) = openModalDialog inistate dialog ps
	= ps
where
	lsfun f (ls,ps)
		= f (ls,ps)
	okFun rgbid lsid dialogId (ls,ps)
		# ps = getColourBoxColour rgbid cont ps
		= (ls,ps)
	where
		cont col ps
			| isNothing col
				= ps
			# col = fromJust col
			# (_,ps) = asyncSend lsid (cont2 col) ps
			= ps
		cont2 col (ls=:{cur},ps)
			# ls	= case cur of
						TXT -> {ls & fc = col}
						BCK -> {ls & bc = col}
			# (ls,ps)= apply (ls,ps)
			= (ls,closeWindow dialogId ps)
	cancelFun inistate dialogId (ls,ps)
		# ls		= inistate
		# (ls,ps)	= apply (ls,ps)
		= (ls,closeWindow dialogId ps)
	applyFun rgbid lsid (ls,ps)
		# ps = getColourBoxColour rgbid cont ps
		= (ls,ps)
	where
		cont col ps
			| isNothing col
				= ps
			# col = fromJust col
			# (_,ps) = asyncSend lsid (cont2 col) ps
			= ps
		cont2 col (ls=:{cur},ps)
			# ls	= case cur of
						TXT -> {ls & fc = col}
						BCK -> {ls & bc = col}
			= apply (ls,ps)
	toStringC :: !Colour -> String
	toStringC c = toString c
	copyFun rgbid (ls,ps)
		# ps = getColourBoxColour rgbid cont ps
		= (ls,ps)
	where
		cont col ps
			| isNothing col
				= ps
			# col = fromJust col
			# ps	= setClipboard [toClipboard (toString col)] ps
			= ps
	pasteFun rgbId fcid bcid (ls=:{cur},ps)
		// get clipboard
		// and put in active colour control
		# (its,ps)	= getClipboard ps
		| isEmpty its
			= (ls,ps)
		# its		= map fromClipboard its
		# its		= filter isJust its
		| isEmpty its
			= (ls,ps)
		# it		= fromJust (hd its)
		| it <> toStringC (fromString it)
			= (ls,ps)
		# col		= fromString it
		# ls		= case cur of
						TXT -> {ls & fc = col}
						BCK -> {ls & bc = col}
		# (ls,ps)	= setBoxCol fcid bcid (ls,ps)
		# ps		= setColourBoxColour` rgbId col ps
		= (ls,ps)
442
	setBoxCol fcid bcid (ls=:{cur,fc,bc},ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
443
		# (cId,col) = case cur of
444
445
						TXT	-> (fcid,fc)
						BCK	-> (bcid,bc)
Diederik van Arkel's avatar
Diederik van Arkel committed
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
		# ps = appPIO (SetColourBox` cId (toRGBColour col)) ps
		= (ls,ps)
	mfilter (MouseDown _ _ _) = True
	mfilter _ = False
	mfun rgbid lsid fcid bcid act _ (ls=:{cur,fc,bc},ps)
		| act == cur = (ls,ps)
		# ps = getColourBoxColour rgbid cont ps
		= (ls,ps)
	where
		cont col ps
			| isNothing col = ps
			# col = fromJust col
			# ps	= appPIO (case act of
								TXT	-> SetColourBox` fcid (case cur of
									TXT	-> toRGBColour col
									_	-> toRGBColour fc
									)
								_	-> SetColourBox fcid (case cur of
									TXT	-> toRGBColour col
									_	-> toRGBColour fc
									)
							) ps
			# ps	= appPIO (case act of
								BCK	-> SetColourBox` bcid (case cur of
									BCK	-> toRGBColour col
									_	-> toRGBColour bc
									)
								_	-> SetColourBox bcid (case cur of
									BCK	-> toRGBColour col
									_	-> toRGBColour bc
									)
							) ps
			# cId = case act of
						TXT -> fcid
						BCK -> bcid
			# col` = case act of
						TXT -> fc
						BCK -> bc
			# ps	= setColourBoxId rgbid cId ps
			# ps	= setColourBoxColour` rgbid col` ps
			# (_,ps) = asyncSend lsid (cont2 col) ps
			= ps
		cont2 col (ls=:{cur},ps)
			# ls	= case cur of
						TXT -> {ls & fc = col, cur = act}
						BCK -> {ls & bc = col, cur = act}
			= (ls,ps)
493
	apply (ls=:{fc,bc,fn,fs},ps)
Diederik van Arkel's avatar
Diederik van Arkel committed
494
495
		# (errinf,ps)	= getErrInfo ps
		# lbId			= errinf.infoId
496
		# (fnt,ps)	= accScreenPicture (safeOpenFixedFont {fName = fn, fSize = fs, fStyles = []}) ps
Diederik van Arkel's avatar
Diederik van Arkel committed
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
		# pen		= [PenFont fnt, PenColour fc, PenBack bc] 
		# ps		= setFilteredListBoxPen lbId pen ps
		# errinf	= {errinf & err_font = fnt, err_forg = fc, err_back = bc}
		# ps		= setErrInfo errinf ps
		= (ls,ps)
    left = ControlPos (Left, zero)
	fontfun name (ls,ps)
		# ls		= {EWO | ls & fn = name}
		= (ls,ps)
	sizefun size (ls,ps)
		# ls		= {EWO | ls & fs = size}
		= (ls,ps)


err_init :: !ErrPrefs *World -> *(.ErrorInfo .c,*World)
err_init {err_pos, err_siz, err_forc, err_bacc, err_fname, err_fsize, err_err, err_wrn, err_inf} w
	# (errorId,w)	= openId w
	# (infoId,w)	= openFilteredListBoxId w
	# (ebId,w) = openId w
	# (ecId,w) = openId w
	# (wbId,w) = openId w
	# (wcId,w) = openId w
	# (ibId,w) = openId w
	# (icId,w) = openId w
	# fdef			= {fName = err_fname, fSize = err_fsize, fStyles = []}
	# (efnt,w) = accScreenPicture (safeOpenFixedFont fdef) w
	# errinfo		=
		{ errorId		= errorId
		, infoId		= infoId
		, err_offset	= err_pos
		, err_font		= efnt			// now start using font in ExtListBox
		, err_size		= err_siz
		, err_forg		= err_forc
		, err_back		= err_bacc
		, err_buttonId	= ebId
		, err_countId	= ecId
		, err_count		= 0
		, err			= err_err
		, wrn_buttonId	= wbId
		, wrn_countId	= wcId
		, wrn_count		= 0
		, wrn			= err_wrn
		, inf_buttonId	= ibId
		, inf_countId	= icId
		, inf_count		= 0
		, inf			= err_inf
		}
	= (errinfo,w)

err_shut :: !(ErrorInfo .a) -> !ErrPrefs
err_shut info
	# fdef					= getFontDef info.err_font
	# prefs					=
						 		{ err_pos		= info.err_offset
						 		, err_siz		= info.err_size
						 		, err_fname		= fdef.fName
						 		, err_fsize		= fdef.fSize
						 		, err_forc		= info.err_forg
						 		, err_bacc		= info.err_back
						 		, err_err		= info.err
						 		, err_wrn		= info.wrn
						 		, err_inf		= info.inf
						 		}
	= prefs

//
// Extract module name and line number from error message.
//

:: MessageType = Error | Warning | Info

TypeErrorMsg	:: !String -> !MessageType
TypeErrorMsg msg = type
where
	msglen	= size msg
	type
		| msglen > 5 && msg%(0,4)	== "Error"				= Error
		| msglen > 12 && msg%(0,11)	== "Syntax error"		= Error
		| msglen > 11 && msg%(0,10)	== "Parse error"		= Error
		| msglen > 11 && msg%(0,10)	== "Check error"		= Error
		| msglen > 11 && msg%(0,10)	== "Check Error"		= Error
		| msglen > 10 && msg%(0,9)	== "Type error"			= Error
		| msglen > 10 && msg%(0,9)	== "Link error"			= Error
		| msglen > 12 && msg%(0,11)	== "Linker error"		= Error
		| msglen > 16 && msg%(0,15)	== "Uniqueness error"	= Error
		| msglen > 16 && msg%(0,15)	== "Undefined symbol"	= Error
		| msglen > 17 && msg%(0,16)	== "Overloading error"	= Error
		| msglen > 7 && msg%(0,6)	== "Warning"			= Warning
		| msglen > 12 && msg%(0,11)	== "Type warning"		= Warning
		| msglen > 13 && msg%(0,12)	== "Parse warning"		= Warning
		| msglen > 12 && msg%(0,11)	== "Link warning"		= Warning
		| msglen > 14 && msg%(0,13)	== "Linker warning"		= Warning
															= Info
											
ParseErrorMsg	:: !String -> (!Modulename, !Int);
ParseErrorMsg msg
	|	open < msglen	&& comma1 < msglen	&& comma2 < msglen	=  (path, linenr2);
	|	open < msglen	&& comma1 < msglen	&& close1 < msglen	=  (path, linenr1);
	|	open < msglen	&& close2 < msglen						=  (path, 0); 	
																=  (EmptyPathname, 0);
where 
	path	= msg % (inc open, dec comma1);
	linenr1	= dec` (SubStringToInt 0 (inc comma1) (dec comma2) msg);
	linenr2	= dec` (SubStringToInt 0 (inc comma1) (dec close1) msg);
	msglen	= size msg;
	open	= FindOpenChar msg msglen 0;
	close1	= FindCloseChar msg msglen (inc comma1);
	close2	= FindCloseChar msg msglen (inc open);
	comma1	= FindCommaChar msg msglen (inc open);
	comma2	= FindCommaChar msg msglen (inc comma1);
	
	dec`	:: !Int -> Int;
	dec` n | n == 0	= 0;
					= dec n;
	
//	FindOpenChar	:: !String !Int !Int -> Int;
FindOpenChar str len pos	:==  FindChar '[' str len pos;

//	FindCloseChar	:: !String !Int !Int -> Int;
FindCloseChar str len pos	:==  FindChar ']' str len pos;

//	FindCommaChar	:: !String !Int !Int -> Int;
FindCommaChar str len pos	:==  FindChar ',' str len pos;

//	FindQuoteChar	:: !String !Int !Int -> Int;
FindQuoteChar str len pos	:== FindChar '\"' str len pos;
	
//	FindColonChar	:: !String !Int !Int -> Int;
FindColonChar str len pos	:== FindChar ':' str len pos;
	
FindChar	:: !Char !String !Int !Int -> Int;
FindChar c line linelen pos
	| pos >= linelen		=  pos;
	| c ==  line.[pos]		=  pos;
							=  FindChar c line linelen (inc pos);
		
SubStringToInt :: !Int !Int !Int String -> Int;
SubStringToInt acc start stop str
	| start > stop	= acc;
	# curc	= str.[start];
	| isDigit curc
		# acc`	= 10 * acc + toInt curc - toInt '0';
		= SubStringToInt acc` (inc start) stop str;
	= acc;