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 : : #include <stdlib.h>
42 : : #include <string.h>
43 : : #include <ctype.h>
44 : : #include <locale.h>
45 : :
46 : : #include "mode.h"
47 : : #include "ichimake.h"
48 : : #include "inchi_api.h"
49 : : #include "ichimain.h"
50 : : #include "ichister.h"
51 : : #include "ichi_io.h"
52 : : #include "ichitime.h"
53 : : #include "ichi_bns.h"
54 : :
55 : : #include "bcf_s.h"
56 : :
57 : : /*
58 : : Local functions
59 : : */
60 : :
61 : : int inp2spATOM(inp_ATOM* inp_at, int num_inp_at, sp_ATOM* at);
62 : : int GetElementAndCount(const char** f, char* szEl, int* count);
63 : : int CompareHillFormulas(const char* f1, const char* f2);
64 : : int CompareInchiStereo(INChI_Stereo* Stereo1,
65 : : INCHI_MODE nFlags1,
66 : : INChI_Stereo* Stereo2,
67 : : INCHI_MODE nFlags2);
68 : : int CompareReversedStereoINChI(INChI_Stereo* s1,
69 : : INChI_Stereo* s2);
70 : : int GetAtomOrdNbrInCanonOrd(struct tagCANON_GLOBALS* pCG,
71 : : inp_ATOM* norm_at,
72 : : AT_NUMB* nAtomOrdNbr,
73 : : AT_NUMB* nOrigAtNosInCanonOrd,
74 : : int num_at);
75 : : int FillOutCanonInfAtom(struct tagCANON_GLOBALS* pCG,
76 : : inp_ATOM* norm_at,
77 : : INF_ATOM_DATA* inf_norm_at_data,
78 : : int init_num_at,
79 : : int bIsotopic,
80 : : INChI* pINChI,
81 : : INChI_Aux* pINChI_Aux,
82 : : int bAbcNumbers,
83 : : INCHI_MODE nMode);
84 : : int FillOutOneCanonInfAtom(struct tagCANON_GLOBALS* pCG,
85 : : inp_ATOM* inp_norm_at,
86 : : INF_ATOM_DATA* inf_norm_at_data,
87 : : AT_NUMB* pStereoFlags,
88 : : int init_num_at,
89 : : int offset,
90 : : int offset_H,
91 : : int bIsotopic,
92 : : INChI* pINChI,
93 : : INChI_Aux* pINChI_Aux,
94 : : int bAbcNumbers,
95 : : INCHI_MODE nMode);
96 : : int FillOutInputInfAtom(inp_ATOM* inp_at,
97 : : INF_ATOM_DATA* inf_at_data,
98 : : int init_num_at,
99 : : int num_removed_H,
100 : : int bAdd_DT_to_num_H,
101 : : int nNumRemovedProtons,
102 : : NUM_H* nNumRemovedProtonsIsotopic,
103 : : int bIsotopic,
104 : : int bAbcNumbers);
105 : : int CheckCanonNumberingCorrectness(int num_atoms,
106 : : int num_at_tg,
107 : : sp_ATOM* at,
108 : : CANON_STAT* pCS,
109 : : CANON_GLOBALS* pCG,
110 : : int bTautomeric,
111 : : char* pStrErrStruct);
112 : : static int CompareDfsDescendants4CT(const void* a1, const void* a2, void*);
113 : : int GetSp3RelRacAbs(const INChI* pINChI, INChI_Stereo* Stereo);
114 : : #if ( READ_INCHI_STRING == 1 ) /* { */
115 : : int CompareReversedStereoINChI2(INChI_Stereo* s1, INChI_Stereo* s2, ICR* picr);
116 : : #endif
117 : :
118 : : /****************************************************************************/
119 : 69 : int inp2spATOM(inp_ATOM* inp_at, int num_inp_at, sp_ATOM* at)
120 : : {
121 : : int i, j, val, elname_len;
122 : :
123 : 69 : memset(at, 0, sizeof(at[0]) * num_inp_at); /* djb-rwth: memset_s C11/Annex K variant? */
124 : :
125 [ + + ]: 688 : for (i = 0; i < num_inp_at; i++)
126 : : {
127 : 619 : elname_len = sizeof(at[0].elname) - 1; /* djb-rwth: fixing coverity ID #499609 */
128 : 619 : strncpy(at[i].elname, inp_at[i].elname, elname_len);
129 : 619 : at[i].elname[elname_len] = '\0';
130 : 619 : at[i].el_number = (U_CHAR)get_periodic_table_number(at[i].elname);
131 : 619 : val = at[i].valence = inp_at[i].valence;
132 [ + + ]: 1753 : for (j = 0; j < val; j++)
133 : : {
134 : 1134 : at[i].neighbor[j] = inp_at[i].neighbor[j];
135 : 1134 : at[i].bond_type[j] = inp_at[i].bond_type[j];
136 : : }
137 : 619 : at[i].chem_bonds_valence = inp_at[i].chem_bonds_valence;
138 : 619 : at[i].orig_at_number = inp_at[i].orig_at_number;
139 : 619 : at[i].orig_compt_at_numb = inp_at[i].orig_compt_at_numb;
140 : 619 : at[i].endpoint = inp_at[i].endpoint;
141 : 619 : at[i].iso_atw_diff = inp_at[i].iso_atw_diff;
142 : 619 : at[i].num_H = inp_at[i].num_H;
143 : 619 : at[i].cFlags = inp_at[i].cFlags;
144 [ + + ]: 2476 : for (j = 0; j < NUM_H_ISOTOPES; j++)
145 : : {
146 : 1857 : at[i].num_iso_H[j] = inp_at[i].num_iso_H[j];
147 : : }
148 : 619 : at[i].charge = inp_at[i].charge;
149 : 619 : at[i].radical = inp_at[i].radical;
150 : :
151 : : #if ( FIND_RING_SYSTEMS == 1 )
152 : 619 : at[i].nBlockSystem = inp_at[i].nBlockSystem;
153 : 619 : at[i].bCutVertex = inp_at[i].bCutVertex;
154 : 619 : at[i].nRingSystem = inp_at[i].nRingSystem;
155 : 619 : at[i].nNumAtInRingSystem = inp_at[i].nNumAtInRingSystem;
156 : : #if ( FIND_RINS_SYSTEMS_DISTANCES == 1 )
157 : : at[i].nDistanceFromTerminal = inp_at[i].nDistanceFromTerminal;
158 : : #endif
159 : : #endif
160 : :
161 : : /*
162 : : at[i].x = inp_at[i].x;
163 : : at[i].y = inp_at[i].y;
164 : : at[i].z = inp_at[i].z;
165 : : */
166 : : }
167 : :
168 : 69 : return 0;
169 : : }
170 : :
171 : :
172 : : /****************************************************************************/
173 : 260 : int GetElementAndCount(const char** f, char* szEl, int* count)
174 : : {
175 : 260 : const char* p = *f;
176 : : char* q;
177 : 260 : int i = 0;
178 : :
179 : : /* djb-rwth: fixing oss-fuzz issue #37224 */
180 [ + - + + ]: 260 : if (p && *p)
181 : : {
182 [ + - ]: 204 : if (isupper(UCINT * p))
183 : : {
184 : 204 : szEl[i++] = *p++;
185 [ + + + + ]: 204 : if (*p && islower(UCINT * p))
186 : : {
187 : 52 : szEl[i++] = *p++;
188 : : }
189 : 204 : szEl[i] = '\0';
190 [ + + + + ]: 204 : if (1 == i && szEl[0] == 'C')
191 : : {
192 : 62 : szEl[0] = 'A'; /* less than any element: */
193 : : /* carbon-containing compounds should be first */
194 : : }
195 [ + + + + ]: 204 : if (*p && isdigit(UCINT * p))
196 : : {
197 : 110 : *count = strtol(p, &q, 10);
198 : 110 : p = q;
199 : : }
200 : : else
201 : : {
202 : 94 : *count = 1;
203 : : }
204 : 204 : *f = p; /* next element; */
205 : 204 : return 1;
206 : : }
207 : 0 : return -1; /* not a chemical formula */
208 : : }
209 : : /* v. 1.06 Changed "Zz" to "Zzz" as "Zz" is valid symbol now */
210 : 56 : strcpy(szEl, "Zzz");
211 : : /*strcpy( szEl, "Zz" );*/
212 : : /* zero termination 'element' is larger than any other element */
213 : 56 : *count = 99999; /* zero termination 'element count' is larger than any other count */
214 : 56 : return 0;
215 : : }
216 : :
217 : :
218 : : /*
219 : : CompareHillFormulas( ... )
220 : :
221 : : E1 < E2 if strcmp( E1, E2) < 0 OR E2 is empty and E1 is not
222 : : n1 < n2 if value n1 > n2
223 : :
224 : : Sorting order:
225 : :
226 : : C10H22N
227 : : C10H22
228 : : C2
229 : : Ag2Cl2
230 : : Ag2Cl
231 : : Ag2F2
232 : : Ag2
233 : : AgCl
234 : : AgF
235 : : F6S
236 : : F2S
237 : : */
238 : :
239 : :
240 : : /****************************************************************************/
241 : 0 : int CompareHillFormulas(const char* f1, const char* f2)
242 : : {
243 : : char szEl1[4], szEl2[4];
244 : : int count1, count2, ret1, ret2, ret;
245 : :
246 : : do
247 : : {
248 : 0 : ret1 = GetElementAndCount(&f1, szEl1, &count1);
249 : 0 : ret2 = GetElementAndCount(&f2, szEl2, &count2);
250 [ # # # # ]: 0 : if (0 <= ret1 && 0 <= ret2)
251 : : {
252 [ # # ]: 0 : if ((ret = strcmp(szEl1, szEl2))) /* djb-rwth: addressing LLVM warning */
253 : : {
254 : 0 : return ret; /* lexicographic order, string termination > any character */
255 : : }
256 [ # # ]: 0 : if ((ret = count2 - count1)) /* djb-rwth: addressing LLVM warning */
257 : : {
258 : 0 : return ret; /* inverse atom count order */
259 : : }
260 : : }
261 : : else
262 : : {
263 : 0 : return 0; /* program error <BRKPT> */
264 : : }
265 [ # # # # ]: 0 : } while (0 < ret1 && 0 < ret2);
266 : :
267 : 0 : return 0;
268 : : }
269 : :
270 : :
271 : : /****************************************************************************/
272 : 46 : int CompareHillFormulasNoH(const char* f1,
273 : : const char* f2,
274 : : int* num_H1,
275 : : int* num_H2)
276 : : {
277 : : char szEl1[4], szEl2[4];
278 : : int count1, count2, ret1, ret2, ret;
279 : :
280 : : do
281 : : {
282 : 102 : ret1 = GetElementAndCount(&f1, szEl1, &count1);
283 [ + + + + : 102 : if (0 < ret1 && szEl1[0] == 'H' && !szEl1[1])
+ - ]
284 : : {
285 : 28 : *num_H1 += count1;
286 : 28 : ret1 = GetElementAndCount(&f1, szEl1, &count1);
287 : : }
288 : 102 : ret2 = GetElementAndCount(&f2, szEl2, &count2);
289 [ + + + + : 102 : if (0 < ret2 && szEl2[0] == 'H' && !szEl2[1])
+ - ]
290 : : {
291 : 28 : *num_H2 += count2;
292 : 28 : ret2 = GetElementAndCount(&f2, szEl2, &count2);
293 : : }
294 [ + - + - ]: 102 : if (0 <= ret1 && 0 <= ret2)
295 : : {
296 [ + + ]: 102 : if ((ret = strcmp(szEl1, szEl2))) /* djb-rwth: addressing LLVM warning */
297 : : {
298 : 4 : return ret; /* lexicographic order, string termination > any character */
299 : : }
300 [ + + ]: 98 : if ((ret = count2 - count1)) /* djb-rwth: addressing LLVM warning */
301 : : {
302 : 14 : return ret; /* inverse atom count order */
303 : : }
304 : : }
305 : : else
306 : : {
307 : 0 : return 0; /* program error <BRKPT> */
308 : : }
309 [ + + + - ]: 84 : } while (0 < ret1 && 0 < ret2);
310 : :
311 : 28 : return 0;
312 : : }
313 : :
314 : :
315 : : /****************************************************************************/
316 : 36 : int CompareTautNonIsoPartOfINChI(const INChI* i1, const INChI* i2)
317 : : {
318 : : int len1, len2, ret, i;
319 : :
320 [ + + - + ]: 36 : len1 = i1->lenTautomer > 0 && i1->nTautomer[0] ? i1->lenTautomer : 0;
321 [ + + - + ]: 36 : len2 = i2->lenTautomer > 0 && i2->nTautomer[0] ? i2->lenTautomer : 0;
322 [ - + ]: 36 : if ((ret = len2 - len1)) /* djb-rwth: addressing LLVM warning */
323 : : {
324 : 0 : return ret;
325 : : }
326 [ - + ]: 36 : for (i = 0; i < len1; i++)
327 : : {
328 [ # # ]: 0 : if ((ret = (int)i2->nTautomer[i] - (int)i1->nTautomer[i])) /* djb-rwth: addressing LLVM warning */
329 : 0 : return ret;
330 : : }
331 : 36 : return 0;
332 : : }
333 : :
334 : :
335 : : /****************************************************************************
336 : : CompINChITautVsNonTaut( ... )
337 : :
338 : : Sorting in descending order:
339 : : return -1 if *p1 > *p2, return +1 if *p1 < *p2
340 : : ****************************************************************************/
341 : 69 : int CompINChITautVsNonTaut(const INCHI_SORT* p1,
342 : : const INCHI_SORT* p2,
343 : : int bCompareIsotopic)
344 : : {
345 : : int ret, num, i, num_H1, num_H2;
346 : :
347 : 69 : const INChI* i1 = NULL; /* Mobile-H layers in Mobile-H sorting order */
348 : 69 : const INChI* i2 = NULL; /* Fixed-H layers in Fixed-H sorting order */
349 : :
350 : : int n1; /* TAUT_YES if tautomeric i1 exists, otherwise TAUT_NON */
351 : :
352 : : /* INChI_Stereo *Stereo1, *Stereo2; */
353 : :
354 [ + - + - ]: 69 : n1 = (p1->pINChI[TAUT_YES] && p1->pINChI[TAUT_YES]->nNumberOfAtoms) ? TAUT_YES : TAUT_NON;
355 : :
356 : 69 : i1 = p1->pINChI[n1];
357 [ - + ]: 69 : i2 = (n1 == TAUT_YES && p2->pINChI[TAUT_NON] &&
358 [ + - - - ]: 138 : p2->pINChI[TAUT_NON]->nNumberOfAtoms) ? p2->pINChI[TAUT_NON] : (const INChI*)NULL;
359 : :
360 : : /* non-deleted-non-empty < deleted < empty */
361 [ + - + - ]: 69 : if (i1 && !i2)
362 : 69 : return 0; /* non-empty is the smallest (first) */
363 [ # # # # ]: 0 : if (!i1 && i2)
364 : 0 : return 0;
365 [ # # # # ]: 0 : if (!i1 && !i2)
366 : 0 : return 0;
367 [ # # ]: 0 : if (i1->bDeleted)
368 : 0 : return 1; /* deleted is the largest (last) among non-empty */
369 [ # # ]: 0 : if (i2->bDeleted)
370 : 0 : return -1;
371 : :
372 [ # # # # ]: 0 : if (i1->nNumberOfAtoms > 0 && !i2->nNumberOfAtoms)
373 : 0 : return 0;
374 : :
375 : : /* i2 = i2; djb-rwth: an obviously useless statement */
376 : :
377 : 0 : num_H1 = num_H2 = 0;
378 : :
379 : : /* do not compare terminal H */
380 [ # # ]: 0 : if ((ret = CompareHillFormulasNoH(i1->szHillFormula, i2->szHillFormula, &num_H1, &num_H2))) /* djb-rwth: addressing LLVM warning */
381 : : {
382 : 0 : return ret; /* lexicographic order except the shorter one is greater (last): CH2O < CH2; C3XX < C2XX */
383 : : }
384 : :
385 : : /*
386 : : compare non-isotopic non-tautomeric part
387 : : */
388 : :
389 : : /* compare number of atoms (excluding terminal H) */
390 [ # # ]: 0 : if ((ret = i2->nNumberOfAtoms - i1->nNumberOfAtoms)) /* djb-rwth: addressing LLVM warning */
391 : 0 : return ret; /* more atoms first */
392 : :
393 : : /* compare elements (excluding terminal H) */
394 : 0 : num = i1->nNumberOfAtoms;
395 [ # # ]: 0 : for (i = 0; i < num; i++)
396 : : { /* should always be equal if Hill formulas are same */
397 [ # # ]: 0 : if ((ret = (int)i2->nAtom[i] - (int)i1->nAtom[i])) /* djb-rwth: addressing LLVM warning */
398 : 0 : return ret; /* greater periodic number first */
399 : : }
400 : : /*
401 : : compare connection tables
402 : : */
403 [ # # ]: 0 : if ((ret = i2->lenConnTable - i1->lenConnTable)) /* djb-rwth: addressing LLVM warning */
404 : 0 : return ret; /* longer connection table first */
405 : 0 : num = i2->lenConnTable;
406 [ # # ]: 0 : for (i = 0; i < num; i++)
407 : : {
408 [ # # ]: 0 : if ((ret = (int)i2->nConnTable[i] - (int)i1->nConnTable[i])) /* djb-rwth: addressing LLVM warning */
409 : 0 : return ret; /* greater connection table first */
410 : : }
411 : : /*
412 : : compare total number of H (inverse: H3 < H2 )
413 : : */
414 [ # # ]: 0 : if ((ret = num_H2 - num_H1)) /* djb-rwth: addressing LLVM warning */
415 : 0 : return ret;
416 : : /*
417 : : compare non-tautomeric num_H: N < NH3 < NH2 < NH
418 : : */
419 : 0 : num = i1->nNumberOfAtoms;
420 [ # # ]: 0 : for (i = 0; i < num; i++)
421 : : {
422 [ # # ]: 0 : if (i2->nNum_H[i] != i1->nNum_H[i])
423 : : {
424 [ # # ]: 0 : return !i2->nNum_H[i] ? 1 : /* no H first */
425 [ # # ]: 0 : !i1->nNum_H[i] ? -1 :
426 : 0 : (int)i2->nNum_H[i] - (int)i1->nNum_H[i];
427 : : }
428 : : }
429 : : /*
430 : : compare non-isotopic tautomeric part
431 : : */
432 [ # # ]: 0 : if ((ret = CompareTautNonIsoPartOfINChI(i1, i2))) /* djb-rwth: addressing LLVM warning */
433 : : {
434 : 0 : return ret;
435 : : }
436 : : /*
437 : : if ( ret = i2->lenTautomer - i1->lenTautomer )
438 : : return ret;
439 : : num = inchi_min( i2->lenTautomer, i1->lenTautomer );
440 : : for ( i = 0; i < num; i ++ ) {
441 : : if ( ret = (int)i2->nTautomer[i] - (int)i1->nTautomer[i] )
442 : : return ret;
443 : : }
444 : : */
445 : :
446 : : /*
447 : : at this point both components are either tautomeric
448 : : or non-tautomeric
449 : : */
450 : :
451 : : /*
452 : : non-tautomeric "fixed H" specific
453 : : */
454 [ # # ]: 0 : if ( /*TAUT_NON == bTaut && (i2 &&*/ i2->nNum_H_fixed) /* djb-rwth: fixing coverity ID #499493 */
455 : : {
456 : : /* first, compare non-tautomeric chem. formulas -- they may be different */
457 : : /* secondly, compare fixed-H distribution */
458 [ # # ]: 0 : if (i2->nNum_H_fixed)
459 : : {
460 : 0 : num = i2->nNumberOfAtoms;
461 [ # # ]: 0 : for (i = 0; i < num; i++)
462 : : {
463 [ # # ]: 0 : if (i2->nNum_H_fixed[i] != 0)
464 : : {
465 : 0 : return 1;
466 : : }
467 : : }
468 : : }
469 : : }
470 : : /*
471 : : compare non-isotopic stereo
472 : : */
473 : 0 : ret = CompareInchiStereo(i1->Stereo, i1->nFlags, i2->Stereo, i2->nFlags);
474 [ # # ]: 0 : if (ret)
475 : : {
476 : 0 : return ret;
477 : : }
478 : :
479 : : /*
480 : : do not switch back to tautomeric i1, i2
481 : : */
482 : :
483 : : /* -- how to switch back --
484 : : if ( i1t ) {
485 : : i1 = i1t;
486 : : i1t = NULL;
487 : : }
488 : : if ( i2t ) {
489 : : i2 = i2t;
490 : : i2t = NULL;
491 : : }
492 : : */
493 : :
494 : : /*
495 : : compare isotopic non-tautomeric part
496 : : */
497 [ # # ]: 0 : if (bCompareIsotopic)
498 : : {
499 [ # # ]: 0 : if ((ret = i2->nNumberOfIsotopicAtoms - i1->nNumberOfIsotopicAtoms)) /* djb-rwth: addressing LLVM warning */
500 : 0 : return ret;
501 : 0 : num = i1->nNumberOfIsotopicAtoms;
502 : :
503 : : /* compare isotopic atoms */
504 [ # # ]: 0 : for (i = 0; i < num; i++)
505 : : {
506 [ # # ]: 0 : if ((ret = (int)i2->IsotopicAtom[i].nAtomNumber - (int)i1->IsotopicAtom[i].nAtomNumber)) /* djb-rwth: addressing LLVM warning */
507 : 0 : return ret;
508 [ # # ]: 0 : if ((ret = (int)i2->IsotopicAtom[i].nIsoDifference - (int)i1->IsotopicAtom[i].nIsoDifference)) /* djb-rwth: addressing LLVM warning */
509 : 0 : return ret;
510 : : }
511 : :
512 : : /* compare isotopic H */
513 : : /* if tautomeric comparison mode then here are compared only non-tautomeric H */
514 [ # # ]: 0 : for (i = 0; i < num; i++)
515 : : {
516 [ # # ]: 0 : if ((ret = (int)i2->IsotopicAtom[i].nNum_T - (int)i1->IsotopicAtom[i].nNum_T)) /* djb-rwth: addressing LLVM warning */
517 : 0 : return ret;
518 [ # # ]: 0 : if ((ret = (int)i2->IsotopicAtom[i].nNum_D - (int)i1->IsotopicAtom[i].nNum_D)) /* djb-rwth: addressing LLVM warning */
519 : 0 : return ret;
520 [ # # ]: 0 : if ((ret = (int)i2->IsotopicAtom[i].nNum_H - (int)i1->IsotopicAtom[i].nNum_H)) /* djb-rwth: addressing LLVM warning */
521 : 0 : return ret;
522 : : }
523 : :
524 : : /* compare isotopic tautomeric part */
525 [ # # # # : 0 : if ((ret = i2->nNumberOfIsotopicTGroups || i1->nNumberOfIsotopicTGroups)) /* djb-rwth: addressing LLVM warning */
# # ]
526 : 0 : return ret;
527 : :
528 : : /*
529 : : num = i1->nNumberOfIsotopicTGroups;
530 : : for ( i = 0; i < num; i ++ ) {
531 : : if ( ret = (int)i2->IsotopicTGroup[i].nTGroupNumber - (int)i1->IsotopicTGroup[i].nTGroupNumber )
532 : : return ret;
533 : : if ( ret = (int)i2->IsotopicTGroup[i].nNum_T - (int)i1->IsotopicTGroup[i].nNum_T )
534 : : return ret;
535 : : if ( ret = (int)i2->IsotopicTGroup[i].nNum_D - (int)i1->IsotopicTGroup[i].nNum_D )
536 : : return ret;
537 : : if ( ret = (int)i2->IsotopicTGroup[i].nNum_H - (int)i1->IsotopicTGroup[i].nNum_H )
538 : : return ret;
539 : : }
540 : : */
541 : :
542 : : /* compare isotopic stereo */
543 : 0 : ret = CompareInchiStereo(i1->StereoIsotopic, i1->nFlags,
544 : 0 : i2->StereoIsotopic, i2->nFlags);
545 [ # # ]: 0 : if (ret)
546 : : {
547 : 0 : return ret;
548 : : }
549 : : }
550 : :
551 : : /*
552 : : compare charges: non-charged first, then in order of
553 : : ascending charges (negative first)
554 : : */
555 : :
556 [ # # # # ]: 0 : if (i2->nTotalCharge && i1->nTotalCharge)
557 : : {
558 : : /* both are charged; smaller charges first */
559 : 0 : ret = (int)i1->nTotalCharge - (int)i2->nTotalCharge;
560 : 0 : return ret;
561 : : }
562 [ # # ]: 0 : if ((ret = (i1->nTotalCharge ? 1 : 0) - (i2->nTotalCharge ? 1 : 0))) /* djb-rwth: addressing LLVM warning */
563 : : {
564 : : /* only one is charged; uncharged first */
565 : 0 : return ret;
566 : : }
567 : : /* stable sort */
568 : : /*ret = p1->ord_number - p2->ord_number;*/
569 : :
570 : 0 : return ret;
571 : : }
572 : :
573 : : /*
574 : : Stereo
575 : : */
576 : :
577 : :
578 : : /****************************************************************************/
579 : : typedef enum tagSp3StereoTypeTmp
580 : : {
581 : : SP3_NONE = 0, /* no sp3 stereo: no /t, /m, /s segments */
582 : : /* /t is present: */
583 : : SP3_ONLY = 1, /* no /s or /m segment: inversion leaves the structure unchanged */
584 : : SP3_ABS = 2, /* abs stereo: both /m and /s are present */
585 : : SP3_REL = 4, /* rel stereo: /s is present, /m is not */
586 : : SP3_RAC = 8, /* racemic stereo: /s is presen, /m is nott */
587 : : SP3_TYPE = (SP3_ABS | SP3_REL | SP3_RAC), /* bitmap for checking the presence of /m */
588 : : SP3_ANY = (SP3_ABS | SP3_REL | SP3_RAC | SP3_ONLY) /* bitmap for checking the presence of /t */
589 : : } SP3_TYPE_TMP;
590 : :
591 : :
592 : : /****************************************************************************/
593 : 276 : int GetSp3RelRacAbs(const INChI* pINChI, INChI_Stereo* Stereo)
594 : : {
595 : 276 : int nRet = SP3_NONE;
596 [ + + + - : 276 : if (pINChI && !pINChI->bDeleted && Stereo && 0 < Stereo->nNumberOfStereoCenters)
+ + + + ]
597 : : {
598 [ + - ]: 51 : if (0 != Stereo->nCompInv2Abs)
599 : : {
600 [ - + ]: 51 : if (pINChI->nFlags & INCHI_FLAG_REL_STEREO)
601 : : {
602 : : #if ( REL_RAC_STEREO_IGN_1_SC == 1 )
603 : : if (1 < Stereo->nNumberOfStereoCenters)
604 : : {
605 : : nRet = SP3_REL;
606 : : }
607 : : #else
608 : 0 : nRet = SP3_REL;
609 : : #endif
610 : : }
611 [ - + ]: 51 : else if (pINChI->nFlags & INCHI_FLAG_RAC_STEREO)
612 : : {
613 : : #if ( REL_RAC_STEREO_IGN_1_SC == 1 )
614 : : if (1 < Stereo->nNumberOfStereoCenters)
615 : : {
616 : : nRet = SP3_REL;
617 : : }
618 : : #else
619 : 0 : nRet = SP3_RAC;
620 : : #endif
621 : : }
622 : : else
623 : : {
624 : 51 : nRet = SP3_ABS;
625 : : }
626 : : }
627 : : else
628 : : #if ( REL_RAC_STEREO_IGN_1_SC == 1 )
629 : : if (!((pINChI->nFlags & (INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO)) && 1 == Stereo->nNumberOfStereoCenters))
630 : : #endif
631 : : {
632 : 0 : nRet = SP3_ONLY; /* SP3_NONE if relative stereo and 1 stereocenter */
633 : : }
634 : : }
635 : 276 : return nRet;
636 : : }
637 : :
638 : :
639 : : /****************************************************************************
640 : : CompINChILayers( ... )
641 : :
642 : : Sorting in descending order: return -1 if *p1 > *p2, return +1 if *p1 < *p2
643 : : ****************************************************************************/
644 : 69 : int CompINChILayers(const INCHI_SORT* p1,
645 : : const INCHI_SORT* p2,
646 : : char sDifSegs[][DIFS_LENGTH],
647 : : int bFixTranspChargeBug)
648 : : {
649 : 69 : int ret = 0, num, i, num_H1, num_H2;
650 : :
651 : 69 : const INChI* i1 = NULL; /* Mobile-H layers in Mobile-H sorting order */
652 : 69 : const INChI* i2 = NULL; /* Fixed-H layers in Fixed-H sorting order */
653 : :
654 : : int n1; /* TAUT_YES if tautomeric i1 exists, otherwise TAUT_NON */
655 : :
656 : : INChI_Stereo* Stereo1, * Stereo2;
657 : : INChI_Stereo* IsoStereo1, * IsoStereo2;
658 : : int bRelRac[DIFL_LENGTH];
659 : : char* psDifSegs;
660 : :
661 [ + - + - ]: 69 : n1 = (p1->pINChI[TAUT_YES] && p1->pINChI[TAUT_YES]->nNumberOfAtoms) ? TAUT_YES : TAUT_NON;
662 : :
663 : 69 : i1 = p1->pINChI[n1];
664 [ - + ]: 69 : i2 = (n1 == TAUT_YES && p2->pINChI[TAUT_NON] &&
665 [ + - - - ]: 138 : p2->pINChI[TAUT_NON]->nNumberOfAtoms) ? p2->pINChI[TAUT_NON] : (const INChI*)NULL;
666 : :
667 : 69 : num_H1 = num_H2 = 0;
668 : 69 : memset(bRelRac, DIFV_BOTH_EMPTY, sizeof(bRelRac)); /* djb-rwth: memset_s C11/Annex K variant? */
669 : : /*=====================*/
670 : : /*==== /f ======*/
671 : : /*=====================*/
672 [ + - + - : 69 : if (i1 && !i1->bDeleted && i1->szHillFormula && i1->szHillFormula[0])
+ - + - ]
673 : : {
674 : 69 : sDifSegs[DIFL_M][DIFS_f_FORMULA] |= DIFV_NEQ2PRECED;
675 [ - + - - : 69 : if (i2 && !i2->bDeleted && i2->szHillFormula && i2->szHillFormula[0])
- - - - ]
676 : : {
677 [ # # ]: 0 : if (!CompareHillFormulasNoH(i1->szHillFormula, i2->szHillFormula, &num_H1, &num_H2) &&
678 [ # # ]: 0 : num_H1 == num_H2)
679 : : {
680 : 0 : sDifSegs[DIFL_F][DIFS_f_FORMULA] |= DIFV_EQL2PRECED;
681 : : }
682 : : else
683 : : {
684 : 0 : sDifSegs[DIFL_F][DIFS_f_FORMULA] |= DIFV_NEQ2PRECED;
685 : : }
686 : : }
687 : : else
688 : : {
689 [ - + ]: 69 : sDifSegs[DIFL_F][DIFS_f_FORMULA] |= i2 ? DIFV_IS_EMPTY : DIFV_EQL2PRECED;
690 : : }
691 : : }
692 : : else
693 : : {
694 : 0 : sDifSegs[DIFL_M][DIFS_f_FORMULA] |= DIFV_BOTH_EMPTY;
695 [ # # # # : 0 : if (i2 && !i2->bDeleted && i2->szHillFormula && i2->szHillFormula[0])
# # # # ]
696 : : {
697 : 0 : sDifSegs[DIFL_F][DIFS_f_FORMULA] |= DIFV_NEQ2PRECED;
698 : : }
699 : : else
700 : : {
701 : 0 : sDifSegs[DIFL_F][DIFS_f_FORMULA] |= DIFV_BOTH_EMPTY;
702 : : }
703 : : }
704 : : /*=====================*/
705 : : /*==== /c ======*/
706 : : /*=====================*/
707 [ + - + - : 69 : if (i1 && !i1->bDeleted && i1->lenConnTable > 1)
+ + ]
708 : : {
709 : 64 : sDifSegs[DIFL_M][DIFS_f_FORMULA] |= DIFV_NEQ2PRECED;
710 : : }
711 : : else
712 : : {
713 : 5 : sDifSegs[DIFL_M][DIFS_f_FORMULA] |= DIFV_BOTH_EMPTY;
714 : : }
715 : : /*=====================*/
716 : : /*==== /h ======*/
717 : : /*=====================*/
718 : : /* M: H atoms */
719 [ + - + - ]: 69 : if (i1 && !i1->bDeleted)
720 : : {
721 [ + + + - : 69 : num_H1 = (i1->lenTautomer > 0 && i1->nTautomer && i1->nTautomer[0]) ? 1 : 0; /* number of t-groups */
- + ]
722 [ + - + - ]: 69 : if (!num_H1 && i1->nNum_H)
723 : : {
724 [ + + ]: 85 : for (i = 0; i < i1->nNumberOfAtoms; i++)
725 : : { /* immobile H */
726 [ + + ]: 80 : if (i1->nNum_H[i])
727 : : {
728 : 64 : num_H1 = 1;
729 : 64 : break;
730 : : }
731 : : }
732 : : }
733 [ + + ]: 69 : sDifSegs[DIFL_M][DIFS_h_H_ATOMS] |= num_H1 ? DIFV_NEQ2PRECED : DIFV_BOTH_EMPTY;
734 : : }
735 : : else
736 : : {
737 : 0 : sDifSegs[DIFL_M][DIFS_h_H_ATOMS] |= DIFV_BOTH_EMPTY;
738 : : }
739 : : /* F: fixed mobile H */
740 [ - + - - : 69 : if (i2 && !i2->bDeleted && i2->nNum_H_fixed)
- - ]
741 : : {
742 : 0 : num_H2 = 0;
743 [ # # # # ]: 0 : if (i1 && !i1->bDeleted)
744 : : {
745 [ # # ]: 0 : for (i = 0; i < i1->nNumberOfAtoms; i++)
746 : : {
747 [ # # ]: 0 : if (i2->nNum_H_fixed[i])
748 : : {
749 : 0 : num_H2 = 1;
750 : 0 : break;
751 : : }
752 : : }
753 : : }
754 [ # # ]: 0 : sDifSegs[DIFL_F][DIFS_h_H_ATOMS] |= num_H2 ? DIFV_NEQ2PRECED : DIFV_BOTH_EMPTY;
755 : : }
756 : : else
757 : : {
758 : 69 : sDifSegs[DIFL_F][DIFS_h_H_ATOMS] |= DIFV_BOTH_EMPTY;
759 : : }
760 : : /* MI: exchangable isotopic H: see OutputINChI1(), num_iso_H[] */
761 : :
762 : : /*=====================*/
763 : : /*==== /q ======*/
764 : : /*=====================*/
765 : 69 : psDifSegs = &sDifSegs[DIFL_F][DIFS_q_CHARGE];
766 [ + - + - ]: 69 : if (i1 && !i1->bDeleted)
767 : : {
768 [ + + ]: 69 : if (i1->nTotalCharge)
769 : : {
770 : 4 : sDifSegs[DIFL_M][DIFS_q_CHARGE] |= DIFV_NEQ2PRECED;
771 : : }
772 : : else
773 : : {
774 : 65 : sDifSegs[DIFL_M][DIFS_q_CHARGE] |= DIFV_BOTH_EMPTY;
775 : : }
776 [ - + - - ]: 69 : if (i2 && !i2->bDeleted)
777 : : {
778 [ # # ]: 0 : if (i1->nTotalCharge)
779 : : {
780 [ # # ]: 0 : if (i1->nTotalCharge == i2->nTotalCharge)
781 : : {
782 : 0 : *psDifSegs |= DIFV_EQL2PRECED;
783 : : }
784 : : else
785 : : {
786 [ # # ]: 0 : if (i2->nTotalCharge)
787 : : {
788 : 0 : *psDifSegs |= DIFV_NEQ2PRECED;
789 : : }
790 : : else
791 : : {
792 : 0 : *psDifSegs |= DIFV_IS_EMPTY;
793 : : }
794 : : }
795 : : }
796 : : else
797 : : {
798 [ # # ]: 0 : if (i2->nTotalCharge)
799 : : {
800 : 0 : *psDifSegs |= DIFV_NEQ2PRECED;
801 : : }
802 : : else
803 : : {
804 : 0 : *psDifSegs |= DIFV_BOTH_EMPTY;
805 : : }
806 : : }
807 : : }
808 : : else
809 : : {
810 [ + - ]: 69 : if (!i2)
811 : : {
812 [ + - ]: 69 : if (bFixTranspChargeBug == 1)
813 : : {
814 : : /* bug explanation:
815 : :
816 : : component #1 is tautomeric, component #2 is not
817 : : Mobile-H(#2) > Mobile-H(#1)
818 : : Fixed-H(#2) = Mobile-H(#2) < Fixed-H(#1)
819 : :
820 : : Layer first_charge second_charge
821 : :
822 : : Mobile-H 0 (comp#1) -1 (comp#2)
823 : : Fixed-H none (comp#2) -1 (comp#1)
824 : :
825 : : v1.01 charge compared decided that charge layers are same and omitted Fixed-H /q layer
826 : :
827 : : Solution: when component permutation is detected AND fixed-H component does not exist,
828 : : compare Mobile-H charge [0 (comp#1) in the example] to the charge of Mobile-H [-1 (comp#2)]
829 : : of the component that has none Fixed-H charge
830 : : */
831 : :
832 : : /* Fixed-H i2 is empty because Fixed-H struct is same as Mobile-H */
833 [ - + - - ]: 69 : if (p1->ord_number != p2->ord_number && /* component order in Fixed-H is different from Mobile-H */
834 [ # # # # ]: 0 : n1 == TAUT_YES && p2->pINChI[TAUT_YES] && !p2->pINChI[TAUT_YES]->bDeleted &&
835 [ # # ]: 0 : p2->pINChI[TAUT_YES]->nNumberOfAtoms)
836 : 0 : {
837 : 0 : int i2_nTotalCharge = p2->pINChI[TAUT_YES]->nTotalCharge;
838 : :
839 [ # # ]: 0 : if (i1->nTotalCharge)
840 : : {
841 [ # # ]: 0 : if (i1->nTotalCharge == i2_nTotalCharge)
842 : : {
843 : 0 : *psDifSegs |= DIFV_EQL2PRECED;
844 : : }
845 : : else
846 : : {
847 [ # # ]: 0 : if (i2_nTotalCharge)
848 : : {
849 : 0 : *psDifSegs |= DIFV_NEQ2PRECED;
850 : : }
851 : : else
852 : : {
853 : 0 : *psDifSegs |= DIFV_IS_EMPTY;
854 : : }
855 : : }
856 : : }
857 : : else
858 : : {
859 [ # # ]: 0 : if (i2_nTotalCharge)
860 : : {
861 : 0 : *psDifSegs |= DIFV_NEQ2PRECED;
862 : : }
863 : : else
864 : : {
865 : 0 : *psDifSegs |= DIFV_BOTH_EMPTY;
866 : : }
867 : : }
868 : : }
869 : : else
870 : : {
871 : 69 : *psDifSegs |= i1->nTotalCharge ? DIFV_EQL2PRECED : DIFV_BOTH_EMPTY;
872 : : }
873 : : }
874 : : else /* if (bFixTranspChargeBug==1) */
875 : : {
876 : 0 : *psDifSegs |= i1->nTotalCharge ? DIFV_EQL2PRECED : DIFV_BOTH_EMPTY;
877 : : }
878 : : }
879 : : else /* if ( !i2 ) { */
880 : : {
881 : : /* i2 && i2->bDeleted */
882 [ # # ]: 0 : *psDifSegs |= i1->nTotalCharge ? DIFV_IS_EMPTY : DIFV_BOTH_EMPTY;
883 : : }
884 : : }
885 : : }
886 : : else
887 : : {
888 : 0 : sDifSegs[DIFL_M][DIFS_q_CHARGE] |= DIFV_BOTH_EMPTY;
889 [ # # # # ]: 0 : if (i2 && !i2->bDeleted)
890 : : {
891 [ # # ]: 0 : if (i2->nTotalCharge)
892 : : {
893 : 0 : sDifSegs[DIFL_F][DIFS_q_CHARGE] |= DIFV_NEQ2PRECED;
894 : : }
895 : : else
896 : : {
897 : 0 : sDifSegs[DIFL_F][DIFS_q_CHARGE] |= DIFV_BOTH_EMPTY;
898 : : }
899 : : }
900 : : }
901 : :
902 : :
903 : : /*************** stereo *****************/
904 : :
905 [ + - + - ]: 69 : if (i1 && !i1->bDeleted)
906 : : {
907 : 69 : Stereo1 = i1->Stereo;
908 : 69 : IsoStereo1 = i1->StereoIsotopic;
909 : : }
910 : : else
911 : : {
912 : 0 : Stereo1 = NULL;
913 : 0 : IsoStereo1 = NULL;
914 : : }
915 [ - + - - ]: 69 : if (i2 && !i2->bDeleted)
916 : : {
917 : 0 : Stereo2 = i2->Stereo;
918 : 0 : IsoStereo2 = i2->StereoIsotopic;
919 : : }
920 : : else
921 : : {
922 : 69 : Stereo2 = NULL;
923 : 69 : IsoStereo2 = NULL;
924 : : }
925 : :
926 : : /*=====================*/
927 : : /*==== /b ======*/
928 : : /*=====================*/
929 : : /* M double bond stereo */
930 : 69 : psDifSegs = &sDifSegs[DIFL_M][DIFS_b_SBONDS];
931 [ + - - + ]: 69 : if (Stereo1 && Stereo1->nNumberOfStereoBonds)
932 : : {
933 : 0 : *psDifSegs |= DIFV_NEQ2PRECED;
934 : : }
935 : : else
936 : : {
937 : 69 : *psDifSegs |= DIFV_BOTH_EMPTY;
938 : : }
939 : : /* F double bond stereo */
940 : 69 : psDifSegs = &sDifSegs[DIFL_F][DIFS_b_SBONDS];
941 [ - + - - ]: 69 : if (Stereo2 && Stereo2->nNumberOfStereoBonds)
942 : : {
943 [ # # # # ]: 0 : if (Stereo1 && Stereo1->nNumberOfStereoBonds)
944 : : {
945 [ # # ]: 0 : if (Eql_INChI_Stereo(Stereo1, EQL_SP2, Stereo2, EQL_SP2, 0))
946 : : {
947 : 0 : *psDifSegs |= DIFV_EQL2PRECED;
948 : : }
949 : : else
950 : : {
951 : 0 : *psDifSegs |= DIFV_NEQ2PRECED;
952 : : }
953 : : }
954 : : else
955 : : {
956 : 0 : *psDifSegs |= DIFV_NEQ2PRECED;
957 : : }
958 : : }
959 : : else
960 : : {
961 [ + - - + ]: 69 : if (Stereo1 && Stereo1->nNumberOfStereoBonds)
962 : : {
963 [ # # ]: 0 : *psDifSegs |= i2 ? DIFV_IS_EMPTY : DIFV_EQL2PRECED;
964 : : }
965 : : else
966 : : {
967 : 69 : *psDifSegs |= DIFV_BOTH_EMPTY;
968 : : }
969 : : }
970 : :
971 : : /* MI double bond stereo */
972 : 69 : psDifSegs = &sDifSegs[DIFL_MI][DIFS_b_SBONDS];
973 [ - + - - ]: 69 : if (IsoStereo1 && IsoStereo1->nNumberOfStereoBonds)
974 : : {
975 [ # # ]: 0 : if (Eql_INChI_Stereo(IsoStereo1, EQL_SP2, Stereo1, EQL_SP2, 0))
976 : : {
977 : 0 : *psDifSegs |= DIFV_EQL2PRECED;
978 : : }
979 : : else
980 : : {
981 : 0 : *psDifSegs |= DIFV_NEQ2PRECED;
982 : : }
983 : : }
984 : : else
985 : : {
986 [ + - - + ]: 69 : if (Stereo1 && Stereo1->nNumberOfStereoBonds)
987 : : {
988 : 0 : *psDifSegs |= DIFV_EQL2PRECED; /* isotopic is missing because there is no isotopes */
989 : : }
990 : : else
991 : : {
992 : 69 : *psDifSegs |= DIFV_BOTH_EMPTY;
993 : : }
994 : : }
995 : :
996 : : /* FI double bond stereo */
997 : 69 : psDifSegs = &sDifSegs[DIFL_FI][DIFS_b_SBONDS];
998 [ - + - - ]: 69 : if (IsoStereo2 && IsoStereo2->nNumberOfStereoBonds)
999 : : {
1000 [ # # ]: 0 : if (Eql_INChI_Stereo(IsoStereo2, EQL_SP2, Stereo2, EQL_SP2, 0))
1001 : : {
1002 : 0 : *psDifSegs |= DIFV_EQL2PRECED;
1003 : : }
1004 : : else
1005 : : {
1006 [ # # # # : 0 : if (!(Stereo1 && Stereo1->nNumberOfStereoBonds) &&
# # ]
1007 [ # # # # ]: 0 : !(Stereo2 && Stereo2->nNumberOfStereoBonds) &&
1008 : 0 : Eql_INChI_Stereo(IsoStereo2, EQL_SP2, IsoStereo1, EQL_SP2, 0))
1009 : : {
1010 : 0 : *psDifSegs |= DIFV_FI_EQ_MI;
1011 : : }
1012 : : else
1013 : : {
1014 : 0 : *psDifSegs |= DIFV_NEQ2PRECED;
1015 : : }
1016 : : }
1017 : : }
1018 : : else
1019 : : {
1020 : : /* the solution table for FI stereo,
1021 : : in case of FI stereo is empty
1022 : : E = segment is empty, NE = not empty
1023 : : +==============================+
1024 : : | M | MI | F | result |
1025 : : +=====+=====+=====+============+
1026 : : | E | E | E | both empty |
1027 : : +-----+-----+-----+------------+
1028 : : | NE | E | E | both empty |
1029 : : +-----+-----+-----+------------+
1030 : : | E | NE | E | is empty |
1031 : : +-----+-----+-----+------------+
1032 : : | NE | NE | E | both empty |
1033 : : +-----+-----+-----+------------+
1034 : : | E | E | NE | is empty |
1035 : : +-----+-----+-----+------------+
1036 : : | NE | E | NE | is empty |
1037 : : +-----+-----+-----+------------+
1038 : : | E | NE | NE | is empty |
1039 : : +-----+-----+-----+------------+
1040 : : | NE | NE | ME | is empty |
1041 : : +==============================+
1042 : : */
1043 [ - + - - ]: 69 : if (Stereo2 && Stereo2->nNumberOfStereoBonds)
1044 : : {
1045 : 0 : *psDifSegs |= DIFV_EQL2PRECED; /* isotopic is missing because there is no isotopes */
1046 : : }
1047 : : else
1048 [ - + - - : 69 : if (IsoStereo1 && IsoStereo1->nNumberOfStereoBonds &&
- - ]
1049 [ # # ]: 0 : !(Stereo1 && Stereo1->nNumberOfStereoBonds)
1050 : : )
1051 : : {
1052 [ # # ]: 0 : *psDifSegs |= i2 ? DIFV_IS_EMPTY : DIFV_EQL2PRECED;
1053 : : }
1054 : : else
1055 : : {
1056 : 69 : *psDifSegs |= DIFV_BOTH_EMPTY;
1057 : : }
1058 : : }
1059 : :
1060 : : /*==================================*/
1061 : : /*==== /t, /m, /s for M ======*/
1062 : : /*==================================*/
1063 : : /* M sp3 stereo */
1064 : 69 : bRelRac[DIFL_M] = GetSp3RelRacAbs(i1, Stereo1); /* Mobile-H */
1065 : 69 : bRelRac[DIFL_MI] = GetSp3RelRacAbs(i1, IsoStereo1);
1066 : 69 : bRelRac[DIFL_F] = GetSp3RelRacAbs(i2, Stereo2); /* Fixed-H */
1067 : 69 : bRelRac[DIFL_FI] = GetSp3RelRacAbs(i2, IsoStereo2);
1068 [ + + ]: 69 : if (SP3_NONE != bRelRac[DIFL_M])
1069 : : {
1070 [ + - ]: 51 : sDifSegs[DIFL_M][DIFS_t_SATOMS] |= (bRelRac[DIFL_M] & SP3_ANY) ? DIFV_NEQ2PRECED : DIFV_BOTH_EMPTY;
1071 : 51 : sDifSegs[DIFL_M][DIFS_m_SP3INV] |= (bRelRac[DIFL_M] & SP3_ABS) ? DIFV_NEQ2PRECED : DIFV_BOTH_EMPTY;
1072 [ + - ]: 51 : sDifSegs[DIFL_M][DIFS_s_STYPE] |= (bRelRac[DIFL_M] & SP3_TYPE) ? DIFV_NEQ2PRECED : DIFV_BOTH_EMPTY;
1073 : : }
1074 : : else
1075 : : {
1076 : 18 : sDifSegs[DIFL_M][DIFS_t_SATOMS] |= DIFV_BOTH_EMPTY;
1077 : 18 : sDifSegs[DIFL_M][DIFS_m_SP3INV] |= DIFV_BOTH_EMPTY;
1078 : 18 : sDifSegs[DIFL_M][DIFS_s_STYPE] |= DIFV_BOTH_EMPTY;
1079 : : }
1080 : :
1081 : : /*=====================*/
1082 : : /*==== /t ======*/
1083 : : /*=====================*/
1084 : : /* F sp3 stereo */
1085 : 69 : psDifSegs = &sDifSegs[DIFL_F][DIFS_t_SATOMS];
1086 [ - + ]: 69 : if (SP3_ANY & bRelRac[DIFL_F])
1087 : : {
1088 [ # # ]: 0 : if (Eql_INChI_Stereo(Stereo2, EQL_SP3, Stereo1, EQL_SP3, 0))
1089 : : {
1090 : 0 : *psDifSegs |= DIFV_EQL2PRECED;
1091 : : }
1092 : : else
1093 : : {
1094 : 0 : *psDifSegs |= DIFV_NEQ2PRECED;
1095 : : }
1096 : : }
1097 : : else
1098 : : {
1099 [ + + ]: 69 : if (SP3_ANY & bRelRac[DIFL_M])
1100 : : {
1101 [ - + ]: 51 : *psDifSegs |= i2 ? DIFV_IS_EMPTY : DIFV_EQL2PRECED;
1102 : : }
1103 : : else
1104 : : {
1105 : 18 : *psDifSegs |= DIFV_BOTH_EMPTY;
1106 : : }
1107 : : }
1108 : :
1109 : : /* MI sp3 stereo */
1110 : 69 : psDifSegs = &sDifSegs[DIFL_MI][DIFS_t_SATOMS];
1111 [ - + ]: 69 : if (SP3_ANY & bRelRac[DIFL_MI])
1112 : : {
1113 [ # # ]: 0 : if (Eql_INChI_Stereo(IsoStereo1, EQL_SP3, Stereo1, EQL_SP3, 0))
1114 : : {
1115 : 0 : *psDifSegs |= DIFV_EQL2PRECED;
1116 : : }
1117 : : else
1118 : : {
1119 : 0 : *psDifSegs |= DIFV_NEQ2PRECED;
1120 : : }
1121 : : }
1122 : : else
1123 : : {
1124 [ + + ]: 69 : if (SP3_ANY & bRelRac[DIFL_M])
1125 : : {
1126 : 51 : *psDifSegs |= DIFV_EQL2PRECED; /* isotopic is missing because there is no isotopes */
1127 : : }
1128 : : else
1129 : : {
1130 : 18 : *psDifSegs |= DIFV_BOTH_EMPTY;
1131 : : }
1132 : : }
1133 : :
1134 : : /* FI sp3 stereo */
1135 : 69 : psDifSegs = &sDifSegs[DIFL_FI][DIFS_t_SATOMS];
1136 [ - + ]: 69 : if (SP3_ANY & bRelRac[DIFL_FI])
1137 : : {
1138 [ # # ]: 0 : if (Eql_INChI_Stereo(IsoStereo2, EQL_SP3, Stereo2, EQL_SP3, 0))
1139 : : {
1140 : 0 : *psDifSegs |= DIFV_EQL2PRECED;
1141 : : }
1142 : : else
1143 : : {
1144 [ # # ]: 0 : if (!(SP3_ANY & bRelRac[DIFL_M]) &&
1145 [ # # # # ]: 0 : !(SP3_ANY & bRelRac[DIFL_F]) &&
1146 : 0 : Eql_INChI_Stereo(IsoStereo2, EQL_SP3, IsoStereo1, EQL_SP3, 0))
1147 : : {
1148 : 0 : *psDifSegs |= DIFV_FI_EQ_MI;
1149 : : }
1150 : : else
1151 : : {
1152 : 0 : *psDifSegs |= DIFV_NEQ2PRECED;
1153 : : }
1154 : : }
1155 : : }
1156 : : else /* similar to /b */
1157 [ - + ]: 69 : if ((SP3_ANY & bRelRac[DIFL_F]))
1158 : : {
1159 : 0 : *psDifSegs |= DIFV_EQL2PRECED; /* isotopic is missing because there is no isotopes */
1160 : : }
1161 : : else
1162 : : {
1163 [ - + - - ]: 69 : if ((SP3_ANY & bRelRac[DIFL_MI]) && !(SP3_ANY & bRelRac[DIFL_M]))
1164 : : {
1165 [ # # ]: 0 : *psDifSegs |= i2 ? DIFV_IS_EMPTY : DIFV_EQL2PRECED;
1166 : : }
1167 : : else
1168 : : {
1169 : 69 : *psDifSegs |= DIFV_BOTH_EMPTY;
1170 : : }
1171 : : }
1172 : :
1173 : : /*=====================*/
1174 : : /*==== /m ======*/
1175 : : /*=====================*/
1176 : : /* F sp3 abs stereo inversion */
1177 : 69 : psDifSegs = &sDifSegs[DIFL_F][DIFS_m_SP3INV];
1178 [ - + ]: 69 : if (bRelRac[DIFL_F] & SP3_ABS)
1179 : : {
1180 : : /* the order of || operands below is critically important: || is not a commutative operation */
1181 [ # # # # ]: 0 : if (!(bRelRac[DIFL_M] & SP3_ABS) || Stereo2->nCompInv2Abs != Stereo1->nCompInv2Abs)
1182 : : {
1183 : 0 : *psDifSegs |= DIFV_NEQ2PRECED;
1184 : : }
1185 : : else
1186 : : {
1187 : 0 : *psDifSegs |= DIFV_EQL2PRECED;
1188 : : }
1189 : : }
1190 : : else
1191 : : {
1192 [ + + ]: 69 : if (bRelRac[DIFL_M] & SP3_ABS)
1193 : : {
1194 [ - + ]: 51 : *psDifSegs |= i2 ? DIFV_IS_EMPTY : DIFV_EQL2PRECED;
1195 : : }
1196 : : else
1197 : : {
1198 : 18 : *psDifSegs |= DIFV_BOTH_EMPTY;
1199 : : }
1200 : : }
1201 : :
1202 : : /* MI sp3 abs stereo inversion */
1203 : 69 : psDifSegs = &sDifSegs[DIFL_MI][DIFS_m_SP3INV];
1204 [ - + ]: 69 : if (SP3_ABS & bRelRac[DIFL_MI])
1205 : : {
1206 [ # # # # ]: 0 : if ((SP3_ABS & bRelRac[DIFL_M]) && IsoStereo1->nCompInv2Abs == Stereo1->nCompInv2Abs)
1207 : : {
1208 : 0 : *psDifSegs |= DIFV_EQL2PRECED;
1209 : : }
1210 : : else
1211 : : {
1212 : 0 : *psDifSegs |= DIFV_NEQ2PRECED;
1213 : : }
1214 : : }
1215 : : else
1216 : : {
1217 [ + + ]: 69 : if (SP3_ABS & bRelRac[DIFL_M])
1218 : : {
1219 : 51 : *psDifSegs |= DIFV_EQL2PRECED; /* isotopic is missing because there is no isotopes */
1220 : : }
1221 : : else
1222 : : {
1223 : 18 : *psDifSegs |= DIFV_BOTH_EMPTY;
1224 : : }
1225 : : }
1226 : :
1227 : : /* FI sp3 abs stereo inversion */
1228 : 69 : psDifSegs = &sDifSegs[DIFL_FI][DIFS_m_SP3INV];
1229 [ - + ]: 69 : if (SP3_ABS & bRelRac[DIFL_FI])
1230 : : {
1231 [ # # # # ]: 0 : if ((SP3_ABS & bRelRac[DIFL_F]) && IsoStereo2->nCompInv2Abs == Stereo2->nCompInv2Abs)
1232 : : {
1233 : 0 : *psDifSegs |= DIFV_EQL2PRECED;
1234 : : }
1235 : : else
1236 : : {
1237 [ # # ]: 0 : if (!(SP3_ABS & bRelRac[DIFL_M]) &&
1238 [ # # ]: 0 : !(SP3_ABS & bRelRac[DIFL_F]) &&
1239 [ # # ]: 0 : (SP3_ABS & bRelRac[DIFL_MI]) && /* make sure IsoStereo1 != NULL */
1240 [ # # ]: 0 : IsoStereo2->nCompInv2Abs == IsoStereo1->nCompInv2Abs)
1241 : : {
1242 : 0 : *psDifSegs |= DIFV_FI_EQ_MI;
1243 : : }
1244 : : else
1245 : : {
1246 : 0 : *psDifSegs |= DIFV_NEQ2PRECED;
1247 : : }
1248 : : }
1249 : : }
1250 : :
1251 : : else
1252 : : {
1253 : : /* similar to /b */
1254 : : /* the order of || operands below is critically important: || is no a commutative operation */
1255 [ - + ]: 69 : if ((SP3_ABS & bRelRac[DIFL_F]))
1256 : : {
1257 : 0 : *psDifSegs |= DIFV_EQL2PRECED; /* isotopic is missing because there is no isotopes */
1258 : : }
1259 : : else
1260 : : {
1261 [ - + - - ]: 69 : if ((SP3_ABS & bRelRac[DIFL_MI]) && !(SP3_ABS & bRelRac[DIFL_M]))
1262 : : {
1263 [ # # ]: 0 : *psDifSegs |= i2 ? DIFV_IS_EMPTY : DIFV_EQL2PRECED;
1264 : : }
1265 : : else
1266 : : {
1267 : 69 : *psDifSegs |= DIFV_BOTH_EMPTY;
1268 : : }
1269 : : }
1270 : : }
1271 : :
1272 : : /*=====================*/
1273 : : /*==== /s ======*/
1274 : : /*=====================*/
1275 : : /* F sp3 stereo type */
1276 : 69 : psDifSegs = &sDifSegs[DIFL_F][DIFS_s_STYPE];
1277 [ - + ]: 69 : if (bRelRac[DIFL_F] & SP3_TYPE)
1278 : : {
1279 [ # # ]: 0 : if ((bRelRac[DIFL_F] & SP3_TYPE) == (bRelRac[DIFL_M] & SP3_TYPE))
1280 : : {
1281 : 0 : *psDifSegs |= DIFV_EQL2PRECED;
1282 : : }
1283 : : else
1284 : : {
1285 : 0 : *psDifSegs |= DIFV_NEQ2PRECED;
1286 : : }
1287 : : }
1288 : : else
1289 : : {
1290 [ + + ]: 69 : if (bRelRac[DIFL_M] & SP3_TYPE)
1291 : : {
1292 [ - + ]: 51 : *psDifSegs |= i2 ? DIFV_IS_EMPTY : DIFV_EQL2PRECED;
1293 : : }
1294 : : else
1295 : : {
1296 : 18 : *psDifSegs |= DIFV_BOTH_EMPTY;
1297 : : }
1298 : : }
1299 : :
1300 : : /* MI sp3 stereo type */
1301 : 69 : psDifSegs = &sDifSegs[DIFL_MI][DIFS_s_STYPE];
1302 [ - + ]: 69 : if (SP3_TYPE & bRelRac[DIFL_MI])
1303 : : {
1304 [ # # ]: 0 : if ((SP3_TYPE & bRelRac[DIFL_MI]) == (SP3_TYPE & bRelRac[DIFL_M]))
1305 : : {
1306 : 0 : *psDifSegs |= DIFV_EQL2PRECED;
1307 : : }
1308 : : else
1309 : : {
1310 : 0 : *psDifSegs |= DIFV_NEQ2PRECED;
1311 : : }
1312 : : }
1313 : : else
1314 : : {
1315 [ + + ]: 69 : if (SP3_TYPE & bRelRac[DIFL_M])
1316 : : {
1317 : 51 : *psDifSegs |= DIFV_EQL2PRECED; /* isotopic is missing because there is no isotopes */
1318 : : }
1319 : : else
1320 : : {
1321 : 18 : *psDifSegs |= DIFV_BOTH_EMPTY;
1322 : : }
1323 : : }
1324 : :
1325 : : /* FI sp3 stereo type */
1326 : 69 : psDifSegs = &sDifSegs[DIFL_FI][DIFS_s_STYPE];
1327 [ - + ]: 69 : if (SP3_TYPE & bRelRac[DIFL_FI])
1328 : : {
1329 [ # # ]: 0 : if ((SP3_TYPE & bRelRac[DIFL_FI]) == (SP3_TYPE & bRelRac[DIFL_F]))
1330 : : {
1331 : 0 : *psDifSegs |= DIFV_EQL2PRECED;
1332 : : }
1333 : : else
1334 : : {
1335 [ # # ]: 0 : if (!(SP3_TYPE & bRelRac[DIFL_M]) &&
1336 [ # # ]: 0 : !(SP3_TYPE & bRelRac[DIFL_F]) &&
1337 [ # # ]: 0 : (SP3_TYPE & bRelRac[DIFL_MI]))
1338 : : {
1339 : 0 : *psDifSegs |= DIFV_FI_EQ_MI;
1340 : : }
1341 : : else
1342 : : {
1343 : 0 : *psDifSegs |= DIFV_NEQ2PRECED;
1344 : : }
1345 : : }
1346 : : }
1347 : : else
1348 : : {
1349 : : /* similar to /b */
1350 : : /* the order of || operands below is critically important: || is not a commutative operation */
1351 [ - + ]: 69 : if ((SP3_TYPE & bRelRac[DIFL_F]))
1352 : : {
1353 : 0 : *psDifSegs |= DIFV_EQL2PRECED; /* isotopic is missing because there is no isotopes */
1354 : : }
1355 : : else
1356 : : {
1357 [ - + - - ]: 69 : if ((SP3_TYPE & bRelRac[DIFL_MI]) && !(SP3_TYPE & bRelRac[DIFL_M]))
1358 : : {
1359 [ # # ]: 0 : *psDifSegs |= i2 ? DIFV_IS_EMPTY : DIFV_EQL2PRECED;
1360 : : }
1361 : : else
1362 : : {
1363 : 69 : *psDifSegs |= DIFV_BOTH_EMPTY;
1364 : : }
1365 : : }
1366 : : }
1367 : :
1368 : : /*=====================*/
1369 : : /*==== /o ======*/
1370 : : /*=====================*/
1371 [ + - + - : 69 : if (p1 && p2 && p1->ord_number != p2->ord_number)
- + ]
1372 : : {
1373 : 0 : sDifSegs[DIFL_F][DIFS_o_TRANSP] |= DIFV_NEQ2PRECED;
1374 : : }
1375 : : /*=====================*/
1376 : : /*==== /i ======*/
1377 : : /*=====================*/
1378 : :
1379 : : /* M isotopic atoms */
1380 : 69 : psDifSegs = &sDifSegs[DIFL_MI][DIFS_i_IATOMS];
1381 [ + - + - : 69 : if (i1 && !i1->bDeleted && (i1->nNumberOfIsotopicAtoms || i1->nNumberOfIsotopicTGroups))
+ - - + ]
1382 : : {
1383 : 0 : *psDifSegs |= DIFV_NEQ2PRECED;
1384 : : }
1385 : : else
1386 : : {
1387 : 69 : *psDifSegs |= DIFV_BOTH_EMPTY;
1388 : : }
1389 : : /* F isotopic atoms */
1390 : 69 : psDifSegs = &sDifSegs[DIFL_FI][DIFS_i_IATOMS];
1391 [ - + - - ]: 69 : if (i2 && !i2->bDeleted)
1392 : : {
1393 [ # # # # ]: 0 : if (i2->nNumberOfIsotopicAtoms || i2->nNumberOfIsotopicTGroups)
1394 : : {
1395 [ # # # # ]: 0 : if (!i1 || i1->bDeleted ||
1396 [ # # ]: 0 : i2->nNumberOfIsotopicAtoms != i1->nNumberOfIsotopicAtoms ||
1397 [ # # ]: 0 : i2->nNumberOfIsotopicTGroups != i1->nNumberOfIsotopicTGroups)
1398 : : {
1399 : 0 : *psDifSegs |= DIFV_NEQ2PRECED;
1400 : : }
1401 : : else
1402 : : {
1403 : : int diff;
1404 : 0 : num = i1->nNumberOfIsotopicAtoms;
1405 : 0 : diff = 0;
1406 [ # # ]: 0 : for (i = 0; i < num; i++)
1407 : : {
1408 : : /* compare isotopic atoms */
1409 [ # # ]: 0 : if ((diff = (int)i2->IsotopicAtom[i].nAtomNumber - (int)i1->IsotopicAtom[i].nAtomNumber)) /* djb-rwth: addressing LLVM warning */
1410 : : {
1411 : 0 : break;
1412 : : }
1413 [ # # ]: 0 : if ((diff = (int)i2->IsotopicAtom[i].nIsoDifference - (int)i1->IsotopicAtom[i].nIsoDifference)) /* djb-rwth: addressing LLVM warning */
1414 : : {
1415 : 0 : break;
1416 : : }
1417 : : /* compare isotopic H */
1418 [ # # ]: 0 : if ((diff = (int)i2->IsotopicAtom[i].nNum_T - (int)i1->IsotopicAtom[i].nNum_T)) /* djb-rwth: addressing LLVM warning */
1419 : : {
1420 : 0 : break;
1421 : : }
1422 [ # # ]: 0 : if ((diff = (int)i2->IsotopicAtom[i].nNum_D - (int)i1->IsotopicAtom[i].nNum_D)) /* djb-rwth: addressing LLVM warning */
1423 : : {
1424 : 0 : break;
1425 : : }
1426 [ # # ]: 0 : if ((diff = (int)i2->IsotopicAtom[i].nNum_H - (int)i1->IsotopicAtom[i].nNum_H)) /* djb-rwth: addressing LLVM warning */
1427 : : {
1428 : 0 : break;
1429 : : }
1430 : : }
1431 [ # # ]: 0 : if (!diff)
1432 : : {
1433 : 0 : num = i1->nNumberOfIsotopicTGroups;
1434 [ # # ]: 0 : for (i = 0; i < num; i++)
1435 : : {
1436 [ # # ]: 0 : if ((diff = (int)i2->IsotopicTGroup[i].nTGroupNumber - (int)i1->IsotopicTGroup[i].nTGroupNumber)) /* djb-rwth: addressing LLVM warning */
1437 : : {
1438 : 0 : break;
1439 : : }
1440 [ # # ]: 0 : if ((diff = (int)i2->IsotopicTGroup[i].nNum_T - (int)i1->IsotopicTGroup[i].nNum_T)) /* djb-rwth: addressing LLVM warning */
1441 : : {
1442 : 0 : break;
1443 : : }
1444 [ # # ]: 0 : if ((diff = (int)i2->IsotopicTGroup[i].nNum_D - (int)i1->IsotopicTGroup[i].nNum_D)) /* djb-rwth: addressing LLVM warning */
1445 : : {
1446 : 0 : return diff;
1447 : : }
1448 [ # # ]: 0 : if ((diff = (int)i2->IsotopicTGroup[i].nNum_H - (int)i1->IsotopicTGroup[i].nNum_H)) /* djb-rwth: addressing LLVM warning */
1449 : : {
1450 : 0 : break;
1451 : : }
1452 : : }
1453 : : }
1454 [ # # ]: 0 : *psDifSegs |= diff ? DIFV_NEQ2PRECED : DIFV_FI_EQ_MI;
1455 : : }
1456 : : }
1457 : : else
1458 : : {
1459 [ # # # # : 0 : if (i1 && !i1->bDeleted && (i1->nNumberOfIsotopicAtoms || i1->nNumberOfIsotopicTGroups))
# # # # ]
1460 : : {
1461 : 0 : *psDifSegs |= DIFV_IS_EMPTY;
1462 : : }
1463 : : }
1464 : : }
1465 : : else
1466 : : {
1467 [ + - ]: 69 : if (!i2)
1468 : : {
1469 [ + - + - : 69 : if (i1 && !i1->bDeleted && (i1->nNumberOfIsotopicAtoms || i1->nNumberOfIsotopicTGroups))
+ - - + ]
1470 : : {
1471 : 0 : *psDifSegs |= DIFV_EQL2PRECED;
1472 : : }
1473 : : else
1474 : : {
1475 : 69 : *psDifSegs |= DIFV_BOTH_EMPTY;
1476 : : }
1477 : : }
1478 : : }
1479 : :
1480 : 69 : return ret;
1481 : : }
1482 : :
1483 : :
1484 : : /****************************************************************************/
1485 : 516 : int INChI_SegmentAction(char cDifSegs)
1486 : : {
1487 [ + + ]: 516 : if (!(cDifSegs & DIFV_OUTPUT_OMIT_F))
1488 : : {
1489 : 293 : return INCHI_SEGM_OMIT;
1490 : : }
1491 [ - + - - ]: 223 : if ((cDifSegs & DIFV_OUTPUT_EMPTY_T) && !(cDifSegs & DIFV_OUTPUT_EMPTY_F))
1492 : : {
1493 : 0 : return INCHI_SEGM_EMPTY;
1494 : : }
1495 [ + - ]: 223 : if ((cDifSegs & DIFV_OUTPUT_FILL_T))
1496 : : {
1497 : 223 : return INCHI_SEGM_FILL;
1498 : : }
1499 : :
1500 : 0 : return INCHI_SEGM_OMIT; /* the control flow shoul never reach this point */
1501 : : }
1502 : :
1503 : :
1504 : : /****************************************************************************
1505 : : MarkUnusedAndEmptyLayers( ... )
1506 : :
1507 : : 1. If all elements of a layer are DIFV_IS_EMPTY and/or DIFV_BOTH_EMPTY
1508 : : and/or DIFV_EQL2PRECED and/or DIFV_FI_EQ_MI
1509 : : and there is NO succeeding non-empty layer then mark the 1st element
1510 : : of the layer DIFV_BOTH_EMPTY; this layerr will be omitted.
1511 : :
1512 : : 2. If all elements of a layer are DIFV_IS_EMPTY and/or DIFV_BOTH_EMPTY
1513 : : and/or DIFV_EQL2PRECED and/or DIFV_FI_EQ_MI
1514 : : and there IS a succeeding non-empty layer then mark the 1st element
1515 : : of the layer DIFV_IS_EMPTY and all other elements DIFV_BOTH_EMPTY;
1516 : : only the first empty segment of this layerr will be output.
1517 : :
1518 : : 3. If NOT all elements of a layer are DIFV_IS_EMPTY and/or DIFV_BOTH_EMPTY
1519 : : and/or DIFV_EQL2PRECED and/or DIFV_FI_EQ_MI
1520 : : and the 1st element of the layer is DIFV_BOTH_EMPTY then mark it
1521 : : DIFV_IS_EMPTY; it will be output as empty (except M layer).
1522 : :
1523 : : ****************************************************************************/
1524 : 54 : int MarkUnusedAndEmptyLayers(char sDifSegs[][DIFS_LENGTH])
1525 : : {
1526 : : int i, nLayer, sBits, nFirstSegm;
1527 : : #define nFirstFmlSegm DIFS_f_FORMULA
1528 : : #define nFirstIsoSegm DIFS_i_IATOMS
1529 : : /* FI */
1530 : 54 : nLayer = DIFL_FI;
1531 : 54 : nFirstSegm = nFirstIsoSegm;
1532 : 54 : sBits = 0;
1533 [ + + ]: 648 : for (i = 0; i < DIFS_idf_LENGTH; i++)
1534 : : {
1535 : 594 : sBits |= sDifSegs[nLayer][i];
1536 : : }
1537 [ + - ]: 54 : if (!(sBits & DIFV_OUTPUT_OMIT_F))
1538 : : {
1539 : : /* Omit the FI layer */
1540 : 54 : memset(sDifSegs[nLayer], DIFV_BOTH_EMPTY, DIFS_idf_LENGTH); /* djb-rwth: memset_s C11/Annex K variant? */
1541 : : }
1542 : : else
1543 : : {
1544 [ # # ]: 0 : if (sDifSegs[nLayer][nFirstSegm] == DIFV_BOTH_EMPTY ||
1545 [ # # ]: 0 : !(sDifSegs[nLayer][nFirstSegm] & DIFV_OUTPUT_OMIT_F))
1546 : : {
1547 : 0 : sDifSegs[nLayer][nFirstSegm] = DIFV_IS_EMPTY;
1548 : : }
1549 : : }
1550 : :
1551 : : /* MI */
1552 : 54 : nLayer = DIFL_MI;
1553 : 54 : nFirstSegm = nFirstIsoSegm;
1554 : 54 : sBits = 0;
1555 [ + + ]: 648 : for (i = 0; i < DIFS_idf_LENGTH; i++)
1556 : : {
1557 : 594 : sBits |= sDifSegs[nLayer][i];
1558 : : }
1559 [ + - ]: 54 : if (!(sBits & DIFV_OUTPUT_OMIT_F))
1560 : : {
1561 : : /* Omit the MI layer */
1562 : 54 : memset(sDifSegs[nLayer], DIFV_BOTH_EMPTY, DIFS_idf_LENGTH); /* djb-rwth: memset_s C11/Annex K variant? */
1563 : : }
1564 : : else
1565 : : {
1566 [ # # ]: 0 : if (sDifSegs[nLayer][nFirstSegm] == DIFV_BOTH_EMPTY ||
1567 [ # # ]: 0 : !(sDifSegs[nLayer][nFirstSegm] & DIFV_OUTPUT_OMIT_F))
1568 : : {
1569 : 0 : sDifSegs[nLayer][nFirstSegm] = DIFV_IS_EMPTY;
1570 : : }
1571 : : }
1572 : :
1573 : : /* F */
1574 : 54 : nLayer = DIFL_F;
1575 : 54 : nFirstSegm = nFirstFmlSegm;
1576 : 54 : sBits = 0;
1577 [ + + ]: 648 : for (i = 0; i < DIFS_idf_LENGTH; i++)
1578 : : {
1579 : 594 : sBits |= sDifSegs[nLayer][i];
1580 : : }
1581 [ + - ]: 54 : if (!(sBits & DIFV_OUTPUT_OMIT_F) &&
1582 [ + - ]: 54 : sDifSegs[DIFL_FI][nFirstIsoSegm] == DIFV_BOTH_EMPTY)
1583 : : {
1584 : : /* Omit the F layer: no non-iotopic and no isotopic segments */
1585 : 54 : memset(sDifSegs[nLayer], DIFV_BOTH_EMPTY, DIFS_idf_LENGTH); /* djb-rwth: memset_s C11/Annex K variant? */
1586 : : }
1587 : : else
1588 : : { /* do not omit fixed-H layer */
1589 [ # # ]: 0 : if (sDifSegs[nLayer][nFirstSegm] == DIFV_BOTH_EMPTY ||
1590 [ # # ]: 0 : !(sDifSegs[nLayer][nFirstSegm] & DIFV_OUTPUT_OMIT_F))
1591 : : {
1592 : 0 : sDifSegs[nLayer][nFirstSegm] = DIFV_IS_EMPTY;
1593 : : }
1594 : : }
1595 : :
1596 : : /* M -- leave as it is */
1597 : :
1598 : 54 : return 0;
1599 : :
1600 : : #undef nFirstFmlSegm
1601 : : #undef nFirstIsoSegm
1602 : : }
1603 : :
1604 : :
1605 : : /****************************************************************************/
1606 : 48 : int CompareInchiStereo(INChI_Stereo* Stereo1,
1607 : : INCHI_MODE nFlags1,
1608 : : INChI_Stereo* Stereo2,
1609 : : INCHI_MODE nFlags2)
1610 : : {
1611 : : int i, num, ret;
1612 [ + + + - ]: 48 : if (Stereo2 && Stereo1)
1613 : : {
1614 : : /* compare stereogenic bonds */
1615 : 28 : num = inchi_min(Stereo2->nNumberOfStereoBonds, Stereo1->nNumberOfStereoBonds);
1616 [ - + ]: 28 : for (i = 0; i < num; i++)
1617 : : {
1618 [ # # ]: 0 : if ((ret = (int)Stereo2->nBondAtom1[i] - (int)Stereo1->nBondAtom1[i])) /* djb-rwth: addressing LLVM warning */
1619 : : {
1620 : 0 : return ret;
1621 : : }
1622 [ # # ]: 0 : if ((ret = (int)Stereo2->nBondAtom2[i] - (int)Stereo1->nBondAtom2[i])) /* djb-rwth: addressing LLVM warning */
1623 : : {
1624 : 0 : return ret;
1625 : : }
1626 [ # # ]: 0 : if ((ret = (int)Stereo2->b_parity[i] - (int)Stereo1->b_parity[i])) /* djb-rwth: addressing LLVM warning */
1627 : : {
1628 : 0 : return ret;
1629 : : }
1630 : : }
1631 [ - + ]: 28 : if ((ret = (int)Stereo2->nNumberOfStereoBonds - (int)Stereo1->nNumberOfStereoBonds)) /* djb-rwth: addressing LLVM warning */
1632 : : {
1633 : 0 : return ret;
1634 : : }
1635 : :
1636 : : /* compare stereogenic atoms */
1637 : : #if ( REL_RAC_STEREO_IGN_1_SC == 1 )
1638 : : if (((nFlags1 | nFlags2) & (INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO)) &&
1639 : : 1 == Stereo2->nNumberOfStereoCenters &&
1640 : : 1 == Stereo1->nNumberOfStereoCenters)
1641 : : {
1642 : : ; /* do not compare single stereocenters in case of relative stereo */
1643 : : }
1644 : : else
1645 : : #endif
1646 : : {
1647 : 28 : num = inchi_min(Stereo2->nNumberOfStereoCenters, Stereo1->nNumberOfStereoCenters);
1648 [ + + ]: 60 : for (i = 0; i < num; i++)
1649 : : {
1650 [ - + ]: 40 : if ((ret = (int)Stereo2->nNumber[i] - (int)Stereo1->nNumber[i])) /* djb-rwth: addressing LLVM warning */
1651 : : {
1652 : 0 : return ret;
1653 : : }
1654 [ + + ]: 40 : if ((ret = (int)Stereo2->t_parity[i] - (int)Stereo1->t_parity[i])) /* djb-rwth: addressing LLVM warning */
1655 : : {
1656 : 8 : return ret;
1657 : : }
1658 : : }
1659 [ - + ]: 20 : if ((ret = (int)Stereo2->nNumberOfStereoCenters - (int)Stereo1->nNumberOfStereoCenters)) /* djb-rwth: addressing LLVM warning */
1660 : 0 : return ret;
1661 : : /* compare stereo-abs-is-inverted flags for non-relative, non-racemic */
1662 [ + - ]: 20 : if (!((nFlags1 | nFlags2) & (INCHI_FLAG_RAC_STEREO | INCHI_FLAG_REL_STEREO)))
1663 : : {
1664 [ - + ]: 20 : if ((ret = (Stereo2->nCompInv2Abs < 0) - (Stereo1->nCompInv2Abs < 0))) /* djb-rwth: addressing LLVM warning */
1665 : : {
1666 : 0 : return ret;
1667 : : }
1668 : : }
1669 : : }
1670 : : }
1671 : : else
1672 : : {
1673 [ - + - - : 20 : if (Stereo2 && (Stereo2->nNumberOfStereoBonds > 0 || Stereo2->nNumberOfStereoCenters > 0
- - ]
1674 : : #if ( REL_RAC_STEREO_IGN_1_SC == 1 )
1675 : : && /* do not compare single stereocenters in case of relative stereo */
1676 : : !((nFlags2 & (INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO)) &&
1677 : : 1 == Stereo2->nNumberOfStereoCenters
1678 : : )
1679 : : #endif
1680 : : ))
1681 : : {
1682 : 0 : return 1;
1683 : : }
1684 : : else
1685 : : {
1686 [ - + - - : 20 : if (Stereo1 && (Stereo1->nNumberOfStereoBonds > 0 || Stereo1->nNumberOfStereoCenters > 0
- - ]
1687 : : #if ( REL_RAC_STEREO_IGN_1_SC == 1 )
1688 : : && /* do not compare single stereocenters in case of relative stereo */
1689 : : !((nFlags1 & (INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO)) &&
1690 : : 1 == Stereo1->nNumberOfStereoCenters
1691 : : )
1692 : : #endif
1693 : : ))
1694 : : {
1695 : 0 : return -1;
1696 : : }
1697 : : }
1698 : : }
1699 : :
1700 : 40 : return 0;
1701 : : }
1702 : :
1703 : :
1704 : : /****************************************************************************
1705 : : CompINChI2( ... )
1706 : :
1707 : : Sorting in descending order:
1708 : : return -1 if *p1 > *p2, return +1 if *p1 < *p2
1709 : :
1710 : : ****************************************************************************/
1711 : 46 : int CompINChI2(const INCHI_SORT* p1,
1712 : : const INCHI_SORT* p2,
1713 : : int bTaut,
1714 : : int bCompareIsotopic)
1715 : : {
1716 : : int ret, num, i, num_H1, num_H2;
1717 : :
1718 : 46 : const INChI* i1 = NULL; /* tautomeric if exists, otherwise non-tautomeric */
1719 : 46 : const INChI* i2 = NULL; /* tautomeric if exists, otherwise non-tautomeric */
1720 : :
1721 : : int n1; /* TAUT_YES if tautomeric i1 exists, otherwise TAUT_NON */
1722 : : int n2; /* TAUT_YES if tautomeric i2 exists, otherwise TAUT_NON */
1723 : :
1724 : 46 : const INChI* i1n = NULL; /* non-tautomeric if both tautomeric AND non-tautomeric exist */
1725 : 46 : const INChI* i2n = NULL; /* non-tautomeric if both tautomeric AND non-tautomeric exist */
1726 : :
1727 : : /*const INChI *i1t = NULL;*/ /* temp for i1 if both tautomeric AND non-tautomeric exist */
1728 : : /*const INChI *i2t = NULL;*/ /* temp for i2 if both tautomeric AND non-tautomeric exist */
1729 : :
1730 : : /* INChI_Stereo *Stereo1, *Stereo2; */
1731 : :
1732 [ + - + - ]: 46 : n1 = (p1->pINChI[TAUT_YES] && p1->pINChI[TAUT_YES]->nNumberOfAtoms) ? TAUT_YES : TAUT_NON;
1733 [ + - + - ]: 46 : n2 = (p2->pINChI[TAUT_YES] && p2->pINChI[TAUT_YES]->nNumberOfAtoms) ? TAUT_YES : TAUT_NON;
1734 : :
1735 : 46 : i1 = p1->pINChI[n1];
1736 [ - + ]: 46 : i1n = (n1 == TAUT_YES && p1->pINChI[TAUT_NON] &&
1737 [ + - - - ]: 92 : p1->pINChI[TAUT_NON]->nNumberOfAtoms) ? p1->pINChI[TAUT_NON] : (const INChI*)NULL;
1738 : :
1739 : 46 : i2 = p2->pINChI[n2];
1740 [ - + ]: 46 : i2n = (n2 == TAUT_YES && p2->pINChI[TAUT_NON] &&
1741 [ + - - - ]: 92 : p2->pINChI[TAUT_NON]->nNumberOfAtoms) ? p2->pINChI[TAUT_NON] : (const INChI*)NULL;
1742 : :
1743 : : /* non-deleted-non-empty < deleted < empty */
1744 [ + - - + ]: 46 : if (i1 && !i2)
1745 : 0 : return -1; /* non-empty is the smallest (first) */
1746 [ - + - - ]: 46 : if (!i1 && i2)
1747 : 0 : return 1;
1748 [ - + - - ]: 46 : if (!i1 && !i2)
1749 : 0 : return 0;
1750 [ - + - - ]: 46 : if (i1->bDeleted && !i2->bDeleted)
1751 : 0 : return 1; /* deleted is the largest (last) among non-empty */
1752 [ + - - + ]: 46 : if (!i1->bDeleted && i2->bDeleted)
1753 : 0 : return -1;
1754 : :
1755 : 46 : num_H1 = num_H2 = 0;
1756 : :
1757 : : /* do not compare terminal H */
1758 [ + + ]: 46 : if ((ret = CompareHillFormulasNoH(i1->szHillFormula, i2->szHillFormula, &num_H1, &num_H2))) /* djb-rwth: addressing LLVM warning */
1759 : : {
1760 : 18 : return ret; /* lexicographic order except the shorter one is greater (last): CH2O < CH2; C3XX < C2XX */
1761 : : }
1762 : :
1763 : : /*********************************************************
1764 : : compare non-isotopic non-tautomeric part
1765 : : *********************************************************/
1766 : :
1767 : : /* compare number of atoms (excluding terminal H) */
1768 [ - + ]: 28 : if ((ret = i2->nNumberOfAtoms - i1->nNumberOfAtoms)) /* djb-rwth: addressing LLVM warning */
1769 : 0 : return ret; /* more atoms first */
1770 : :
1771 : : /* compare elements (excluding terminal H) */
1772 : 28 : num = i1->nNumberOfAtoms;
1773 [ + + ]: 232 : for (i = 0; i < num; i++)
1774 : : {
1775 : : /* should always be equal if Hill formulas are same */
1776 [ - + ]: 204 : if ((ret = (int)i2->nAtom[i] - (int)i1->nAtom[i])) /* djb-rwth: addressing LLVM warning */
1777 : 0 : return ret; /* greater periodic number first */
1778 : : }
1779 : :
1780 : : /**********************************************************
1781 : : compare connection tables
1782 : : ***********************************************************/
1783 [ - + ]: 28 : if ((ret = i2->lenConnTable - i1->lenConnTable)) /* djb-rwth: addressing LLVM warning */
1784 : 0 : return ret; /* longer connection table first */
1785 : 28 : num = i2->lenConnTable;
1786 [ + + ]: 412 : for (i = 0; i < num; i++)
1787 : : {
1788 [ - + ]: 384 : if ((ret = (int)i2->nConnTable[i] - (int)i1->nConnTable[i])) /* djb-rwth: addressing LLVM warning */
1789 : 0 : return ret; /* greater connection table first */
1790 : : }
1791 : :
1792 : : /*********************************************************
1793 : : compare compare total number of H (inverse: H3 < H2 )
1794 : : **********************************************************/
1795 [ - + ]: 28 : if ((ret = num_H2 - num_H1)) /* djb-rwth: addressing LLVM warning */
1796 : : {
1797 : 0 : return ret;
1798 : : }
1799 : :
1800 : : /*********************************************************
1801 : : compare non-tautomeric num_H: N < NH3 < NH2 < NH
1802 : : **********************************************************/
1803 : 28 : num = i1->nNumberOfAtoms;
1804 [ + + ]: 232 : for (i = 0; i < num; i++)
1805 : : {
1806 [ - + ]: 204 : if (i2->nNum_H[i] != i1->nNum_H[i])
1807 : : {
1808 [ # # ]: 0 : return !i2->nNum_H[i] ? 1 : /* no H first */
1809 [ # # ]: 0 : !i1->nNum_H[i] ? -1 :
1810 : 0 : (int)i2->nNum_H[i] - (int)i1->nNum_H[i];
1811 : : }
1812 : : }
1813 : :
1814 : : /*********************************************************
1815 : : compare non-isotopic tautomeric part
1816 : : *********************************************************/
1817 [ - + ]: 28 : if ((ret = CompareTautNonIsoPartOfINChI(i1, i2))) /* djb-rwth: addressing LLVM warning */
1818 : : {
1819 : 0 : return ret;
1820 : : }
1821 : : /*
1822 : : if ( ret = i2->lenTautomer - i1->lenTautomer )
1823 : : return ret;
1824 : : num = inchi_min( i2->lenTautomer, i1->lenTautomer );
1825 : : for ( i = 0; i < num; i ++ ) {
1826 : : if ( ret = (int)i2->nTautomer[i] - (int)i1->nTautomer[i] )
1827 : : return ret;
1828 : : }
1829 : : */
1830 : :
1831 : : /*********************************************************
1832 : : * *
1833 : : * at this point both components are either tautomeric *
1834 : : * or non-tautomeric *
1835 : : * *
1836 : : *********************************************************/
1837 : :
1838 : : /*********************************************************
1839 : : non-tautomeric "fixed H" specific
1840 : : *********************************************************/
1841 [ + + - + : 28 : if (TAUT_NON == bTaut && ((i1n && i1n->nNum_H_fixed) || (i2n && i2n->nNum_H_fixed))) /* djb-rwth: addressing LLVM warning */
- - - + -
- ]
1842 : : {
1843 : : /* first, compare non-tautomeric chem. formulas -- they may be different */
1844 [ # # ]: 0 : const char* f1 = (i1n /*&& i1n->nNum_H_fixed*/) ? i1n->szHillFormula : i1->szHillFormula;
1845 [ # # ]: 0 : const char* f2 = (i2n /*&& i2n->nNum_H_fixed*/) ? i2n->szHillFormula : i2->szHillFormula;
1846 [ # # # # : 0 : if (f1 && f2 && (ret = CompareHillFormulas(f1, f2)))
# # ]
1847 : : {
1848 : 0 : return ret;
1849 : : }
1850 : : /* secondly, compare fixed-H distribution */
1851 [ # # # # : 0 : if (i1n && i1n->nNum_H_fixed && i2n && i2n->nNum_H_fixed)
# # # # ]
1852 : : {
1853 : 0 : num = inchi_min(i1n->nNumberOfAtoms, i2n->nNumberOfAtoms);
1854 [ # # ]: 0 : for (i = 0; i < num; i++)
1855 : : {
1856 [ # # ]: 0 : if (i2n->nNum_H_fixed[i] != i1n->nNum_H_fixed[i])
1857 : : {
1858 [ # # ]: 0 : return !i2n->nNum_H_fixed[i] ? 1 : /* no fixed H first */
1859 [ # # ]: 0 : !i1n->nNum_H_fixed[i] ? -1 :
1860 : 0 : (int)i2n->nNum_H_fixed[i] - (int)i1n->nNum_H_fixed[i];
1861 : : }
1862 : : }
1863 [ # # ]: 0 : if ((ret = (int)i2n->nNumberOfAtoms - (int)i1n->nNumberOfAtoms)) /* djb-rwth: addressing LLVM warning */
1864 : : {
1865 : 0 : return ret; /* should not happen <BRKPT> */
1866 : : }
1867 : : }
1868 : : else
1869 : : {
1870 [ # # # # ]: 0 : if (i1n && i1n->nNum_H_fixed)
1871 : : {
1872 : 0 : num = i1n->nNumberOfAtoms;
1873 [ # # ]: 0 : for (i = 0; i < num; i++)
1874 : : {
1875 : : /* added 2004-05-04 */
1876 [ # # ]: 0 : if (i1n->nNum_H_fixed[i])
1877 : : {
1878 : 0 : return -1; /* i1n->nNum_H_fixed[i] > 0? -1:1;*/
1879 : : }
1880 : : }
1881 : : /* p1 is tautomeric, p2 is not tautomeric; this must have been detected earlier */
1882 : : /*return -1;*/ /* has fixed H first *//* <BRKPT> */ /* removed 2004-05-04 */
1883 : : }
1884 : : else
1885 : : {
1886 : 0 : num = i2n->nNumberOfAtoms;
1887 [ # # ]: 0 : for (i = 0; i < num; i++)
1888 : : {
1889 : : /* added 2004-05-04 */
1890 [ # # ]: 0 : if (i2n->nNum_H_fixed[i])
1891 : : {
1892 : 0 : return 1; /* i2n->nNum_H_fixed[i] > 0? 1:-1;*/
1893 : : }
1894 : : }
1895 : : /* p2 is tautomeric, p1 is not tautomeric; this must have been detected earlier */
1896 : : /*return 1; */ /* has fixed H first *//* <BRKPT> */ /* removed 2004-05-04 */
1897 : : }
1898 : : }
1899 : : }
1900 : :
1901 : : /*************************************************************************
1902 : : if requested non-tautomeric comparison then
1903 : : prepare to compare non-taut non-isotopic stereo, etc.
1904 : : *************************************************************************/
1905 [ + + ]: 28 : if (TAUT_NON == bTaut)
1906 : : {
1907 [ - + ]: 14 : if (i1n)
1908 : : {
1909 : : /*i1t = i1;*/
1910 : 0 : i1 = i1n;
1911 : : }
1912 [ - + ]: 14 : if (i2n)
1913 : : {
1914 : : /*i2t = i2;*/
1915 : 0 : i2 = i2n;
1916 : : }
1917 : : }
1918 : :
1919 : : /*********************************************************
1920 : : compare non-isotopic stereo
1921 : : *********************************************************/
1922 : 28 : ret = CompareInchiStereo(i1->Stereo, i1->nFlags, i2->Stereo, i2->nFlags);
1923 [ + + ]: 28 : if (ret)
1924 : : {
1925 : 8 : return ret;
1926 : : }
1927 : : /*******************************************************
1928 : : do not switch back to tautomeric i1, i2
1929 : : *******************************************************/
1930 : : /* -- how to switch back --
1931 : : if ( i1t ) {
1932 : : i1 = i1t;
1933 : : i1t = NULL;
1934 : : }
1935 : : if ( i2t ) {
1936 : : i2 = i2t;
1937 : : i2t = NULL;
1938 : : }
1939 : : */
1940 : :
1941 : : /******************************************************
1942 : : compare isotopic non-tautomeric part
1943 : : ******************************************************/
1944 [ + - ]: 20 : if (bCompareIsotopic)
1945 : : {
1946 [ - + ]: 20 : if ((ret = i2->nNumberOfIsotopicAtoms - i1->nNumberOfIsotopicAtoms)) /* djb-rwth: addressing LLVM warning */
1947 : : {
1948 : 0 : return ret;
1949 : : }
1950 : 20 : num = i1->nNumberOfIsotopicAtoms;
1951 : : /* compare isotopic atoms */
1952 [ - + ]: 20 : for (i = 0; i < num; i++)
1953 : : {
1954 [ # # ]: 0 : if ((ret = (int)i2->IsotopicAtom[i].nAtomNumber - (int)i1->IsotopicAtom[i].nAtomNumber)) /* djb-rwth: addressing LLVM warning */
1955 : : {
1956 : 0 : return ret;
1957 : : }
1958 [ # # ]: 0 : if ((ret = (int)i2->IsotopicAtom[i].nIsoDifference - (int)i1->IsotopicAtom[i].nIsoDifference)) /* djb-rwth: addressing LLVM warning */
1959 : : {
1960 : 0 : return ret;
1961 : : }
1962 : : }
1963 : :
1964 : : /* compare isotopic H */
1965 : : /* if tautomeric comparison mode then here are compared only non-tautomeric H */
1966 [ - + ]: 20 : for (i = 0; i < num; i++)
1967 : : {
1968 [ # # ]: 0 : if ((ret = (int)i2->IsotopicAtom[i].nNum_T - (int)i1->IsotopicAtom[i].nNum_T)) /* djb-rwth: addressing LLVM warning */
1969 : : {
1970 : 0 : return ret;
1971 : : }
1972 [ # # ]: 0 : if ((ret = (int)i2->IsotopicAtom[i].nNum_D - (int)i1->IsotopicAtom[i].nNum_D)) /* djb-rwth: addressing LLVM warning */
1973 : : {
1974 : 0 : return ret;
1975 : : }
1976 [ # # ]: 0 : if ((ret = (int)i2->IsotopicAtom[i].nNum_H - (int)i1->IsotopicAtom[i].nNum_H)) /* djb-rwth: addressing LLVM warning */
1977 : : {
1978 : 0 : return ret;
1979 : : }
1980 : : }
1981 : :
1982 : : /*****************************************************
1983 : : compare isotopic tautomeric part
1984 : : *****************************************************/
1985 [ - + ]: 20 : if ((ret = i2->nNumberOfIsotopicTGroups - i1->nNumberOfIsotopicTGroups)) /* djb-rwth: addressing LLVM warning */
1986 : 0 : return ret;
1987 : 20 : num = i1->nNumberOfIsotopicTGroups;
1988 [ - + ]: 20 : for (i = 0; i < num; i++)
1989 : : {
1990 [ # # ]: 0 : if ((ret = (int)i2->IsotopicTGroup[i].nTGroupNumber - (int)i1->IsotopicTGroup[i].nTGroupNumber)) /* djb-rwth: addressing LLVM warning */
1991 : : {
1992 : 0 : return ret;
1993 : : }
1994 [ # # ]: 0 : if ((ret = (int)i2->IsotopicTGroup[i].nNum_T - (int)i1->IsotopicTGroup[i].nNum_T)) /* djb-rwth: addressing LLVM warning */
1995 : : {
1996 : 0 : return ret;
1997 : : }
1998 [ # # ]: 0 : if ((ret = (int)i2->IsotopicTGroup[i].nNum_D - (int)i1->IsotopicTGroup[i].nNum_D)) /* djb-rwth: addressing LLVM warning */
1999 : : {
2000 : 0 : return ret;
2001 : : }
2002 [ # # ]: 0 : if ((ret = (int)i2->IsotopicTGroup[i].nNum_H - (int)i1->IsotopicTGroup[i].nNum_H)) /* djb-rwth: addressing LLVM warning */
2003 : : {
2004 : 0 : return ret;
2005 : : }
2006 : : }
2007 : :
2008 : : /****************************************************
2009 : : compare isotopic stereo
2010 : : ****************************************************/
2011 : 20 : ret = CompareInchiStereo(i1->StereoIsotopic, i1->nFlags, i2->StereoIsotopic, i2->nFlags);
2012 [ - + ]: 20 : if (ret)
2013 : : {
2014 : 0 : return ret;
2015 : : }
2016 : : }
2017 : :
2018 : : /**********************************************************
2019 : : compare charges: non-charged first, then in order of
2020 : : ascending charges (negative first)
2021 : : ***********************************************************/
2022 [ + + + - ]: 20 : if (i2->nTotalCharge && i1->nTotalCharge)
2023 : : {
2024 : : /* both are charged; smaller charges first */
2025 : 4 : ret = (int)i1->nTotalCharge - (int)i2->nTotalCharge;
2026 : 4 : return ret;
2027 : : }
2028 [ - + ]: 16 : if ((ret = (i1->nTotalCharge ? 1 : 0) - (i2->nTotalCharge ? 1 : 0))) /* djb-rwth: addressing LLVM warning */
2029 : : {
2030 : : /* only one is charged; uncharged first */
2031 : 0 : return ret;
2032 : : }
2033 : : /* stable sort */
2034 : : /*ret = p1->ord_number - p2->ord_number;*/
2035 : :
2036 : 16 : return ret;
2037 : : }
2038 : :
2039 : :
2040 : : /****************************************************************************/
2041 : 18 : int CompINChINonTaut2(const void* p1, const void* p2)
2042 : : {
2043 : : int ret;
2044 : 18 : ret = CompINChI2((const INCHI_SORT*)p1, (const INCHI_SORT*)p2, TAUT_NON, 1);
2045 : : #if ( CANON_FIXH_TRANS == 1 )
2046 [ + + ]: 18 : if (!ret)
2047 : : {
2048 : : /* to obtain canonical transposition 2004-05-10 */
2049 : 5 : ret = CompINChI2((const INCHI_SORT*)p1, (const INCHI_SORT*)p2, TAUT_YES, 1);
2050 : : }
2051 : : #endif
2052 [ + + ]: 18 : if (!ret)
2053 : : {
2054 : : /* stable sort */
2055 : 5 : ret = ((const INCHI_SORT*)p1)->ord_number - ((const INCHI_SORT*)p2)->ord_number;
2056 : : }
2057 : :
2058 : 18 : return ret;
2059 : : }
2060 : :
2061 : :
2062 : : /****************************************************************************/
2063 : 18 : int CompINChITaut2(const void* p1, const void* p2)
2064 : : {
2065 : : int ret;
2066 : 18 : ret = CompINChI2((const INCHI_SORT*)p1, (const INCHI_SORT*)p2, TAUT_YES, 1);
2067 : : #if ( CANON_FIXH_TRANS == 1 )
2068 [ + + ]: 18 : if (!ret)
2069 : : {
2070 : : /* to obtain canonical transposition 2004-05-10 */
2071 : 5 : ret = CompINChI2((const INCHI_SORT*)p1, (const INCHI_SORT*)p2, TAUT_NON, 1);
2072 : : }
2073 : : #endif
2074 [ + + ]: 18 : if (!ret)
2075 : : {
2076 : : /* stable sort */
2077 : 5 : ret = ((const INCHI_SORT*)p1)->ord_number - ((const INCHI_SORT*)p2)->ord_number;
2078 : : }
2079 : :
2080 : 18 : return ret;
2081 : : }
2082 : :
2083 : :
2084 : : /****************************************************************************
2085 : : mystrrev( ... )
2086 : : NB:
2087 : : strrev from K&R is not in ANSI-compatible C library
2088 : : ****************************************************************************/
2089 : 2024 : void mystrrev(char* p)
2090 : : {
2091 : 2024 : char c, * q = p;
2092 [ + + ]: 4382 : while (*q++)
2093 : : {
2094 : : ;
2095 : : }
2096 : 2024 : q -= 2; /* pointer to the last character */
2097 [ + + ]: 2358 : while (p < q)
2098 : : {
2099 : 334 : c = *q; /* swap */
2100 : 334 : *q-- = *p;
2101 : 334 : *p++ = c;
2102 : : }
2103 : 2024 : }
2104 : :
2105 : :
2106 : : /****************************************************************************
2107 : : Find DFS order for CT(canon. numbers and Hs) output
2108 : : ****************************************************************************/
2109 : : typedef struct tagOrderStruct
2110 : : {
2111 : : AT_NUMB* m_gDfs4CT_nDfsNumber;
2112 : : AT_NUMB* m_gDfs4CT_nNumDescendants;
2113 : : int m_gDfs4CT_nCurrentAtom;
2114 : : } OrderStruct;
2115 : :
2116 : :
2117 : : /****************************************************************************/
2118 : 601 : static int CompareDfsDescendants4CT(const void* a1, const void* a2, void* p)
2119 : : {
2120 : 601 : OrderStruct* os = (OrderStruct*)p;
2121 : 601 : int neigh1 = (int)*(const AT_RANK*)a1;
2122 : 601 : int neigh2 = (int)*(const AT_RANK*)a2;
2123 [ + + ]: 601 : if (neigh1 > MAX_ATOMS)
2124 : : {
2125 [ + + ]: 291 : if (neigh2 > MAX_ATOMS)
2126 : : {
2127 : 15 : return 0;
2128 : : }
2129 : 276 : return 1;
2130 : : }
2131 [ + + ]: 310 : else if (neigh2 > MAX_ATOMS)
2132 : : {
2133 : 144 : return -1;
2134 : : }
2135 : : else
2136 : : {
2137 : 166 : AT_RANK nCurDfsNumber = os->m_gDfs4CT_nDfsNumber[os->m_gDfs4CT_nCurrentAtom];
2138 : 332 : int nDesc1 = nCurDfsNumber > os->m_gDfs4CT_nDfsNumber[neigh1] ?
2139 [ + + ]: 166 : 0 : (int)os->m_gDfs4CT_nNumDescendants[neigh1];
2140 : 332 : int nDesc2 = nCurDfsNumber > os->m_gDfs4CT_nDfsNumber[neigh2] ?
2141 [ + - ]: 166 : 0 : (int)os->m_gDfs4CT_nNumDescendants[neigh2];
2142 : : int ret;
2143 [ + + ]: 166 : if ((ret = nDesc1 - nDesc2)) /* djb-rwth: addressing LLVM warning */
2144 : : {
2145 : 122 : return ret;
2146 : : }
2147 : 44 : return (int)neigh1 - (int)neigh2; /* canon. numbers difference */
2148 : : }
2149 : : }
2150 : :
2151 : :
2152 : : /****************************************************************************/
2153 : 58 : AT_NUMB* GetDfsOrder4CT(CANON_GLOBALS* pCG,
2154 : : AT_NUMB* LinearCT,
2155 : : int nLenCT,
2156 : : S_CHAR* nNum_H,
2157 : : int num_atoms,
2158 : : int nCtMode)
2159 : : {
2160 : 58 : AT_NUMB* nStackAtom = NULL;
2161 : 58 : int nTopStackAtom = -1;
2162 : 58 : AT_NUMB* nNumDescendants = NULL; /* number of descendants incl. closures and the atom itself */
2163 : 58 : AT_NUMB* nDfsNumber = NULL;
2164 : 58 : S_CHAR* cNeighNumb = NULL;
2165 : 58 : NEIGH_LIST* nl = NULL;
2166 : : AT_NUMB nDfs;
2167 : : int i, j, u, k, start, num_rings, nTotOutputStringLen;
2168 : 58 : AT_NUMB* nOutputString = NULL, cDelim;
2169 : 58 : int bCtPredecessors = (nCtMode & CT_MODE_PREDECESSORS);
2170 : : OrderStruct os;
2171 : :
2172 : : /* allocate arrays */
2173 : 58 : nStackAtom = (AT_NUMB*)inchi_malloc(num_atoms * sizeof(nStackAtom[0]));
2174 : 58 : nNumDescendants = (AT_NUMB*)inchi_malloc(num_atoms * sizeof(nNumDescendants[0]));
2175 : 58 : nDfsNumber = (AT_NUMB*)inchi_malloc(num_atoms * sizeof(nDfsNumber[0]));
2176 : 58 : cNeighNumb = (S_CHAR*)inchi_malloc(num_atoms * sizeof(cNeighNumb[0]));
2177 : 58 : nl = CreateNeighListFromLinearCT(LinearCT, nLenCT, num_atoms);
2178 : :
2179 : : /* check allocation */
2180 [ + - + - : 58 : if (!nStackAtom || !nNumDescendants || !nDfsNumber || !cNeighNumb || !nl)
+ - + - -
+ ]
2181 : : {
2182 : : /* ret = CT_OUT_OF_RAM; */ /* program error */ /* <BRKPT> */
2183 : 0 : goto exit_function;
2184 : : }
2185 [ - + ]: 58 : if (bCtPredecessors)
2186 : : {
2187 : 0 : start = 0;
2188 : : }
2189 : : else
2190 : : {
2191 : : /* find DFS start vertex (atom) */
2192 [ + + ]: 530 : for (i = 1, start = 0; i < num_atoms; i++)
2193 : : {
2194 [ + + ]: 472 : if (nl[i][0] < nl[start][0])
2195 : : { /* index = nRank-1 */
2196 : 14 : start = i;
2197 : : }
2198 : : }
2199 : : }
2200 : :
2201 : : /*
2202 : : vertex information:
2203 : : 1. Number of (forward edges) + (back edges, first visit -- ring closures): nl[i][0]
2204 : : 2. Number of vertices traversed from this vertex, including the vertex: nNumDescendants[i]
2205 : : 3. Each edge information:
2206 : : a. forward edge (0) or back edge (1) indicator: nDfsNumber[i] > nDfsNumber[neigh]
2207 : : b. neighbor at another end of the edge neigh = nl[i][k+1], k < i
2208 : :
2209 : : Total per edge: 2 + 2*(number of edges)
2210 : : */
2211 : :
2212 : : /* DFS initiation */
2213 : 58 : u = start; /* start atom */
2214 : 58 : nDfs = 0;
2215 : 58 : nTopStackAtom = -1;
2216 : 58 : memset(nDfsNumber, 0, num_atoms * sizeof(nDfsNumber[0])); /* djb-rwth: memset_s C11/Annex K variant? */
2217 : 58 : memset(nNumDescendants, 0, num_atoms * sizeof(nNumDescendants[0])); /* djb-rwth: memset_s C11/Annex K variant? */
2218 : 58 : memset(cNeighNumb, 0, num_atoms * sizeof(cNeighNumb[0])); /* djb-rwth: memset_s C11/Annex K variant? */
2219 : : /* push the start atom on the stack */
2220 : 58 : nDfsNumber[u] = ++nDfs;
2221 [ - + ]: 58 : if (bCtPredecessors)
2222 : : {
2223 : 0 : nNumDescendants[u] = 0; /* atom #1 has no predecessor */
2224 : : }
2225 : : else
2226 : : {
2227 : 58 : nNumDescendants[u] = 1; /* count itself as a descendant */
2228 : : }
2229 : 58 : nStackAtom[++nTopStackAtom] = (AT_NUMB)u;
2230 : : /* nNumStartChildren = 0; */
2231 : 58 : num_rings = 0;
2232 : :
2233 : : /* DFS */
2234 : : do
2235 : : {
2236 : : /* advance */
2237 [ + + ]: 1506 : while (i = (int)nStackAtom[nTopStackAtom], j = (int)cNeighNumb[i] + 1, (int)nl[i][0] >= j)
2238 : : /*while ( (int)nl[i=nStackAtom[nTopStackAtom]][0] >= (j = (int)cNeighNumb[i]+1) )*/
2239 : :
2240 : : /* replaced due to missing sequence point; undefined behavior, pointed by Geoffrey Hutchison */
2241 : : {
2242 : 976 : cNeighNumb[i]++;
2243 : 976 : u = (int)nl[i][j]; /* jth neighbor of the vertex i */
2244 [ + + ]: 976 : if (!nDfsNumber[u])
2245 : : {
2246 : : /* tree edge, 1st visit -- advance */
2247 : : /* put unexplored vertex u on the stack for further examination */
2248 : 472 : nStackAtom[++nTopStackAtom] = (AT_NUMB)u;
2249 : 472 : nDfsNumber[u] = ++nDfs;
2250 [ - + ]: 472 : if (bCtPredecessors)
2251 : : {
2252 : 0 : nNumDescendants[u] = i + 1; /* predecessor's rank */
2253 : : }
2254 : : else
2255 : : {
2256 : 472 : nNumDescendants[u]++; /* count atom u as its descendant */
2257 : : }
2258 : : }
2259 : : else
2260 : : {
2261 [ + + + + ]: 504 : if (nTopStackAtom && u != (int)nStackAtom[nTopStackAtom - 1] &&
2262 : : /* back edge: u is not a predecessor of i */
2263 [ + + ]: 31 : nDfsNumber[u] < nDfsNumber[i])
2264 : : {
2265 : : /* Back edge, 1st visit: u is an ancestor of i (ring closure) */
2266 [ + - ]: 16 : if (!bCtPredecessors)
2267 : : {
2268 : 16 : nNumDescendants[i]++; /* count closures as descendants */
2269 : : }
2270 : 16 : num_rings++; /* count ring closures */
2271 : : }
2272 : : else
2273 : : {
2274 : 488 : nl[i][j] = MAX_ATOMS + 1; /* back edge, 2nd visit: mark as deleted */
2275 : : }
2276 : : }
2277 : : }
2278 : 530 : cNeighNumb[i] = 0; /* all neighbors of the ith atom have been
2279 : : traversed; resore the neighbor counter */
2280 : : /* back up */
2281 [ + - + + ]: 530 : if (!bCtPredecessors && nTopStackAtom /* that is, i != start */)
2282 : : {
2283 : 472 : u = (int)nStackAtom[nTopStackAtom - 1]; /* predecessor of i */
2284 : 472 : nNumDescendants[u] += nNumDescendants[i]; /* add descendants */
2285 : : }
2286 [ + + ]: 530 : } while (--nTopStackAtom >= 0);
2287 : :
2288 : : /* Sort the neighbors in ascending order so that:
2289 : : primary key = number of descendants in the DFS tree; closure neighbor is 0
2290 : : secondary key = canonical number (here vertex number = canonical number - 1)
2291 : : */
2292 : :
2293 : 58 : os.m_gDfs4CT_nDfsNumber = nDfsNumber;
2294 : 58 : os.m_gDfs4CT_nNumDescendants = nNumDescendants;
2295 : 58 : os.m_gDfs4CT_nCurrentAtom = -1;
2296 : :
2297 : : /* sorting; deleted will be the last neighbors */
2298 [ + + ]: 588 : for (i = 0; i < num_atoms; i++)
2299 : : {
2300 [ + + ]: 530 : if (nl[i][0] > 1)
2301 : : {
2302 : 266 : os.m_gDfs4CT_nCurrentAtom = i;
2303 : 266 : insertions_sort(&os, &nl[i][1], nl[i][0], sizeof(nl[i][1]), CompareDfsDescendants4CT);
2304 : : }
2305 : : /* reduce number of neighbors to exclude deleted */
2306 [ + + + + ]: 1018 : for (k = 0; k < nl[i][0] && nl[i][k + 1] <= MAX_ATOMS; k++)
2307 : : {
2308 : : ;
2309 : : }
2310 : 530 : nl[i][0] = k;
2311 : : }
2312 : :
2313 : 58 : nTotOutputStringLen = 3 * (num_atoms + num_rings + 1); /* last 3 elements are a 'zero termination' */
2314 : :
2315 [ - + ]: 58 : if (bCtPredecessors)
2316 : : {
2317 [ # # ]: 0 : if ((nOutputString = (AT_RANK*)inchi_calloc(nTotOutputStringLen, sizeof(nOutputString[0])))) /* djb-rwth: addressing LLVM warning */
2318 : : {
2319 : 0 : cDelim = '-';
2320 [ # # ]: 0 : for (u = 0, k = -3; u < num_atoms; u++)
2321 : : {
2322 : 0 : k += 3;
2323 [ # # ]: 0 : if (k + 6 > nTotOutputStringLen)
2324 : : {
2325 : 0 : goto exit_error; /* program error */
2326 : : }
2327 [ # # ]: 0 : nOutputString[k] = nNumDescendants[u] ? nNumDescendants[u] : MAX_ATOMS + 1;
2328 [ # # ]: 0 : nOutputString[k + 1] = nNum_H ? 16 + nNum_H[u] : 0;
2329 [ # # ]: 0 : nOutputString[k + 2] = k ? ',' : '\0';
2330 [ # # # # ]: 0 : for (j = 1; j <= nl[u][0] && nDfsNumber[u] > nDfsNumber[i = nl[u][j]]; j++)
2331 : : {
2332 : : /* closures */
2333 : 0 : k += 3;
2334 [ # # ]: 0 : if (k + 6 > nTotOutputStringLen)
2335 : : {
2336 : 0 : goto exit_error; /* program error */
2337 : : }
2338 : 0 : nOutputString[k] = i + 1; /* closure */
2339 : 0 : nOutputString[k + 1] = 0;
2340 : 0 : nOutputString[k + 2] = cDelim;
2341 : : }
2342 : : }
2343 : : }
2344 : : }
2345 : : else
2346 : : {
2347 [ + - ]: 58 : if (nNumDescendants)
2348 : : { /* do not need anymore */
2349 [ + - ]: 58 : inchi_free(nNumDescendants);
2350 : 58 : nNumDescendants = NULL;
2351 : : }
2352 : :
2353 : : /*
2354 : : the output string contains:
2355 : : (num_atoms) atoms for the DFS (spanning) tree
2356 : : (num_atoms-1) delimiters for the DFS (spanning) tree
2357 : : 1 character for each atom that has 1 terminal hydrogen atoms
2358 : : 2 characters for each atom that has 2-9 terminal hydrogen atoms
2359 : : 3 characters for each atom that has 10-99 terminal hydrogen atoms, etc.
2360 : : (num_rings) atoms for the ring closures
2361 : : (num_rings) delimiters for the ring closures
2362 : : */
2363 : :
2364 [ + - ]: 58 : if ((nOutputString = (AT_RANK*)inchi_calloc(nTotOutputStringLen, sizeof(nOutputString[0])))) /* djb-rwth: addressing LLVM warning */
2365 : : {
2366 : 58 : u = start; /* start atom */
2367 : 58 : nTopStackAtom = -1;
2368 : 58 : memset(cNeighNumb, 0, num_atoms * sizeof(cNeighNumb[0])); /* djb-rwth: memset_s C11/Annex K variant? */
2369 : : /* push the start atom on the stack */
2370 : 58 : nStackAtom[++nTopStackAtom] = (AT_NUMB)u;
2371 : : /* output the starting atom */
2372 : 58 : k = 0;
2373 : 58 : nOutputString[k] = u + 1;
2374 [ - + ]: 58 : nOutputString[k + 1] = nNum_H ? 16 + nNum_H[u] : 0;
2375 : 58 : nOutputString[k + 2] = '\0';
2376 : :
2377 : : do
2378 : : {
2379 : : /* advance */
2380 [ + - + + : 1018 : while (i = (int)nStackAtom[nTopStackAtom], j = (int)cNeighNumb[i] + 1, i < num_atoms && (int)nl[i][0] >= j) /* djb-rwth: additional condition to avoid buffer overruns */
+ + ]
2381 : : /*while ( (int)nl[i=nStackAtom[nTopStackAtom]][0] >= (j = (int)cNeighNumb[i]+1) )*/
2382 : : /* replaced due to missing sequence point; undefined behavior, reported by Geoffrey Hutchison */
2383 : : {
2384 : 488 : k += 3;
2385 [ - + ]: 488 : if (k + 6 > nTotOutputStringLen)
2386 : : {
2387 : 0 : goto exit_error; /* program error */
2388 : : }
2389 : 488 : cNeighNumb[i]++;
2390 : 488 : u = (int)nl[i][j]; /* neighbor */
2391 : :
2392 : : /* output neighbor's canonical number */
2393 : 488 : nOutputString[k] = u + 1;
2394 : :
2395 [ + + ]: 488 : if (nDfsNumber[u] > nDfsNumber[i])
2396 : : {
2397 : : /* tree edge, 1st visit -- advance */
2398 : : /* put 'unexplored' vertex u on the stack */
2399 : 472 : nStackAtom[++nTopStackAtom] = (AT_NUMB)u;
2400 : :
2401 : : /* output neighbor's number of H */
2402 [ - + ]: 472 : nOutputString[k + 1] = nNum_H ? 16 + nNum_H[u] : 0;
2403 : : }
2404 : : else
2405 : : {
2406 : 16 : nOutputString[k + 1] = 0;
2407 : : }
2408 : : /* output a delimiter preceding the neighbor */
2409 [ + + ]: 488 : if (1 < nl[i][0])
2410 : : {
2411 [ + + ]: 327 : if (j == 1)
2412 : : {
2413 : 162 : cDelim = '(';
2414 : : }
2415 : : else
2416 : : {
2417 [ + + ]: 165 : if (j == nl[i][0])
2418 : : {
2419 : 162 : cDelim = ')';
2420 : : }
2421 : : else
2422 : : {
2423 : 3 : cDelim = ',';
2424 : : }
2425 : : }
2426 : : }
2427 : : else
2428 : : {
2429 : 161 : cDelim = '-';
2430 : : }
2431 : 488 : nOutputString[k + 2] = cDelim;
2432 : : }
2433 : :
2434 [ + - + - ]: 530 : if ((i >= 0) && (i < num_atoms)) /* djb-rwth: fixing coverity ID #499483 */
2435 : : {
2436 : 530 : cNeighNumb[i] = 0;
2437 : : }
2438 : :
2439 : : /* back up: nothing else to do */
2440 [ + + ]: 530 : } while (--nTopStackAtom >= 0);
2441 : : }
2442 : : }
2443 : 58 : goto exit_function;
2444 : :
2445 : 0 : exit_error:
2446 [ # # ]: 0 : if (nOutputString)
2447 : : {
2448 [ # # ]: 0 : inchi_free(nOutputString);
2449 : 0 : nOutputString = NULL;
2450 : : }
2451 : :
2452 : 0 : exit_function:
2453 [ + - ]: 58 : if (nStackAtom)
2454 : : {
2455 [ + - ]: 58 : inchi_free(nStackAtom);
2456 : : }
2457 [ - + ]: 58 : if (nNumDescendants)
2458 : : {
2459 [ # # ]: 0 : inchi_free(nNumDescendants);
2460 : : }
2461 [ + - ]: 58 : if (nDfsNumber)
2462 : : {
2463 [ + - ]: 58 : inchi_free(nDfsNumber);
2464 : : }
2465 [ + - ]: 58 : if (cNeighNumb)
2466 : : {
2467 [ + - ]: 58 : inchi_free(cNeighNumb);
2468 : : }
2469 [ + - ]: 58 : if (nl)
2470 : : {
2471 : 58 : FreeNeighList(nl);
2472 : : }
2473 : :
2474 : 58 : return nOutputString;
2475 : : }
2476 : :
2477 : :
2478 : : /****************************************************************************/
2479 : 54 : int GetInpStructErrorType(INPUT_PARMS* ip,
2480 : : int err,
2481 : : char* pStrErrStruct,
2482 : : int num_inp_atoms)
2483 : : {
2484 [ - + - - ]: 54 : if (err && err == 9)
2485 : : {
2486 : 0 : return _IS_ERROR; /* sdfile bypassed to $$$$ */
2487 : : }
2488 [ - + - - ]: 54 : if (err && err < 30)
2489 : : {
2490 : 0 : return _IS_FATAL;
2491 : : }
2492 [ + - - + ]: 54 : if (num_inp_atoms <= 0 || err)
2493 : : {
2494 [ # # # # : 0 : if (98 == err && 0 == num_inp_atoms && ip->bAllowEmptyStructure)
# # ]
2495 : : {
2496 : 0 : return _IS_WARNING;
2497 : : }
2498 : 0 : return _IS_ERROR;
2499 : : }
2500 [ + + ]: 54 : if (pStrErrStruct[0])
2501 : : {
2502 : 2 : return _IS_WARNING;
2503 : : }
2504 : :
2505 : 52 : return _IS_OKAY;
2506 : : }
2507 : :
2508 : :
2509 : : /****************************************************************************/
2510 : 0 : int ProcessStructError(INCHI_IOSTREAM* out_file,
2511 : : INCHI_IOSTREAM* log_file,
2512 : : char* pStrErrStruct,
2513 : : int nErrorType,
2514 : : long num_inp,
2515 : : INPUT_PARMS* ip)
2516 : : {
2517 : : int b_ok;
2518 : : #ifdef TARGET_LIB_FOR_WINCHI
2519 : : int bPlainText = (ip->bINChIOutputOptions & INCHI_OUT_PLAIN_TEXT) &&
2520 : : (ip->bINChIOutputOptions & INCHI_OUT_WINCHI_WINDOW);
2521 : : #else
2522 : 0 : int bPlainText = 0;
2523 : : #endif
2524 [ # # ]: 0 : if (!bPlainText)
2525 : : {
2526 : 0 : return nErrorType;
2527 : : }
2528 : :
2529 : : /* Fatal error, Error, Warning */
2530 [ # # ]: 0 : if (nErrorType)
2531 : : {
2532 : 0 : b_ok = 0; /* to make VC++ happy */
2533 [ # # ]: 0 : if (bPlainText)
2534 : : {
2535 [ # # ]: 0 : if (!(b_ok = OutputINChIPlainError(out_file, pStrErrStruct, nErrorType)))
2536 : : {
2537 : 0 : inchi_ios_eprint(log_file, "Cannot create message for error (structure #%ld.%s%s%s%s) Terminating.\n",
2538 [ # # # # : 0 : num_inp, SDF_LBL_VAL(ip->pSdfLabel, ip->pSdfValue));
# # # # #
# # # # #
# # # # #
# # # #
# ]
2539 : : }
2540 : : else
2541 : : {
2542 : 0 : inchi_ios_print(out_file, "\n"); /* add a blank line after the WINCHI Window message */
2543 : : }
2544 : : }
2545 [ # # ]: 0 : return b_ok ? nErrorType : _IS_FATAL;
2546 : : }
2547 : :
2548 : 0 : return nErrorType;
2549 : : }
2550 : :
2551 : :
2552 : : #if ( READ_INCHI_STRING == 1 ) /* { */
2553 : : /****************************************************************************/
2554 : 0 : int CompareReversedStereoINChI(INChI_Stereo* s1/* InChI from reversed struct */,
2555 : : INChI_Stereo* s2 /* input InChI */
2556 : : )
2557 : : {
2558 [ # # # # ]: 0 : if (s1 == NULL && s2 == NULL)
2559 : : {
2560 : 0 : return 0;
2561 : : }
2562 [ # # ]: 0 : if ((s1 == NULL) ^ (s2 == NULL))
2563 : : {
2564 [ # # ]: 0 : INChI_Stereo* s = s1 ? s1 : s2;
2565 [ # # # # ]: 0 : if (s->nNumberOfStereoCenters || s->nNumberOfStereoBonds)
2566 : : {
2567 : 0 : return 20; /* Diff: Missing Stereo */
2568 : : }
2569 : : else
2570 : : {
2571 : 0 : return 0;
2572 : : }
2573 : : }
2574 : :
2575 [ # # ]: 0 : if (s1->nNumberOfStereoCenters != s2->nNumberOfStereoCenters)
2576 : : {
2577 : 0 : return 21; /* Diff: Number of sp3 stereocenters */
2578 : : }
2579 [ # # ]: 0 : if (s1->nNumberOfStereoCenters > 0)
2580 : : {
2581 [ # # ]: 0 : if (memcmp(s1->nNumber, s2->nNumber, s1->nNumberOfStereoCenters * sizeof(s1->nNumber[0])))
2582 : : {
2583 : 0 : return 22; /* Diff: sp3 stereocenter locations */
2584 : : }
2585 [ # # ]: 0 : if (memcmp(s1->t_parity, s2->t_parity, s1->nNumberOfStereoCenters * sizeof(s1->t_parity[0])))
2586 : : {
2587 : 0 : return 23; /* Diff: sp3 stereocenter parities */
2588 : : }
2589 [ # # # # : 0 : if (s1->nCompInv2Abs != s2->nCompInv2Abs && s1->nCompInv2Abs && s2->nCompInv2Abs)
# # ]
2590 : : {
2591 : 0 : return 24; /* Diff: sp3 inversion */
2592 : : }
2593 : : /*
2594 : : if ( s1->nNumberInv && s2->nNumberInv ) {
2595 : : if ( memcmp( s1->nNumberInv, s2->nNumberInv, s1->nNumberOfStereoCenters*sizeof(s1->nNumber[0]) ) )
2596 : : return 25;
2597 : : if ( memcmp( s1->t_parityInv, s2->t_parityInv, s1->nNumberOfStereoCenters*sizeof(s1->t_parity[0]) ) )
2598 : : return 26;
2599 : : if ( s1->nCompInv2Abs != s2->nCompInv2Abs ||
2600 : : s1->bTrivialInv != s2->bTrivialInv ) {
2601 : : return 27;
2602 : : }
2603 : : } else
2604 : : if ( s1->nNumberInv || s2->nNumberInv ) {
2605 : : return 28;
2606 : : }
2607 : : */
2608 : : }
2609 [ # # ]: 0 : if (s1->nNumberOfStereoBonds != s2->nNumberOfStereoBonds)
2610 : : {
2611 : 0 : return 25; /* Diff: Number of stereobonds */
2612 : : }
2613 [ # # ]: 0 : if (s1->nNumberOfStereoBonds > 0)
2614 : : {
2615 [ # # ]: 0 : if (memcmp(s1->nBondAtom1, s2->nBondAtom1, s1->nNumberOfStereoBonds * sizeof(s1->nBondAtom1[0])))
2616 : : {
2617 : 0 : return 26; /* Diff: Stereobond 1st atom locations */
2618 : : }
2619 [ # # ]: 0 : if (memcmp(s1->nBondAtom2, s2->nBondAtom2, s1->nNumberOfStereoBonds * sizeof(s1->nBondAtom2[0])))
2620 : : {
2621 : 0 : return 27; /* Diff: Stereobond 2nd atom locations */
2622 : : }
2623 [ # # ]: 0 : if (memcmp(s1->b_parity, s2->b_parity, s1->nNumberOfStereoBonds * sizeof(s1->b_parity[0])))
2624 : : {
2625 : 0 : return 28; /* Diff: Stereobond parities */
2626 : : }
2627 : : }
2628 : :
2629 : 0 : return 0;
2630 : : }
2631 : :
2632 : :
2633 : : /****************************************************************************/
2634 : 0 : int CompareReversedStereoINChI2(INChI_Stereo* s1/* InChI from reversed struct */,
2635 : : INChI_Stereo* s2 /* input InChI */,
2636 : : ICR* picr)
2637 : : {
2638 : 0 : int ret = 0;
2639 : : int j1, j2, num_dif, num_extra_undf, num_miss_undf, num_in1_only, num_in2_only; /* djb-rwth: removing redundant variables */
2640 : 0 : int bAddSb = !(picr->num_sb_undef_in1_only + picr->num_sb_in1_only + picr->num_sb_in2_only);
2641 : 0 : int bAddSc = !(picr->num_sc_undef_in1_only + picr->num_sc_in1_only + picr->num_sc_in2_only);
2642 : :
2643 [ # # ]: 0 : int nNumSc1 = s1 ? s1->nNumberOfStereoCenters : 0;
2644 [ # # ]: 0 : int nNumSc2 = s2 ? s2->nNumberOfStereoCenters : 0;
2645 [ # # ]: 0 : int nNumSb1 = s1 ? s1->nNumberOfStereoBonds : 0;
2646 [ # # ]: 0 : int nNumSb2 = s2 ? s2->nNumberOfStereoBonds : 0;
2647 : :
2648 : : /* djb-rwth: redundant part of the condition corrected; fixing a NULL pointer dereference */
2649 [ # # # # : 0 : if (s1 && s2 && (nNumSc1 || nNumSc2) && (nNumSc1 != nNumSc2 ||
# # # # #
# ]
2650 [ # # ]: 0 : memcmp(s1->nNumber, s2->nNumber, nNumSc1 * sizeof(s1->nNumber[0])) ||
2651 [ # # ]: 0 : memcmp(s1->t_parity, s2->t_parity, nNumSc1 * sizeof(s1->t_parity[0]))))
2652 : : {
2653 : 0 : num_dif = num_extra_undf = num_miss_undf = num_in1_only = num_in2_only = 0;
2654 [ # # # # ]: 0 : for (j1 = j2 = 0; j1 < nNumSc1 && j2 < nNumSc2; )
2655 : : {
2656 [ # # ]: 0 : if (s1->nNumber[j1] == s2->nNumber[j2])
2657 : : {
2658 [ # # ]: 0 : if (s1->t_parity[j1] != s2->t_parity[j2]) /* djb-rwth: removing redundant code */
2659 : : {
2660 : 0 : num_dif++;
2661 : : }
2662 : 0 : j1++;
2663 : 0 : j2++;
2664 : : }
2665 : : else
2666 : : {
2667 [ # # ]: 0 : if (s1->nNumber[j1] < s2->nNumber[j2])
2668 : : {
2669 : 0 : num_in1_only++;
2670 [ # # ]: 0 : if (s1->t_parity[j1] == AB_PARITY_UNDF)
2671 : : {
2672 : 0 : num_extra_undf++;
2673 : : }
2674 [ # # ]: 0 : if (bAddSc)
2675 : : {
2676 [ # # ]: 0 : if (picr->num_sc_in1_only < ICR_MAX_SC_IN1_ONLY)
2677 : : {
2678 : 0 : picr->sc_in1_only[picr->num_sc_in1_only++] = j1;
2679 : : }
2680 [ # # ]: 0 : if (s1->t_parity[j1] == AB_PARITY_UNDF)
2681 : : {
2682 [ # # ]: 0 : if (picr->num_sc_undef_in1_only < ICR_MAX_SC_UNDF)
2683 : : {
2684 : 0 : picr->sc_undef_in1_only[picr->num_sc_undef_in1_only++] = j1;
2685 : : }
2686 : : }
2687 : : }
2688 : 0 : j1++;
2689 : : }
2690 : : else
2691 : : {
2692 : 0 : num_in2_only++;
2693 [ # # ]: 0 : if (s2->t_parity[j2] == AB_PARITY_UNDF)
2694 : : {
2695 : 0 : num_miss_undf++;
2696 : : }
2697 [ # # ]: 0 : if (bAddSc)
2698 : : {
2699 [ # # ]: 0 : if (picr->num_sc_in2_only < ICR_MAX_SC_IN2_ONLY)
2700 : : {
2701 : 0 : picr->sc_in2_only[picr->num_sc_in2_only++] = j2;
2702 : : }
2703 [ # # ]: 0 : if (s2->t_parity[j2] == AB_PARITY_UNDF)
2704 : : {
2705 [ # # ]: 0 : if (picr->num_sc_undef_in2_only < ICR_MAX_SC_UNDF)
2706 : : {
2707 : 0 : picr->sc_undef_in2_only[picr->num_sc_undef_in2_only++] = j1;
2708 : : }
2709 : : }
2710 : : }
2711 : 0 : j2++;
2712 : : }
2713 : : }
2714 : : }
2715 [ # # ]: 0 : while (j1 < nNumSc1)
2716 : : {
2717 [ # # ]: 0 : if (s1->t_parity[j1] == AB_PARITY_UNDF)
2718 : : {
2719 : 0 : num_extra_undf++;
2720 : : }
2721 : 0 : num_in1_only++;
2722 [ # # ]: 0 : if (bAddSc)
2723 : : {
2724 [ # # ]: 0 : if (picr->num_sc_in1_only < ICR_MAX_SC_IN1_ONLY)
2725 : : {
2726 : 0 : picr->sc_in1_only[picr->num_sc_in1_only++] = j1;
2727 : : }
2728 [ # # ]: 0 : if (s1->t_parity[j1] == AB_PARITY_UNDF)
2729 : : {
2730 [ # # ]: 0 : if (picr->num_sc_undef_in1_only < ICR_MAX_SC_UNDF)
2731 : : {
2732 : 0 : picr->sc_undef_in1_only[picr->num_sc_undef_in1_only++] = j1;
2733 : : }
2734 : : }
2735 : : }
2736 : 0 : j1++;
2737 : : }
2738 [ # # ]: 0 : while (j2 < nNumSc2)
2739 : : {
2740 [ # # ]: 0 : if (s2->t_parity[j2] == AB_PARITY_UNDF)
2741 : : {
2742 : 0 : num_miss_undf++;
2743 : : }
2744 : 0 : num_in2_only++;
2745 [ # # ]: 0 : if (bAddSc)
2746 : : {
2747 [ # # ]: 0 : if (picr->num_sc_in2_only < ICR_MAX_SC_IN2_ONLY)
2748 : : {
2749 : 0 : picr->sc_in2_only[picr->num_sc_in2_only++] = j2;
2750 : : }
2751 : : }
2752 : 0 : j2++;
2753 : : }
2754 [ # # ]: 0 : if (num_dif)
2755 : : {
2756 : 0 : ret |= IDIF_SC_PARITY;
2757 : : }
2758 [ # # ]: 0 : if (num_in1_only)
2759 : : {
2760 [ # # ]: 0 : if (num_extra_undf)
2761 : : {
2762 : 0 : ret |= IDIF_SC_EXTRA_UNDF;
2763 : : }
2764 [ # # ]: 0 : if (num_in1_only != num_extra_undf)
2765 : : {
2766 : 0 : ret |= IDIF_SC_EXTRA;
2767 : : }
2768 : : }
2769 [ # # ]: 0 : if (num_in2_only)
2770 : : {
2771 [ # # ]: 0 : if (num_miss_undf)
2772 : : {
2773 : 0 : ret |= IDIF_SC_MISS_UNDF;
2774 : : }
2775 [ # # ]: 0 : if (num_in2_only != num_miss_undf)
2776 : : {
2777 : 0 : ret |= IDIF_SC_MISS;
2778 : : }
2779 : : }
2780 : : }
2781 [ # # # # : 0 : if (s1 && s2 && s1->nCompInv2Abs != s2->nCompInv2Abs && s1->nCompInv2Abs && s2->nCompInv2Abs)
# # # # #
# ]
2782 : : {
2783 : 0 : ret |= IDIF_SC_INV;
2784 : : }
2785 : :
2786 [ # # # # : 0 : if ((nNumSb1 || nNumSb2) &&
# # ]
2787 : 0 : (nNumSb1 != nNumSb2 ||
2788 [ # # ]: 0 : memcmp(s1->nBondAtom1, s2->nBondAtom1, nNumSb1 * sizeof(s1->nBondAtom1[0])) ||
2789 [ # # ]: 0 : memcmp(s1->nBondAtom2, s2->nBondAtom2, nNumSb1 * sizeof(s1->nBondAtom2[0])) ||
2790 [ # # ]: 0 : memcmp(s1->b_parity, s2->b_parity, nNumSb1 * sizeof(s1->b_parity[0]))))
2791 : : {
2792 : 0 : num_dif = num_extra_undf = num_miss_undf = num_in1_only = num_in2_only = 0; /* djb-rwth: removing redundant code */
2793 [ # # # # ]: 0 : for (j1 = j2 = 0; j1 < nNumSb1 && j2 < nNumSb2; )
2794 : : {
2795 [ # # ]: 0 : if (s1->nBondAtom1[j1] == s2->nBondAtom1[j2] &&
2796 [ # # ]: 0 : s1->nBondAtom2[j1] == s2->nBondAtom2[j2])
2797 : : {
2798 [ # # ]: 0 : if (s1->b_parity[j1] != s2->b_parity[j2]) /* djb-rwth: removing redundant code */
2799 : : {
2800 : 0 : num_dif++;
2801 : : }
2802 : 0 : j1++;
2803 : 0 : j2++;
2804 : : }
2805 : : else
2806 : : {
2807 [ # # ]: 0 : if (s1->nBondAtom1[j1] < s2->nBondAtom1[j2] ||
2808 [ # # # # ]: 0 : (s1->nBondAtom1[j1] == s2->nBondAtom1[j2] && s1->nBondAtom2[j1] < s2->nBondAtom2[j2])) /* djb-rwth: addressing LLVM warning */
2809 : : {
2810 : 0 : num_in1_only++;
2811 [ # # ]: 0 : if (s1->b_parity[j1] == AB_PARITY_UNDF)
2812 : : {
2813 : 0 : num_extra_undf++;
2814 : : }
2815 [ # # ]: 0 : if (bAddSb)
2816 : : {
2817 [ # # ]: 0 : if (picr->num_sb_in1_only < ICR_MAX_SB_IN1_ONLY)
2818 : : {
2819 : 0 : picr->sb_in1_only[picr->num_sb_in1_only++] = j1;
2820 : : }
2821 [ # # ]: 0 : if (s1->b_parity[j1] == AB_PARITY_UNDF)
2822 : : {
2823 [ # # ]: 0 : if (picr->num_sb_undef_in1_only < ICR_MAX_SB_UNDF)
2824 : : {
2825 : 0 : picr->sb_undef_in1_only[picr->num_sb_undef_in1_only++] = j1;
2826 : : }
2827 : : }
2828 : : }
2829 : 0 : j1++;
2830 : : }
2831 : : else
2832 : : {
2833 : 0 : num_in2_only++;
2834 [ # # ]: 0 : if (s2->b_parity[j2] == AB_PARITY_UNDF)
2835 : : {
2836 : 0 : num_miss_undf++;
2837 : : }
2838 [ # # ]: 0 : if (bAddSb)
2839 : : {
2840 [ # # ]: 0 : if (picr->num_sb_in2_only < ICR_MAX_SB_IN2_ONLY)
2841 : : {
2842 : 0 : picr->sb_in2_only[picr->num_sb_in2_only++] = j2;
2843 : : }
2844 [ # # ]: 0 : if (s2->b_parity[j2] == AB_PARITY_UNDF)
2845 : : {
2846 [ # # ]: 0 : if (picr->num_sb_undef_in2_only < ICR_MAX_SB_UNDF)
2847 : : {
2848 : 0 : picr->sb_undef_in2_only[picr->num_sb_undef_in2_only++] = j1;
2849 : : }
2850 : : }
2851 : : }
2852 : 0 : j2++;
2853 : : }
2854 : : }
2855 : : }
2856 [ # # ]: 0 : while (j1 < nNumSb1)
2857 : : {
2858 : 0 : num_in1_only++;
2859 [ # # ]: 0 : if (s1->b_parity[j1] == AB_PARITY_UNDF)
2860 : : {
2861 : 0 : num_extra_undf++;
2862 : : }
2863 [ # # ]: 0 : if (bAddSb)
2864 : : {
2865 [ # # ]: 0 : if (picr->num_sb_in1_only < ICR_MAX_SB_IN1_ONLY)
2866 : : {
2867 : 0 : picr->sb_in1_only[picr->num_sb_in1_only++] = j1;
2868 : : }
2869 [ # # ]: 0 : if (s1->b_parity[j1] == AB_PARITY_UNDF)
2870 : : {
2871 [ # # ]: 0 : if (picr->num_sb_undef_in1_only < ICR_MAX_SB_UNDF)
2872 : : {
2873 : 0 : picr->sb_undef_in1_only[picr->num_sb_undef_in1_only++] = j1;
2874 : : }
2875 : : }
2876 : : }
2877 : 0 : j1++;
2878 : : }
2879 [ # # ]: 0 : while (j2 < nNumSb2)
2880 : : {
2881 : 0 : num_in2_only++;
2882 [ # # ]: 0 : if (s2->b_parity[j2] == AB_PARITY_UNDF)
2883 : : {
2884 : 0 : num_miss_undf++;
2885 : : }
2886 [ # # ]: 0 : if (bAddSb)
2887 : : {
2888 [ # # ]: 0 : if (picr->num_sb_in2_only < ICR_MAX_SB_IN2_ONLY)
2889 : : {
2890 : 0 : picr->sb_in2_only[picr->num_sb_in2_only++] = j2;
2891 : : }
2892 [ # # ]: 0 : if (s2->b_parity[j2] == AB_PARITY_UNDF)
2893 : : {
2894 [ # # ]: 0 : if (picr->num_sb_undef_in2_only < ICR_MAX_SB_UNDF)
2895 : : {
2896 : 0 : picr->sb_undef_in2_only[picr->num_sb_undef_in2_only++] = j1;
2897 : : }
2898 : : }
2899 : : }
2900 : 0 : j2++;
2901 : : }
2902 [ # # ]: 0 : if (num_dif)
2903 : : {
2904 : 0 : ret |= IDIF_SB_PARITY;
2905 : : }
2906 [ # # ]: 0 : if (num_in1_only)
2907 : : {
2908 [ # # ]: 0 : if (num_extra_undf)
2909 : : {
2910 : 0 : ret |= IDIF_SB_EXTRA_UNDF;
2911 : : }
2912 [ # # ]: 0 : if (num_in1_only != num_extra_undf)
2913 : : {
2914 : 0 : ret |= IDIF_SB_EXTRA;
2915 : : }
2916 : : }
2917 [ # # ]: 0 : if (num_in2_only)
2918 : : {
2919 [ # # ]: 0 : if (num_miss_undf)
2920 : : {
2921 : 0 : ret |= IDIF_SB_MISS_UNDF;
2922 : : }
2923 [ # # ]: 0 : if (num_in2_only != num_miss_undf)
2924 : : {
2925 : 0 : ret |= IDIF_SB_MISS;
2926 : : }
2927 : : }
2928 : : }
2929 : :
2930 : 0 : return ret;
2931 : : }
2932 : :
2933 : :
2934 : : /****************************************************************************/
2935 : 0 : int CompareReversedINChI(INChI* i1 /* InChI from reversed struct */,
2936 : : INChI* i2 /* input InChI */,
2937 : : INChI_Aux* a1,
2938 : : INChI_Aux* a2)
2939 : : {
2940 : : int ret;
2941 : :
2942 [ # # # # ]: 0 : if (i1 == NULL && i2 == NULL)
2943 : : {
2944 : 0 : return 0;
2945 : : }
2946 [ # # ]: 0 : if ((i1 == NULL) ^ (i2 == NULL))
2947 : : {
2948 : 0 : return 1; /* Diff: Missing InChI */
2949 : : }
2950 : :
2951 [ # # ]: 0 : if (i1->nErrorCode == i2->nErrorCode)
2952 : : {
2953 [ # # ]: 0 : if (i1->nErrorCode)
2954 : : {
2955 : 0 : return 0;
2956 : : }
2957 : : }
2958 : : else
2959 : : {
2960 : 0 : return 2; /* Diff: Error codes */
2961 : : }
2962 [ # # ]: 0 : if (i1->bDeleted != i2->bDeleted)
2963 : : {
2964 : 0 : return 1; /* Diff: Missing InChI */
2965 : : }
2966 [ # # ]: 0 : if (i1->nNumberOfAtoms != i2->nNumberOfAtoms)
2967 : : {
2968 : 0 : return 3; /* Diff: Num. atoms */
2969 : : }
2970 : :
2971 [ # # ]: 0 : if (i1->nNumberOfAtoms > 0)
2972 : : {
2973 [ # # ]: 0 : if (memcmp(i1->nAtom, i2->nAtom, i1->nNumberOfAtoms * sizeof(i1->nAtom[0])))
2974 : : {
2975 : 0 : return 4; /* Diff: Elements */
2976 : : }
2977 [ # # ]: 0 : if (strcmp(i1->szHillFormula, i2->szHillFormula))
2978 : : {
2979 : 0 : return 7; /* Diff: Hill Formulas */
2980 : : }
2981 [ # # ]: 0 : if (memcmp(i1->nNum_H, i2->nNum_H, i1->nNumberOfAtoms * sizeof(i1->nNum_H[0])))
2982 : : {
2983 [ # # # # ]: 0 : if (i1->lenConnTable > 1 || i2->lenConnTable > 1)
2984 : : {
2985 : 0 : return 5; /* Diff: H Locations (mobile H present) */
2986 : : }
2987 : : else
2988 : : {
2989 : 0 : return 6; /* Diff: H Locations (no mobile H) */
2990 : : }
2991 : : }
2992 : :
2993 : : /* fixed H */
2994 [ # # # # ]: 0 : if (i1->nNum_H_fixed || i2->nNum_H_fixed)
2995 : : {
2996 : 0 : int bHasFixedH1 = 0, bHasFixedH2 = 0, i, j1, j2;
2997 [ # # ]: 0 : if (i1->nNum_H_fixed)
2998 : : {
2999 [ # # ]: 0 : for (i = 0; i < i1->nNumberOfAtoms; i++)
3000 : : {
3001 [ # # ]: 0 : if (i1->nNum_H_fixed[i])
3002 : : {
3003 : 0 : bHasFixedH1++;
3004 : : }
3005 : : }
3006 : : }
3007 [ # # ]: 0 : if (i2->nNum_H_fixed)
3008 : : {
3009 [ # # ]: 0 : for (i = 0; i < i2->nNumberOfAtoms; i++)
3010 : : {
3011 [ # # ]: 0 : if (i2->nNum_H_fixed[i])
3012 : : {
3013 : 0 : bHasFixedH2++;
3014 : : }
3015 : : }
3016 : : }
3017 : :
3018 : : /* count the differences */
3019 : 0 : j1 = j2 = 0;
3020 [ # # # # ]: 0 : if (bHasFixedH1 && !bHasFixedH2)
3021 : : {
3022 [ # # ]: 0 : for (i = 0; i < i1->nNumberOfAtoms; i++)
3023 : : {
3024 [ # # ]: 0 : if (i1->nNum_H_fixed[i] > 0)
3025 : : {
3026 : 0 : j1++;
3027 : : }
3028 : : else
3029 [ # # ]: 0 : if (i1->nNum_H_fixed[i] < 0)
3030 : : {
3031 : 0 : j2++;
3032 : : }
3033 : : }
3034 : 0 : return 18; /* Diff: Extra Fixed-H */
3035 : : }
3036 : : else
3037 : : {
3038 [ # # # # ]: 0 : if (!bHasFixedH1 && bHasFixedH2)
3039 : : {
3040 [ # # ]: 0 : for (i = j1 = j2 = 0; i < i1->nNumberOfAtoms; i++)
3041 : : {
3042 [ # # ]: 0 : if (0 > i2->nNum_H_fixed[i])
3043 : : {
3044 : 0 : j1++;
3045 : : }
3046 : : else
3047 [ # # ]: 0 : if (0 < i2->nNum_H_fixed[i])
3048 : : {
3049 : 0 : j2++;
3050 : : }
3051 : : }
3052 : 0 : return 19; /* Diff: Missed Fixed-H */
3053 : : }
3054 : : else
3055 : : {
3056 [ # # # # ]: 0 : if (bHasFixedH1 && bHasFixedH2 &&
3057 [ # # ]: 0 : memcmp(i1->nNum_H_fixed, i2->nNum_H_fixed, i1->nNumberOfAtoms * sizeof(i1->nNum_H_fixed[0])))
3058 : : {
3059 [ # # ]: 0 : for (i = j1 = j2 = 0; i < i1->nNumberOfAtoms; i++)
3060 : : {
3061 [ # # ]: 0 : if (i1->nNum_H_fixed[i] > i2->nNum_H_fixed[i])
3062 : : {
3063 : 0 : j1++;
3064 : : }
3065 : : else
3066 : : {
3067 [ # # ]: 0 : if (i1->nNum_H_fixed[i] < i2->nNum_H_fixed[i])
3068 : : {
3069 : 0 : j2++;
3070 : : }
3071 : : }
3072 : : }
3073 : : }
3074 : : }
3075 : : }
3076 [ # # # # : 0 : ret = (j1 && j2) ? 20 : j1 ? 18 : j2 ? 19 : 0;
# # # # ]
3077 [ # # ]: 0 : if (ret)
3078 : : {
3079 : 0 : return ret; /* 20 => Diff: NotEql Fixed-H */
3080 : : /* 19 => Diff: Missed Fixed-H (i1 has less) */
3081 : : /* 18 => Diff: Extra Fixed-H (i1 has more) */
3082 : : }
3083 : : }
3084 : : }
3085 : :
3086 [ # # ]: 0 : if (i1->lenConnTable != i2->lenConnTable)
3087 : : {
3088 : 0 : return 8; /* Diff: Connections length */
3089 : : }
3090 [ # # # # ]: 0 : if (i1->lenConnTable > 0 && memcmp(i1->nConnTable, i2->nConnTable, i1->lenConnTable * sizeof(i1->nConnTable[0])))
3091 : : {
3092 : 0 : return 9; /* Diff: Connections */
3093 : : }
3094 : :
3095 : : /* output special cases: different number of t-groups, different sizes of t-groups, different endpoints */
3096 [ # # # # : 0 : if (i1->lenTautomer != i2->lenTautomer && (i1->lenTautomer > 1 || i2->lenTautomer > 1))
# # ]
3097 : : {
3098 : 0 : return 10; /* Diff: Mobile groups length */ /* in isotopic or deprotonated cases i1->lenTautomer == 1 && i1->nTautomer[0] = 0 */
3099 : : }
3100 [ # # # # ]: 0 : if ((i1->lenTautomer > 1 && i2->lenTautomer > 1) &&
3101 [ # # ]: 0 : memcmp(i1->nTautomer, i2->nTautomer, i1->lenTautomer * sizeof(i1->nTautomer[0])))
3102 : : {
3103 : 0 : return 11; /* Diff: Mobile groups */
3104 : : }
3105 : :
3106 [ # # ]: 0 : if (i1->nNumberOfIsotopicAtoms != i2->nNumberOfIsotopicAtoms)
3107 : : {
3108 : 0 : return 12; /* Diff: Isotopic atoms number */
3109 : : }
3110 [ # # # # ]: 0 : if (i1->nNumberOfIsotopicAtoms > 0 && memcmp(i1->IsotopicAtom, i2->IsotopicAtom, i1->nNumberOfIsotopicAtoms * sizeof(i1->IsotopicAtom[0])))
3111 : : {
3112 : 0 : return 13; /* Diff: Isotopic atoms */
3113 : : }
3114 [ # # ]: 0 : if (i1->nTotalCharge != i2->nTotalCharge)
3115 : : {
3116 : 0 : return 14; /* Diff: Charge */
3117 : : }
3118 : :
3119 : : /*
3120 : : if ( i1->nNumberOfIsotopicTGroups != i2->nNumberOfIsotopicTGroups )
3121 : : {
3122 : : return 14;
3123 : : }
3124 : : if ( i1->nNumberOfIsotopicTGroups > 0 && memcmp( i1->IsotopicTGroup, i2->IsotopicTGroup, i1->nNumberOfIsotopicTGroups*sizeof(i1->IsotopicTGroup[0]) ) )
3125 : : {
3126 : : return 15;
3127 : : }
3128 : : */
3129 : :
3130 [ # # # # ]: 0 : if (a1 && a2)
3131 : : {
3132 [ # # ]: 0 : if (a1->nNumRemovedProtons != a2->nNumRemovedProtons)
3133 : : {
3134 : 0 : return 16; /* Diff: Number of removed protons */
3135 : : }
3136 [ # # ]: 0 : if (memcmp(a1->nNumRemovedIsotopicH, a2->nNumRemovedIsotopicH, sizeof(a1->nNumRemovedIsotopicH)))
3137 : : {
3138 : 0 : return 17; /* Diff: Removed isotopic H */
3139 : : }
3140 : : }
3141 : :
3142 : : /*
3143 : : if ( i1->nPossibleLocationsOfIsotopicH && i2->nPossibleLocationsOfIsotopicH ) {
3144 : : {
3145 : : if ( i1->nPossibleLocationsOfIsotopicH[0] != i2->nPossibleLocationsOfIsotopicH[0] ||
3146 : : memcmp(i1->nPossibleLocationsOfIsotopicH, i2->nPossibleLocationsOfIsotopicH,
3147 : : sizeof(i1->nPossibleLocationsOfIsotopicH[0])*i1->nPossibleLocationsOfIsotopicH[0]) )
3148 : : {
3149 : : return 18;
3150 : : }
3151 : : }
3152 : : } else
3153 : : {
3154 : : if ( !i1->nPossibleLocationsOfIsotopicH != !i2->nPossibleLocationsOfIsotopicH ) {
3155 : : {
3156 : : return 19;}
3157 : : }
3158 : : }
3159 : : */
3160 : :
3161 : : /* ret = 20..31 => 40..51 */
3162 [ # # ]: 0 : if ((ret = CompareReversedStereoINChI(i1->Stereo, i2->Stereo))) /* djb-rwth: addressing LLVM warning */
3163 : : {
3164 : 0 : return ret + 20;
3165 : : }
3166 : : /* ret = 40..51 => 60..71 */
3167 : :
3168 [ # # # # : 0 : if (!i2->StereoIsotopic && i2->Stereo && i1->StereoIsotopic &&
# # ]
3169 [ # # # # ]: 0 : 0 < (i1->StereoIsotopic->nNumberOfStereoBonds + i1->StereoIsotopic->nNumberOfStereoCenters) &&
3170 : 0 : 0 == CompareReversedStereoINChI(i1->StereoIsotopic, i2->Stereo))
3171 : : {
3172 : : /* InChI from reversed structure does not contain fully duplicated isotopic stereo */
3173 : : ;
3174 : : }
3175 : : else
3176 : : {
3177 [ # # ]: 0 : if ((ret = CompareReversedStereoINChI(i1->StereoIsotopic, i2->StereoIsotopic))) /* djb-rwth: addressing LLVM warning */
3178 : : {
3179 : 0 : return ret + 40;
3180 : : }
3181 : : }
3182 : :
3183 : 0 : return 0;
3184 : : }
3185 : :
3186 : :
3187 : : /****************************************************************************/
3188 : 0 : int CompareIcr(ICR* picr1,
3189 : : ICR* picr2,
3190 : : INCHI_MODE* pin1,
3191 : : INCHI_MODE* pin2,
3192 : : INCHI_MODE mask)
3193 : : {
3194 : 0 : int nNumExtraBits1 = 0, nNumExtraBits2 = 0, bit1, bit2;
3195 : 0 : INCHI_MODE Flg1 = picr1->flags, Flg2 = picr2->flags, cur_bit = 1, in1, in2;
3196 : : int i, ret;
3197 : :
3198 : : /* compare flags */
3199 : 0 : in1 = in2 = 0;
3200 [ # # # # ]: 0 : for (i = 0; Flg1 || Flg2; i++, Flg1 >>= 1, Flg2 >>= 1, cur_bit <<= 1)
3201 : : {
3202 [ # # ]: 0 : if (!(mask & cur_bit))
3203 : : {
3204 : 0 : continue;
3205 : : }
3206 : 0 : bit1 = Flg1 & 1;
3207 : 0 : bit2 = Flg2 & 1;
3208 [ # # # # ]: 0 : if (bit1 && !bit2)
3209 : : {
3210 : 0 : in1 |= 1 << i;
3211 : 0 : nNumExtraBits1++;
3212 : : }
3213 : : else
3214 : : {
3215 [ # # # # ]: 0 : if (!bit1 && bit2)
3216 : : {
3217 : 0 : in2 |= 1 << i;
3218 : 0 : nNumExtraBits2++;
3219 : : }
3220 : : }
3221 : : }
3222 [ # # # # ]: 0 : if (nNumExtraBits1 && !nNumExtraBits2)
3223 : : {
3224 : 0 : ret = 1;
3225 : : }
3226 : : else
3227 : : {
3228 [ # # # # ]: 0 : if (!nNumExtraBits1 && nNumExtraBits2)
3229 : : {
3230 : 0 : ret = -1;
3231 : : }
3232 : : else
3233 : : {
3234 [ # # # # ]: 0 : if (!in1 && !in2)
3235 : : {
3236 : 0 : ret = 0;
3237 : : }
3238 : : else
3239 : : {
3240 : 0 : ret = 2; /* compare produced undefined results */
3241 : : }
3242 : : }
3243 : : }
3244 : :
3245 [ # # ]: 0 : if (pin1)
3246 : : {
3247 : 0 : *pin1 = in1;
3248 : : }
3249 [ # # ]: 0 : if (pin2)
3250 : : {
3251 : 0 : *pin2 = in2;
3252 : : }
3253 : :
3254 : : /* more detailed compare not implemented */
3255 : :
3256 : 0 : return ret;
3257 : : }
3258 : :
3259 : :
3260 : : /****************************************************************************/
3261 : 0 : INCHI_MODE CompareReversedINChI2(INChI* i1 /* InChI from reversed struct */,
3262 : : INChI* i2 /* input InChI */,
3263 : : INChI_Aux* a1,
3264 : : INChI_Aux* a2,
3265 : : ICR* picr,
3266 : : int* err)
3267 : : {
3268 : 0 : INCHI_MODE ret = 0;
3269 : 0 : INChI_Stereo* Stereo1 = NULL, * Stereo2 = NULL;
3270 : : int n1, n2, m, j, j1, j2, ret2, num_H1, num_H2;
3271 : :
3272 : 0 : *err = 0;
3273 : :
3274 : 0 : memset(picr, 0, sizeof(*picr)); /* djb-rwth: memset_s C11/Annex K variant? */
3275 : :
3276 [ # # # # ]: 0 : if (i1 == NULL && i2 == NULL)
3277 : : {
3278 : 0 : return 0;
3279 : : }
3280 [ # # ]: 0 : if ((i1 == NULL) ^ (i2 == NULL))
3281 : : {
3282 : 0 : ret |= IDIF_PROBLEM; /* one InChI exists while another doesn't */
3283 : 0 : goto exit_function;
3284 : : }
3285 : :
3286 [ # # ]: 0 : if (i1->nErrorCode == i2->nErrorCode)
3287 : : {
3288 [ # # ]: 0 : if (i1->nErrorCode)
3289 : : {
3290 : 0 : ret |= IDIF_PROBLEM; /* both InChI have same error codes */
3291 : 0 : goto exit_function;
3292 : : }
3293 : : }
3294 : : else
3295 : : {
3296 : 0 : ret |= IDIF_PROBLEM; /* at least one InChI has an error code */
3297 : 0 : goto exit_function;
3298 : : }
3299 : :
3300 [ # # ]: 0 : if (i1->nNumberOfAtoms != i2->nNumberOfAtoms)
3301 : : {
3302 : 0 : ret |= IDIF_NUM_AT;
3303 : 0 : goto exit_function;
3304 : : }
3305 [ # # ]: 0 : if (i1->nNumberOfAtoms > 0)
3306 : : {
3307 [ # # ]: 0 : if (memcmp(i1->nAtom, i2->nAtom, i1->nNumberOfAtoms * sizeof(i1->nAtom[0])))
3308 : : {
3309 : 0 : ret |= IDIF_ATOMS;
3310 : 0 : goto exit_function;
3311 : : }
3312 : : /* IDIF_NON_TAUT_H, IDIF_MORE_FH, IDIF_LESS_FH */
3313 [ # # ]: 0 : if (memcmp(i1->nNum_H, i2->nNum_H, i1->nNumberOfAtoms * sizeof(i1->nNum_H[0])))
3314 : : {
3315 : 0 : ret |= IDIF_POSITION_H;
3316 [ # # ]: 0 : for (j1 = 0; j1 < i1->nNumberOfAtoms; j1++)
3317 : : {
3318 [ # # # # ]: 0 : if (i1->nNum_H[j1] != i2->nNum_H[j1] && picr->num_diff_pos_H < ICR_MAX_DIFF_FIXED_H)
3319 : : {
3320 : 0 : picr->diff_pos_H_at[picr->num_diff_pos_H] = j1;
3321 : 0 : picr->diff_pos_H_nH[picr->num_diff_pos_H] = i1->nNum_H[j1] - i2->nNum_H[j1];
3322 : 0 : picr->num_diff_pos_H++;
3323 : : }
3324 : : }
3325 : : }
3326 : : /* fixed H */
3327 [ # # # # ]: 0 : if (i1->nNum_H_fixed || i2->nNum_H_fixed)
3328 : : {
3329 : 0 : int bHasFixedH1 = 0, bHasFixedH2 = 0, i;
3330 [ # # ]: 0 : if (i1->nNum_H_fixed)
3331 : : {
3332 [ # # ]: 0 : for (i = 0; i < i1->nNumberOfAtoms; i++)
3333 : : {
3334 [ # # ]: 0 : if (i1->nNum_H_fixed[i])
3335 : : {
3336 : 0 : bHasFixedH1++;
3337 : : }
3338 : : }
3339 : : }
3340 [ # # ]: 0 : if (i2->nNum_H_fixed)
3341 : : {
3342 [ # # ]: 0 : for (i = 0; i < i2->nNumberOfAtoms; i++)
3343 : : {
3344 [ # # ]: 0 : if (i2->nNum_H_fixed[i])
3345 : : {
3346 : 0 : bHasFixedH2++;
3347 : : }
3348 : : }
3349 : : }
3350 [ # # # # ]: 0 : if (bHasFixedH1 && !bHasFixedH2)
3351 : : {
3352 [ # # ]: 0 : for (i = j = 0; i < i1->nNumberOfAtoms; i++)
3353 : : {
3354 [ # # ]: 0 : if (i1->nNum_H_fixed[i])
3355 : : {
3356 [ # # ]: 0 : if (j < ICR_MAX_DIFF_FIXED_H)
3357 : : {
3358 : 0 : picr->fixed_H_at1_more[j] = i;
3359 : 0 : picr->fixed_H_nH1_more[j] = i1->nNum_H_fixed[i];
3360 : 0 : j++;
3361 : : }
3362 : : }
3363 : : }
3364 : 0 : picr->num_fixed_H1_more = j;
3365 : 0 : ret |= IDIF_MORE_FH; /* Extra Fixed-H */
3366 : : }
3367 : : else
3368 : : {
3369 [ # # # # ]: 0 : if (!bHasFixedH1 && bHasFixedH2)
3370 : : {
3371 [ # # ]: 0 : for (i = j = 0; i < i2->nNumberOfAtoms; i++)
3372 : : {
3373 [ # # ]: 0 : if (i2->nNum_H_fixed[i])
3374 : : {
3375 [ # # ]: 0 : if (j < ICR_MAX_DIFF_FIXED_H)
3376 : : {
3377 : 0 : picr->fixed_H_at2_more[j] = i;
3378 : 0 : picr->fixed_H_nH2_more[j] = i2->nNum_H_fixed[i];
3379 : 0 : j++;
3380 : : }
3381 : : }
3382 : : }
3383 : 0 : picr->num_fixed_H2_more = j;
3384 : 0 : ret |= IDIF_LESS_FH; /* Missed Fixed-H */
3385 : : }
3386 : : else
3387 : : {
3388 [ # # # # ]: 0 : if (bHasFixedH1 && bHasFixedH2 &&
3389 [ # # ]: 0 : memcmp(i1->nNum_H_fixed, i2->nNum_H_fixed, i1->nNumberOfAtoms * sizeof(i1->nNum_H_fixed[0])))
3390 : : {
3391 [ # # ]: 0 : for (i = j1 = j2 = 0; i < i1->nNumberOfAtoms; i++)
3392 : : {
3393 [ # # ]: 0 : if (i1->nNum_H_fixed[i] > i2->nNum_H_fixed[i])
3394 : : {
3395 [ # # ]: 0 : if (j1 < ICR_MAX_DIFF_FIXED_H)
3396 : : {
3397 : 0 : picr->fixed_H_at1_more[j1] = i;
3398 : 0 : picr->fixed_H_nH1_more[j1] = i1->nNum_H_fixed[i] - i2->nNum_H_fixed[i];
3399 : 0 : j1++;
3400 : : }
3401 : : }
3402 : : else
3403 : : {
3404 [ # # ]: 0 : if (i1->nNum_H_fixed[i] < i2->nNum_H_fixed[i])
3405 : : {
3406 [ # # ]: 0 : if (j2 < ICR_MAX_DIFF_FIXED_H)
3407 : : {
3408 : 0 : picr->fixed_H_at2_more[j2] = i;
3409 : 0 : picr->fixed_H_nH2_more[j2] = i2->nNum_H_fixed[i] - i1->nNum_H_fixed[i];
3410 : 0 : j2++;
3411 : : }
3412 : : }
3413 : : }
3414 : : }
3415 [ # # # # ]: 0 : ret |= (j1 ? IDIF_MORE_FH : 0) | (j2 ? IDIF_LESS_FH : 0);
3416 : 0 : picr->num_fixed_H1_more = j1;
3417 : 0 : picr->num_fixed_H2_more = j2;
3418 : : }
3419 : : }
3420 : : }
3421 : : }
3422 : : }
3423 : :
3424 : : /* compare formulas and H */
3425 : 0 : num_H1 = 0;
3426 : 0 : num_H2 = 0;
3427 : 0 : ret2 = CompareHillFormulasNoH(i1->szHillFormula, i2->szHillFormula, &num_H1, &num_H2);
3428 : 0 : picr->tot_num_H1 = num_H1;
3429 : 0 : picr->tot_num_H2 = num_H2;
3430 [ # # ]: 0 : if (ret2)
3431 : : {
3432 : 0 : ret |= IDIF_NUM_EL;
3433 : 0 : goto exit_function;
3434 : : }
3435 [ # # ]: 0 : if (num_H1 > num_H2)
3436 : : {
3437 : 0 : ret |= IDIF_MORE_H;
3438 : : }
3439 [ # # ]: 0 : if (num_H1 < num_H2)
3440 : : {
3441 : 0 : ret |= IDIF_LESS_H;
3442 : : }
3443 [ # # ]: 0 : if (i1->lenConnTable != i2->lenConnTable)
3444 : : {
3445 : 0 : ret |= IDIF_CON_LEN;
3446 : 0 : goto exit_function;
3447 : : }
3448 : : else
3449 : : {
3450 [ # # # # ]: 0 : if (i1->lenConnTable > 0 && memcmp(i1->nConnTable, i2->nConnTable, i1->lenConnTable * sizeof(i1->nConnTable[0])))
3451 : : {
3452 : 0 : ret |= IDIF_CON_TBL;
3453 : 0 : goto exit_function;
3454 : : }
3455 : : }
3456 : :
3457 : : /* output special cases: different number of t-groups, different sizes of t-groups, different endpoints */
3458 : : /* in isotopic or deprotonated cases i1->lenTautomer == 1 && i1->nTautomer[0] = 0 */
3459 : :
3460 : : /*
3461 : : if ( i1->lenTautomer != i2->lenTautomer && (i1->lenTautomer > 1 || i2->lenTautomer > 1) ) {
3462 : : ret |= IDIF_TAUT_LEN;
3463 : : }
3464 : : */
3465 : :
3466 : : /* compare number of t-groups */
3467 [ # # ]: 0 : n1 = i1->lenTautomer ? i1->nTautomer[0] : 0;
3468 [ # # ]: 0 : n2 = i2->lenTautomer ? i2->nTautomer[0] : 0;
3469 [ # # # # ]: 0 : if (!n1 && n2)
3470 : : {
3471 : 0 : ret |= IDIF_NO_TAUT;
3472 : : }
3473 : : else
3474 : : {
3475 [ # # # # ]: 0 : if (n1 && !n2)
3476 : : {
3477 : 0 : ret |= IDIF_WRONG_TAUT;
3478 : : }
3479 : : else
3480 : : {
3481 [ # # # # ]: 0 : if (n1 == 1 && n2 > 1)
3482 : : {
3483 : 0 : ret |= IDIF_SINGLE_TG;
3484 : : }
3485 : : else
3486 : : {
3487 [ # # # # ]: 0 : if (n1 > 1 && n2 == 1)
3488 : : {
3489 : 0 : ret |= IDIF_MULTIPLE_TG;
3490 : : }
3491 : : else
3492 : : {
3493 [ # # ]: 0 : if (n1 != n2)
3494 : : {
3495 : 0 : ret |= IDIF_NUM_TG;
3496 : : }
3497 : : }
3498 : : }
3499 : : }
3500 : : }
3501 : :
3502 [ # # # # ]: 0 : if (n1 || n2)
3503 : : {
3504 : : /* number of endpoints */
3505 : 0 : int num1 = 0, num2 = 0, num_M1 = 0, num_M2 = 0;
3506 : : int len, num_eq, num_in1_only, num_in2_only;
3507 : 0 : AT_NUMB* pe1 = (AT_NUMB*)inchi_malloc(((long long)i1->lenTautomer + 1) * sizeof(pe1[0])); /* djb-rwth: cast operator added */
3508 : 0 : AT_NUMB* pe2 = (AT_NUMB*)inchi_malloc(((long long)i2->lenTautomer + 1) * sizeof(pe2[0])); /* djb-rwth: cast operator added */
3509 : 0 : num_H1 = num_H2 = 0;
3510 : : /* collect endpoints, H, (-) */
3511 [ # # # # ]: 0 : if (!pe1 || !pe2)
3512 : : {
3513 [ # # ]: 0 : if (pe1)
3514 : : {
3515 [ # # ]: 0 : inchi_free(pe1);
3516 : : }
3517 [ # # ]: 0 : if (pe2)
3518 : : {
3519 [ # # ]: 0 : inchi_free(pe2);
3520 : : }
3521 : 0 : *err = -1; /* allocation error */
3522 : 0 : goto exit_function;
3523 : : }
3524 [ # # ]: 0 : for (m = 1; m < i1->lenTautomer; m += len)
3525 : : {
3526 : 0 : len = i1->nTautomer[m++];
3527 : 0 : num_H1 += i1->nTautomer[m];
3528 : 0 : num_M1 += i1->nTautomer[m + 1];
3529 [ # # ]: 0 : for (j = 2; j < len; j++)
3530 : : {
3531 : 0 : pe1[num1++] = i1->nTautomer[m + j];
3532 : : }
3533 : : }
3534 [ # # ]: 0 : for (m = 1; m < i2->lenTautomer; m += len)
3535 : : {
3536 : 0 : len = i2->nTautomer[m++];
3537 : 0 : num_H2 += i2->nTautomer[m];
3538 : 0 : num_M2 += i2->nTautomer[m + 1];
3539 [ # # ]: 0 : for (j = 2; j < len; j++)
3540 : : {
3541 : 0 : pe2[num2++] = i2->nTautomer[m + j];
3542 : : }
3543 : : }
3544 : 0 : picr->num_taut_H1 = num_H1;
3545 : 0 : picr->num_taut_H2 = num_H2;
3546 : 0 : picr->num_taut_M1 = num_M1;
3547 : 0 : picr->num_taut_M2 = num_M2;
3548 : : /* sort endpoints */
3549 : 0 : insertions_sort_AT_RANK(pe1, num1);
3550 : 0 : insertions_sort_AT_RANK(pe2, num2);
3551 : : /* compare */
3552 : : /*
3553 : : if ( num1 < num2 ) {
3554 : : ret |= IDIF_LESS_TG_ENDP;
3555 : : } else
3556 : : if ( num1 > num2 ) {
3557 : : ret |= IDIF_MORE_TG_ENDP;
3558 : : }
3559 : : */
3560 : : /* compare all */
3561 : 0 : num_eq = num_in1_only = num_in2_only = 0;
3562 [ # # # # ]: 0 : for (j1 = j2 = 0; j1 < num1 && j2 < num2; )
3563 : : {
3564 [ # # ]: 0 : if (pe1[j1] == pe2[j2])
3565 : : {
3566 : 0 : j1++;
3567 : 0 : j2++;
3568 : 0 : num_eq++;
3569 : : }
3570 : : else
3571 : : {
3572 [ # # ]: 0 : if (pe1[j1] < pe2[j2])
3573 : : { /* BC: fixed, was pe2[j1] 2006-03-27 */
3574 [ # # ]: 0 : if (picr->num_endp_in1_only < ICR_MAX_ENDP_IN1_ONLY)
3575 : : {
3576 : 0 : picr->endp_in1_only[picr->num_endp_in1_only++] = pe1[j1];
3577 : : }
3578 : 0 : j1++;
3579 : 0 : num_in1_only++;
3580 : : }
3581 : : else
3582 : : {
3583 [ # # ]: 0 : if (picr->num_endp_in2_only < ICR_MAX_ENDP_IN2_ONLY)
3584 : : {
3585 : 0 : picr->endp_in2_only[picr->num_endp_in2_only++] = pe2[j2];
3586 : : }
3587 : 0 : j2++;
3588 : 0 : num_in2_only++;
3589 : : }
3590 : : }
3591 : : }
3592 [ # # ]: 0 : while (j1 < num1)
3593 : : {
3594 [ # # ]: 0 : if (picr->num_endp_in1_only < ICR_MAX_ENDP_IN1_ONLY)
3595 : : {
3596 : 0 : picr->endp_in1_only[picr->num_endp_in1_only++] = pe1[j1];
3597 : : }
3598 : 0 : j1++;
3599 : 0 : num_in1_only++;
3600 : : }
3601 [ # # ]: 0 : while (j2 < num2)
3602 : : {
3603 [ # # ]: 0 : if (picr->num_endp_in2_only < ICR_MAX_ENDP_IN2_ONLY)
3604 : : {
3605 : 0 : picr->endp_in2_only[picr->num_endp_in2_only++] = pe2[j2];
3606 : : }
3607 : 0 : j2++;
3608 : 0 : num_in2_only++;
3609 : : }
3610 [ # # ]: 0 : if (num_in1_only)
3611 : : {
3612 : 0 : ret |= IDIF_EXTRA_TG_ENDP;
3613 : : }
3614 [ # # ]: 0 : if (num_in2_only)
3615 : : {
3616 : 0 : ret |= IDIF_MISS_TG_ENDP;
3617 : : }
3618 [ # # # # : 0 : if (!num_in1_only && !num_in2_only && num_eq)
# # ]
3619 : : {
3620 : : ; /* same t-groups endpoints */
3621 : : }
3622 : : else
3623 : : {
3624 : 0 : ret |= IDIF_DIFF_TG_ENDP;
3625 : : }
3626 [ # # ]: 0 : inchi_free(pe1);
3627 [ # # ]: 0 : inchi_free(pe2);
3628 : : }
3629 : :
3630 [ # # # # ]: 0 : if ((i1->lenTautomer > 1 && i2->lenTautomer > 1) &&
3631 [ # # ]: 0 : (i1->lenTautomer != i2->lenTautomer ||
3632 [ # # ]: 0 : memcmp(i1->nTautomer, i2->nTautomer, i1->lenTautomer * sizeof(i1->nTautomer[0]))))
3633 : : {
3634 : 0 : ret |= IDIF_TG;
3635 : : }
3636 : :
3637 [ # # ]: 0 : if (i1->nNumberOfIsotopicAtoms != i2->nNumberOfIsotopicAtoms)
3638 : : {
3639 : 0 : ret |= IDIF_NUM_ISO_AT;
3640 : : }
3641 : : else
3642 : : {
3643 [ # # # # ]: 0 : if (i1->nNumberOfIsotopicAtoms > 0 && memcmp(i1->IsotopicAtom, i2->IsotopicAtom, i1->nNumberOfIsotopicAtoms * sizeof(i1->IsotopicAtom[0])))
3644 : : {
3645 : 0 : ret |= IDIF_ISO_AT;
3646 : : }
3647 : : }
3648 [ # # ]: 0 : if (i1->nTotalCharge != i2->nTotalCharge)
3649 : : {
3650 : 0 : ret |= IDIF_CHARGE;
3651 : : }
3652 [ # # # # : 0 : if (a1 && a1->nNumRemovedProtons && (!a2 || a2->nNumRemovedProtons != a1->nNumRemovedProtons))
# # # # ]
3653 : : {
3654 : 0 : ret |= IDIF_REM_PROT;
3655 : : }
3656 [ # # # # ]: 0 : if (a1 && (!a2 ||
3657 [ # # ]: 0 : a2->nNumRemovedIsotopicH[0] != a1->nNumRemovedIsotopicH[0] ||
3658 [ # # ]: 0 : a2->nNumRemovedIsotopicH[1] != a1->nNumRemovedIsotopicH[1] ||
3659 [ # # ]: 0 : a2->nNumRemovedIsotopicH[2] != a1->nNumRemovedIsotopicH[2]))
3660 : : {
3661 : 0 : ret |= IDIF_REM_ISO_H;
3662 : : }
3663 : :
3664 : : /*
3665 : : if ( i1->nPossibleLocationsOfIsotopicH && i2->nPossibleLocationsOfIsotopicH ) {
3666 : : if ( i1->nPossibleLocationsOfIsotopicH[0] != i2->nPossibleLocationsOfIsotopicH[0] ||
3667 : : memcmp(i1->nPossibleLocationsOfIsotopicH, i2->nPossibleLocationsOfIsotopicH,
3668 : : sizeof(i1->nPossibleLocationsOfIsotopicH[0])*i1->nPossibleLocationsOfIsotopicH[0]) )
3669 : : return 18;
3670 : : } else
3671 : : if ( !i1->nPossibleLocationsOfIsotopicH != !i2->nPossibleLocationsOfIsotopicH ) {
3672 : : return 19;
3673 : : }
3674 : : */
3675 : :
3676 [ # # ]: 0 : if (i1->StereoIsotopic &&
3677 [ # # ]: 0 : i1->StereoIsotopic->nNumberOfStereoBonds + i1->StereoIsotopic->nNumberOfStereoCenters)
3678 : : {
3679 : 0 : Stereo1 = i1->StereoIsotopic;
3680 : : }
3681 : : else
3682 : : {
3683 : 0 : Stereo1 = i1->Stereo;
3684 : : }
3685 [ # # ]: 0 : if (i2->StereoIsotopic &&
3686 [ # # ]: 0 : i2->StereoIsotopic->nNumberOfStereoBonds + i2->StereoIsotopic->nNumberOfStereoCenters)
3687 : : {
3688 : 0 : Stereo2 = i2->StereoIsotopic;
3689 : : }
3690 : : else
3691 : : {
3692 : 0 : Stereo2 = i2->Stereo;
3693 : : }
3694 : 0 : ret |= CompareReversedStereoINChI2(Stereo1, Stereo2, picr);
3695 : :
3696 : 0 : exit_function:
3697 : :
3698 : 0 : picr->flags = ret;
3699 : :
3700 : 0 : return ret;
3701 : : }
3702 : : #endif /* } READ_INCHI_STRING */
3703 : :
3704 : :
3705 : : /****************************************************************************/
3706 : 69 : int Create_INChI(CANON_GLOBALS* pCG,
3707 : : INCHI_CLOCK* ic,
3708 : : INPUT_PARMS* ip,
3709 : : INChI** ppINChI,
3710 : : INChI_Aux** ppINChI_Aux,
3711 : : ORIG_ATOM_DATA* orig_inp_data,
3712 : : inp_ATOM* inp_at,
3713 : : INP_ATOM_DATA* out_norm_data[2],
3714 : : int num_inp_at,
3715 : : INCHI_MODE nUserMode,
3716 : : INCHI_MODE* pbTautFlags,
3717 : : INCHI_MODE* pbTautFlagsDone,
3718 : : struct tagInchiTime* ulMaxTime,
3719 : : T_GROUP_INFO* ti_out,
3720 : : char* pStrErrStruct)
3721 : : {
3722 : : /*
3723 : : #define NON_TAUT 0
3724 : : #define TAUT 1
3725 : : */
3726 : 69 : int nebend = 0, * ebend = NULL;
3727 : :
3728 : : sp_ATOM* at[TAUT_NUM]; /* at[0]=>non-tautomeric, at[1]=>tautomeric */
3729 : 69 : int i, n1, n2, num_atoms, num_at_tg, num_removed_H, num_removed_H_taut = 0, ret = 0, ret2 = 0;
3730 : 69 : INCHI_MODE nMode = 0;
3731 : : T_GROUP_INFO vt_group_info;
3732 : : T_GROUP_INFO vt_group_info_orig;
3733 : 69 : T_GROUP_INFO* /*const*/ t_group_info = &vt_group_info;
3734 : 69 : T_GROUP_INFO* /*const*/ t_group_info_orig = &vt_group_info_orig;
3735 : :
3736 : : CANON_STAT CS, CS2;
3737 : 69 : CANON_STAT* pCS = &CS;
3738 : 69 : CANON_STAT* pCS2 = &CS2; /* save all allocations to avoid memory leaks in case Canon_INChI() removes the pointer */
3739 : :
3740 : : ATOM_SIZES s[TAUT_NUM];
3741 : :
3742 : : BCN Bcn;
3743 : 69 : BCN* pBCN = &Bcn;
3744 : :
3745 : 69 : int bHasIsotopicAtoms = 0;
3746 : 69 : int bMayHaveStereo = 0;
3747 : 69 : int num_taut_at = 0;
3748 : :
3749 : 69 : inp_ATOM* out_at = NULL; /*, *norm_at_fixed_bonds[TAUT_NUM]; */ /* = {out_norm_nontaut_at, out_norm_taut_at} ; */
3750 : 69 : INChI* pINChI = NULL; /* added initialization 2006-03 */
3751 : 69 : INChI_Aux* pINChI_Aux = NULL; /* added initialization 2006-03 */
3752 : 69 : int bPointedEdgeStereo = ((TG_FLAG_POINTED_EDGE_STEREO & *pbTautFlags) ? PES_BIT_POINT_EDGE_STEREO : 0)
3753 : 69 : | ((TG_FLAG_PHOSPHINE_STEREO & *pbTautFlags) ? PES_BIT_PHOSPHINE_STEREO : 0)
3754 : 69 : | ((TG_FLAG_ARSINE_STEREO & *pbTautFlags) ? PES_BIT_ARSINE_STEREO : 0)
3755 : 69 : | ((TG_FLAG_FIX_SP3_BUG & *pbTautFlags) ? PES_BIT_FIX_SP3_BUG : 0);
3756 : 69 : INCHI_MODE bTautFlags = (*pbTautFlags & (~(INCHI_MODE)TG_FLAG_ALL_TAUTOMERIC));
3757 : 69 : INCHI_MODE bTautFlagsDone = (*pbTautFlagsDone /*& (~(INCHI_MODE)TG_FLAG_ALL_TAUTOMERIC) */);
3758 : : #if ( bRELEASE_VERSION == 0 )
3759 : : int bExtract = 0; /* EXTR_HAS_ATOM_WITH_DEFINED_PARITY; */
3760 : : #endif
3761 : :
3762 : : #ifdef GHI100_FIX
3763 : : #if ((SPRINTF_FLAG != 1) && (SPRINTF_FLAG != 2))
3764 : : setlocale(LC_ALL, "en-US"); /* djb-rwth: setting all locales to "en-US" */
3765 : : #endif
3766 : : #endif
3767 : :
3768 : : /* */
3769 : 69 : int bFixIsoFixedH = 0;
3770 : 69 : int bFixTermHChrg = 0;
3771 : :
3772 : 69 : int LargeMolecules = ip->bLargeMolecules;
3773 : : /* djb-rwth: removing redundant variables */
3774 : :
3775 : : /* vABParityUnknown holds actual value of an internal constant signifying
3776 : : unknown parity: either the same as for undefined parity (default==standard)
3777 : : or a specific one (non-std; requested by SLUUD switch). */
3778 : 69 : int vABParityUnknown = AB_PARITY_UNDF;
3779 [ - + ]: 69 : if (0 != (nUserMode & REQ_MODE_DIFF_UU_STEREO))
3780 : : {
3781 : : /* Make labels for unknown and undefined stereo different */
3782 : 0 : vABParityUnknown = AB_PARITY_UNKN;
3783 : : }
3784 : :
3785 : : /* djb-rwth: removing redundant code */
3786 : :
3787 : : #if ( FIX_ISO_FIXEDH_BUG == 1 )
3788 [ + - ]: 69 : if (TG_FLAG_FIX_ISO_FIXEDH_BUG & *pbTautFlags)
3789 : 69 : bFixIsoFixedH = 1;
3790 : : #endif
3791 : : #if ( FIX_TERM_H_CHRG_BUG == 1 )
3792 [ + - ]: 69 : if (TG_FLAG_FIX_TERM_H_CHRG_BUG & *pbTautFlags)
3793 : 69 : bFixTermHChrg = 1;
3794 : : #endif
3795 : :
3796 : : #ifdef FIX_SRU_CYCLIZING_PS_BONDS_IN_BNS
3797 : : /* Polymer related */
3798 : : if (orig_inp_data && orig_inp_data->polymer && orig_inp_data->polymer->n > 0 && orig_inp_data->polymer->valid)
3799 : : {
3800 : : int j, jj;
3801 : : nebend = 0;
3802 : : for (j = 0; j < orig_inp_data->polymer->n; j++)
3803 : : if (orig_inp_data->polymer->units[j]->cyclized == 1)
3804 : : nebend++;
3805 : : if (nebend)
3806 : : {
3807 : : nebend *= 2;
3808 : : ebend = inchi_calloc(2 * nebend, sizeof(int));
3809 : : if (!ebend)
3810 : : {
3811 : : ret = CT_OUT_OF_RAM; goto exit_function;
3812 : : }
3813 : : jj = 0;
3814 : : for (j = 0; j < orig_inp_data->polymer->n; j++)
3815 : : {
3816 : : if (orig_inp_data->polymer->units[j]->cyclized == 1)
3817 : : {
3818 : : ebend[jj] = orig_inp_data->polymer->units[j]->end_atom1;
3819 : : ebend[jj + 1] = orig_inp_data->polymer->units[j]->end_atom2;
3820 : : jj += 2;
3821 : : }
3822 : : }
3823 : : }
3824 : : }
3825 : : #endif
3826 : :
3827 : 69 : memset(s, 0, sizeof(s)); /* djb-rwth: memset_s C11/Annex K variant? */
3828 [ + - ]: 69 : if (pBCN)
3829 : : {
3830 : 69 : memset(pBCN, 0, sizeof(pBCN[0])); /* djb-rwth: memset_s C11/Annex K variant? */
3831 : : }
3832 : 69 : memset(t_group_info, 0, sizeof(*t_group_info)); /* djb-rwth: memset_s C11/Annex K variant? */
3833 : 69 : memset(t_group_info_orig, 0, sizeof(*t_group_info_orig)); /* djb-rwth: memset_s C11/Annex K variant? */
3834 : : /*norm_at[TAUT_NON] = out_norm_data[TAUT_NON]->at; *//* output normalized non-tautomeric component */
3835 : : /*norm_at[TAUT_YES] = out_norm_data[TAUT_YES]->at; *//* output normalized tautomeric component */
3836 : : /*norm_at_fixed_bonds[TAUT_NON] = NULL;*/
3837 : : /*norm_at_fixed_bonds[TAUT_YES] = out_norm_data[TAUT_YES]->at_fixed_bonds;*/
3838 [ + + ]: 207 : for (i = 0; i < TAUT_NUM; i++)
3839 : : {
3840 [ + + ]: 138 : if (out_norm_data[i]->at)
3841 : : {
3842 [ - + ]: 69 : if (!(at[i] = (sp_ATOM*)inchi_malloc(num_inp_at * sizeof(*at[0]))))
3843 : : {
3844 : 0 : ret = -1;
3845 : : }
3846 : : }
3847 : : else
3848 : : {
3849 : 69 : at[i] = NULL;
3850 : : }
3851 : : }
3852 : :
3853 [ + - + - ]: 69 : if ((!out_norm_data[TAUT_NON]->at && !out_norm_data[TAUT_YES]->at)
3854 [ + - - + ]: 69 : || !inp_at || ret) /* djb-rwth: addressing LLVM warning */
3855 : : {
3856 : 0 : ret = -1;
3857 : 0 : goto exit_function;
3858 : : }
3859 : :
3860 : : /* the first struct to process: tautomeric if exists else non-tautomeric */
3861 [ + - ]: 69 : out_at = out_norm_data[TAUT_YES]->at ? out_norm_data[TAUT_YES]->at : out_norm_data[TAUT_NON]->at;
3862 : : /* copy the input structure to be normalized to the buffer for the normalization data */
3863 : 69 : memcpy(out_at, inp_at, num_inp_at * sizeof(out_at[0]));
3864 : : /* tautomeric groups setting */
3865 : 69 : t_group_info->bIgnoreIsotopic = 0; /* include tautomeric group isotopic info in MarkTautomerGroups() */
3866 : 69 : t_group_info->bTautFlags = *pbTautFlags;
3867 : 69 : t_group_info->bTautFlagsDone = *pbTautFlagsDone;
3868 : 69 : t_group_info->t_group = NULL; /* djb-rwth: fixing oss-fuzz issue #70475 */
3869 : :
3870 : : /*
3871 : : Preprocess the structure
3872 : : (here THE NUMBER OF ATOMS MAY BE REDUCED)
3873 : : */
3874 : :
3875 : : /* ??? Ambiguity: H-D may become HD or DH
3876 : : (that is, H+implicit D or D+implicit H) */
3877 [ - + ]: 69 : if (TG_FLAG_H_ALREADY_REMOVED & bTautFlags)
3878 : : {
3879 [ # # ]: 0 : INP_ATOM_DATA* out_norm_data1 = out_norm_data[TAUT_YES]->at ? out_norm_data[TAUT_YES] :
3880 [ # # ]: 0 : out_norm_data[TAUT_NON]->at ? out_norm_data[TAUT_NON] : NULL;
3881 [ # # ]: 0 : if (out_norm_data1)
3882 : : {
3883 : 0 : num_at_tg =
3884 : 0 : num_atoms = out_norm_data1->num_at - out_norm_data1->num_removed_H;
3885 : 0 : num_removed_H = out_norm_data1->num_removed_H;
3886 : 0 : t_group_info->tni.nNumRemovedExplicitH = num_removed_H;
3887 : : }
3888 : : else
3889 : : {
3890 : 0 : ret = -1;
3891 : 0 : goto exit_function;
3892 : : }
3893 : : }
3894 : : else
3895 : : {
3896 : 69 : num_at_tg = num_atoms = remove_terminal_HDT(num_inp_at, out_at, bFixTermHChrg);
3897 : 69 : num_removed_H = num_inp_at - num_atoms;
3898 : 69 : t_group_info->tni.nNumRemovedExplicitH = num_removed_H;
3899 : 69 : add_DT_to_num_H(num_atoms, out_at);
3900 : : }
3901 : : /*fix_odd_things( num_atoms, out_at );*/
3902 : : #if ( FIND_RING_SYSTEMS == 1 )
3903 : 69 : MarkRingSystemsInp(out_at, num_atoms, 0);
3904 : : #endif
3905 : : /* duplicate the preprocessed structure so that all supplied out_norm_data[]->at buffers are filled */
3906 [ - + - - ]: 69 : if (out_at != out_norm_data[TAUT_YES]->at && out_norm_data[TAUT_YES]->at)
3907 : : {
3908 : 0 : memcpy(out_norm_data[TAUT_YES]->at, out_at, num_inp_at * sizeof(out_at[0]));
3909 : : }
3910 [ + - + - ]: 69 : if (out_norm_data[TAUT_YES]->at_fixed_bonds && out_norm_data[TAUT_YES]->at)
3911 : : {
3912 : 69 : memcpy(out_norm_data[TAUT_YES]->at_fixed_bonds, out_at, num_inp_at * sizeof(out_at[0]));
3913 : : }
3914 [ + - - + ]: 69 : if (out_at != out_norm_data[TAUT_NON]->at && out_norm_data[TAUT_NON]->at)
3915 : : {
3916 : 0 : memcpy(out_norm_data[TAUT_NON]->at, out_at, num_inp_at * sizeof(out_at[0]));
3917 : : }
3918 : :
3919 : : /*
3920 : : ??? not true ??? duplicate inp_at and keep inp_at[] unchanged after terminal hydrogens removal
3921 : : set stereo parities in taut_at[], non_taut_at[]
3922 : : obtain max. lenghts of the name stereo parts
3923 : : Ignore absence/presence of isotopic stereo for now
3924 : : mark isotopic atoms
3925 : : */
3926 [ + - + - ]: 69 : if (out_norm_data[TAUT_YES]->at && at[TAUT_YES])
3927 : : {
3928 : : /* final normalization of possibly tautomeric structure */
3929 : 69 : ret = mark_alt_bonds_and_taut_groups(ic, pCG,
3930 : 69 : out_norm_data[TAUT_YES]->at,
3931 : 69 : out_norm_data[TAUT_YES]->at_fixed_bonds,
3932 : : num_atoms, ulMaxTime, t_group_info,
3933 : : NULL, NULL,
3934 : : nebend, ebend);
3935 [ - + ]: 69 : if (ret < 0)
3936 : : {
3937 : 0 : goto exit_function;/* out of RAM or other normalization problem */
3938 : : }
3939 : 69 : num_taut_at = ret; /* number of atoms without removed H? */
3940 : 69 : num_removed_H_taut = t_group_info->tni.nNumRemovedExplicitH;
3941 : 69 : out_norm_data[TAUT_YES]->num_at = num_atoms + num_removed_H_taut; /* protons might have been removed */
3942 : 69 : out_norm_data[TAUT_YES]->num_removed_H = num_removed_H_taut;
3943 : 69 : out_norm_data[TAUT_YES]->nNumRemovedProtons += t_group_info->tni.nNumRemovedProtons;
3944 [ + + ]: 276 : for (i = 0; i < NUM_H_ISOTOPES; i++)
3945 : : {
3946 : 207 : out_norm_data[TAUT_YES]->nNumRemovedProtonsIsotopic[i] +=
3947 : 207 : t_group_info->tni.nNumRemovedProtonsIsotopic[i] /*+ t_group_info->num_iso_H[i]*/;
3948 : 207 : out_norm_data[TAUT_YES]->num_iso_H[i] +=
3949 : 207 : t_group_info->num_iso_H[i];
3950 : : }
3951 : : /* mark deleted isolated tautomeric H(+) */
3952 [ + + ]: 69 : if (num_taut_at == 1 &&
3953 [ - + - - ]: 5 : out_norm_data[TAUT_YES]->at[0].at_type == ATT_PROTON &&
3954 [ # # ]: 0 : t_group_info && t_group_info->tni.nNumRemovedProtons == 1)
3955 : : {
3956 : 0 : out_norm_data[TAUT_YES]->bDeleted = 1;
3957 : 0 : FreeInpAtom(&out_norm_data[TAUT_YES]->at_fixed_bonds);
3958 : : }
3959 : : else
3960 : : {
3961 [ + + ]: 69 : if ((t_group_info->tni.bNormalizationFlags & FLAG_NORM_CONSIDER_TAUT) &&
3962 [ + - ]: 3 : out_norm_data[TAUT_YES]->at_fixed_bonds)
3963 : : {
3964 : 3 : out_norm_data[TAUT_YES]->bTautPreprocessed = 1;
3965 : : }
3966 : : }
3967 : :
3968 : : /*
3969 : : if ( !(t_group_info->tni.bNormalizationFlags & (FLAG_NORM_CONSIDER_TAUT & ~FLAG_PROTON_SINGLE_REMOVED)) &&
3970 : : out_norm_data[TAUT_YES]->at_fixed_bonds) {
3971 : : FreeInpAtom( &out_norm_data[TAUT_YES]->at_fixed_bonds );
3972 : : }
3973 : : */
3974 : :
3975 : : /*out_norm_data[TAUT_YES]->num_removed_H = num_removed_H_taut;*/
3976 : :
3977 : 69 : out_norm_data[TAUT_YES]->bTautFlags = *pbTautFlags = t_group_info->bTautFlags;
3978 : 69 : out_norm_data[TAUT_YES]->bTautFlagsDone = *pbTautFlagsDone = t_group_info->bTautFlagsDone;
3979 : 69 : out_norm_data[TAUT_YES]->bNormalizationFlags = t_group_info->tni.bNormalizationFlags;
3980 : :
3981 : : /* create internal sp_ATOM at[] out of out_norm_data[]->at */
3982 : 69 : inp2spATOM(out_norm_data[TAUT_YES]->at, num_inp_at, at[TAUT_YES]);
3983 : :
3984 : : /* set stereo parities to at[]; nUserMode: accept alt. stereo bonds, min ring size */
3985 : 69 : ret = set_stereo_parity(pCG, out_norm_data[TAUT_YES]->at, at[TAUT_YES],
3986 : : num_taut_at, num_removed_H_taut,
3987 : : &s[TAUT_YES].nMaxNumStereoAtoms,
3988 : : &s[TAUT_YES].nMaxNumStereoBonds,
3989 : : nUserMode, bPointedEdgeStereo,
3990 : : vABParityUnknown, ip->bLooseTSACheck, ip->bStereoAtZz);
3991 : :
3992 : : #if ( bRELEASE_VERSION == 0 )
3993 : : if (0 < ret)
3994 : : {
3995 : : bExtract |= EXTR_HAS_ATOM_WITH_DEFINED_PARITY;
3996 : : }
3997 : : if (t_group_info->tni.bNormalizationFlags & FLAG_NORM_CONSIDER_TAUT)
3998 : : {
3999 : : bExtract |= EXTR_TAUT_TREATMENT_CHARGES;
4000 : : }
4001 : : #endif
4002 : :
4003 [ + - - + ]: 69 : if (RETURNED_ERROR(ret))
4004 : : {
4005 : 0 : goto exit_function; /* stereo bond error */
4006 : : }
4007 : :
4008 : 69 : s[TAUT_YES].bMayHaveStereo =
4009 [ + + ]: 81 : (s[TAUT_YES].nMaxNumStereoAtoms ||
4010 [ + + ]: 12 : s[TAUT_YES].nMaxNumStereoBonds);
4011 : :
4012 : : /*
4013 : : mark isotopic atoms and atoms that have non-tautomeric
4014 : : isotopic terminal hydrogen atoms 1H, 2H(D), 3H(T)
4015 : : */
4016 : :
4017 : 69 : s[TAUT_YES].num_isotopic_atoms =
4018 : 69 : set_atom_iso_sort_keys(num_taut_at,
4019 : : at[TAUT_YES],
4020 : : t_group_info,
4021 : : &s[TAUT_YES].bHasIsotopicTautGroups);
4022 : :
4023 : : /*
4024 : : Prepare tautomeric (if no tautomerism found then prepare non-tautomeric)
4025 : : structure for canonicalizaton:
4026 : :
4027 : : remove t-groups that have no H,
4028 : : remove charges from t-groups if requested
4029 : : renumber t-groups and find final t_group_info->num_t_groups
4030 : : add to t-groups lists of endpoints tgroup->nEndpointAtomNumber[]
4031 : : calculate length of the t-group part of the connection table
4032 : : */
4033 : :
4034 : 69 : s[TAUT_YES].nLenLinearCTTautomer = CountTautomerGroups(at[TAUT_YES], num_taut_at, t_group_info);
4035 : :
4036 [ + - - + ]: 69 : if (RETURNED_ERROR(s[TAUT_YES].nLenLinearCTTautomer))
4037 : : {
4038 : : /* added error treatment 9-11-2003 */
4039 : 0 : ret = s[TAUT_YES].nLenLinearCTTautomer;
4040 : 0 : goto exit_function;
4041 : : /* error has happened; no breakpoint here
4042 : : s[TAUT_YES].nLenLinearCTTautomer = 0;
4043 : : */
4044 : : }
4045 : :
4046 [ + + ]: 69 : else if (s[TAUT_YES].nLenLinearCTTautomer > 0)
4047 : : {
4048 : 3 : num_at_tg = num_taut_at + t_group_info->num_t_groups;
4049 : : /* ??? -not true- create t_group_info_orig for multiple calls with atom renumbering */
4050 : 3 : make_a_copy_of_t_group_info(t_group_info_orig /* dest*/, t_group_info /* source*/); /* djb-rwth: addressing coverity ID #499544 -- properly used sequence of arguments according to the comment in previous line */
4051 : : /* mark isotopic tautomer groups: calculate t_group->iWeight */
4052 : 3 : s[TAUT_YES].nLenLinearCTIsotopicTautomer = set_tautomer_iso_sort_keys(t_group_info);
4053 [ - + ]: 3 : if (s[TAUT_YES].nLenLinearCTIsotopicTautomer < 0)
4054 : : {
4055 : : /* ??? -error cannot happen- error has happened; no breakpoint here */
4056 : 0 : s[TAUT_YES].nLenLinearCTIsotopicTautomer = 0;
4057 : : }
4058 : 3 : out_norm_data[TAUT_YES]->bTautomeric = s[TAUT_YES].nLenLinearCTTautomer;
4059 : : }
4060 : :
4061 : : /* new variable: s[TAUT_YES].nLenCT introduced 7-22-2002 */
4062 : 69 : GetCanonLengths(num_taut_at, at[TAUT_YES], &s[TAUT_YES], t_group_info);
4063 : : }
4064 : :
4065 [ - + ]: 69 : if (out_norm_data[TAUT_NON]->at &&
4066 [ # # ]: 0 : out_norm_data[TAUT_YES]->at &&
4067 [ # # ]: 0 : at[TAUT_NON] &&
4068 [ # # ]: 0 : !s[TAUT_YES].nLenLinearCTTautomer)
4069 : : {
4070 : : /* the structure is non-tautomeric: use tautomeric treatment results only for it */
4071 [ # # ]: 0 : inchi_free(at[TAUT_NON]);
4072 : 0 : at[TAUT_NON] = NULL;
4073 : : }
4074 : :
4075 [ + - ]: 69 : else if (!out_norm_data[TAUT_NON]->at &&
4076 [ + - ]: 69 : out_norm_data[TAUT_YES]->at &&
4077 [ + - ]: 69 : !at[TAUT_NON] &&
4078 [ + - ]: 69 : at[TAUT_YES] &&
4079 [ + + ]: 69 : !s[TAUT_YES].nLenLinearCTTautomer)
4080 : : {
4081 : : /* requested tautomeric; found non-tautomeric; it is located in out_norm_data[TAUT_YES]->at */
4082 : 66 : out_norm_data[TAUT_YES]->bTautomeric = 0;
4083 : : }
4084 : :
4085 [ - + - - ]: 3 : else if (out_norm_data[TAUT_NON]->at && at[TAUT_NON])
4086 : : {
4087 : : /* the structure needs non-tautomeric treatment:
4088 : : final normalization of non-tautomeric structure */
4089 : 0 : ret = mark_alt_bonds_and_taut_groups(ic, pCG,
4090 : 0 : out_norm_data[TAUT_NON]->at,
4091 : : NULL,
4092 : : num_atoms,
4093 : : ulMaxTime,
4094 : : NULL,
4095 : : &bTautFlags,
4096 : : &bTautFlagsDone,
4097 : : nebend, ebend);
4098 [ # # ]: 0 : if (ret < 0)
4099 : : {
4100 : 0 : goto exit_function; /* out of RAM or other normalization problem */
4101 : : }
4102 : 0 : out_norm_data[TAUT_NON]->num_at = num_atoms + num_removed_H;
4103 : 0 : out_norm_data[TAUT_NON]->num_removed_H = num_removed_H;
4104 : 0 : out_norm_data[TAUT_NON]->bTautFlags = *pbTautFlags;
4105 : 0 : out_norm_data[TAUT_NON]->bTautFlagsDone = *pbTautFlagsDone;
4106 : 0 : out_norm_data[TAUT_NON]->bNormalizationFlags = 0;
4107 : :
4108 : : /* create internal sp_ATOM at[] out of out_norm_data[]->at */
4109 : 0 : inp2spATOM(out_norm_data[TAUT_NON]->at, num_inp_at, at[TAUT_NON]);
4110 : :
4111 : : /* set stereo parities to at[]; nUserMode: accept alt. stereo bonds, min ring size */
4112 : 0 : ret = set_stereo_parity(pCG, out_norm_data[TAUT_NON]->at,
4113 : : at[TAUT_NON], num_atoms, num_removed_H,
4114 : : &s[TAUT_NON].nMaxNumStereoAtoms,
4115 : : &s[TAUT_NON].nMaxNumStereoBonds, nUserMode,
4116 : : bPointedEdgeStereo, vABParityUnknown,
4117 : : ip->bLooseTSACheck, ip->bStereoAtZz);
4118 : : #if ( bRELEASE_VERSION == 0 )
4119 : : if (0 < ret)
4120 : : {
4121 : : bExtract |= EXTR_HAS_ATOM_WITH_DEFINED_PARITY;
4122 : : }
4123 : : #endif
4124 [ # # # # ]: 0 : if (RETURNED_ERROR(ret))
4125 : : {
4126 : 0 : goto exit_function; /* stereo bond error */
4127 : : }
4128 [ # # ]: 0 : s[TAUT_NON].bMayHaveStereo = (s[TAUT_NON].nMaxNumStereoAtoms ||
4129 [ # # ]: 0 : s[TAUT_NON].nMaxNumStereoBonds);
4130 : :
4131 : : /*
4132 : : * mark isotopic atoms and atoms that have non-tautomeric
4133 : : * isotopic terminal hydrogen atoms 1H, 2H(D), 3H(T)
4134 : : */
4135 : 0 : s[TAUT_NON].num_isotopic_atoms = set_atom_iso_sort_keys(num_atoms, at[TAUT_NON], NULL, NULL);
4136 : 0 : GetCanonLengths(num_atoms, at[TAUT_NON], &s[TAUT_NON], NULL);
4137 : 0 : out_norm_data[TAUT_NON]->bTautomeric = 0;
4138 : : }
4139 : :
4140 : : /* common */
4141 [ + + - + ]: 69 : bMayHaveStereo = s[TAUT_YES].bMayHaveStereo || s[TAUT_NON].bMayHaveStereo;
4142 [ + - ]: 69 : bHasIsotopicAtoms = s[TAUT_NON].num_isotopic_atoms > 0 || s[TAUT_NON].bHasIsotopicTautGroups > 0 ||
4143 [ + - + - : 138 : s[TAUT_YES].num_isotopic_atoms > 0 || s[TAUT_YES].bHasIsotopicTautGroups > 0;
- + ]
4144 [ + - ]: 69 : if (bFixIsoFixedH)
4145 : : {
4146 : : /* 2008-03-21 DT */
4147 : 69 : bHasIsotopicAtoms = bHasIsotopicAtoms
4148 [ + - ]: 138 : ||
4149 [ + + + - ]: 69 : (s[TAUT_YES].nLenLinearCTTautomer > 0 && t_group_info &&
4150 [ + - ]: 3 : ((0 < NUM_H_ISOTOPES && t_group_info->tni.nNumRemovedProtonsIsotopic[0]) ||
4151 [ + - ]: 3 : (1 < NUM_H_ISOTOPES && t_group_info->tni.nNumRemovedProtonsIsotopic[1]) ||
4152 [ - + ]: 3 : (2 < NUM_H_ISOTOPES && t_group_info->tni.nNumRemovedProtonsIsotopic[2])
4153 : : )); /* djb-rwth: addressing LLVM warning */
4154 : : }
4155 : 69 : bHasIsotopicAtoms = bHasIsotopicAtoms
4156 [ + - ]: 138 : ||
4157 [ - + - - ]: 69 : (s[TAUT_YES].nLenIsotopicEndpoints > 1 && t_group_info &&
4158 [ # # ]: 0 : (t_group_info->bTautFlagsDone & (TG_FLAG_FOUND_ISOTOPIC_H_DONE | TG_FLAG_FOUND_ISOTOPIC_ATOM_DONE))); /* djb-rwth: addressing LLVM warning */
4159 : :
4160 : : /* default mode */
4161 [ - + ]: 69 : if (!(nUserMode & REQ_MODE_DEFAULT))
4162 : : {
4163 : : /* default */
4164 : 0 : nUserMode |= REQ_MODE_DEFAULT;
4165 : : }
4166 : :
4167 : : /* adjust the mode to the reality */
4168 [ + - + - ]: 69 : if ((nUserMode & REQ_MODE_ISO) && !bHasIsotopicAtoms)
4169 : : {
4170 : 69 : nUserMode ^= REQ_MODE_ISO;
4171 : 69 : nUserMode |= REQ_MODE_NON_ISO; /* at least one is needed */
4172 : : }
4173 [ + - - + ]: 69 : if ((nUserMode & REQ_MODE_STEREO) && (nUserMode & REQ_MODE_ISO))
4174 : : {
4175 : 0 : nUserMode |= REQ_MODE_ISO_STEREO;
4176 : : }
4177 [ + - - + ]: 69 : if ((nUserMode & REQ_MODE_STEREO) && !(nUserMode & REQ_MODE_NON_ISO))
4178 : : {
4179 : 0 : nUserMode ^= REQ_MODE_STEREO;
4180 : : }
4181 [ + + ]: 69 : if (!bMayHaveStereo)
4182 : : {
4183 [ + - ]: 9 : if (nUserMode & REQ_MODE_STEREO)
4184 : 9 : nUserMode ^= REQ_MODE_STEREO;
4185 [ - + ]: 9 : if (nUserMode & REQ_MODE_ISO_STEREO)
4186 : 0 : nUserMode ^= REQ_MODE_ISO_STEREO;
4187 : : }
4188 : :
4189 [ - + ]: 69 : if ((nUserMode & REQ_MODE_BASIC) &&
4190 [ # # # # ]: 0 : (!out_norm_data[TAUT_NON]->at || !ppINChI[TAUT_NON] ||
4191 [ # # # # ]: 0 : !ppINChI_Aux[TAUT_NON] || !at[TAUT_NON]))
4192 : : {
4193 : 0 : nUserMode ^= REQ_MODE_BASIC;
4194 : : }
4195 [ + - ]: 69 : if ((nUserMode & REQ_MODE_TAUT) &&
4196 [ + - + - ]: 69 : (!out_norm_data[TAUT_YES]->at || !ppINChI[TAUT_YES] ||
4197 [ + - - + ]: 69 : !ppINChI_Aux[TAUT_YES] || !at[TAUT_YES]))
4198 : : {
4199 : 0 : nUserMode ^= REQ_MODE_TAUT;
4200 : : }
4201 : :
4202 [ - + - - ]: 69 : switch ((int)nUserMode & (REQ_MODE_BASIC | REQ_MODE_TAUT))
4203 : : {
4204 : 0 : case REQ_MODE_BASIC:
4205 : 0 : n1 = TAUT_NON;
4206 : 0 : n2 = TAUT_NON;
4207 : 0 : break;
4208 : 69 : case REQ_MODE_TAUT:
4209 : 69 : n1 = TAUT_YES;
4210 : 69 : n2 = TAUT_YES;
4211 : 69 : break;
4212 : 0 : case (REQ_MODE_BASIC | REQ_MODE_TAUT):
4213 : 0 : n1 = TAUT_NON;
4214 : 0 : n2 = TAUT_YES;
4215 : 0 : break;
4216 : 0 : default:
4217 : 0 : ret = -3;
4218 : 0 : goto exit_function; /* program error: inconsistent nUserMode or missing taut/non-taut allocation */ /* <BRKPT> */
4219 : : }
4220 : :
4221 : : /*
4222 : : Obtain all non-stereo canonical numberings
4223 : : */
4224 : :
4225 [ + - + - ]: 69 : if ((nUserMode & REQ_MODE_NON_ISO) && !(nUserMode & REQ_MODE_ISO))
4226 : : {
4227 : : /* added for special non-isotopic test mode 2004-10-04 */
4228 [ + - ]: 69 : if (t_group_info)
4229 : : {
4230 : 69 : t_group_info->bIgnoreIsotopic = 1;
4231 [ - + ]: 69 : if (t_group_info->nIsotopicEndpointAtomNumber)
4232 : : {
4233 : 0 : t_group_info->nIsotopicEndpointAtomNumber[0] = inchi_min(1, t_group_info->nIsotopicEndpointAtomNumber[0]);
4234 : : }
4235 : 69 : memset(t_group_info->num_iso_H, 0, sizeof(t_group_info->num_iso_H)); /* djb-rwth: memset_s C11/Annex K variant? */
4236 : 69 : memset(t_group_info->tni.nNumRemovedProtonsIsotopic, 0, sizeof(t_group_info->tni.nNumRemovedProtonsIsotopic)); /* djb-rwth: memset_s C11/Annex K variant? */
4237 : 69 : t_group_info->bTautFlagsDone &= ~(TG_FLAG_FOUND_ISOTOPIC_H_DONE | TG_FLAG_FOUND_ISOTOPIC_ATOM_DONE);
4238 : : }
4239 [ + + ]: 207 : for (i = 0; i < TAUT_NUM; i++)
4240 : : {
4241 : 138 : s[i].bHasIsotopicTautGroups = 0;
4242 : 138 : s[i].bIgnoreIsotopic = 1;
4243 : 138 : s[i].nLenIsotopic = 0;
4244 : 138 : s[i].nLenIsotopicEndpoints = 0;
4245 : 138 : s[i].nLenLinearCTIsotopicTautomer = 0;
4246 : 138 : s[i].num_isotopic_atoms = 0;
4247 : : }
4248 : 69 : bHasIsotopicAtoms = 0;
4249 : : }
4250 : :
4251 : 69 : ret = GetBaseCanonRanking(ic, num_atoms, num_at_tg, at,
4252 : : t_group_info, s, pBCN, ulMaxTime,
4253 : : pCG, bFixIsoFixedH, LargeMolecules);
4254 : :
4255 [ - + ]: 69 : if (ret < 0)
4256 : : {
4257 : 0 : goto exit_function; /* program error */
4258 : : }
4259 : : #if ( bRELEASE_VERSION == 0 && FIND_CANON_NE_EQUITABLE == 1 )
4260 : : /* Debug only: find whether canonical equivalence is different from equitable partition */
4261 : : if (bCanonIsFinerThanEquitablePartition(num_atoms, at[n1], pBCN->ftcn[TAUT_NON].nSymmRankCt))
4262 : : {
4263 : : bExtract |= EXTR_CANON_NE_EQUITABLE;
4264 : : }
4265 : : #endif
4266 : :
4267 : : /* added for special non-isotopic test mode 2004-10-04 */
4268 [ - + ]: 69 : if (!pBCN->ftcn[n1].PartitionCt.Rank)
4269 : : {
4270 [ # # ]: 0 : n1 = ALT_TAUT(n1);
4271 : : }
4272 [ - + ]: 69 : if (!pBCN->ftcn[n2].PartitionCt.Rank)
4273 : : {
4274 [ # # ]: 0 : n2 = ALT_TAUT(n2);
4275 : : }
4276 [ - + ]: 69 : if (n1 > n2)
4277 : : {
4278 : 0 : ret = CT_TAUCOUNT_ERR;
4279 : 0 : goto exit_function; /* program error */
4280 : : }
4281 : :
4282 : : /*
4283 : : Obtain stereo canonical numberings
4284 : : */
4285 : :
4286 [ + + - + : 138 : for (i = n2; i >= n1 && !RETURNED_ERROR(ret); i--)
+ - ]
4287 : : {
4288 : 69 : memset(pCS, 0, sizeof(*pCS)); /* djb-rwth: memset_s C11/Annex K variant? */
4289 : :
4290 [ - + - ]: 69 : switch (i)
4291 : : {
4292 : 0 : case TAUT_NON:
4293 : : /* non-tautomeric */
4294 : : /* djb-rwth: removing redundant code */
4295 [ # # ]: 0 : nMode = (s[i].nLenLinearCTTautomer == 0) ? CANON_MODE_CT : CANON_MODE_TAUT;
4296 [ # # # # ]: 0 : nMode |= (bHasIsotopicAtoms && (nUserMode & REQ_MODE_ISO)) ? CANON_MODE_ISO : 0;
4297 [ # # # # ]: 0 : nMode |= (s[TAUT_NON].bMayHaveStereo && (nUserMode & REQ_MODE_STEREO)) ? CANON_MODE_STEREO : 0;
4298 [ # # # # : 0 : nMode |= (bHasIsotopicAtoms && s[TAUT_NON].bMayHaveStereo && (nUserMode & REQ_MODE_ISO_STEREO)) ? CANON_MODE_ISO_STEREO : 0;
# # ]
4299 : 0 : nMode |= (nUserMode & REQ_MODE_NOEQ_STEREO) ? CMODE_NOEQ_STEREO : 0;
4300 : 0 : nMode |= (nUserMode & REQ_MODE_REDNDNT_STEREO) ? CMODE_REDNDNT_STEREO : 0;
4301 : 0 : nMode |= (nUserMode & REQ_MODE_NO_ALT_SBONDS) ? CMODE_NO_ALT_SBONDS : 0;
4302 [ # # ]: 0 : if ((nMode & CANON_MODE_STEREO) == CANON_MODE_STEREO ||
4303 [ # # ]: 0 : (nMode & CANON_MODE_ISO_STEREO) == CANON_MODE_ISO_STEREO)
4304 : : {
4305 : 0 : nMode |= (nUserMode & REQ_MODE_RELATIVE_STEREO) ? CMODE_RELATIVE_STEREO : 0;
4306 : 0 : nMode |= (nUserMode & REQ_MODE_RACEMIC_STEREO) ? CMODE_RACEMIC_STEREO : 0;
4307 : 0 : nMode |= (nUserMode & REQ_MODE_SC_IGN_ALL_UU) ? CMODE_SC_IGN_ALL_UU : 0;
4308 : 0 : nMode |= (nUserMode & REQ_MODE_SB_IGN_ALL_UU) ? CMODE_SB_IGN_ALL_UU : 0;
4309 : : }
4310 [ # # ]: 0 : if ((ret = AllocateCS(pCS, num_atoms, num_atoms, s[TAUT_NON].nLenCT, s[TAUT_NON].nLenCTAtOnly,
4311 : : s[TAUT_NON].nLenLinearCTStereoDble, s[TAUT_NON].nMaxNumStereoBonds,
4312 : : s[TAUT_NON].nLenLinearCTStereoCarb, s[TAUT_NON].nMaxNumStereoAtoms,
4313 : : 0, 0, s[TAUT_NON].nLenIsotopic, nMode, pBCN))) /* djb-rwth: addressing LLVM warning */
4314 : : {
4315 : 0 : goto exit_function;
4316 : : }
4317 : 0 : *pCS2 = *pCS;
4318 : 0 : break;
4319 : 69 : case TAUT_YES: /* tautomeric */
4320 : : /* djb-rwth: removing redundant code */
4321 [ + + ]: 69 : nMode = (s[i].nLenLinearCTTautomer == 0) ? CANON_MODE_CT : CANON_MODE_TAUT;
4322 [ - + - - ]: 69 : nMode |= (bHasIsotopicAtoms && (nUserMode & REQ_MODE_ISO)) ? CANON_MODE_ISO : 0;
4323 [ + + + - ]: 69 : nMode |= (s[TAUT_YES].bMayHaveStereo && (nUserMode & REQ_MODE_STEREO)) ? CANON_MODE_STEREO : 0;
4324 [ - + - - : 69 : nMode |= (bHasIsotopicAtoms && s[TAUT_YES].bMayHaveStereo && (nUserMode & REQ_MODE_ISO_STEREO)) ? CANON_MODE_ISO_STEREO : 0;
- - ]
4325 : 69 : nMode |= (nUserMode & REQ_MODE_NOEQ_STEREO) ? CMODE_NOEQ_STEREO : 0;
4326 : 69 : nMode |= (nUserMode & REQ_MODE_REDNDNT_STEREO) ? CMODE_REDNDNT_STEREO : 0;
4327 : 69 : nMode |= (nUserMode & REQ_MODE_NO_ALT_SBONDS) ? CMODE_NO_ALT_SBONDS : 0;
4328 [ + + ]: 69 : if ((nMode & CANON_MODE_STEREO) == CANON_MODE_STEREO ||
4329 [ - + ]: 9 : (nMode & CANON_MODE_ISO_STEREO) == CANON_MODE_ISO_STEREO)
4330 : : {
4331 : 60 : nMode |= (nUserMode & REQ_MODE_RELATIVE_STEREO) ? CMODE_RELATIVE_STEREO : 0;
4332 : 60 : nMode |= (nUserMode & REQ_MODE_RACEMIC_STEREO) ? CMODE_RACEMIC_STEREO : 0;
4333 : 60 : nMode |= (nUserMode & REQ_MODE_SC_IGN_ALL_UU) ? CMODE_SC_IGN_ALL_UU : 0;
4334 : 60 : nMode |= (nUserMode & REQ_MODE_SB_IGN_ALL_UU) ? CMODE_SB_IGN_ALL_UU : 0;
4335 : : }
4336 [ - + ]: 69 : if ((ret = AllocateCS(pCS, num_atoms, num_at_tg, s[TAUT_YES].nLenCT, s[TAUT_YES].nLenCTAtOnly,
4337 : : s[TAUT_YES].nLenLinearCTStereoDble, s[TAUT_YES].nMaxNumStereoBonds,
4338 : : s[TAUT_YES].nLenLinearCTStereoCarb, s[TAUT_YES].nMaxNumStereoAtoms,
4339 : : s[TAUT_YES].nLenLinearCTTautomer, s[TAUT_YES].nLenLinearCTIsotopicTautomer,
4340 : : s[TAUT_YES].nLenIsotopic, nMode, pBCN))) /* djb-rwth: addressing LLVM warning */
4341 : : {
4342 : 0 : goto exit_function;
4343 : : }
4344 : 69 : *pCS2 = *pCS;
4345 : 69 : break;
4346 : : }
4347 : :
4348 : : /* 2009-12-05 */
4349 : 69 : nMode |= (nUserMode & REQ_MODE_DIFF_UU_STEREO) ? REQ_MODE_DIFF_UU_STEREO : 0;
4350 : : /* 2009-12-05 */
4351 : :
4352 : : /* settings */
4353 : 69 : pCS->lNumDecreasedCT = -1;
4354 : 69 : pCS->bDoubleBondSquare = DOUBLE_BOND_NEIGH_LIST ? 2 : 0; /* 2 => special mode */
4355 [ + - ]: 138 : pCS->bIgnoreIsotopic = !((s[TAUT_NON].num_isotopic_atoms ||
4356 [ + - ]: 69 : s[TAUT_YES].num_isotopic_atoms ||
4357 [ + - ]: 69 : s[TAUT_YES].bHasIsotopicTautGroups) ||
4358 [ - + ]: 69 : (nUserMode & REQ_MODE_NON_ISO) ||
4359 [ # # ]: 0 : !(nUserMode & REQ_MODE_ISO));
4360 : :
4361 [ + - + - ]: 69 : if ((nUserMode & REQ_MODE_NON_ISO) && !(nUserMode & REQ_MODE_ISO))
4362 : : {
4363 : 69 : pCS->bIgnoreIsotopic = 1; /* 10-04-2004 */
4364 : : }
4365 : :
4366 [ + - ]: 69 : if (i == TAUT_YES)
4367 : : {
4368 : : /* tautomeric */
4369 : 69 : pCS->t_group_info = t_group_info; /* ??? make a copy or reuse ??? */
4370 [ + - ]: 138 : pCS->t_group_info->bIgnoreIsotopic = !(s[TAUT_YES].bHasIsotopicTautGroups ||
4371 [ - + ]: 69 : (nUserMode & REQ_MODE_NON_ISO) ||
4372 [ # # ]: 0 : !(nUserMode & REQ_MODE_ISO));
4373 [ + - + - ]: 69 : if ((nUserMode & REQ_MODE_NON_ISO) && !(nUserMode & REQ_MODE_ISO))
4374 : : {
4375 : 69 : pCS->t_group_info->bIgnoreIsotopic = 1; /* 10-04-2004 */
4376 : : }
4377 : : }
4378 : :
4379 : 69 : pCS->ulTimeOutTime = pBCN->ulTimeOutTime;
4380 : : /*=========== Obsolete Mode Bits (bit 0 is Least Significant Bit) ===========
4381 : : *
4382 : : * Mode Bits Description
4383 : : * '0' c 0 Only one connection table canonicalization
4384 : : * '1' C 1 Recalculate CT using fixed nSymmRank
4385 : : * '2' i 1|2 Isotopic canonicalization (internal)
4386 : : * '3' I 1|2|4 Isotopic canonicalization (output)
4387 : : * '4' s 1|8 Stereo canonicalization
4388 : : * '5' S 1|2|4|16 Stereo isotopic canonicalization
4389 : : * '6' A 1|2|4|8|16 Output All
4390 : : */
4391 : :
4392 : : /*
4393 : : The last canonicalization step
4394 : : */
4395 : :
4396 [ + - ]: 69 : if (pBCN)
4397 : : {
4398 : : /* USE_CANON2 == 1 */
4399 : 69 : pCS->NeighList = NULL;
4400 : 69 : pCS->pBCN = pBCN;
4401 : :
4402 [ + - ]: 69 : ret = Canon_INChI(ic,
4403 : : num_atoms,
4404 : : i ? num_at_tg : num_atoms,
4405 : : at[i], pCS,
4406 : : pCG,
4407 : : nMode, i);
4408 : : }
4409 : : else
4410 : : {
4411 : : /* old way */
4412 [ # # ]: 0 : pCS->NeighList = CreateNeighList(num_atoms,
4413 : : i ? num_at_tg : num_atoms,
4414 : : at[i],
4415 : : pCS->bDoubleBondSquare,
4416 : : pCS->t_group_info);
4417 : 0 : pCS->pBCN = NULL;
4418 : :
4419 [ # # ]: 0 : ret = Canon_INChI(ic,
4420 : : num_atoms,
4421 : : i ? num_at_tg : num_atoms,
4422 : : at[i], pCS,
4423 : : pCG,
4424 : : nMode, i);
4425 : : }
4426 : :
4427 : 69 : pINChI = ppINChI[i]; /* pointers to already allocated still empty InChI */
4428 : 69 : pINChI_Aux = ppINChI_Aux[i];
4429 : :
4430 [ - + ]: 69 : if (ret <= 0)
4431 : : {
4432 : : /*
4433 : : Failure in Canon_INChI()
4434 : : */
4435 : 0 : pINChI->nErrorCode = ret;
4436 : 0 : pINChI_Aux->nErrorCode = ret;
4437 : : }
4438 : : else
4439 : : {
4440 : : /*
4441 : : Success Canon_INChI()
4442 : :
4443 : : save canonicalization results in
4444 : : pINChI and pINChI_Aux
4445 : : */
4446 : 69 : pINChI->nErrorCode = 0;
4447 : 69 : pINChI_Aux->nErrorCode = 0;
4448 : 69 : pINChI->bDeleted = pINChI_Aux->bDeleted = out_norm_data[i]->bDeleted;
4449 : 69 : pINChI_Aux->nCanonFlags = pCS->nCanonFlags;
4450 : 69 : pINChI_Aux->bTautFlags = out_norm_data[i]->bTautFlags;
4451 : 69 : pINChI_Aux->bTautFlagsDone = out_norm_data[i]->bTautFlagsDone;
4452 : 69 : pINChI_Aux->bNormalizationFlags = out_norm_data[i]->bNormalizationFlags;
4453 : :
4454 : : /* may return an error or a warning */
4455 [ + - ]: 69 : ret = FillOutINChI(pINChI, pINChI_Aux,
4456 : : num_atoms, i ? num_at_tg : num_atoms,
4457 : : i ? num_removed_H_taut : num_removed_H, at[i],
4458 [ + - ]: 69 : out_norm_data[i]->at, pCS,
4459 : : pCG,
4460 : : i, nUserMode,
4461 : : pStrErrStruct, ip->bNoWarnings);
4462 : :
4463 [ + - - + ]: 69 : if (RETURNED_ERROR(ret))
4464 : : {
4465 : : /* Failure in FillOutINChI() */
4466 : 0 : pINChI->nErrorCode = ret;
4467 : 0 : pINChI_Aux->nErrorCode = ret;
4468 : : }
4469 : : else
4470 : : {
4471 : : /* Success in FillOutINChI() */
4472 : :
4473 : : #if ( bRELEASE_VERSION == 0 )
4474 : : if (pINChI->Stereo &&
4475 : : (pINChI->Stereo->nCompInv2Abs && !pINChI->Stereo->bTrivialInv) ||
4476 : : pINChI->StereoIsotopic &&
4477 : : (pINChI->StereoIsotopic->nCompInv2Abs && !pINChI->StereoIsotopic->bTrivialInv))
4478 : : {
4479 : : bExtract |= EXTR_NON_TRIVIAL_STEREO;
4480 : : }
4481 : : #endif
4482 : : /* Mark non-tautomeric representation as having
4483 : : another, tautomeric representation */
4484 [ + - + + ]: 69 : if (pINChI_Aux && s[TAUT_YES].nLenLinearCTTautomer)
4485 : : {
4486 : 3 : pINChI_Aux->bIsTautomeric = s[TAUT_YES].nLenLinearCTTautomer;
4487 : : }
4488 : : #if ( bRELEASE_VERSION == 0 )
4489 : : pCS->bExtract |= bExtract;
4490 : : pINChI->bExtract |= pCS->bExtract;
4491 : : #endif
4492 : :
4493 [ + - ]: 69 : ret2 = CheckCanonNumberingCorrectness(num_atoms,
4494 : : i ? num_at_tg : num_atoms,
4495 : : at[i], pCS,
4496 : : pCG,
4497 : : i, pStrErrStruct);
4498 [ - + - - ]: 69 : if (ret2 && pINChI_Aux) /* djb-rwth: fixing a NULL pointer dereference */
4499 : : {
4500 : 0 : pINChI->nErrorCode = ret2;
4501 : 0 : pINChI_Aux->nErrorCode = ret2;
4502 : 0 : ret = ret2;
4503 : : }
4504 : : }
4505 : : }
4506 : :
4507 : 69 : FreeNeighList(pCS->NeighList);
4508 : 69 : DeAllocateCS(pCS2);
4509 : :
4510 : 69 : pINChI = NULL; /* avoid dangling pointers */
4511 : 69 : pINChI_Aux = NULL; /* avoid dangling pointers */
4512 : : }
4513 : :
4514 [ - + ]: 69 : if (ret == 0)
4515 : : {
4516 : 69 : ret = num_atoms;
4517 : : }
4518 : : /* treat the results later */
4519 : :
4520 : 0 : exit_function:
4521 : :
4522 : 69 : DeAllocBCN(pBCN);
4523 [ + - ]: 69 : if (at[TAUT_YES])
4524 : : {
4525 [ + - ]: 69 : inchi_free(at[TAUT_YES]);
4526 : : }
4527 [ - + ]: 69 : if (at[TAUT_NON])
4528 : : {
4529 [ # # ]: 0 : inchi_free(at[TAUT_NON]);
4530 : : }
4531 [ - + ]: 69 : if (ti_out)
4532 : : {
4533 : 0 : *ti_out = *t_group_info;
4534 : : }
4535 : : else
4536 : : {
4537 : : /* free_t_group_info(t_group_info); */
4538 [ + - ]: 69 : if (t_group_info) /* djb-rwth: fixing oss-fuzz issue #42537161/70475 */
4539 : : {
4540 [ - + ]: 69 : if (t_group_info->nEndpointAtomNumber)
4541 : : {
4542 [ # # ]: 0 : inchi_free(t_group_info->nEndpointAtomNumber);
4543 : : }
4544 [ - + ]: 69 : if (t_group_info->tGroupNumber)
4545 : : {
4546 [ # # ]: 0 : inchi_free(t_group_info->tGroupNumber);
4547 : : }
4548 [ - + ]: 69 : if (t_group_info->nIsotopicEndpointAtomNumber)
4549 : : {
4550 [ # # ]: 0 : inchi_free(t_group_info->nIsotopicEndpointAtomNumber);
4551 : : }
4552 [ + - ]: 69 : if (t_group_info->t_group)
4553 : : {
4554 [ + - ]: 69 : inchi_free(t_group_info->t_group);
4555 : : }
4556 : 69 : memset(t_group_info, 0, sizeof(*t_group_info)); /* djb-rwth: memset_s C11/Annex K variant? */
4557 : : }
4558 : : }
4559 : 69 : free_t_group_info(t_group_info_orig);
4560 : :
4561 [ - + ]: 69 : if (ebend)
4562 : : {
4563 [ # # ]: 0 : inchi_free(ebend);
4564 : : }
4565 : :
4566 : 69 : return ret;
4567 : : }
4568 : :
4569 : :
4570 : : /****************************************************************************/
4571 : : #ifndef COMPILE_ANSI_ONLY /* { */
4572 : : int GetAtomOrdNbrInCanonOrd(struct tagCANON_GLOBALS* pCG,
4573 : : inp_ATOM* norm_at,
4574 : : AT_NUMB* nAtomOrdNbr,
4575 : : AT_NUMB* nOrigAtNosInCanonOrd,
4576 : : int num_at)
4577 : : {
4578 : : AT_NUMB* nCanonNbr, * nOrigAtNos, * nOrigAtNosOrd;
4579 : : int i, ret;
4580 : :
4581 : : ret = 0;
4582 : :
4583 : : nCanonNbr = (AT_NUMB*)inchi_calloc(num_at, sizeof(nCanonNbr[0]));
4584 : : nOrigAtNos = (AT_NUMB*)inchi_calloc(num_at, sizeof(nOrigAtNos[0]));
4585 : : nOrigAtNosOrd = (AT_NUMB*)inchi_calloc(num_at, sizeof(nOrigAtNosOrd[0]));
4586 : :
4587 : : if (!nCanonNbr || !nOrigAtNos || !nAtomOrdNbr || !nOrigAtNosOrd)
4588 : : {
4589 : : ret = CT_OUT_OF_RAM; /* <BRKPT> */
4590 : : goto exit_function;
4591 : : }
4592 : : for (i = 0; i < num_at; i++)
4593 : : {
4594 : : nCanonNbr[i] = nAtomOrdNbr[i] = nOrigAtNosOrd[i] = (AT_NUMB)i;
4595 : : nOrigAtNos[i] = norm_at[i].orig_at_number;
4596 : : }
4597 : :
4598 : : /* get nCanonNbr[]: canon. numbers-1 in order of increasing original atom numbers */
4599 : : pCG->m_pn_RankForSort = nOrigAtNosInCanonOrd;
4600 : : inchi_qsort(pCG, nCanonNbr, num_at, sizeof(nCanonNbr[0]), CompRank);
4601 : : /* get nOrigAtNosOrd[]: norm_atom ord. numbers the same order of increasing original atom numbers */
4602 : : pCG->m_pn_RankForSort = nOrigAtNos;
4603 : : inchi_qsort(pCG, nOrigAtNosOrd, num_at, sizeof(nOrigAtNosOrd[0]), CompRank);
4604 : :
4605 : : /* check whether the 2 sets of origiginal atom numbers have identical elements */
4606 : : for (i = 0; i < num_at; i++)
4607 : : {
4608 : : if (nOrigAtNosInCanonOrd[nCanonNbr[i]] != nOrigAtNos[nOrigAtNosOrd[i]])
4609 : : {
4610 : : ret = CT_RANKING_ERR; /* <BRKPT> */
4611 : : goto exit_function;
4612 : : }
4613 : : }
4614 : : for (i = 0; i < num_at; i++)
4615 : : {
4616 : : nAtomOrdNbr[(int)nCanonNbr[i]] = nOrigAtNosOrd[i];
4617 : : }
4618 : :
4619 : : /*
4620 : : pn_RankForSort = nCanonNbr;
4621 : : qsort( nAtomOrdNbr, num_at, sizeof(nCanonNbr[0]), CompRank );
4622 : : */
4623 : :
4624 : : exit_function:
4625 : : if (nCanonNbr)
4626 : : {
4627 : : inchi_free(nCanonNbr);
4628 : : }
4629 : : if (nOrigAtNos)
4630 : : {
4631 : : inchi_free(nOrigAtNos);
4632 : : }
4633 : : if (nOrigAtNosOrd)
4634 : : {
4635 : : inchi_free(nOrigAtNosOrd);
4636 : : }
4637 : :
4638 : : return ret;
4639 : : }
4640 : :
4641 : :
4642 : : /****************************************************************************/
4643 : : int FillOutCanonInfAtom(struct tagCANON_GLOBALS* pCG,
4644 : : inp_ATOM* norm_at,
4645 : : INF_ATOM_DATA* inf_norm_at_data,
4646 : : int init_num_at,
4647 : : int bIsotopic,
4648 : : INChI* pINChI,
4649 : : INChI_Aux* pINChI_Aux,
4650 : : int bAbcNumbers,
4651 : : INCHI_MODE nMode)
4652 : : {
4653 : : int i, j, m, n, num_stereo, k, c, ret, len_str, len, atw; /* djb-rwth: removing redundant variable */
4654 : : int next_atom[MAX_CUMULENE_LEN + 1], best_next_atom[MAX_CUMULENE_LEN + 1], cur_atom;
4655 : : int next_neigh[MAX_CUMULENE_LEN + 1], best_next_neigh[MAX_CUMULENE_LEN + 1], best_len;
4656 : : int num_iso_H[NUM_H_ISOTOPES];
4657 : : char* str;
4658 : : AT_NUMB g, e;
4659 : : int num_at = pINChI->nNumberOfAtoms;
4660 : : int nNumberOfTGroups = (pINChI->lenTautomer && pINChI->nTautomer && pINChI->nTautomer[0]) ? (int)pINChI->nTautomer[0] : 0;
4661 : : AT_NUMB* nOrigAtNosInCanonOrd;
4662 : : INChI_Stereo* Stereo;
4663 : : AT_NUMB* nConstitEquNumbers;
4664 : : AT_NUMB* nConstitEquTGroupNumbers;
4665 : : S_CHAR* t_parity = NULL;
4666 : : AT_NUMB* nNumber = NULL;
4667 : : int bIncludeIsotopicH;
4668 : :
4669 : : AT_NUMB* nNormAtNosInCanonOrd;
4670 : : int(*MakeNumber)(char*, int, const char*, int) = bAbcNumbers ? MakeAbcNumber : MakeDecNumber;
4671 : : int bRel = (0 != (nMode & (REQ_MODE_RELATIVE_STEREO)));
4672 : : int bRac = (0 != (nMode & (REQ_MODE_RACEMIC_STEREO)));
4673 : : int bRelRac = bRel || bRac;
4674 : : int bDoDisplaySp3 = 1;
4675 : :
4676 : : inf_ATOM* inf_norm_at = inf_norm_at_data ? inf_norm_at_data->at : NULL;
4677 : :
4678 : : ret = 0;
4679 : : /* djb-rwth: removing redundant code */
4680 : :
4681 : : if (!inf_norm_at)
4682 : : {
4683 : : return ret;
4684 : : }
4685 : :
4686 : : /* prepare removeable protons and H info */
4687 : : inf_norm_at_data->nNumRemovedProtons = pINChI_Aux->nNumRemovedProtons;
4688 : :
4689 : : MakeRemovedProtonsString(pINChI_Aux->nNumRemovedProtons, pINChI_Aux->nNumRemovedIsotopicH, NULL, bIsotopic,
4690 : : inf_norm_at_data->szRemovedProtons, &inf_norm_at_data->num_removed_iso_H);
4691 : :
4692 : : /* fill out info atom */
4693 : : if (bIsotopic && !(pINChI->nNumberOfIsotopicAtoms || pINChI->nNumberOfIsotopicTGroups ||
4694 : : (pINChI->nPossibleLocationsOfIsotopicH && pINChI->nPossibleLocationsOfIsotopicH[0] > 1))) /* djb-rwth: addressing LLVM warning */
4695 : : {
4696 : : bIsotopic = 0;
4697 : : }
4698 : :
4699 : : Stereo = bIsotopic ? pINChI->StereoIsotopic :
4700 : : pINChI->Stereo;
4701 : : bDoDisplaySp3 = (NULL != Stereo) && (Stereo->nNumberOfStereoCenters > 0);
4702 : :
4703 : : #if ( REL_RAC_STEREO_IGN_1_SC == 1 )
4704 : : if (bDoDisplaySp3 && bRelRac && Stereo->nNumberOfStereoCenters < 2 &&
4705 : : (Stereo->nCompInv2Abs || ATOM_PARITY_ILL_DEF(Stereo->t_parity[0])))
4706 : : {
4707 : : bDoDisplaySp3 = 0;
4708 : : if (Stereo->nCompInv2Abs)
4709 : : {
4710 : : inf_norm_at_data->StereoFlags |= bRel ? INF_STEREO_REL : bRac ? INF_STEREO_RAC : 0;
4711 : : }
4712 : : }
4713 : : #endif
4714 : : /* flag has stereo */
4715 : : if ((NULL != Stereo) && (bDoDisplaySp3 || Stereo->nNumberOfStereoBonds > 0))
4716 : : {
4717 : : inf_norm_at_data->StereoFlags |= INF_STEREO;
4718 : : }
4719 : :
4720 : : /*
4721 : : if ( bDoDisplaySp3 && bRelRac && Stereo->nNumberOfStereoCenters < 2 &&
4722 : : (Stereo->nCompInv2Abs || ATOM_PARITY_ILL_DEF(Stereo->t_parity[0]) ) ) {
4723 : : bDoDisplaySp3 = 0;
4724 : : }
4725 : : */
4726 : : if (bDoDisplaySp3 && Stereo->nCompInv2Abs)
4727 : : {
4728 : : /* inversion changes stereo */
4729 : : if (bRel)
4730 : : {
4731 : : inf_norm_at_data->StereoFlags |= INF_STEREO_REL;
4732 : : }
4733 : : else
4734 : : {
4735 : : if (bRac)
4736 : : {
4737 : : inf_norm_at_data->StereoFlags |= INF_STEREO_RAC;
4738 : : }
4739 : : else
4740 : : {
4741 : : inf_norm_at_data->StereoFlags |= INF_STEREO_ABS;
4742 : : }
4743 : : }
4744 : : if (bRelRac)
4745 : : {
4746 : : inf_norm_at_data->StereoFlags |= (Stereo->nCompInv2Abs > 0) ? INF_STEREO_NORM : INF_STEREO_INV;
4747 : : }
4748 : : }
4749 : : if (bDoDisplaySp3 && Stereo->nCompInv2Abs < 0 && !bRelRac)
4750 : : {
4751 : : /* display Inv stereo which is Absolute Stereo */
4752 : : nNumber = Stereo->nNumberInv;
4753 : : t_parity = Stereo->t_parityInv;
4754 : : nOrigAtNosInCanonOrd = bIsotopic ? pINChI_Aux->nIsotopicOrigAtNosInCanonOrdInv :
4755 : : pINChI_Aux->nOrigAtNosInCanonOrdInv;
4756 : : }
4757 : : else
4758 : : {
4759 : : /* display Inv stereo which is Absolute Stereo */
4760 : : if (bDoDisplaySp3)
4761 : : {
4762 : : nNumber = Stereo->nNumber;
4763 : : t_parity = Stereo->t_parity;
4764 : : }
4765 : : nOrigAtNosInCanonOrd = bIsotopic ? pINChI_Aux->nIsotopicOrigAtNosInCanonOrd :
4766 : : pINChI_Aux->nOrigAtNosInCanonOrd;
4767 : : }
4768 : :
4769 : : nConstitEquNumbers = bIsotopic ? pINChI_Aux->nConstitEquIsotopicNumbers :
4770 : : pINChI_Aux->nConstitEquNumbers;
4771 : : nConstitEquTGroupNumbers = bIsotopic ? pINChI_Aux->nConstitEquIsotopicTGroupNumbers :
4772 : : pINChI_Aux->nConstitEquTGroupNumbers;
4773 : : memset(inf_norm_at, 0, init_num_at * sizeof(inf_norm_at[0])); /* djb-rwth: memset_s C11/Annex K variant? */
4774 : :
4775 : : /* obtain norm_at[] atom numbers (from zero) in order of canonical numbers */
4776 : : nNormAtNosInCanonOrd = (AT_NUMB*)inchi_calloc(num_at, sizeof(nNormAtNosInCanonOrd[0]));
4777 : : if ((ret = GetAtomOrdNbrInCanonOrd(pCG, norm_at, nNormAtNosInCanonOrd, nOrigAtNosInCanonOrd, num_at))) /* djb-rwth: addressing LLVM warning */
4778 : : {
4779 : : goto exit_function;
4780 : : }
4781 : :
4782 : : /* atom canonical and equivalence numbers > 0 */
4783 : : for (i = 0; i < num_at; i++)
4784 : : {
4785 : : j = (int)nNormAtNosInCanonOrd[i];
4786 : : if (j < 0 || j >= num_at)
4787 : : {
4788 : : continue;
4789 : : }
4790 : : inf_norm_at[j].nCanonNbr = (AT_NUMB)(i + 1);
4791 : : inf_norm_at[j].nCanonEquNbr = nConstitEquNumbers[i];
4792 : : #ifdef DISPLAY_DEBUG_DATA
4793 : : inf_norm_at[j].nDebugData = 0;
4794 : : #if ( DISPLAY_DEBUG_DATA == DISPLAY_DEBUG_DATA_C_POINT )
4795 : : inf_norm_at[j].nDebugData = norm_at[j].c_point;
4796 : : #endif
4797 : : #endif
4798 : : }
4799 : : /* tautomeric groups */
4800 : : if (nNumberOfTGroups)
4801 : : {
4802 : : /*
4803 : : : start from 1: bypass number of t-groups
4804 : : : j is a counter within the current t-group
4805 : : : g is a tautomeric group canonical number
4806 : : : e is a tautomeric group equivalence
4807 : : */
4808 : : for (g = 1, i = 1; g <= nNumberOfTGroups; g++)
4809 : : {
4810 : : n = (int)pINChI->nTautomer[i] - INCHI_T_NUM_MOVABLE; /* number of atoms in t-group */
4811 : : e = nConstitEquTGroupNumbers[(int)g - 1];
4812 : : /* bypass number of hydrogen atoms, negative charges, ... */
4813 : : for (i += INCHI_T_NUM_MOVABLE + 1, j = 0; j < n && i < pINChI->lenTautomer; j++, i++)
4814 : : {
4815 : : /* scan canonical numbers of atoms within the atom t-group */
4816 : : k = (int)nNormAtNosInCanonOrd[(int)pINChI->nTautomer[i] - 1];
4817 : : inf_norm_at[k].nTautGroupCanonNbr = g;
4818 : : inf_norm_at[k].nTautGroupEquNbr = e;
4819 : : }
4820 : : }
4821 : : if (i != pINChI->lenTautomer || g != nNumberOfTGroups + 1)
4822 : : {
4823 : : ret = CT_TAUCOUNT_ERR; /* <BRKPT> */
4824 : : goto exit_function;
4825 : : }
4826 : : }
4827 : : /* atoms that may exchange isotopic H */
4828 : : if (bIsotopic && pINChI->nPossibleLocationsOfIsotopicH && (n = (int)pINChI->nPossibleLocationsOfIsotopicH[0]))
4829 : : {
4830 : : for (i = 1; i < n; i++)
4831 : : {
4832 : : j = (int)pINChI->nPossibleLocationsOfIsotopicH[i];
4833 : : k = (int)nNormAtNosInCanonOrd[j - 1];
4834 : : if (!inf_norm_at[k].nTautGroupCanonNbr)
4835 : : {
4836 : : inf_norm_at[k].cFlags |= AT_FLAG_ISO_H_POINT;
4837 : : }
4838 : : }
4839 : : }
4840 : :
4841 : : #if ( DISPLAY_RING_SYSTEMS == 1 )
4842 : : /* debug only */
4843 : : for (j = 0; j < num_at; j++)
4844 : : {
4845 : : inf_norm_at[j].nCanonNbr = norm_at[j].nBlockSystem;
4846 : : inf_norm_at[j].nCanonEquNbr = norm_at[j].nRingSystem;
4847 : : #if ( USE_DISTANCES_FOR_RANKING == 1 )
4848 : : inf_norm_at[j].nTautGroupCanonNbr = norm_at[j].nDistanceFromTerminal;
4849 : : inf_norm_at[j].nTautGroupEquNbr = norm_at[j].bCutVertex;
4850 : : #else
4851 : : inf_norm_at[j].nTautGroupCanonNbr = norm_at[j].bCutVertex;
4852 : : inf_norm_at[j].nTautGroupEquNbr = 0;
4853 : : #endif
4854 : : }
4855 : : #endif
4856 : :
4857 : : /* Fill inf_at[i] field 'at_string':
4858 : : write isotopic mass, chemical element symbols and hydrogens, charge, radical, canon. numbers
4859 : : */
4860 : : len_str = sizeof(inf_norm_at[0].at_string);
4861 : : for (i = 0; i < init_num_at; i++)
4862 : : {
4863 : : str = inf_norm_at[i].at_string;
4864 : : len = 0;
4865 : : bIncludeIsotopicH = bIsotopic && !inf_norm_at[i].nTautGroupCanonNbr && !(inf_norm_at[i].cFlags & AT_FLAG_ISO_H_POINT);
4866 : : /* isotopic mass */
4867 : : atw = 0;
4868 : : if (norm_at[i].iso_atw_diff && bIsotopic)
4869 : : {
4870 : : if (norm_at[i].at_type == ATT_PROTON)
4871 : : {
4872 : : ; /* do not set isotopic mass of a tautomeric proton */
4873 : : }
4874 : : else
4875 : : {
4876 : : if (norm_at[i].el_number == PERIODIC_NUMBER_H && norm_at[i].chem_bonds_valence == 1 &&
4877 : : !norm_at[i].charge && !norm_at[i].radical && !norm_at[i].num_H &&
4878 : : (inf_norm_at[j = (int)norm_at[i].neighbor[0]].nTautGroupCanonNbr || (inf_norm_at[j].cFlags & AT_FLAG_ISO_H_POINT)))
4879 : : {
4880 : : ; /* do not set isotopic mass of an exchangeable proton */
4881 : : }
4882 : : else
4883 : : {
4884 : : atw = get_atomic_mass(norm_at[i].elname);
4885 : : atw += (norm_at[i].iso_atw_diff > 0) ? norm_at[i].iso_atw_diff - 1 : norm_at[i].iso_atw_diff;
4886 : : /*len += sprintf( str+len, "^%d", atw );*/
4887 : : }
4888 : : }
4889 : : }
4890 : : /* element name */
4891 : : if (norm_at[i].el_number == PERIODIC_NUMBER_H && 2 <= atw && atw <= 3)
4892 : : {
4893 : : len += sprintf(str + len, "%s", atw == 2 ? "D" : "T");
4894 : : }
4895 : : else
4896 : : {
4897 : : if (atw)
4898 : : {
4899 : : len += sprintf(str + len, "^%d", atw);
4900 : : }
4901 : : if (strcmp(norm_at[i].elname, "Zz") && strcmp(norm_at[i].elname, "Zy"))
4902 : : {
4903 : : len += sprintf(str + len, "%s", norm_at[i].elname);
4904 : : }
4905 : : else /* always show "Zy" as "Zz" */
4906 : : {
4907 : : #if ( DISPLAY_ZZ_AS_STAR == 1 )
4908 : : len += sprintf(str + len, "*");
4909 : : #else
4910 : : len += sprintf(str + len, "Zz");
4911 : : #endif
4912 : : }
4913 : : }
4914 : :
4915 : : /* hydrogens */
4916 : : /* find number of previuosly removed terminal hydrogen atoms because these terminal H will be displayed */
4917 : :
4918 : : for (j = 0; j < NUM_H_ISOTOPES; j++)
4919 : : {
4920 : : num_iso_H[j] = norm_at[i].num_iso_H[j];
4921 : : }
4922 : : /* n = number of implicit H to display */
4923 : : for (j = num_at, n = (int)norm_at[i].num_H; j < init_num_at; j++)
4924 : : {
4925 : : /* subtract number of removed terminal */
4926 : : /* H atoms from the total number of H atoms */
4927 : : if (i == (int)norm_at[j].neighbor[0])
4928 : : {
4929 : : n -= 1; /* found explicit H => decrement number of implicit H */
4930 : : m = (int)norm_at[j].iso_atw_diff - 1;
4931 : : if (0 <= m && m < NUM_H_ISOTOPES)
4932 : : {
4933 : : /* subtract number of removed terminal isotopic H */
4934 : : /* atoms from the total number of isotopic H atoms */
4935 : : num_iso_H[m] -= 1;
4936 : : }
4937 : : }
4938 : : }
4939 : : /* at this point n = number of implicit H to display,
4940 : : num_iso_H[] contains number of implicit isotopic H among n */
4941 : : if (bIncludeIsotopicH)
4942 : : {
4943 : : /* subtract number of isotopic H atoms from the total number of H atoms */
4944 : : for (j = 0; j < NUM_H_ISOTOPES; j++)
4945 : : {
4946 : : n -= num_iso_H[j];
4947 : : }
4948 : : }
4949 : : /* non-isotopic hydrogen atoms */
4950 : : if (n > 1)
4951 : : {
4952 : : len += sprintf(str + len, "H%d", n);
4953 : : }
4954 : : else
4955 : : {
4956 : : if (n == 1)
4957 : : {
4958 : : len += sprintf(str + len, "H");
4959 : : }
4960 : : }
4961 : :
4962 : : /* isotopic hydrogen atoms */
4963 : : if (bIncludeIsotopicH)
4964 : : {
4965 : : for (j = 0; j < NUM_H_ISOTOPES; j++)
4966 : : {
4967 : : if (num_iso_H[j])
4968 : : {
4969 : : if (j == 0 || (j != 1 && j != 2)) /* djb-rwth: addressing LLVM warning */
4970 : : {
4971 : : len += sprintf(str + len, "^%dH", j + 1);
4972 : : }
4973 : : else
4974 : : {
4975 : : len += sprintf(str + len, j == 1 ? "D" : "T");
4976 : : }
4977 : : if (num_iso_H[j] != 1)
4978 : : {
4979 : : len += sprintf(str + len, "%d", (int)num_iso_H[j]);
4980 : : }
4981 : : }
4982 : : }
4983 : : }
4984 : : if (norm_at[i].el_number == PERIODIC_NUMBER_H && str[0] == str[1])
4985 : : {
4986 : : char* q;
4987 : : if (!str[2])
4988 : : {
4989 : : str[1] = '2'; /* quick fix: replace HH with H2 */
4990 : : }
4991 : : else
4992 : : {
4993 : : if (isdigit(UCINT str[2]) && (n = strtol(str + 2, &q, 10)) && !q[0])
4994 : : {
4995 : : len = 1 + sprintf(str + 1, "%d", n + 1);
4996 : : }
4997 : : }
4998 : : }
4999 : : /*
5000 : : if ( str[0] == 'H' && str[1] == 'H' && !str[2] ) {
5001 : : str[1] = '2';
5002 : : }
5003 : : */
5004 : : /* charge */
5005 : : if (abs(norm_at[i].charge) > 1)
5006 : : {
5007 : : len += sprintf(str + len, "%+d", norm_at[i].charge);
5008 : : }
5009 : : else
5010 : : {
5011 : : if (abs(norm_at[i].charge) == 1)
5012 : : {
5013 : : len += sprintf(str + len, "%s", norm_at[i].charge > 0 ? "+" : "-");
5014 : : }
5015 : : }
5016 : : /* radical */
5017 : : if (norm_at[i].radical)
5018 : : {
5019 : : len += sprintf(str + len, "%s", norm_at[i].radical == RADICAL_SINGLET ? ":" :
5020 : : norm_at[i].radical == RADICAL_DOUBLET ? "." :
5021 : : norm_at[i].radical == RADICAL_TRIPLET ? ".." : "?");
5022 : : }
5023 : : }
5024 : :
5025 : : /* Stereogenic centers */
5026 : : if (bDoDisplaySp3 && Stereo && 0 < (num_stereo = Stereo->nNumberOfStereoCenters))
5027 : : {
5028 : : for (i = 0; i < num_stereo; i++)
5029 : : {
5030 : : j = (int)nNormAtNosInCanonOrd[(int)nNumber[i] - 1];
5031 : : c = t_parity[i];
5032 : : c = c == 1 ? '-' : c == 2 ? '+' : c == 3 ? 'u' : c == 4 ? '?' : '*';
5033 : : inf_norm_at[j].cStereoCenterParity = c;
5034 : : str = inf_norm_at[j].at_string;
5035 : : len = (int)strlen(str);
5036 : : if (len + 3 < (int)sizeof(inf_norm_at[0].at_string))
5037 : : {
5038 : : str[len++] = '(';
5039 : : str[len++] = inf_norm_at[j].cStereoCenterParity;
5040 : : str[len++] = ')';
5041 : : str[len] = '\0';
5042 : : /* mark ambuguous stereo center */
5043 : : if (norm_at[j].bAmbiguousStereo && (c == '+' || c == '-' || c == '?') && str[0] != '!' &&
5044 : : len + 1 < (int)sizeof(inf_norm_at[0].at_string))
5045 : : {
5046 : : memmove(str + 1, str, (long long)len + 1); /* djb-rwth: cast operator added */
5047 : : str[0] = '!'; /* output the atom in red color */
5048 : : }
5049 : : }
5050 : : }
5051 : : }
5052 : :
5053 : : /* Stereogenic bonds */
5054 : : /* (cumulenes with odd number of double bonds are stereocenters, */
5055 : : /* and atom parity should be set) */
5056 : : if (Stereo && 0 < (num_stereo = Stereo->nNumberOfStereoBonds))
5057 : : {
5058 : : for (i = 0; i < num_stereo; i++)
5059 : : {
5060 : : int start_at, bAmbiguousStereoBond = 0; /* djb-rwth: removing redundant variable */
5061 : : j = (int)nNormAtNosInCanonOrd[(int)Stereo->nBondAtom1[i] - 1];
5062 : : k = (int)nNormAtNosInCanonOrd[(int)Stereo->nBondAtom2[i] - 1];
5063 : : start_at = j;
5064 : : c = Stereo->b_parity[i];
5065 : :
5066 : : c = c == 1 ? '-' : c == 2 ? '+' : c == 3 ? 'u' : c == 4 ? '?' : '*';
5067 : :
5068 : : /* mark ambuguous stereo bond atom(s) */
5069 : : if (norm_at[j].bAmbiguousStereo && (c == '+' || c == '-') &&
5070 : : (len = strlen(str = inf_norm_at[j].at_string) + 1) < (int)sizeof(inf_norm_at[0].at_string) &&
5071 : : str[0] != '!')
5072 : : {
5073 : : memmove(str + 1, str, len);
5074 : : str[0] = '!'; /* output the atom in red color */
5075 : : bAmbiguousStereoBond++;
5076 : : }
5077 : :
5078 : : if (norm_at[k].bAmbiguousStereo && (c == '+' || c == '-') &&
5079 : : (len = strlen(str = inf_norm_at[k].at_string) + 1) < (int)sizeof(inf_norm_at[0].at_string) &&
5080 : : str[0] != '!')
5081 : : {
5082 : : memmove(str + 1, str, len);
5083 : : str[0] = '!'; /* output the atom in red color */
5084 : : bAmbiguousStereoBond++;
5085 : : }
5086 : :
5087 : : /* find the opposite atom k. */
5088 : : /* Note: since it may be a cumulene, find the shortest(best) path */
5089 : : /* to atom number k to avoid confusion in case of, for example, */
5090 : : /* 4-member aromatic rings. */
5091 : : best_len = MAX_CUMULENE_LEN + 1; /* moved here from inside the cycle 1-8-2003 */
5092 : : for (n = 0; n < norm_at[j].valence; n++)
5093 : : {
5094 : : if (norm_at[j].bond_type[n] == BOND_SINGLE)
5095 : : {
5096 : : /* single bond cannot be stereogenic. */
5097 : : continue;
5098 : : }
5099 : : /* best_len = MAX_CUMULENE_LEN+1; */
5100 : : len = 0; /* number of bonds in cumulene - 1 */
5101 : : next_atom[len] = (int)norm_at[j].neighbor[n];
5102 : : next_neigh[len] = n;
5103 : : cur_atom = j;
5104 : : while (next_atom[len] != k && len < MAX_CUMULENE_LEN && 2 == norm_at[next_atom[len]].valence)
5105 : : {
5106 : : next_neigh[len + 1] = ((int)norm_at[next_atom[len]].neighbor[0] == cur_atom);
5107 : : next_atom[len + 1] = (int)norm_at[next_atom[len]].neighbor[next_neigh[len + 1]];
5108 : : cur_atom = next_atom[len];
5109 : : len++;
5110 : : }
5111 : : if (next_atom[len] == k)
5112 : : {
5113 : : if (len < best_len)
5114 : : {
5115 : : memcpy(best_next_neigh, next_neigh, sizeof(best_next_neigh));
5116 : : memcpy(best_next_atom, next_atom, sizeof(best_next_atom));
5117 : : best_len = len;
5118 : : /* djb-rwth: removing redundant code */
5119 : : if (len == 0)
5120 : : {
5121 : : break; /* path length cannot be smaller than 1 */
5122 : : }
5123 : : }
5124 : : /* djb-rwth: removing redundant code */
5125 : : }
5126 : : }
5127 : : if (best_len <= MAX_CUMULENE_LEN && best_next_atom[best_len] == k)
5128 : : {
5129 : : /* djb-rwth: removing redundant code */
5130 : : if (best_len % 2)
5131 : : {
5132 : : /* even number of bonds: chiral atom, draw parity on the cenrtal atom */
5133 : : j = best_next_atom[best_len / 2];
5134 : : inf_norm_at[j].cStereoCenterParity = c;
5135 : : str = inf_norm_at[j].at_string;
5136 : : len = (int)strlen(str);
5137 : : if (len + 3 < (int)sizeof(inf_norm_at[0].at_string))
5138 : : {
5139 : : str[len++] = '(';
5140 : : str[len++] = inf_norm_at[j].cStereoCenterParity;
5141 : : str[len++] = ')';
5142 : : str[len] = '\0';
5143 : : }
5144 : : }
5145 : : else
5146 : : {
5147 : : /* odd number of bonds: draw parity on the central bond */
5148 : : if (best_len == 0)
5149 : : {
5150 : : /* double bond */
5151 : : j = start_at;
5152 : : k = best_next_neigh[0];
5153 : : }
5154 : : else
5155 : : {
5156 : : /* cumulene */
5157 : : best_len = best_len / 2 - 1;
5158 : : j = best_next_atom[best_len];
5159 : : k = best_next_neigh[best_len + 1]; /* added +1 to display cumulene parity on the middle bond (6-24-2002) */
5160 : : }
5161 : : /* mark "forward" bond */
5162 : : for (m = 0; m < MAX_STEREO_BONDS && inf_norm_at[j].cStereoBondParity[m]; m++)
5163 : : ;
5164 : : if (m < MAX_STEREO_BONDS)
5165 : : {
5166 : : inf_norm_at[j].cStereoBondParity[m] = c;
5167 : : inf_norm_at[j].cStereoBondNumber[m] = k;
5168 : : inf_norm_at[j].cStereoBondWarning[m] = bAmbiguousStereoBond;
5169 : : }
5170 : : /* djb-rwth: removing redundant code */
5171 : : /* mark "backward" bond */
5172 : : n = norm_at[j].neighbor[k];
5173 : : for (k = 0; k < norm_at[n].valence && j != (int)norm_at[n].neighbor[k]; k++)
5174 : : {
5175 : : ;
5176 : : }
5177 : : if (k < norm_at[n].valence)
5178 : : {
5179 : : j = n;
5180 : : for (m = 0; m < MAX_STEREO_BONDS && inf_norm_at[j].cStereoBondParity[m]; m++)
5181 : : {
5182 : : ;
5183 : : }
5184 : : if (m < MAX_STEREO_BONDS)
5185 : : {
5186 : : inf_norm_at[j].cStereoBondParity[m] = c;
5187 : : inf_norm_at[j].cStereoBondNumber[m] = k;
5188 : : inf_norm_at[j].cStereoBondWarning[m] = bAmbiguousStereoBond;
5189 : : }
5190 : : /* djb-rwth: removing redundant code */
5191 : : }
5192 : : /* djb-rwth: removing redundant code */
5193 : : }
5194 : : }
5195 : : /* djb-rwth: removing redundant code */
5196 : : }
5197 : : }
5198 : :
5199 : : for (i = 0; i < init_num_at; i++)
5200 : : {
5201 : : /* canonical numbers */
5202 : : if (inf_norm_at[i].nCanonNbr)
5203 : : {
5204 : : str = inf_norm_at[i].at_string;
5205 : : len = (int)strlen(str);
5206 : : len += (*MakeNumber)(str + len, len_str - len, "/", (int)inf_norm_at[i].nCanonNbr);
5207 : : if (inf_norm_at[i].nCanonEquNbr || inf_norm_at[i].nTautGroupCanonNbr || (inf_norm_at[i].cFlags & AT_FLAG_ISO_H_POINT))
5208 : : {
5209 : : if (inf_norm_at[i].nCanonEquNbr)
5210 : : {
5211 : : len += (*MakeNumber)(str + len, len_str - len, "/", (int)inf_norm_at[i].nCanonEquNbr);
5212 : : }
5213 : : else
5214 : : {
5215 : : if (len + 1 < len_str)
5216 : : {
5217 : : len += 1;
5218 : : strcat(str, "/");
5219 : : }
5220 : : }
5221 : : }
5222 : : /* tautomeric groups */
5223 : : if (inf_norm_at[i].nTautGroupCanonNbr)
5224 : : {
5225 : : len += (*MakeNumber)(str + len, len_str - len, "/", (int)inf_norm_at[i].nTautGroupCanonNbr);
5226 : : if (inf_norm_at[i].nTautGroupEquNbr)
5227 : : {
5228 : : len += (*MakeNumber)(str + len, len_str - len, "/", (int)inf_norm_at[i].nTautGroupEquNbr);
5229 : : }
5230 : : }
5231 : : if ((inf_norm_at[i].cFlags & AT_FLAG_ISO_H_POINT) && len + 2 <= len_str)
5232 : : {
5233 : : str[len++] = '/';
5234 : : str[len++] = '*';
5235 : : str[len] = '\0';
5236 : : }
5237 : : #ifdef DISPLAY_DEBUG_DATA
5238 : : if (inf_norm_at[i].nDebugData)
5239 : : {
5240 : : len += (*MakeNumber)(str + len, len_str - len, "`", (int)inf_norm_at[i].nDebugData);
5241 : : }
5242 : : #endif
5243 : : }
5244 : : }
5245 : :
5246 : : exit_function:
5247 : :
5248 : : if (nNormAtNosInCanonOrd)
5249 : : {
5250 : : inchi_free(nNormAtNosInCanonOrd);
5251 : : }
5252 : :
5253 : : return ret;
5254 : : }
5255 : :
5256 : :
5257 : : /****************************************************************************/
5258 : : int FillOutOneCanonInfAtom(struct tagCANON_GLOBALS* pCG,
5259 : : inp_ATOM* inp_norm_at,
5260 : : INF_ATOM_DATA* inf_norm_at_data,
5261 : : AT_NUMB* pStereoFlags,
5262 : : int init_num_at,
5263 : : int offset,
5264 : : int offset_H,
5265 : : int bIsotopic,
5266 : : INChI* pINChI,
5267 : : INChI_Aux* pINChI_Aux,
5268 : : int bAbcNumbers,
5269 : : INCHI_MODE nMode)
5270 : : {
5271 : : int i, j, m, n, num_stereo, k, c, ret, len_str, len, atw; /* djb-rwth: removing redundant variable */
5272 : : int next_atom[MAX_CUMULENE_LEN + 1], best_next_atom[MAX_CUMULENE_LEN + 1], cur_atom;
5273 : : int next_neigh[MAX_CUMULENE_LEN + 1], best_next_neigh[MAX_CUMULENE_LEN + 1], best_len, bIncludeIsotopicH;
5274 : : int num_iso_H[NUM_H_ISOTOPES];
5275 : : char* str;
5276 : : AT_NUMB g, e;
5277 : : int num_at = pINChI->nNumberOfAtoms;
5278 : : int num_H = init_num_at - num_at; /* number of removed H */
5279 : : int nNumberOfTGroups = (pINChI->lenTautomer && pINChI->nTautomer && pINChI->nTautomer[0]) ? (int)pINChI->nTautomer[0] : 0;
5280 : : AT_NUMB* nOrigAtNosInCanonOrd;
5281 : : INChI_Stereo* Stereo;
5282 : : AT_NUMB* nConstitEquNumbers;
5283 : : AT_NUMB* nConstitEquTGroupNumbers;
5284 : : S_CHAR* t_parity = NULL;
5285 : : AT_NUMB* nNumber = NULL;
5286 : :
5287 : : AT_NUMB* nNormAtNosInCanonOrd;
5288 : : int(*MakeNumber)(char*, int, const char*, int) = bAbcNumbers ? MakeAbcNumber : MakeDecNumber;
5289 : : int bRel = (0 != (nMode & (REQ_MODE_RELATIVE_STEREO)));
5290 : : int bRac = (0 != (nMode & (REQ_MODE_RACEMIC_STEREO)));
5291 : : int bRelRac = bRel || bRac;
5292 : : int bDoDisplaySp3 = 1;
5293 : :
5294 : : inf_ATOM* inf_norm_at = (inf_norm_at_data && inf_norm_at_data->at) ? inf_norm_at_data->at + offset : NULL;
5295 : : inp_ATOM* norm_at = inp_norm_at ? inp_norm_at + offset : NULL;
5296 : : inf_ATOM* inf_norm_at_H = (inf_norm_at_data && inf_norm_at_data->at) ? inf_norm_at_data->at + offset_H : NULL;
5297 : : inp_ATOM* norm_at_H = inp_norm_at ? inp_norm_at + offset_H : NULL;
5298 : :
5299 : : ret = 0;
5300 : : /* djb-rwth: removing redundant code */
5301 : :
5302 : : if (!inf_norm_at)
5303 : : return ret;
5304 : : /* -- already added in FillOutCompositeCanonInfAtom() --
5305 : : if ( bIsotopic ) {
5306 : : for ( i = 0, j = 0; i < NUM_H_ISOTOPES; i ++ ) {
5307 : : if ( pINChI_Aux->nNumRemovedIsotopicH[i] ) {
5308 : : inf_norm_at_data->num_iso_H[i] += pINChI_Aux->nNumRemovedIsotopicH[i];
5309 : : inf_norm_at_data->num_removed_iso_H ++;
5310 : : }
5311 : : }
5312 : : }
5313 : : */
5314 : :
5315 : : if (bIsotopic && !(pINChI->nNumberOfIsotopicAtoms || pINChI->nNumberOfIsotopicTGroups ||
5316 : : (pINChI->nPossibleLocationsOfIsotopicH && pINChI->nPossibleLocationsOfIsotopicH[0] > 1))) /* djb-rwth: addressing LLVM warning */
5317 : : {
5318 : : bIsotopic = 0;
5319 : : }
5320 : :
5321 : : Stereo = bIsotopic ? pINChI->StereoIsotopic : pINChI->Stereo;
5322 : :
5323 : : bDoDisplaySp3 = (NULL != Stereo) && (Stereo->nNumberOfStereoCenters > 0);
5324 : :
5325 : : #if ( REL_RAC_STEREO_IGN_1_SC == 1 )
5326 : : if (bDoDisplaySp3 && bRelRac && Stereo->nNumberOfStereoCenters < 2 &&
5327 : : (Stereo->nCompInv2Abs || ATOM_PARITY_ILL_DEF(Stereo->t_parity[0])))
5328 : : {
5329 : : bDoDisplaySp3 = 0;
5330 : : if (Stereo->nCompInv2Abs)
5331 : : {
5332 : : inf_norm_at_data->StereoFlags |= bRel ? INF_STEREO_REL : bRac ? INF_STEREO_RAC : 0;
5333 : : }
5334 : : }
5335 : : #endif
5336 : : /* flag has stereo */
5337 : : if ((NULL != Stereo) && (bDoDisplaySp3 || Stereo->nNumberOfStereoBonds > 0))
5338 : : {
5339 : : (*pStereoFlags) |= INF_STEREO;
5340 : : }
5341 : :
5342 : : /*
5343 : : if ( bDoDisplaySp3 && bRelRac && Stereo->nCompInv2Abs && Stereo->nNumberOfStereoCenters < 2 ) {
5344 : : bDoDisplaySp3 = 0;
5345 : : }
5346 : : */
5347 : : if (bDoDisplaySp3 && Stereo->nCompInv2Abs)
5348 : : {
5349 : : /* inversion changes stereo */
5350 : : if (bRel)
5351 : : {
5352 : : (*pStereoFlags) |= INF_STEREO_REL;
5353 : : }
5354 : : else
5355 : : {
5356 : : if (bRac)
5357 : : {
5358 : : (*pStereoFlags) |= INF_STEREO_RAC;
5359 : : }
5360 : : else
5361 : : {
5362 : : (*pStereoFlags) |= INF_STEREO_ABS;
5363 : : }
5364 : : }
5365 : : if (bRelRac)
5366 : : {
5367 : : (*pStereoFlags) |= (Stereo->nCompInv2Abs > 0) ? INF_STEREO_NORM : INF_STEREO_INV;
5368 : : }
5369 : : }
5370 : : if (bDoDisplaySp3 && Stereo->nCompInv2Abs < 0 && !bRelRac)
5371 : : {
5372 : : /* display Inv stereo which is Absolute Stereo */
5373 : : nNumber = Stereo->nNumberInv;
5374 : : t_parity = Stereo->t_parityInv;
5375 : : nOrigAtNosInCanonOrd = bIsotopic ? pINChI_Aux->nIsotopicOrigAtNosInCanonOrdInv :
5376 : : pINChI_Aux->nOrigAtNosInCanonOrdInv;
5377 : : }
5378 : : else
5379 : : {
5380 : : /* display Output stereo which is Absolute Stereo */
5381 : : if (bDoDisplaySp3)
5382 : : {
5383 : : nNumber = Stereo->nNumber;
5384 : : t_parity = Stereo->t_parity;
5385 : : }
5386 : : nOrigAtNosInCanonOrd = bIsotopic
5387 : : ? pINChI_Aux->nIsotopicOrigAtNosInCanonOrd
5388 : : : pINChI_Aux->nOrigAtNosInCanonOrd;
5389 : : }
5390 : :
5391 : : nConstitEquNumbers = bIsotopic ? pINChI_Aux->nConstitEquIsotopicNumbers :
5392 : : pINChI_Aux->nConstitEquNumbers;
5393 : : nConstitEquTGroupNumbers = bIsotopic ? pINChI_Aux->nConstitEquIsotopicTGroupNumbers :
5394 : : pINChI_Aux->nConstitEquTGroupNumbers;
5395 : : memset(inf_norm_at, 0, num_at * sizeof(inf_norm_at[0])); /* djb-rwth: memset_s C11/Annex K variant? */
5396 : : if (num_H > 0)
5397 : : {
5398 : : memset(inf_norm_at_H, 0, num_H * sizeof(inf_norm_at[0])); /* djb-rwth: memset_s C11/Annex K variant? */
5399 : : }
5400 : :
5401 : : /* obtain norm_at[] atom numbers (from zero) in order of canonical numbers */
5402 : : nNormAtNosInCanonOrd = (AT_NUMB*)inchi_calloc(num_at, sizeof(nNormAtNosInCanonOrd[0]));
5403 : : if ((ret = GetAtomOrdNbrInCanonOrd(pCG, norm_at, nNormAtNosInCanonOrd, nOrigAtNosInCanonOrd, num_at))) /* djb-rwth: addressing LLVM warning */
5404 : : {
5405 : : goto exit_function;
5406 : : }
5407 : :
5408 : : /* atom canonical and equivalence numbers > 0 */
5409 : : for (i = 0; i < num_at; i++)
5410 : : {
5411 : : j = (int)nNormAtNosInCanonOrd[i];
5412 : : if (j < 0 || j >= num_at)
5413 : : {
5414 : : continue;
5415 : : }
5416 : : inf_norm_at[j].nCanonNbr = (AT_NUMB)(i + 1);
5417 : : inf_norm_at[j].nCanonEquNbr = nConstitEquNumbers[i];
5418 : : #ifdef DISPLAY_DEBUG_DATA
5419 : : inf_norm_at[j].nDebugData = 0;
5420 : : #if ( DISPLAY_DEBUG_DATA == DISPLAY_DEBUG_DATA_C_POINT )
5421 : : inf_norm_at[j].nDebugData = norm_at[j].c_point;
5422 : : #endif
5423 : : #endif
5424 : : }
5425 : : /* tautomeric groups */
5426 : : if (nNumberOfTGroups)
5427 : : {
5428 : : /*
5429 : : : start from 1: bypass number of t-groups
5430 : : : j is a counter within the current t-group
5431 : : : g is a tautomeric group canonical number
5432 : : : e is a tautomeric group equivalence
5433 : : */
5434 : : for (g = 1, i = 1; g <= nNumberOfTGroups; g++)
5435 : : {
5436 : : n = (int)pINChI->nTautomer[i] - INCHI_T_NUM_MOVABLE; /* number of atoms in t-group */
5437 : : e = nConstitEquTGroupNumbers[(int)g - 1];
5438 : : /* bypass number of hydrogen atoms, negative charges, ... */
5439 : : for (i += INCHI_T_NUM_MOVABLE + 1, j = 0; j < n && i < pINChI->lenTautomer; j++, i++)
5440 : : {
5441 : : /* scan canonical numbers of atoms within the atom t-group */
5442 : : k = (int)nNormAtNosInCanonOrd[(int)pINChI->nTautomer[i] - 1];
5443 : : inf_norm_at[k].nTautGroupCanonNbr = g;
5444 : : inf_norm_at[k].nTautGroupEquNbr = e;
5445 : : }
5446 : : }
5447 : : if (i != pINChI->lenTautomer || g != nNumberOfTGroups + 1)
5448 : : {
5449 : : ret = CT_TAUCOUNT_ERR; /* <BRKPT> */
5450 : : goto exit_function;
5451 : : }
5452 : : }
5453 : : /* atoms that may exchange isotopic H */
5454 : : if (bIsotopic && pINChI->nPossibleLocationsOfIsotopicH && (n = (int)pINChI->nPossibleLocationsOfIsotopicH[0]))
5455 : : {
5456 : : for (i = 1; i < n; i++)
5457 : : {
5458 : : j = (int)pINChI->nPossibleLocationsOfIsotopicH[i];
5459 : : k = (int)nNormAtNosInCanonOrd[j - 1];
5460 : : if (!inf_norm_at[k].nTautGroupCanonNbr)
5461 : : {
5462 : : inf_norm_at[k].cFlags |= AT_FLAG_ISO_H_POINT;
5463 : : }
5464 : : }
5465 : : }
5466 : : #if ( DISPLAY_RING_SYSTEMS == 1 )
5467 : : /* debug only */
5468 : : for (j = 0; j < num_at; j++)
5469 : : {
5470 : : inf_norm_at[j].nCanonNbr = norm_at[j].nBlockSystem;
5471 : : inf_norm_at[j].nCanonEquNbr = norm_at[j].nRingSystem;
5472 : : #if ( USE_DISTANCES_FOR_RANKING == 1 )
5473 : : inf_norm_at[j].nTautGroupCanonNbr = norm_at[j].nDistanceFromTerminal;
5474 : : inf_norm_at[j].nTautGroupEquNbr = norm_at[j].bCutVertex;
5475 : : #else
5476 : : inf_norm_at[j].nTautGroupCanonNbr = norm_at[j].bCutVertex;
5477 : : inf_norm_at[j].nTautGroupEquNbr = 0;
5478 : : #endif
5479 : : }
5480 : : #endif
5481 : :
5482 : : /* Fill inf_at[i] field 'at_string':
5483 : : write isotopic mass, chemical element symbols and hydrogens, charge, radical, canon.numbers
5484 : : */
5485 : : len_str = sizeof(inf_norm_at[0].at_string);
5486 : : for (i = 0; i < init_num_at; i++)
5487 : : {
5488 : : inf_ATOM* cur_inf_norm_at = (i < num_at) ? inf_norm_at + i : inf_norm_at_H + i - num_at;
5489 : : inp_ATOM* cur_norm_at = (i < num_at) ? norm_at + i : norm_at_H + i - num_at;
5490 : : str = cur_inf_norm_at->at_string;
5491 : : len = 0;
5492 : : bIncludeIsotopicH = bIsotopic && (i >= num_at || (!inf_norm_at[i].nTautGroupCanonNbr && !(inf_norm_at[i].cFlags & AT_FLAG_ISO_H_POINT))); /* djb-rwth: addressing LLVM warning */
5493 : : /* isotopic mass */
5494 : : atw = 0;
5495 : : if (cur_norm_at) /* djb-rwth: fixing a NULL pointer dereference */
5496 : : {
5497 : : if (cur_norm_at->iso_atw_diff && bIsotopic)
5498 : : {
5499 : : if (cur_norm_at->at_type == ATT_PROTON)
5500 : : {
5501 : : ; /* do not set isotopic mass of a tautomeric proton */
5502 : : }
5503 : : else
5504 : : {
5505 : : if (num_at <= i && cur_norm_at->el_number == PERIODIC_NUMBER_H && cur_norm_at->chem_bonds_valence == 1 &&
5506 : : !cur_norm_at->charge && !cur_norm_at->radical && !cur_norm_at->num_H &&
5507 : : 0 <= (j = (int)cur_norm_at->neighbor[0] - offset) && j < num_at &&
5508 : : (inf_norm_at[j].nTautGroupCanonNbr || (inf_norm_at[j].cFlags & AT_FLAG_ISO_H_POINT)))
5509 : : {
5510 : : ; /* do not set isotopic mass of an exchangeable proton */
5511 : : }
5512 : : else
5513 : : {
5514 : : atw = get_atomic_mass(cur_norm_at->elname);
5515 : : atw += (cur_norm_at->iso_atw_diff > 0) ? cur_norm_at->iso_atw_diff - 1 : cur_norm_at->iso_atw_diff;
5516 : : /*len += sprintf( str+len, "^%d", atw );*/
5517 : : }
5518 : : }
5519 : : }
5520 : : /* element name */
5521 : : if (cur_norm_at->el_number == PERIODIC_NUMBER_H && 2 <= atw && atw <= 3)
5522 : : {
5523 : : len += sprintf(str + len, "%s", atw == 2 ? "D" : "T");
5524 : : }
5525 : : else
5526 : : {
5527 : : if (atw)
5528 : : {
5529 : : len += sprintf(str + len, "^%d", atw);
5530 : : }
5531 : : /*if (strcmp( cur_norm_at->elname, "Zz" ))*/
5532 : : if (strcmp(cur_norm_at->elname, "Zz") && strcmp(cur_norm_at->elname, "Zy"))
5533 : : {
5534 : : len += sprintf(str + len, "%s", cur_norm_at->elname);
5535 : : }
5536 : : else /* always show "Zy" as "Zz" */
5537 : : {
5538 : : #if ( DISPLAY_ZZ_AS_STAR == 1 )
5539 : : len += sprintf(str + len, "*");
5540 : : #else
5541 : : len += sprintf(str + len, "Zz");
5542 : : #endif
5543 : : }
5544 : : }
5545 : :
5546 : : /* hydrogens */
5547 : : /* find number of previuosly removed terminal hydrogen atoms */
5548 : : for (j = 0; j < NUM_H_ISOTOPES; j++)
5549 : : {
5550 : : num_iso_H[j] = cur_norm_at->num_iso_H[j];
5551 : : }
5552 : : for (j = 0, n = (int)cur_norm_at->num_H; j < num_H; j++)
5553 : : {
5554 : : /* subtract number of removed terminal */
5555 : : /* H atoms from the total number of H atoms */
5556 : : if (i == (int)norm_at_H[j].neighbor[0] - offset)
5557 : : {
5558 : : n -= 1;
5559 : : m = (int)norm_at_H[j].iso_atw_diff - 1;
5560 : : if (0 <= m && m < NUM_H_ISOTOPES)
5561 : : {
5562 : : /* subtract number of removed terminal isotopic */
5563 : : /* H atoms from the total number of isotopic H atoms */
5564 : : num_iso_H[m] -= 1;
5565 : : }
5566 : : }
5567 : : }
5568 : : if (bIncludeIsotopicH)
5569 : : {
5570 : : /* subtract number of isotopic H atoms from the total number of H atoms */
5571 : : for (j = 0; j < NUM_H_ISOTOPES; j++)
5572 : : {
5573 : : n -= num_iso_H[j];
5574 : : }
5575 : : }
5576 : : /* non-isotopic hydrogen atoms */
5577 : : if (n > 1)
5578 : : {
5579 : : len += sprintf(str + len, "H%d", n);
5580 : : }
5581 : : else
5582 : : {
5583 : : if (n == 1)
5584 : : {
5585 : : len += sprintf(str + len, "H");
5586 : : }
5587 : : }
5588 : :
5589 : : /* isotopic hydrogen atoms */
5590 : : if (bIncludeIsotopicH)
5591 : : {
5592 : : for (j = 0; j < NUM_H_ISOTOPES; j++)
5593 : : {
5594 : : if (num_iso_H[j])
5595 : : {
5596 : : if (j == 0 || (j != 1 && j != 2)) /* djb-rwth: addressing LLVM warning */
5597 : : {
5598 : : len += sprintf(str + len, "^%dH", j + 1);
5599 : : }
5600 : : else
5601 : : {
5602 : : len += sprintf(str + len, j == 1 ? "D" : "T");
5603 : : }
5604 : : if (num_iso_H[j] != 1)
5605 : : {
5606 : : len += sprintf(str + len, "%d", (int)num_iso_H[j]);
5607 : : }
5608 : : }
5609 : : }
5610 : : }
5611 : : if (cur_norm_at->el_number == PERIODIC_NUMBER_H && str[0] == str[1])
5612 : : {
5613 : : char* q;
5614 : : if (!str[2])
5615 : : {
5616 : : str[1] = '2'; /* quick fix: replace HH with H2 */
5617 : : }
5618 : : else
5619 : : {
5620 : : if (isdigit(UCINT str[2]) && (n = strtol(str + 2, &q, 10)) && !q[0])
5621 : : {
5622 : : len = 1 + sprintf(str + 1, "%d", n + 1);
5623 : : }
5624 : : }
5625 : : }
5626 : : /* charge */
5627 : : if (abs(cur_norm_at->charge) > 1)
5628 : : {
5629 : : len += sprintf(str + len, "%+d", cur_norm_at->charge);
5630 : : }
5631 : : else
5632 : : {
5633 : : if (abs(cur_norm_at->charge) == 1)
5634 : : {
5635 : : len += sprintf(str + len, "%s", cur_norm_at->charge > 0 ? "+" : "-");
5636 : : }
5637 : : }
5638 : : /* radical */
5639 : : if (cur_norm_at->radical)
5640 : : {
5641 : : len += sprintf(str + len, "%s", cur_norm_at->radical == RADICAL_SINGLET ? ":" :
5642 : : cur_norm_at->radical == RADICAL_DOUBLET ? "." :
5643 : : cur_norm_at->radical == RADICAL_TRIPLET ? ".." : "?");
5644 : : }
5645 : : }
5646 : : }
5647 : :
5648 : : /* Stereogenic centers */
5649 : : if (bDoDisplaySp3 && Stereo && 0 < (num_stereo = Stereo->nNumberOfStereoCenters))
5650 : : {
5651 : : for (i = 0; i < num_stereo; i++)
5652 : : {
5653 : : j = (int)nNormAtNosInCanonOrd[(int)nNumber[i] - 1];
5654 : : c = t_parity[i];
5655 : : c = c == 1 ? '-' : c == 2 ? '+' : c == 3 ? 'u' : c == 4 ? '?' : '*';
5656 : : inf_norm_at[j].cStereoCenterParity = c;
5657 : : str = inf_norm_at[j].at_string;
5658 : : len = (int)strlen(str);
5659 : : if (len + 3 < (int)sizeof(inf_norm_at[0].at_string))
5660 : : {
5661 : : str[len++] = '(';
5662 : : str[len++] = inf_norm_at[j].cStereoCenterParity;
5663 : : str[len++] = ')';
5664 : : str[len] = '\0';
5665 : : /* mark ambuguous stereo center */
5666 : : if (norm_at[j].bAmbiguousStereo && (c == '+' || c == '-' || c == '?') && str[0] != '!' &&
5667 : : len + 1 < (int)sizeof(inf_norm_at[0].at_string))
5668 : : {
5669 : : memmove(str + 1, str, (long long)len + 1); /* djb-rwth: cast operator added */
5670 : : str[0] = '!'; /* output the atom in red color */
5671 : : }
5672 : : }
5673 : : }
5674 : : }
5675 : :
5676 : : /* Stereogenic bonds */
5677 : : /* (cumulenes with odd number of double bonds are stereocenters, */
5678 : : /* and atom parity should be set) */
5679 : : if (Stereo && 0 < (num_stereo = Stereo->nNumberOfStereoBonds))
5680 : : {
5681 : : for (i = 0; i < num_stereo; i++)
5682 : : {
5683 : : int start_at, bAmbiguousStereoBond = 0; /* djb-rwth: removing redundant variable */
5684 : : j = (int)nNormAtNosInCanonOrd[(int)Stereo->nBondAtom1[i] - 1];
5685 : : k = (int)nNormAtNosInCanonOrd[(int)Stereo->nBondAtom2[i] - 1];
5686 : : start_at = j;
5687 : : c = Stereo->b_parity[i];
5688 : :
5689 : : c = c == 1 ? '-' : c == 2 ? '+' : c == 3 ? 'u' : c == 4 ? '?' : '*';
5690 : :
5691 : : /* mark ambuguous stereo bond atom(s) */
5692 : : if (norm_at[j].bAmbiguousStereo && (c == '+' || c == '-') &&
5693 : : (len = strlen(str = inf_norm_at[j].at_string) + 1) < (int)sizeof(inf_norm_at[0].at_string) &&
5694 : : str[0] != '!')
5695 : : {
5696 : : memmove(str + 1, str, len);
5697 : : str[0] = '!'; /* output the atom in red color */
5698 : : bAmbiguousStereoBond++;
5699 : : }
5700 : : if (norm_at[k].bAmbiguousStereo && (c == '+' || c == '-') &&
5701 : : (len = strlen(str = inf_norm_at[k].at_string) + 1) < (int)sizeof(inf_norm_at[0].at_string) &&
5702 : : str[0] != '!')
5703 : : {
5704 : : memmove(str + 1, str, len);
5705 : : str[0] = '!'; /* output the atom in red color */
5706 : : bAmbiguousStereoBond++;
5707 : : }
5708 : :
5709 : : /* find the opposite atom k. */
5710 : : /* Note: since it may be a cumulene, find the shortest(best) path */
5711 : : /* to atom number k to avoid confusion in case of, for example, */
5712 : : /* 4-member aromatic rings. */
5713 : : best_len = MAX_CUMULENE_LEN + 1; /* moved here from inside the cycle 1-8-2003 */
5714 : : for (n = 0; n < norm_at[j].valence; n++)
5715 : : {
5716 : : if (norm_at[j].bond_type[n] == BOND_SINGLE)
5717 : : {
5718 : : /* single bond cannot be stereogenic. */
5719 : : continue;
5720 : : }
5721 : : /* best_len = MAX_CUMULENE_LEN+1; */
5722 : : len = 0; /* number of bonds in cumulene - 1 */
5723 : : next_atom[len] = (int)norm_at[j].neighbor[n] - offset;
5724 : : next_neigh[len] = n;
5725 : : cur_atom = j;
5726 : : while (next_atom[len] != k && len < MAX_CUMULENE_LEN && 2 == norm_at[next_atom[len]].valence)
5727 : : {
5728 : : next_neigh[len + 1] = ((int)norm_at[next_atom[len]].neighbor[0] - offset == cur_atom);
5729 : : next_atom[len + 1] = (int)norm_at[next_atom[len]].neighbor[next_neigh[len + 1]] - offset;
5730 : : cur_atom = next_atom[len];
5731 : : len++;
5732 : : }
5733 : : if (next_atom[len] == k)
5734 : : {
5735 : : if (len < best_len)
5736 : : {
5737 : : memcpy(best_next_neigh, next_neigh, sizeof(best_next_neigh));
5738 : : memcpy(best_next_atom, next_atom, sizeof(best_next_atom));
5739 : : best_len = len;
5740 : : /* djb-rwth: removing redundant code */
5741 : : if (len == 0)
5742 : : {
5743 : : break; /* path length cannot be smaller than 1 */
5744 : : }
5745 : : }
5746 : : /* djb-rwth: removing redundant code */
5747 : : }
5748 : : }
5749 : : if (best_len <= MAX_CUMULENE_LEN && best_next_atom[best_len] == k)
5750 : : {
5751 : : /* djb-rwth: removing redundant code */
5752 : : if (best_len % 2)
5753 : : {
5754 : : /* even number of bonds: chiral atom, draw parity on the cenrtal atom */
5755 : : j = best_next_atom[best_len / 2];
5756 : : inf_norm_at[j].cStereoCenterParity = c;
5757 : : str = inf_norm_at[j].at_string;
5758 : : len = (int)strlen(str);
5759 : : if (len + 3 < (int)sizeof(inf_norm_at[0].at_string))
5760 : : {
5761 : : str[len++] = '(';
5762 : : str[len++] = inf_norm_at[j].cStereoCenterParity;
5763 : : str[len++] = ')';
5764 : : str[len] = '\0';
5765 : : }
5766 : : }
5767 : : else
5768 : : {
5769 : : /* odd number of bonds: draw parity on the central bond */
5770 : : if (best_len == 0)
5771 : : {
5772 : : /* double bond */
5773 : : j = start_at;
5774 : : k = best_next_neigh[0];
5775 : : }
5776 : : else
5777 : : {
5778 : : /* cumulene */
5779 : : best_len = best_len / 2 - 1;
5780 : : j = best_next_atom[best_len];
5781 : : k = best_next_neigh[best_len + 1]; /* added +1 to display cumulene parity on the middle bond (6-24-2002) */
5782 : : }
5783 : : /* mark "forward" bond */
5784 : : for (m = 0; m < MAX_STEREO_BONDS && inf_norm_at[j].cStereoBondParity[m]; m++)
5785 : : ;
5786 : : if (m < MAX_STEREO_BONDS)
5787 : : {
5788 : : inf_norm_at[j].cStereoBondParity[m] = c;
5789 : : inf_norm_at[j].cStereoBondNumber[m] = k;
5790 : : inf_norm_at[j].cStereoBondWarning[m] = bAmbiguousStereoBond;
5791 : : }
5792 : : /* djb-rwth: removing redundant code */
5793 : : /* mark "backward" bond */
5794 : : n = norm_at[j].neighbor[k] - offset;
5795 : : for (k = 0; k < norm_at[n].valence && j != (int)norm_at[n].neighbor[k] - offset; k++)
5796 : : {
5797 : : ;
5798 : : }
5799 : : if (k < norm_at[n].valence)
5800 : : {
5801 : : j = n;
5802 : : for (m = 0; m < MAX_STEREO_BONDS && inf_norm_at[j].cStereoBondParity[m]; m++)
5803 : : {
5804 : : ;
5805 : : }
5806 : : if (m < MAX_STEREO_BONDS)
5807 : : {
5808 : : inf_norm_at[j].cStereoBondParity[m] = c;
5809 : : inf_norm_at[j].cStereoBondNumber[m] = k;
5810 : : inf_norm_at[j].cStereoBondWarning[m] = bAmbiguousStereoBond;
5811 : : }
5812 : : /* djb-rwth: removing redundant code */
5813 : : }
5814 : : /* djb-rwth: removing redundant code */
5815 : : }
5816 : : }
5817 : : /* djb-rwth: removing redundant code */
5818 : : }
5819 : : }
5820 : :
5821 : : for (i = 0; i < num_at; i++)
5822 : : {
5823 : : /* canonical numbers */
5824 : : if (inf_norm_at[i].nCanonNbr)
5825 : : {
5826 : : str = inf_norm_at[i].at_string;
5827 : : len = (int)strlen(str);
5828 : : #define SHOW_GLOBAL_CANO_NUMBERING 1
5829 : : #if SHOW_GLOBAL_CANO_NUMBERING==1
5830 : : len += (*MakeNumber)(str + len, len_str - len, "/", (int)inf_norm_at[i].nCanonNbr); // -offset );
5831 : : #else
5832 : : len += (*MakeNumber)(str + len, len_str - len, "/", (int)inf_norm_at[i].nCanonNbr);
5833 : : #endif
5834 : : if (inf_norm_at[i].nCanonEquNbr || inf_norm_at[i].nTautGroupCanonNbr || (inf_norm_at[i].cFlags & AT_FLAG_ISO_H_POINT))
5835 : : {
5836 : : if (inf_norm_at[i].nCanonEquNbr)
5837 : : {
5838 : : len += (*MakeNumber)(str + len, len_str - len, "/", (int)inf_norm_at[i].nCanonEquNbr);
5839 : : }
5840 : : else
5841 : : {
5842 : : if (len + 1 < len_str)
5843 : : {
5844 : : len += 1;
5845 : : strcat(str, "/");
5846 : : }
5847 : : }
5848 : : }
5849 : : /* tautomeric groups */
5850 : : if (inf_norm_at[i].nTautGroupCanonNbr)
5851 : : {
5852 : : len += (*MakeNumber)(str + len, len_str - len, "/", (int)inf_norm_at[i].nTautGroupCanonNbr);
5853 : : if (inf_norm_at[i].nTautGroupEquNbr)
5854 : : {
5855 : : len += (*MakeNumber)(str + len, len_str - len, "/", (int)inf_norm_at[i].nTautGroupEquNbr);
5856 : : }
5857 : : }
5858 : : if ((inf_norm_at[i].cFlags & AT_FLAG_ISO_H_POINT) && len + 2 <= len_str)
5859 : : {
5860 : : str[len++] = '/';
5861 : : str[len++] = '*';
5862 : : str[len] = '\0';
5863 : : }
5864 : : #ifdef DISPLAY_DEBUG_DATA
5865 : : if (inf_norm_at[i].nDebugData)
5866 : : {
5867 : : len += (*MakeNumber)(str + len, len_str - len, "`", (int)inf_norm_at[i].nDebugData);
5868 : : }
5869 : : #endif
5870 : : }
5871 : : }
5872 : :
5873 : : exit_function:
5874 : :
5875 : : if (nNormAtNosInCanonOrd)
5876 : : {
5877 : : inchi_free(nNormAtNosInCanonOrd);
5878 : : }
5879 : :
5880 : : return ret;
5881 : : }
5882 : :
5883 : :
5884 : : /****************************************************************************/
5885 : : int FillOutInputInfAtom(inp_ATOM* inp_at,
5886 : : INF_ATOM_DATA* inf_at_data,
5887 : : int init_num_at,
5888 : : int num_removed_H,
5889 : : int bAdd_DT_to_num_H,
5890 : : int nNumRemovedProtons,
5891 : : NUM_H* nNumRemovedProtonsIsotopic,
5892 : : int bIsotopic,
5893 : : int bAbcNumbers) /* djb-rwth: this whole function seems to be useless as it returns the value of a function argument -- init_num_at */
5894 : : {
5895 : : int i, j, m, n, ret, len_str, len, atw;
5896 : : int num_iso_H[NUM_H_ISOTOPES];
5897 : : char* str;
5898 : : int num_at = init_num_at - num_removed_H;
5899 : : int(*MakeNumber)(char*, int, const char*, int) = MakeDecNumber;
5900 : :
5901 : : inf_ATOM* inf_at = inf_at_data ? inf_at_data->at : NULL;
5902 : :
5903 : : ret = 0;
5904 : :
5905 : : if (!inf_at)
5906 : : {
5907 : : return ret;
5908 : : }
5909 : :
5910 : : memset(inf_at, 0, init_num_at * sizeof(inf_at[0])); /* djb-rwth: memset_s C11/Annex K variant? */
5911 : :
5912 : : inf_at_data->nNumRemovedProtons = nNumRemovedProtons;
5913 : : MakeRemovedProtonsString(nNumRemovedProtons, nNumRemovedProtonsIsotopic, NULL, bIsotopic, inf_at_data->szRemovedProtons, NULL);
5914 : : /* atom canonical and equivalence numbers > 0 */
5915 : : for (i = 0; i < num_at; i++)
5916 : : {
5917 : : #if ( DISPLAY_ORIG_AT_NUMBERS == 1 )
5918 : : inf_at[i].nCanonNbr = inp_at[i].orig_at_number;
5919 : : #else
5920 : : inf_at[i].nCanonNbr = (AT_NUMB)(i + 1);
5921 : : #endif
5922 : : }
5923 : : /* Fill inf_at[i] field 'at_string':
5924 : : write isotopic mass, chemical element symbols and hydrogens, charge, radical, canon. numbers
5925 : : */
5926 : : len_str = sizeof(inf_at[0].at_string);
5927 : : for (i = 0; i < init_num_at; i++)
5928 : : {
5929 : : str = inf_at[i].at_string;
5930 : : len = 0;
5931 : : /* isotopic mass */
5932 : : atw = 0;
5933 : : if (inp_at[i].iso_atw_diff && bIsotopic)
5934 : : {
5935 : : atw = get_atomic_mass(inp_at[i].elname);
5936 : : atw += (inp_at[i].iso_atw_diff > 0) ? inp_at[i].iso_atw_diff - 1 : inp_at[i].iso_atw_diff;
5937 : : /*len += sprintf( str+len, "^%d", atw );*/
5938 : : }
5939 : : /* element name */
5940 : : if (inp_at[i].el_number == PERIODIC_NUMBER_H && 2 <= atw && atw <= 3)
5941 : : {
5942 : : len += sprintf(str + len, "%s", atw == 2 ? "D" : "T");
5943 : : }
5944 : : else
5945 : : {
5946 : : if (atw)
5947 : : {
5948 : : len += sprintf(str + len, "^%d", atw);
5949 : : }
5950 : : /*if (strcmp( inp_at[i].elname, "Zz" ))*/
5951 : : if (strcmp(inp_at[i].elname, "Zz") && strcmp(inp_at[i].elname, "Zy"))
5952 : : {
5953 : : len += sprintf(str + len, "%s", inp_at[i].elname);
5954 : : }
5955 : : else /* always show "Zy" as "Zz" */
5956 : : {
5957 : : #if ( DISPLAY_ZZ_AS_STAR == 1 )
5958 : : len += sprintf(str + len, "*");
5959 : : #else
5960 : : len += sprintf(str + len, "Zz");
5961 : : #endif
5962 : : }
5963 : : }
5964 : :
5965 : : /* hydrogens */
5966 : : /* find number of previuosly removed terminal hydrogen atoms */
5967 : : for (j = 0; j < NUM_H_ISOTOPES; j++)
5968 : : {
5969 : : num_iso_H[j] = inp_at[i].num_iso_H[j];
5970 : : }
5971 : : for (j = num_at, n = (int)inp_at[i].num_H; j < init_num_at; j++)
5972 : : {
5973 : : /* subtract number of removed terminal */
5974 : : /* H atoms from the total number of H atoms */
5975 : : if (i == (int)inp_at[j].neighbor[0])
5976 : : {
5977 : : n -= 1;
5978 : : m = (int)inp_at[j].iso_atw_diff - 1;
5979 : : if (0 <= m && m < NUM_H_ISOTOPES)
5980 : : {
5981 : : /* subtract number of removed terminal isotopic */
5982 : : /* H atoms from the total number of isotopic H atoms */
5983 : : num_iso_H[m] -= 1;
5984 : : }
5985 : : }
5986 : : }
5987 : : if (bIsotopic && !bAdd_DT_to_num_H)
5988 : : {
5989 : : /* subtract number of isotopic H atoms from the total number of H atoms */
5990 : : for (j = 0; j < NUM_H_ISOTOPES; j++)
5991 : : {
5992 : : n -= num_iso_H[j];
5993 : : }
5994 : : }
5995 : : /* non-isotopic hydrogen atoms */
5996 : : if (n > 1)
5997 : : {
5998 : : len += sprintf(str + len, "H%d", n);
5999 : : }
6000 : : else
6001 : : {
6002 : : if (n == 1)
6003 : : {
6004 : : len += sprintf(str + len, "H"); /* fixed 12-21-2002: removed 3rd argument */
6005 : : }
6006 : : }
6007 : : if (bIsotopic)
6008 : : {
6009 : : /* isotopic hydrogen atoms */
6010 : : for (j = 0; j < NUM_H_ISOTOPES; j++)
6011 : : {
6012 : : if (num_iso_H[j])
6013 : : {
6014 : : if (j == 0 || (j != 1 && j != 2))
6015 : : {
6016 : : len += sprintf(str + len, "^%dH", j + 1);
6017 : : }
6018 : : else
6019 : : {
6020 : : len += sprintf(str + len, j == 1 ? "D" : "T");
6021 : : }
6022 : : if (num_iso_H[j] != 1)
6023 : : {
6024 : : len += sprintf(str + len, "%d", (int)num_iso_H[j]);
6025 : : }
6026 : : }
6027 : : }
6028 : : }
6029 : : if (inp_at[i].el_number == PERIODIC_NUMBER_H && str[0] == str[1])
6030 : : {
6031 : : char* q;
6032 : : if (!str[2])
6033 : : {
6034 : : str[1] = '2'; /* quick fix: replace HH with H2 */
6035 : : }
6036 : : else
6037 : : {
6038 : : if (isdigit(UCINT str[2]) && (n = strtol(str + 2, &q, 10)) && !q[0])
6039 : : {
6040 : : len = 1 + sprintf(str + 1, "%d", n + 1);
6041 : : }
6042 : : }
6043 : : }
6044 : : /*
6045 : : if ( str[0] == 'H' && str[1] == 'H' && !str[2] ) {
6046 : : str[1] = '2';
6047 : : }
6048 : : */
6049 : : /* charge */
6050 : : if (abs(inp_at[i].charge) > 1)
6051 : : {
6052 : : len += sprintf(str + len, "%+d", inp_at[i].charge);
6053 : : }
6054 : : else
6055 : : {
6056 : : if (abs(inp_at[i].charge) == 1)
6057 : : {
6058 : : len += sprintf(str + len, "%s", inp_at[i].charge > 0 ? "+" : "-");
6059 : : }
6060 : : }
6061 : :
6062 : : /* radical */
6063 : : if (inp_at[i].radical)
6064 : : {
6065 : : len += sprintf(str + len, "%s", inp_at[i].radical == RADICAL_SINGLET ? ":" :
6066 : : inp_at[i].radical == RADICAL_DOUBLET ? "." :
6067 : : inp_at[i].radical == RADICAL_TRIPLET ? ".." : "?");
6068 : : }
6069 : : }
6070 : :
6071 : : for (i = 0; i < init_num_at; i++)
6072 : : {
6073 : : /* canonical numbers */
6074 : : if (inf_at[i].nCanonNbr)
6075 : : {
6076 : : str = inf_at[i].at_string;
6077 : : len = (int)strlen(str);
6078 : : len += (*MakeNumber)(str + len, len_str - len, "/", (int)inf_at[i].nCanonNbr);
6079 : : if (inf_at[i].nCanonEquNbr || inf_at[i].nTautGroupCanonNbr)
6080 : : {
6081 : : len += (*MakeNumber)(str + len, len_str - len, "/", (int)inf_at[i].nCanonEquNbr);
6082 : : }
6083 : : /* tautomeric groups */
6084 : : if (inf_at[i].nTautGroupCanonNbr)
6085 : : {
6086 : : len += (*MakeNumber)(str + len, len_str - len, "/", (int)inf_at[i].nTautGroupCanonNbr);
6087 : : if (inf_at[i].nTautGroupEquNbr)
6088 : : {
6089 : : len += (*MakeNumber)(str + len, len_str - len, "/", (int)inf_at[i].nTautGroupEquNbr); /* djb-rwth: ignoring LLVM warning: variable used? */
6090 : : }
6091 : : }
6092 : : }
6093 : : }
6094 : : ret = init_num_at;
6095 : :
6096 : : return ret;
6097 : : }
6098 : :
6099 : :
6100 : : /****************************************************************************/
6101 : : int FillOutInfAtom(struct tagCANON_GLOBALS* pCG,
6102 : : inp_ATOM* norm_at,
6103 : : INF_ATOM_DATA* inf_norm_at_data,
6104 : : int init_num_at,
6105 : : int num_removed_H,
6106 : : int bAdd_DT_to_num_H,
6107 : : int nNumRemovedProtons,
6108 : : NUM_H* nNumRemovedProtonsIsotopic,
6109 : : int bIsotopic,
6110 : : INChI* pINChI,
6111 : : INChI_Aux* pINChI_Aux,
6112 : : int bAbcNumbers,
6113 : : INCHI_MODE nMode)
6114 : : {
6115 : : if (norm_at && inf_norm_at_data && inf_norm_at_data->at)
6116 : : {
6117 : : if (pINChI && pINChI_Aux)
6118 : : {
6119 : : return FillOutCanonInfAtom(pCG, norm_at, inf_norm_at_data, init_num_at, bIsotopic, pINChI,
6120 : : pINChI_Aux, bAbcNumbers, nMode);
6121 : : }
6122 : : else
6123 : : {
6124 : : return FillOutInputInfAtom(norm_at, inf_norm_at_data, init_num_at, num_removed_H, bAdd_DT_to_num_H,
6125 : : nNumRemovedProtons, nNumRemovedProtonsIsotopic, bIsotopic, bAbcNumbers);
6126 : : }
6127 : : }
6128 : :
6129 : : return 0;
6130 : : }
6131 : :
6132 : :
6133 : : /****************************************************************************/
6134 : : int FillOutCompositeCanonInfAtom(struct tagCANON_GLOBALS* pCG,
6135 : : COMP_ATOM_DATA* composite_norm_data,
6136 : : INF_ATOM_DATA* inf_norm_at_data,
6137 : : int bIsotopic, int bTautomeric,
6138 : : PINChI2* pINChI2,
6139 : : PINChI_Aux2* pINChI_Aux2,
6140 : : int bAbcNumbers,
6141 : : INCHI_MODE nMode)
6142 : : {
6143 : : int i, num_components, j, k, ret;
6144 : : inp_ATOM* inp_norm_at;
6145 : : INChI* pINChI;
6146 : : INChI_Aux* pINChI_Aux;
6147 : : int num_inp_at, num_at, num_H, offset, offset_H, next_offset, next_offset_H;
6148 : :
6149 : : if (composite_norm_data && inf_norm_at_data && (bTautomeric == TAUT_INI || (pINChI2 && pINChI_Aux2))) /* djb-rwth: addressing LLVM warning */
6150 : : {
6151 : : composite_norm_data += bTautomeric;
6152 : : inp_norm_at = composite_norm_data->at;
6153 : : num_components = composite_norm_data->num_components;
6154 : : offset = 0;
6155 : : offset_H = composite_norm_data->num_at - composite_norm_data->num_removed_H;
6156 : : if (bTautomeric == TAUT_INI)
6157 : : {
6158 : : ret = FillOutInputInfAtom(composite_norm_data->at, inf_norm_at_data, composite_norm_data->num_at,
6159 : : composite_norm_data->num_removed_H, 0 /*bAdd_DT_to_num_H*/,
6160 : : composite_norm_data->nNumRemovedProtons,
6161 : : composite_norm_data->nNumRemovedProtonsIsotopic,
6162 : : bIsotopic, bAbcNumbers);
6163 : : return ret;
6164 : : }
6165 : : else
6166 : : {
6167 : : for (i = 0; i < num_components; i++)
6168 : : {
6169 : : j = inchi_min(bTautomeric, TAUT_YES);
6170 : : /* count isotopic H on removed atoms -- isolated H(+) cations */
6171 : : inf_norm_at_data->nNumRemovedProtons += pINChI_Aux2[i][j]->nNumRemovedProtons;
6172 : : if (bIsotopic && bTautomeric == TAUT_YES)
6173 : : {
6174 : : for (k = 0; k < NUM_H_ISOTOPES; k++)
6175 : : {
6176 : : if (pINChI_Aux2[i][j]->nNumRemovedIsotopicH[k])
6177 : : {
6178 : : inf_norm_at_data->num_iso_H[k] += pINChI_Aux2[i][j]->nNumRemovedIsotopicH[k];
6179 : : inf_norm_at_data->num_removed_iso_H += pINChI_Aux2[i][j]->nNumRemovedIsotopicH[k];
6180 : : }
6181 : : }
6182 : : }
6183 : : /* ignore deleted components */
6184 : : if (pINChI2[i][j] && pINChI2[i][j]->bDeleted)
6185 : : {
6186 : : continue;
6187 : : }
6188 : : if (!pINChI2[i][j] || !pINChI2[i][j]->nNumberOfAtoms)
6189 : : {
6190 : : j = ALT_TAUT(j);
6191 : : if (!pINChI2[i][j] || !pINChI2[i][j]->nNumberOfAtoms)
6192 : : {
6193 : : continue; /* error ??? */
6194 : : }
6195 : : }
6196 : : pINChI = pINChI2[i][j];
6197 : : pINChI_Aux = pINChI_Aux2[i][j];
6198 : : next_offset = composite_norm_data->nOffsetAtAndH[2 * i];
6199 : : next_offset_H = composite_norm_data->nOffsetAtAndH[2 * i + 1];
6200 : : num_at = next_offset - offset;
6201 : : if (num_at <= 0)
6202 : : continue;
6203 : : num_H = next_offset_H - offset_H;
6204 : : num_inp_at = num_at + num_H;
6205 : : if (num_at != pINChI->nNumberOfAtoms || num_at != pINChI_Aux->nNumberOfAtoms)
6206 : : {
6207 : : return 0; /* error */
6208 : : }
6209 : : ret = FillOutOneCanonInfAtom(pCG,
6210 : : inp_norm_at, inf_norm_at_data,
6211 : : inf_norm_at_data->pStereoFlags + i + 1,
6212 : : num_inp_at,
6213 : : offset, offset_H, bIsotopic,
6214 : : pINChI, pINChI_Aux, bAbcNumbers, nMode);
6215 : : if (ret)
6216 : : return 0; /* error */
6217 : :
6218 : : inf_norm_at_data->StereoFlags |= inf_norm_at_data->pStereoFlags[i + 1];
6219 : : offset = next_offset;
6220 : : offset_H = next_offset_H;
6221 : : }
6222 : : }
6223 : : MakeRemovedProtonsString(inf_norm_at_data->nNumRemovedProtons, inf_norm_at_data->num_iso_H, NULL, bIsotopic,
6224 : : inf_norm_at_data->szRemovedProtons, &inf_norm_at_data->num_removed_iso_H);
6225 : : }
6226 : :
6227 : : return 1;
6228 : : }
6229 : : #endif /* } ifndef COMPILE_ANSI_ONLY */
6230 : :
6231 : :
6232 : : /****************************************************************************/
6233 : 69 : int CheckCanonNumberingCorrectness(int num_atoms,
6234 : : int num_at_tg,
6235 : : sp_ATOM* at,
6236 : : CANON_STAT* pCS,
6237 : : CANON_GLOBALS* pCG,
6238 : : int bTautomeric,
6239 : : char* pStrErrStruct)
6240 : : {
6241 : 69 : int i, ret = 0;
6242 : 69 : AT_NUMB* pCanonOrd = NULL;
6243 : 69 : int nErrorCode = 0;
6244 : : AT_NUMB* pCanonRank; /* canonical ranks of the atoms or tautomeric groups */
6245 : 69 : AT_NUMB* pCanonRankAtoms = NULL;
6246 : :
6247 : : /* djb-rwth: removing redundant code */
6248 : :
6249 : 69 : pCanonRankAtoms = (AT_NUMB*)inchi_calloc((long long)num_at_tg + 1, sizeof(pCanonRankAtoms[0])); /* djb-rwth: cast operator added */
6250 : :
6251 : : /*
6252 : : Non-isotopic part
6253 : : */
6254 : :
6255 [ + + ]: 82 : pCanonOrd = pCS->nLenCanonOrdStereo > 0 ? pCS->nCanonOrdStereo :
6256 [ + - ]: 13 : pCS->nLenCanonOrd > 0 ? pCS->nCanonOrd : NULL;
6257 : 69 : pCanonRank = pCanonRankAtoms;
6258 [ + - + - ]: 69 : if (pCanonOrd && pCanonRank)
6259 : : {
6260 [ + + ]: 688 : for (i = 0; i < num_at_tg; i++)
6261 : : {
6262 : 619 : pCanonRank[pCanonOrd[i]] = (AT_NUMB)(i + 1);
6263 : : }
6264 : 69 : ret = UpdateFullLinearCT(num_atoms, num_at_tg, at, pCanonRank, pCanonOrd, pCS,
6265 : : pCG,
6266 : : 0);
6267 [ - + ]: 69 : if (ret /*|| memcmp(pCS->LinearCT, pCS->LinearCT2, sizeof(AT_RANK) * pCS->nLenLinearCT )*/)
6268 : : {
6269 : 0 : nErrorCode |= WARN_FAILED_STEREO;
6270 : : }
6271 : : }
6272 : : else
6273 : : {
6274 : 0 : nErrorCode |= ERR_NO_CANON_RESULTS;
6275 : 0 : goto exit_function;
6276 : : }
6277 : :
6278 : : /*
6279 : : Isotopic part
6280 : : */
6281 : :
6282 [ - + ]: 138 : pCanonOrd = pCS->nLenCanonOrdIsotopicStereo > 0 ? pCS->nCanonOrdIsotopicStereo :
6283 [ - + ]: 69 : pCS->nLenCanonOrdIsotopic > 0 ? pCS->nCanonOrdIsotopic : NULL;
6284 : 69 : pCanonRank = pCanonRankAtoms;
6285 : :
6286 [ + - - - ]: 69 : if (pCanonOrd && pCanonRank)
6287 : : {
6288 [ # # ]: 0 : for (i = 0; i < num_at_tg; i++)
6289 : : {
6290 : 0 : pCanonRank[pCanonOrd[i]] = (AT_NUMB)(i + 1);
6291 : : }
6292 : 0 : ret = UpdateFullLinearCT(num_atoms, num_at_tg, at, pCanonRank, pCanonOrd, pCS,
6293 : : pCG,
6294 : : 0);
6295 [ # # ]: 0 : if (ret /*|| memcmp(pCS->LinearCT, pCS->LinearCT2, sizeof(AT_RANK) * pCS->nLenLinearCT )*/)
6296 : : {
6297 [ # # ]: 0 : nErrorCode |= (pCS->nLenCanonOrdIsotopicStereo ? WARN_FAILED_ISOTOPIC_STEREO : WARN_FAILED_ISOTOPIC);
6298 : : }
6299 : : }
6300 : :
6301 : 69 : exit_function:
6302 [ + - ]: 69 : if (pCanonRankAtoms)
6303 : : {
6304 [ + - ]: 69 : inchi_free(pCanonRankAtoms);
6305 : : }
6306 : :
6307 [ - + ]: 69 : if (nErrorCode)
6308 : : {
6309 : 0 : return CT_CANON_ERR;
6310 : : }
6311 : :
6312 : 69 : return 0;
6313 : : }
|