Branch data Line data Source code
1 : : /*
2 : : * International Chemical Identifier (InChI)
3 : : * Version 1
4 : : * Software version 1.07
5 : : * April 30, 2024
6 : : *
7 : : * MIT License
8 : : *
9 : : * Copyright (c) 2024 IUPAC and InChI Trust
10 : : *
11 : : * Permission is hereby granted, free of charge, to any person obtaining a copy
12 : : * of this software and associated documentation files (the "Software"), to deal
13 : : * in the Software without restriction, including without limitation the rights
14 : : * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 : : * copies of the Software, and to permit persons to whom the Software is
16 : : * furnished to do so, subject to the following conditions:
17 : : *
18 : : * The above copyright notice and this permission notice shall be included in all
19 : : * copies or substantial portions of the Software.
20 : : *
21 : : * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 : : * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 : : * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 : : * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 : : * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 : : * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 : : * SOFTWARE.
28 : : *
29 : : * The InChI library and programs are free software developed under the
30 : : * auspices of the International Union of Pure and Applied Chemistry (IUPAC).
31 : : * Originally developed at NIST.
32 : : * Modifications and additions by IUPAC and the InChI Trust.
33 : : * Some portions of code were developed/changed by external contributors
34 : : * (either contractor or volunteer) which are listed in the file
35 : : * 'External-contributors' included in this distribution.
36 : : *
37 : : * info@inchi-trust.org
38 : : *
39 : : */
40 : :
41 : : #pragma warning( disable : 4706 4127 4514 4100 4786 4996 4244 4267 )
42 : :
43 : : #include <string.h>
44 : :
45 : : #include "mode.h"
46 : : #include "ichierr.h"
47 : :
48 : : #include "bcf_s.h"
49 : :
50 : : static int already_have_this_message( char *prev_messages, const char *new_message );
51 : :
52 : :
53 : : /****************************************************************************/
54 : 0 : const char *ErrMsg( int nErrorCode )
55 : : {
56 : : const char *p;
57 : : static char szErrMsg[64];
58 [ # # # # : 0 : switch (nErrorCode)
# # # # #
# # # # #
# # # # #
# # # # #
# ]
59 : : {
60 : 0 : case 0: p = ""; break;
61 : 0 : case CT_OVERFLOW: p = "ARRAY OVERFLOW"; break;
62 : 0 : case CT_LEN_MISMATCH: p = "LENGTH_MISMATCH"; break;
63 : 0 : case CT_OUT_OF_RAM: p = "Out of RAM"; break;
64 : 0 : case CT_RANKING_ERR: p = "RANKING_ERR"; break;
65 : 0 : case CT_ISOCOUNT_ERR: p = "ISOCOUNT_ERR"; break;
66 : 0 : case CT_TAUCOUNT_ERR: p = "TAUCOUNT_ERR"; break;
67 : 0 : case CT_ISOTAUCOUNT_ERR: p = "ISOTAUCOUNT_ERR"; break;
68 : 0 : case CT_MAPCOUNT_ERR: p = "MAPCOUNT_ERR"; break;
69 : 0 : case CT_TIMEOUT_ERR: p = "Time limit exceeded"; break;
70 : 0 : case CT_ISO_H_ERR: p = "ISO_H_ERR"; break;
71 : 0 : case CT_STEREOCOUNT_ERR: p = "STEREOCOUNT_ERR"; break;
72 : 0 : case CT_ATOMCOUNT_ERR: p = "ATOMCOUNT_ERR"; break;
73 : 0 : case CT_STEREOBOND_ERROR: p = "STEREOBOND_ERR"; break;
74 : 0 : case CT_USER_QUIT_ERR: p = "User requested termination"; break;
75 : 0 : case CT_REMOVE_STEREO_ERR: p = "REMOVE_STEREO_ERR"; break;
76 : 0 : case CT_CALC_STEREO_ERR: p = "CALC_STEREO_ERR"; break;
77 : 0 : case CT_STEREO_CANON_ERR: p = "STEREO_CANON_ERR"; break;
78 : 0 : case CT_CANON_ERR: p = "CANON_ERR"; break;
79 : 0 : case CT_WRONG_FORMULA: p = "Wrong or missing chemical formula"; break;
80 : : /*case CT_CANON_ERR2: p = "CT_CANON_ERR2"; break;*/
81 : 0 : case CT_UNKNOWN_ERR: p = "UNKNOWN_ERR"; break;
82 : 0 : case BNS_RADICAL_ERR: p = "Cannot process free radical center"; break;
83 : 0 : case BNS_ALTBOND_ERR: p = "Cannot process aromatic bonds"; break;
84 : : /* v. 1.05 */
85 : 0 : case BNS_TIMEOUT: p = "Structure normalization timeout"; break;
86 : :
87 : 0 : default:
88 [ # # ]: 0 : if (nErrorCode > CT_UNKNOWN_ERR)
89 : : {
90 : 0 : sprintf(szErrMsg, "No description(%d)", nErrorCode);
91 : 0 : p = szErrMsg;
92 : : }
93 : : else
94 : : {
95 : 0 : sprintf(szErrMsg, "UNKNOWN_ERR(%d)", CT_UNKNOWN_ERR - nErrorCode);
96 : 0 : p = szErrMsg;
97 : : }
98 : 0 : break;
99 : : }
100 : :
101 : 0 : return p;
102 : : }
103 : :
104 : :
105 : : /****************************************************************************/
106 : 62 : int AddErrorMessage( char *all_messages, const char *new_message )
107 : : {
108 : : int len_all, len;
109 : :
110 [ - + ]: 62 : if (!all_messages)
111 : : {
112 : 0 : return 0;
113 : : }
114 [ - + ]: 62 : if (!new_message)
115 : : {
116 : 0 : return 0;
117 : : }
118 [ - + ]: 62 : if (!new_message[0])
119 : : {
120 : 0 : return 0;
121 : : }
122 [ + + ]: 62 : if (already_have_this_message( all_messages, new_message ))
123 : : {
124 : 24 : return 1;
125 : : }
126 : :
127 : 38 : len_all = (int) strlen( all_messages );
128 : 38 : len = (int) strlen( new_message );
129 : :
130 [ + + + + ]: 38 : if (len_all + len + 2 * ( len_all > 0 ) < STR_ERR_LEN)
131 : : {
132 : : /* enough room... add message and return */
133 [ + + ]: 11 : if (len_all > 0)
134 : : {
135 [ + - ]: 4 : if (all_messages[len_all - 1] != ':')
136 : : {
137 : 4 : strcat(all_messages, ";");
138 : : }
139 : 4 : strcat(all_messages, " ");
140 : : }
141 : 11 : strcat(all_messages, new_message);
142 : 11 : return 1;
143 : : }
144 : :
145 : : /* not enough room... add no-room marker if not yet added */
146 [ - + ]: 27 : if (strstr( all_messages, "..." ))
147 : : {
148 : 0 : return 0;
149 : : }
150 [ - + ]: 27 : if (len_all + 3 < STR_ERR_LEN)
151 : : {
152 : 0 : strcat(all_messages, "...");
153 : : }
154 : :
155 : 27 : return 0;
156 : : }
157 : :
158 : :
159 : : /****************************************************************************/
160 : 62 : int already_have_this_message( char *prev_messages, const char *new_message )
161 : : {
162 : 62 : int have = 0;
163 : :
164 : 62 : char *p = strstr( prev_messages, new_message );
165 : :
166 [ + + ]: 62 : if (p)
167 : : {
168 [ + + + - : 24 : have = ( p == prev_messages || (*( p - 1 ) == ' ' && ( *( p - 2 ) == ';' || *( p - 2 ) == ':' )) ); /* djb-rwth: addressing LLVM warning */
- + - - ]
169 [ + - ]: 24 : if (have)
170 : : {
171 : 24 : int len_prev = (int) strlen( prev_messages );
172 : 24 : int len = (int) strlen( new_message );
173 [ - + - - : 24 : have = ( p + len == prev_messages + len_prev || (p[len] == ';' && p[len + 1] == ' ') || (p[len - 1] == ':' && p[len] == ' ') ); /* djb-rwth: addressing LLVM warning */
- - - - -
- ]
174 : : }
175 : : }
176 : :
177 : 62 : return have;
178 : : }
|