summaryrefslogtreecommitdiff
path: root/src/Xw/Xw_set_trace.cxx
blob: 06c13cd2872afb22a346b173572e22e8fa01cf1e (plain)
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
442
443
444
445
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
493
494
495
496
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
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834

/***********************************************************************

     FONCTION :
     ----------
        Classe GUI_WidgetTools :

     HISTORIQUE DES MODIFICATIONS   :
     --------------------------------
      ??-??-?? : ??? ; Creation.
      19-01-98 : GG ; Xw_error_handler()
                      Ignorer les messages d'erreur en provenance de
                      XConfigureWindow (arrive souvent avec MOTIF).

************************************************************************/

#include <Xw_Extension.h>
#include <X11/Xproto.h>
#include <X11/Xmu/Xmu.h>


        /* ifdef then trace on */
#ifdef TRACE
#define TRACE_SET_TRACE
#endif

#define MAXERROR 8
#define MAXERRORSTRING 512

static int Nerror = 0 ;
static int Lstring = 0 ;
static char ErrorString[MAXERRORSTRING] ;
static char *PErrorString ;
static char *ErrorMessag[MAXERROR] ;
static char *ErrorRoutine[MAXERROR] ;
static int ErrorCount[MAXERROR] ;
static int ErrorCode[MAXERROR] ;
static int ErrorGravity[MAXERROR] ;
static int TraceLevel = 0 ;
static int ErrorLevel = 4 ;
static int TestMask = 0 ;

/*
   void Xw_set_trace (tracelevel,errorlevel):
   int tracelevel   ;      
   int errorlevel   ;        

        ENABLE/DISABLE Xw package Trace or Error printing 

                  TraceLevel can have the value :

                        0: Disable trace printing       (DEFAULT)
                        1: Print All first level routines calls tiny
                        2: Print routines calls offen but with a low amount of
                                                                trace info .
                        3: Print routines calls offen with an amount of infos .

                  NOTE than XSynchronize is call depending of the Trace level

                  ErrorLevel can have the value :

                        0: Disable Error printing 
                        1: Print any Errors or Warnings (DEFAULT)
                        2: Print high and low gravity errors
                        3: Print only high gravity errors
                        4: Print only Unimplemented errors

===============================================================================

        char* Xw_get_error(error,gravity)
        int *error ;
        int *gravity ;
  
        Returns the last Error Code,Gravity and Messag found if any

        Returns Messag string if any Error has been found
        Returns NULL if No Error has been found

===============================================================================

        STATUS Xw_print_error()
 
        Print Error Stack

        Returns XW_ERROR if no erreur exist
        Returns XW_SUCCESS if successful 

*/

#ifdef XW_PROTOTYPE
void Xw_set_trace(int tracelevel,int errorlevel)
#else
void Xw_set_trace(tracelevel,errorlevel)
int tracelevel ;
int errorlevel ;
#endif /*XW_PROTOTYPE*/
{

        TraceLevel = tracelevel ;
        ErrorLevel = errorlevel ;

        if( Xw_get_env("Xw_TEST",ErrorString,sizeof(ErrorString)) ){
            if( strlen(ErrorString) ) {
                sscanf(ErrorString,"%x",&TestMask) ;
            }
            printf(" Xw_TEST is %x\n",TestMask) ;
        }

        if( Xw_get_env("Xw_SET_TRACE",ErrorString,sizeof(ErrorString)) ){
            if( strlen(ErrorString) ) {
                sscanf(ErrorString,"%d %d",&TraceLevel,&ErrorLevel) ;
            }
            printf(" Xw_SET_TRACE is %d %d\n",TraceLevel,ErrorLevel) ;
        }

        Xw_set_synchronize(NULL,TraceLevel) ;
}

#ifdef XW_PROTOTYPE
int Xw_test(unsigned long mask)
#else
int Xw_test(mask)
unsigned long mask;
#endif /*XW_PROTOTYPE*/
/*
        Returns TRUE if mask & TestMask is != 0
*/
{
        if( mask & TestMask ) return (True) ;
        else return (False) ;
}

#ifdef XW_PROTOTYPE
int Xw_get_trace()
#else
int Xw_get_trace()
#endif /*XW_PROTOTYPE*/
/*
        Returns the Trace level
*/
{
        return (TraceLevel) ;
}

/*
   void Xw_set_error(code,routine,param):
   int code                     Error Number
   char *routine                Routine name from error occurs
   void *param                  Associated Error value

        Set Error Message And Print eventually depending of Error trace level .

        Returns NONE

*/

#ifdef XW_PROTOTYPE
void Xw_set_error(int code,const char *routine,void* param)
#else
void Xw_set_error(code,routine,param)
int code ;
const char *routine ;
void *param ;
#endif /*XW_PROTOTYPE*/
{
union {
    void *pv ;
    char *pc ;
    short *ps ;
    int *pi ;
    long *pl ;
    float *pf ;
} value ;
char error[512] ;
int gravity ;

    value.pv = param ;

    switch (code) {
        case 1 :
            gravity = 1 ;
            sprintf(error,"Bad Color Index %d",*value.pi) ;
            break ;
        case 2 :
            gravity = 3 ;
            sprintf(error,"Colormap creation failed") ;
            break ;
        case 3 :
            gravity = 3 ;
            sprintf(error,"USER Colormap %lx allocation failed",(long ) *value.pl) ;
            break ;
        case 4 :
            gravity = 3 ;
            sprintf(error,"STD Colormap %lx allocation failed",(long ) *value.pl) ;
            break ;
        case 5 :
            gravity = 4 ;
            sprintf(error,"Unimplemented Visual class %d",*value.pi) ;
            break ;
        case 6 :
            gravity = 3 ;
            sprintf(error,"EXT_COLORMAP allocation failed") ;
            break ;
        case 7 :
            gravity = 1 ;
            sprintf(error,"Bad Font Index %d",*value.pi) ;
            break ;
        case 8 :
            gravity = 1 ;
            if( value.pc ) sprintf(error,"Bad Font Name '%s'",value.pc) ;
            else           sprintf(error,"Bad Font Name address") ;
            break ;
        case 9 :
            gravity = 3 ;
            sprintf(error,"EXT_FONTMAP allocation failed") ;
            break ;
        case 10 :
            gravity = 1 ;
            sprintf(error,"Bad Marker Index %d",*value.pi) ;
            break ;
        case 11 :
            gravity = 2 ;
            sprintf(error,"Marker Allocation failed") ;
            break ;
        case 12 :
            gravity = 3 ;
            sprintf(error,"EXT_MARKMAP allocation failed") ;
            break ;
        case 13 :
            gravity = 1 ;
            sprintf(error,"Bad Tile Index %d",*value.pi) ;
            break ;
        case 14 :
            gravity = 1 ;
            sprintf(error,"Bad Tile Index %d Size",*value.pi) ;
            break ;
        case 15 :
            gravity = 1 ;
            sprintf(error,"Bad Tile %d Data",*value.pi) ;
            break ;
        case 16 :
            gravity = 2 ;
            sprintf(error,"Tile Bitmap Allocation failed") ;
            break ;
        case 17 :
            gravity = 3 ;
            sprintf(error,"EXT_TILEMAP allocation failed") ;
            break ;
        case 18 :
            gravity = 1 ;
            sprintf(error,"Bad Type Index %d",*value.pi) ;
            break ;
        case 19 :
            gravity = 1 ;
            sprintf(error,"Bad Type %d Data",*value.pi) ;
            break ;
        case 20 :
            gravity = 3 ;
            sprintf(error,"EXT_TYPEMAP allocation failed") ;
            break ;
        case 21 :
            gravity = 1 ;
            sprintf(error,"Bad Width Index %d",*value.pi) ;
            break ;
        case 22 :
            gravity = 1 ;
            sprintf(error,"Bad Width Thickness %f",*value.pf) ;
            break ;
        case 23 :
            gravity = 3 ;
            sprintf(error,"EXT_WIDTHMAP allocation failed") ;
            break ;
        case 24 :
            gravity = 3 ;
            sprintf(error,"Bad EXT_WINDOW Address %lx",(long ) value.pl) ;
            break ;
        case 25 :
            gravity = 3 ;
            sprintf(error,"Bad EXT_IMAGEDATA Address %lx",(long ) value.pl) ;
            break ;
        case 26 :
            gravity = 1 ;
            sprintf(error,"Try to Draw Image %lx outside the window",(long ) value.pl) ;
            break ;
        case 27 :
            gravity = 3 ;
            sprintf(error,"EXT_IMAGE allocation failed") ;
            break ;
        case 28 :
            gravity = 2 ;
            sprintf(error,"Too many points in POLYLINE,max is %d",*value.pi) ;
            break ;
        case 29 :
            gravity = 1 ;
            sprintf(error,"POLYLINE is empty !!!") ;
            break ;
        case 30 :
            gravity = 3 ;
            sprintf(error,"EXT_POLYLINE allocation failed") ;
            break ;
        case 31 :
            gravity = 3 ;
            sprintf(error,"EXT_MARKER allocation failed") ;
            break ;
        case 32 :
            gravity = 2 ;
            sprintf(error,"Too many points in POLYGONE,max is %d",*value.pi) ;
            break ;
        case 33 :
            gravity = 1 ;
            sprintf(error,"POLYGONE is empty !!!") ;
            break ;
        case 34 :
            gravity = 3 ;
            sprintf(error,"EXT_POLYGONE allocation failed") ;
            break ;
        case 35 :
            gravity = 3 ;
            sprintf(error,"EXT_SEGMENT allocation failed") ;
            break ;
        case 36 :
            gravity = 3 ;
            sprintf(error,"Bad EXT_POLYLINE Address") ;
            break ;
        case 37 :
            gravity = 3 ;
            sprintf(error,"Bad EXT_POLYGONE Address") ;
            break ;
        case 38 :
            gravity = 2 ;
            sprintf(error,"Too big TEXT string,max is %d",*value.pi) ;
            break ;
        case 39 :
            gravity = 3 ;
            sprintf(error,"EXT_TEXT allocation failed") ;
            break ;
        case 40 :
            gravity = 1 ;
            sprintf(error,"Try to Erase outside the window %lx",(long ) value.pl) ;
            break ;
        case 41 :
            gravity = 2 ;
            sprintf(error,"Bad Defined Color at index %d",*value.pi) ;
            break ;
        case 42 :
            gravity = 3 ;
            sprintf(error,"Bad EXT_COLORMAP Address %lx",(long ) value.pl) ;
            break ;
        case 43 :
            gravity = 1 ;
            sprintf(error,"Bad Defined Font at index %d",*value.pi) ;
            break ;
        case 44 :
            gravity = 3 ;
            sprintf(error,"Bad EXT_FONTMAP Address %lx",(long ) value.pl) ;
            break ;
        case 45 :
            gravity = 1 ;
            sprintf(error,"Try to Get Image from outside the window") ;
            break ;
        case 46 :
            gravity = 3 ;
            sprintf(error,"Bad EXT_MARKMAP Address %lx",(long ) value.pl) ;
            break ;
        case 47 :
            gravity = 1 ;
            sprintf(error,"Bad PIXEL position,max is %d",*value.pi) ;
            break ;
        case 48 :
            gravity = 3 ;
            sprintf(error,"Visual %d must be TRUECOLOR",*value.pi) ;
            break ;
        case 49 :
            gravity = 3 ;
            sprintf(error,"Bad EXT_TILEMAP Address %lx",(long ) value.pl) ;
            break ;
        case 50 :
            gravity = 1 ;
            sprintf(error,"Bad Defined Type at index %d",*value.pi) ;
            break ;
        case 51 :
            gravity = 3 ;
            sprintf(error,"Bad EXT_TYPEMAP Address %lx",(long ) value.pl) ;
            break ;
        case 52 :
            gravity = 1 ;
            sprintf(error,"Bad Defined Width at index %d",*value.pi) ;
            break ;
        case 53 :
            gravity = 3 ;
            sprintf(error,"Bad EXT_WIDTHMAP Address %lx",(long ) value.pl) ;
            break ;
        case 54 :
            gravity = 3 ;
            sprintf(error,"Bad Window %lx Attributes",(long ) *value.pl) ;
            break ;
        case 55 :
            gravity = 2 ;
            if(value.pc) sprintf(error,"Bad XWD FileName '%s'",value.pc) ;
            else         sprintf(error,"Bad XWD FileName %lx",(long ) value.pc) ;
            break ;
        case 56 :
            gravity = 2 ;
            sprintf(error,"Unable to read XWD File Header of '%s'",value.pc) ;
            break ;
        case 57 :
            gravity = 2 ;
            sprintf(error,"Bad XWD File format of '%s'",value.pc) ;
            break ;
        case 58 :
            gravity = 2 ;
            sprintf(error,"Bad XWD Pixmap format of '%s'",value.pc) ;
            break ;
        case 59 :
            gravity = 4 ;
            sprintf(error,"Unimplemented Image Visual class %d",*value.pi) ;
            break ;
        case 60 :
            gravity = 3 ;
            sprintf(error,"XImage Allocation failed");
            break ;
        case 61 :
            gravity = 3 ;
            sprintf(error,"Unable to read Image data of '%s'",value.pc) ;
            break ;
        case 62 :
            gravity = 3 ;
            sprintf(error,"XImage Creation failed");
            break ;
        case 63 :
            gravity = 3 ;
            sprintf(error,"No more FREE pixel in Colormap %lx",(long ) *value.pl);
            break ;
        case 64 :
            gravity = 4 ;
            sprintf(error,"Unimplemented Image Visual depth %d",*value.pi) ;
            break ;
        case 65 :
            gravity = 3 ;
            sprintf(error,"Display Stack OVERFLOW") ;
            break ;
        case 66 :
            gravity = 3 ;
            if( value.pc ) sprintf(error,"Bad Display connexion '%s'",value.pc);
            else           sprintf(error,"Bad Display connexion '%lx'",(long ) value.pc);
            break ;
        case 67 :
            gravity = 3 ;
            sprintf(error,"Unmatchable Visual class %d",*value.pi) ;
            break ;
        case 68 :
            gravity = 1 ;
            sprintf(error,"Bad AREA position") ;
            break ;
        case 69 :
            gravity = 3 ;
            sprintf(error,"EXT_WINDOW allocation failed") ;
            break ;
        case 70 :
            gravity = 1 ;
            sprintf(error,"Bad Cursor Index %d",*value.pi) ;
            break ;
        case 71 :
            gravity = 1 ;
            sprintf(error,"Double Buffering is DISABLE") ;
            break ;
        case 72 :
            gravity = 1 ;
            sprintf(error,"Lose RETAIN lines buffer attrib %x",*value.pi) ;
            break ;
        case 73 :
            gravity = 1 ;
            sprintf(error,"Lose RETAIN polygons buffer attrib %x",*value.pi) ;
            break ;
        case 74 :
            gravity = 1 ;
            sprintf(error,"Lose RETAIN texts buffer attrib %x",*value.pi) ;
            break ;
        case 75 :
            gravity = 1 ;
            sprintf(error,"Lose RETAIN markers buffer attrib %x",*value.pi) ;
            break ;
        case 76 :
            gravity = 1 ;
            sprintf(error,"Bad Mapping Size %f",*value.pf) ;
            break ;
        case 77 :
            gravity = 1 ;
            sprintf(error,"Bad Defined Marker at index %d",*value.pi) ;
            break ;
        case 78 :
            gravity = 1 ;
            sprintf(error,"Bad Defined Tile at index %d",*value.pi) ;
            break ;
        case 79 :
            gravity = 4 ;
            sprintf(error,"Unimplemented Marker type %d",*value.pi) ;
            break ;
        case 80 :
            gravity = 4 ;
            sprintf(error,"Unimplemented Polygon type %d",*value.pi) ;
            break ;
        case 81 :
            gravity = 4 ;
            sprintf(error,"Unimplemented Text type %d",*value.pi) ;
            break ;
        case 82 :
            gravity = 3 ;
            sprintf(error,"Bad Line Attrib %lx",(long ) *value.pl) ;
            break ;
        case 83 :
            gravity = 3 ;
            sprintf(error,"Bad Polygon Attrib %lx",(long ) *value.pl) ;
            break ;
        case 84 :
            gravity = 3 ;
            sprintf(error,"Bad Text Attrib %lx",(long ) *value.pl) ;
            break ;
        case 85 :
            gravity = 3 ;
            sprintf(error,"Bad Marker Attrib %lx",(long ) *value.pl) ;
            break ;
        case 86 :
            gravity = 1 ;
            sprintf(error,"Unimplemented EVENT type %d",*value.pi) ;
            break ;
        case 87 :
            gravity = 1 ;
            sprintf(error,"Use def_background_color instead on index %d",
                                                                *value.pi) ;
            break ;
        case 88 :
            gravity = 2 ;
            sprintf(error,"Bad RGB file name %s",value.pc) ;
            break ;
        case 89 :
            gravity = 1 ;
            sprintf(error,"Bad Named Color %s",value.pc) ;
            break ;
        case 90 :
            gravity = 3 ;
            sprintf(error,"Unable to Create DisplayPostScript Context") ;
            break ;
        case 91 :
            gravity = 2 ;
            sprintf(error,"Coordinate must be in [0,1] space") ;
            break ;
        case 92 :
            gravity = 2 ;
            sprintf(error,"ColorCube Creation failed width %d Colors",*value.pi) ;
            break ;
        case 93 :
            gravity = 2 ;
            sprintf(error,"ColorCube Allocation failed");
            break ;
        case 94 :
            gravity = 3 ;
            sprintf(error,"EXT_DISPLAY allocation failed") ;
            break ;
        case 95 :
            gravity = 1 ;
            sprintf(error,"Bad Mouse Button number %d",*value.pi) ;
            break ;
        case 96 :
            gravity = 3 ;
            sprintf(error,"Bad EXT_DISPLAY Address %lx",(long ) value.pl) ;
            break ;
        case 97 :
            gravity = 1 ;
            sprintf(error,"Unimplemented Internal Event number %d",*value.pi) ;
            break ;
        case 98 :
            gravity = 1 ;
            sprintf(error,"Can't GRAB Cursor id %d on this Window",*value.pi) ;
            break ;
        case 99 :
            gravity = 3 ;
            sprintf(error,"Can't OPEN IconBox Window") ;
            break ;
        case 100 :
            gravity = 1 ;
            if( value.pc ) 
                sprintf(error,"Can't OPEN Icon File Directory '%s'",value.pc);
            else sprintf(error,"Can't OPEN Icon File Directory '%lx'",(long ) value.pc);
            break ;
        case 101 :
            gravity = 3 ;
            sprintf(error,"EXT_ICON allocation failed") ;
            break ;
        case 102 :
            gravity = 1 ;
            sprintf(error,"Icon Box is EMPTY !") ;
            break ;
        case 103 :
            gravity = 1 ;
            if( value.pc ) 
                sprintf(error,"Bad Icon Name '%s'",value.pc);
            else sprintf(error,"Bad Icon Name '%lx'",(long ) value.pc);
            break ;
        case 104 :
            gravity = 3 ;
            sprintf(error,"PIXMAP allocation failed") ;
            break ;
        case 105 :
            gravity = 1 ;
            sprintf(error,"Allocates ONLY %d contiguous colors",*value.pi);
            break ;
        case 106 :
            gravity = 1 ;
            sprintf(error,"Bad Icon Index %d",*value.pi);
            break ;
        case 107 :
            gravity = 1 ;
            sprintf(error,"XImage BAD pixel color %x",*value.pi);
            break ;
        case 108 :
            gravity = 1 ;
            sprintf(error,"BAD Icon Name size,must be < %d",*value.pi);
            break ;
        case 109 :
            gravity = 1 ;
            if( value.pc ) 
                sprintf(error,"Bad Icon FileName '%s'",value.pc);
            else sprintf(error,"Bad Icon FileName '%lx'",(long ) value.pc);
            break ;
        case 110 :
            gravity = 1 ;
            sprintf(error,"No more FREE pixel in STD Colormap %d",*value.pi);
            break ;
        case 111 :
            gravity = 2 ;
            sprintf(error,"Too many SEGMENTS,max is %d",*value.pi) ;
            break ;
        case 112 :
            gravity = 2 ;
            sprintf(error,"Too many points in MARKER,max is %d",*value.pi) ;
            break ;
        case 113 :
            gravity = 2 ;
            sprintf(error,"Bad Image zoom factor %f",*value.pf) ;
            break ;
        case 114 :
            gravity = 2 ;
            sprintf(error,"Bad Image translation") ;
            break ;
        case 115 :
            gravity = 2 ;
            sprintf(error,"Bad arc radius %f",*value.pf) ;
            break ;
        case 116 :
            gravity = 1 ;
            sprintf(error,"Too big arc radius") ;
            break ;
        case 117 :
            gravity = 3 ;
            sprintf(error,"EXT_POINT allocation failed") ;
            break ;
        case 118 :
            gravity = 3 ;
            sprintf(error,"EXT_CHAR allocation failed") ;
            break ;
        case 119 :
            gravity = 2 ;
            sprintf(error,"BUFFER %d is not opened",*value.pi) ;
            break ;
        case 120 :
            gravity = 1 ;
            sprintf(error,"BUFFER %d is already opened",*value.pi) ;
            break ;
        case 121 :
            gravity = 3 ;
            sprintf(error,"Too many opened BUFFERS,max is %d",*value.pi) ;
            break ;
        case 122 :
            gravity = 3 ;
            sprintf(error,"Bad BUFFER identification %d",*value.pi) ;
            break ;
        case 123 :
            gravity = 2 ;
            sprintf(error,"Bad BUFFER scale factor %f",*value.pf) ;
            break ;
        case 124 :
            gravity = 1 ;
            sprintf(error,"Bad margin poly text ratio %f",*value.pf) ;
            break ;
        case 125 :
            gravity = 1 ;
            sprintf(error,"Bad BUFFER drawing mode %d",*value.pi) ;
            break ;
        case 126 :
            gravity = 1 ;
            sprintf(error,"MultiBuffering Extension is not accessible here") ;
            break ;
        case 127 :
            gravity = 1 ;
            sprintf(error,"Bad Color Index Allocation %d",*value.pi) ;
            break ;
        case 128 :
            gravity = 3 ;
            sprintf(error,"XDPS_EXT_WINDOW allocation failed") ;
            break ;
        case 129 :
            gravity = 1 ;
            sprintf(error,"Too many entry in the virtual colormap %lx",(long ) value.pl) ;
            break ;
        case 130 :
            gravity = 1;
            sprintf(error,"Too big ZOOM factor (%f)", *value.pf);
            break;
        default :
            gravity = 4 ;
            if( code >= 1000 ) {
              sprintf(error,"code %d/'%s'\n",code-1000,value.pc) ;
            } else {
              sprintf(error,"Bad Error Code %d",code) ;
            }
    }
    
    if( gravity > ErrorLevel ) {
        printf("*Xw_Error_%d*%s from %s routine\n",gravity,error,routine) ;
    } else {                    /* Put Messag in Error Stack */
        int lr = strlen(routine) + 1 ;
        int lm = strlen(error) + 1 ;
        int i = 0 ;

        if( Nerror > 0 ) {
          for( i=0 ; i<Nerror ; i++ ) {
            if( code == ErrorCode[i] ) break;
          }
        }

        if( i < Nerror ) {
          ErrorCount[i]++;
        } else {
          if( (Nerror >= MAXERROR) || (Lstring + lr + lm > MAXERRORSTRING) ) {
                                        /* Stack Overflow */
            printf("*Xw_Error*Stack OVERFLOW,use Xw_get_error a lot !!!\n") ;
            Xw_print_error() ;
          }

          ErrorCode[Nerror] = code ;            /* Push Error Stack */
          ErrorGravity[Nerror] = gravity ;
          ErrorCount[Nerror] = 1 ;
          ErrorRoutine[Nerror] = &ErrorString[Lstring] ;
          strcpy(&ErrorString[Lstring],routine) ; Lstring += lr ;
          ErrorMessag[Nerror] = &ErrorString[Lstring] ;
          strcpy(&ErrorString[Lstring],error) ; Lstring += lm ;
          Nerror++ ;
        }
    }
}

#ifdef XW_PROTOTYPE
XW_STATUS Xw_print_error()
#else
XW_STATUS Xw_print_error()
#endif /*XW_PROTOTYPE*/
/*
        Print Error Stack

        Returns XW_ERROR if no erreur exist
        Returns XW_SUCCESS if successful 
*/
{
XW_STATUS status = XW_SUCCESS ;
int i ;

    if( Nerror ) {
       for( i=0 ; i<Nerror ; i++ ) {
         printf("*Xw_Error_%d/%d*%s from %s routine\n",
                        ErrorGravity[i],ErrorCount[i],ErrorMessag[i],ErrorRoutine[i]) ;
       }
       Nerror = 0 ;
       Lstring = 0 ;
    } else status = XW_ERROR ;

    return (status) ;
}

#ifdef XW_PROTOTYPE
char* Xw_get_error(int *error,int *gravity)
#else
char* Xw_get_error(error,gravity)
int *error ;
int *gravity ;
#endif /*XW_PROTOTYPE*/
/*
        Returns the last Error Code,Gravity and Messag found if any

        Returns Messag string if any Error has been found
        Returns NULL if No Error has been found
*/
{

    if( Nerror > 0 ) {
        *error = ErrorCode[Nerror-1] ;
        *gravity = ErrorGravity[Nerror-1] ;
        PErrorString = ErrorMessag[Nerror-1] ;
        --Nerror ;                      /* Pop Error Stack */
        Lstring -= strlen(ErrorMessag[Nerror]) + 
                                strlen(ErrorRoutine[Nerror]) + 2 ;
    } else {
        *error = 0 ;
        *gravity = 0 ;
        PErrorString = NULL ;
    }

    return (PErrorString) ;
}

#ifdef XW_PROTOTYPE
int Xw_error_handler(Display *display,XErrorEvent *event)
#else
int Xw_error_handler(display,event)
Display *display ;
XErrorEvent *event ;
#endif /*XW_PROTOTYPE*/
{
  if( TraceLevel != 0 ) {
    XmuPrintDefaultErrorMessage(display,event,stderr);
  } else {
    char xerrormessag[128] ;
    if( event->request_code != X_ConfigureWindow
#ifndef DEBUG
	&& event->request_code != X_ChangeWindowAttributes //error reproduced for several X servers (Mandriva 2008)
#endif
	) {
      XGetErrorText(display,event->error_code,xerrormessag,sizeof(xerrormessag))
 ;
      Xw_set_error(1000+event->error_code,"Xw_error_handler",xerrormessag) ;
    }
  }
  return True;
}