1 | /*
|
---|
2 | * TOPPERS Software
|
---|
3 | * Toyohashi Open Platform for Embedded Real-Time Systems
|
---|
4 | *
|
---|
5 | * Copyright (C) 2007-2008 by TAKAGI Nobuhisa
|
---|
6 | *
|
---|
7 | * ãLì ÒÍCȺÌ(1)`(4)Ìðð½·êÉÀèC{\tgEF
|
---|
8 | * Ai{\tgEFAðüϵ½àÌðÜÞDȺ¯¶jðgpE¡»Eü
|
---|
9 | * ÏEÄzziȺCpÆÄÔj·é±Æð³Åø·éD
|
---|
10 | * (1) {\tgEFAð\[XR[hÌ`Åp·éêÉÍCãLÌì
|
---|
11 | * \¦C±Ìpð¨æÑºLÌ³ÛØKèªC»ÌÜÜÌ`Å\[
|
---|
12 | * XR[hÉÜÜêĢ鱯D
|
---|
13 | * (2) {\tgEFAðCCu`®ÈÇC¼Ì\tgEFAJÉg
|
---|
14 | * pÅ«é`ÅÄzz·éêÉÍCÄzzɺ¤hL
|
---|
15 | gip
|
---|
16 | * Ò}j
|
---|
17 | AÈÇjÉCãLÌì \¦C±Ìpð¨æÑºL
|
---|
18 | * Ì³ÛØKèðfÚ·é±ÆD
|
---|
19 | * (3) {\tgEFAðC@íÉgÝÞÈÇC¼Ì\tgEFAJÉg
|
---|
20 | * pūȢ`ÅÄzz·éêÉÍCÌ¢¸ê©Ìðð½·±
|
---|
21 | * ÆD
|
---|
22 | * (a) Äzzɺ¤hL
|
---|
23 | gipÒ}j
|
---|
24 | AÈÇjÉCãLÌ
|
---|
25 | * ì \¦C±Ìpð¨æÑºLÌ³ÛØKèðfÚ·é±ÆD
|
---|
26 | * (b) ÄzzÌ`ÔðCÊÉèßéû@ÉæÁÄCTOPPERSvWFNgÉ
|
---|
27 | * ñ·é±ÆD
|
---|
28 | * (4) {\tgEFAÌpÉæè¼ÚIܽÍÔÚIɶ¶é¢©Èé¹
|
---|
29 | * Q©çàCãLì Ò¨æÑTOPPERSvWFNgðÆÓ·é±ÆD
|
---|
30 | * ܽC{\tgEFAÌ[UܽÍGh[U©çÌ¢©Èé
|
---|
31 | * RÉîÿ©çàCãLì Ò¨æÑTOPPERSvWFNgð
|
---|
32 | * ÆÓ·é±ÆD
|
---|
33 | *
|
---|
34 | * {\tgEFAÍC³ÛØÅñ³êÄ¢éàÌÅ éDãLì Ò¨
|
---|
35 | * æÑTOPPERSvWFNgÍC{\tgEFAÉÖµÄCÁèÌgpÚI
|
---|
36 | * ÉηéK«àÜßÄC¢©ÈéÛØàsíÈ¢DܽC{\tgEF
|
---|
37 | * AÌpÉæè¼ÚIܽÍÔÚIɶ¶½¢©Èé¹QÉÖµÄàC»
|
---|
38 | * ÌÓCðíÈ¢D
|
---|
39 | *
|
---|
40 | */
|
---|
41 | #include <cstdio>
|
---|
42 | #include <string>
|
---|
43 | #include "toppers/diagnostics.hpp"
|
---|
44 | #include "toppers/text_line.hpp"
|
---|
45 |
|
---|
46 | namespace toppers
|
---|
47 | {
|
---|
48 | namespace
|
---|
49 | {
|
---|
50 | int error_abort_threshold = 100;
|
---|
51 | int error_count = 0;
|
---|
52 | std::string program_name( "(unknown)" );
|
---|
53 | }
|
---|
54 |
|
---|
55 | int get_error_count()
|
---|
56 | {
|
---|
57 | return error_count;
|
---|
58 | }
|
---|
59 |
|
---|
60 | int increment_error_count()
|
---|
61 | {
|
---|
62 | return ++error_count;
|
---|
63 | }
|
---|
64 |
|
---|
65 | void set_program_name( char const* name )
|
---|
66 | {
|
---|
67 | program_name = name;
|
---|
68 | }
|
---|
69 |
|
---|
70 | std::string const& get_program_name()
|
---|
71 | {
|
---|
72 | return program_name;
|
---|
73 | }
|
---|
74 |
|
---|
75 | int set_error_abort_threshold( int thresh )
|
---|
76 | {
|
---|
77 | if ( thresh < 1 )
|
---|
78 | {
|
---|
79 | return -1;
|
---|
80 | }
|
---|
81 | int previous = error_abort_threshold;
|
---|
82 | error_abort_threshold = thresh;
|
---|
83 | return previous;
|
---|
84 | }
|
---|
85 |
|
---|
86 | void warning( const char* msg )
|
---|
87 | {
|
---|
88 | fprintf( stderr, "%s: %s: %s\n", program_name.c_str(), _( "warning" ), msg );
|
---|
89 | }
|
---|
90 | void warning( text_line const& line, const char* msg )
|
---|
91 | {
|
---|
92 | fprintf( stderr, "%s:%s:%ld: %s: %s\n", program_name.c_str(), line.file.c_str(), line.line, _( "warning" ), msg );
|
---|
93 | }
|
---|
94 | void error( const char* msg )
|
---|
95 | {
|
---|
96 | fprintf( stderr, "%s: %s: %s\n", program_name.c_str(), _( "error" ), msg );
|
---|
97 | ++error_count;
|
---|
98 | if ( error_abort_threshold <= error_count )
|
---|
99 | {
|
---|
100 | throw diagnostics_error( _( "too many errors" ) );
|
---|
101 | }
|
---|
102 | }
|
---|
103 | void error( text_line const& line, const char* msg )
|
---|
104 | {
|
---|
105 | fprintf( stderr, "%s:%s:%ld: %s: %s\n", program_name.c_str(), line.file.c_str(), line.line, _( "error" ), msg );
|
---|
106 | ++error_count;
|
---|
107 | if ( error_abort_threshold <= error_count )
|
---|
108 | {
|
---|
109 | throw diagnostics_error( _( "too many errors" ) );
|
---|
110 | }
|
---|
111 | }
|
---|
112 | void fatal( const char* msg )
|
---|
113 | {
|
---|
114 | fprintf( stderr, "%s: %s: %s\n", program_name.c_str(), _( "error" ), msg );
|
---|
115 | throw diagnostics_error( _( "fatal error" ) );
|
---|
116 | }
|
---|
117 | void fatal( text_line const& line, const char* msg )
|
---|
118 | {
|
---|
119 | fprintf( stderr, "%s:%s:%d: %s: %s\n", program_name.c_str(), line.file.c_str(), line.line, _( "error" ), msg );
|
---|
120 | throw diagnostics_error( _( "fatal error" ) );
|
---|
121 | }
|
---|
122 |
|
---|
123 | }
|
---|