Branch data Line data Source code
1 : : /*
2 : : * SPDX-License-Identifier: MIT
3 : : * Copyright (c) 2024 IUPAC and InChI Trust
4 : : */
5 : :
6 : : #include <stdlib.h>
7 : : #include <string.h>
8 : : #include <ctype.h>
9 : : #include <math.h>
10 : :
11 : : #include "mode.h"
12 : :
13 : : #include "ichister.h"
14 : : #include "ichimain.h"
15 : : #include "ichimake.h"
16 : : #include "ichi_io.h"
17 : : #include "strutil.h"
18 : : #include "bcf_s.h"
19 : :
20 : : #include "logging.h" /*(@nnuk : Nauman Ullah Khan) :: Needed for logging functionality*/
21 : :
22 : : /*
23 : : Local functions
24 : : */
25 : :
26 : : /* djb-rwth: removing redundant code */
27 : : static int str_LineEnd( const char *tag,
28 : : int *bOverflow,
29 : : INCHI_IOS_STRING *buf,
30 : : int ind,
31 : : int bPlainTextTags );
32 : : static int CleanOrigCoord( MOL_COORD szCoord, int delim );
33 : : static int WriteOrigCoord( int num_inp_atoms,
34 : : MOL_COORD *szMolCoord,
35 : : int *i,
36 : : char *szBuf,
37 : : int buf_len );
38 : : static int WriteOrigAtoms( CANON_GLOBALS *pCG,
39 : : int num_inp_atoms,
40 : : inp_ATOM *at,
41 : : int *i,
42 : : char *szBuf,
43 : : int buf_len,
44 : : STRUCT_DATA *sd );
45 : : static int WriteOrigBonds( CANON_GLOBALS *pCG,
46 : : int num_inp_atoms,
47 : : inp_ATOM *at,
48 : : int *i,
49 : : char *szBuf,
50 : : int buf_len,
51 : : STRUCT_DATA *sd );
52 : : static void GetSaveOptLetters( unsigned char save_opt_bits,
53 : : char* let1,
54 : : char* let2 );
55 : : static int OutputINCHI_VersionAndKind( INCHI_IOSTREAM *out_file,
56 : : INCHI_IOS_STRING *strbuf,
57 : : int bINChIOutputOptions,
58 : : int is_beta,
59 : : int is_molecular_inorganic,
60 : : char *pLF,
61 : : char *pTAB );
62 : : static int OutputINCHI_MainLayerFormula( CANON_GLOBALS *pCG,
63 : : INCHI_IOSTREAM *out_file,
64 : : INCHI_IOS_STRING *strbuf,
65 : : int num_components2[],
66 : : int *INCHI_basic_or_INCHI_reconnected,
67 : : INCHI_OUT_CTL *io,
68 : : char *pLF,
69 : : char *pTAB );
70 : : static int OutputINCHI_MainLayerConnections( CANON_GLOBALS *pCG,
71 : : INCHI_IOSTREAM *out_file,
72 : : INCHI_IOS_STRING *strbuf,
73 : : int num_components2[],
74 : : int *INCHI_basic_or_INCHI_reconnected,
75 : : INCHI_OUT_CTL *io,
76 : : char *pLF,
77 : : char *pTAB );
78 : : static int OutputINCHI_MainLayerHydrogens( CANON_GLOBALS *pCG,
79 : : INCHI_IOSTREAM *out_file,
80 : : INCHI_IOS_STRING *strbuf,
81 : : int num_components2[],
82 : : int *INCHI_basic_or_INCHI_reconnected,
83 : : INCHI_OUT_CTL *io,
84 : : char *pLF,
85 : : char *pTAB );
86 : : static int OutputINCHI_ChargeAndRemovedAddedProtonsLayers( CANON_GLOBALS *pCG,
87 : : INCHI_IOSTREAM *out_file,
88 : : INCHI_IOS_STRING *strbuf,
89 : : INCHI_OUT_CTL *io,
90 : : char *pLF,
91 : : char *pTAB );
92 : : static int OutputINCHI_StereoLayer( CANON_GLOBALS *pCG,
93 : : INCHI_IOSTREAM *out_file,
94 : : INCHI_IOS_STRING *strbuf,
95 : : INCHI_OUT_CTL *io,
96 : : char *pLF,
97 : : char *pTAB );
98 : : static int OutputINCHI_StereoLayer_EnhancedStereo( CANON_GLOBALS *pCG,
99 : : INCHI_IOSTREAM *out_file,
100 : : INCHI_IOS_STRING *strbuf,
101 : : INCHI_OUT_CTL *io,
102 : : ORIG_ATOM_DATA *orig_inp_data,
103 : : char *pLF,
104 : : char *pTAB );
105 : : static int OutputINCHI_IsotopicLayer( CANON_GLOBALS *pCG,
106 : : INCHI_IOSTREAM *out_file,
107 : : INCHI_IOS_STRING *strbuf,
108 : : int *INCHI_basic_or_INCHI_reconnected,
109 : : INCHI_OUT_CTL *io,
110 : : char *pLF,
111 : : char *pTAB );
112 : : static int OutputINCHI_FixedHLayerWithSublayers( CANON_GLOBALS *pCG,
113 : : INCHI_IOSTREAM *out_file,
114 : : INCHI_IOS_STRING *strbuf,
115 : : int *INCHI_basic_or_INCHI_reconnected,
116 : : INCHI_OUT_CTL *io,
117 : : char *pLF,
118 : : char *pTAB,
119 : : int *then_goto_repeat );
120 : : static int OutputINCHI_PolymerLayer( CANON_GLOBALS *pCG, INCHI_IOSTREAM *out_file, INCHI_IOS_STRING *strbuf,
121 : : int *INCHI_basic_or_INCHI_reconnected,
122 : : ORIG_ATOM_DATA *orig_inp_data, ORIG_STRUCT *pOrigStruct,
123 : : INCHI_OUT_CTL *io, char *pLF, char *pTAB );
124 : : static int OutputINCHI_PolymerLayer_SingleUnit( OAD_PolymerUnit *u,
125 : : int bPolymers,
126 : : int total_star_atoms,
127 : : int *n_used_stars,
128 : : OAD_AtProps *aprops,
129 : : int *cano_nums,
130 : : ORIG_ATOM_DATA *orig_inp_data,
131 : : ORIG_STRUCT *pOrigStruct,
132 : : INCHI_IOS_STRING *strbuf );
133 : : static int OutputAUXINFO_HeaderAndNormalization_type( CANON_GLOBALS *pCG,
134 : : INCHI_IOSTREAM *out_file,
135 : : INCHI_IOS_STRING *strbuf,
136 : : int bINChIOutputOptions,
137 : : int *INCHI_basic_or_INCHI_reconnected,
138 : : int num_components2[],
139 : : INCHI_OUT_CTL *io,
140 : : char *pLF,
141 : : char *pTAB );
142 : : static int OutputAUXINFO_OriginalNumbersAndEquivalenceClasses( CANON_GLOBALS *pCG,
143 : : INCHI_IOSTREAM *out_file,
144 : : INCHI_IOS_STRING *strbuf,
145 : : int num_components2[],
146 : : INCHI_OUT_CTL *io,
147 : : char *pLF,
148 : : char *pTAB );
149 : : static int OutputAUXINFO_TautomericGroupsEquivalence( CANON_GLOBALS *pCG,
150 : : INCHI_IOSTREAM *out_file,
151 : : INCHI_IOS_STRING *strbuf,
152 : : INCHI_OUT_CTL *io );
153 : : static int OutputAUXINFO_Stereo( CANON_GLOBALS *pCG,
154 : : INCHI_IOSTREAM *out_file,
155 : : INCHI_IOS_STRING *strbuf,
156 : : INCHI_OUT_CTL *io,
157 : : char *pLF,
158 : : char *pTAB );
159 : : static int OutputAUXINFO_IsotopicInfo( CANON_GLOBALS *pCG,
160 : : INCHI_IOSTREAM *out_file,
161 : : INCHI_IOS_STRING *strbuf,
162 : : int *INCHI_basic_or_INCHI_reconnected,
163 : : INCHI_OUT_CTL *io,
164 : : char *pLF, char *pTAB );
165 : : /* djb-rwth: removing redundant code */
166 : : static int OutputAUXINFO_ChargesRadicalsAndUnusualValences( CANON_GLOBALS *pCG,
167 : : INCHI_IOSTREAM *out_file,
168 : : INCHI_IOS_STRING *strbuf,
169 : : INCHI_OUT_CTL *io,
170 : : char *pLF,
171 : : char *pTAB );
172 : : static int OutputAUXINFO_ReversibilityInfo( CANON_GLOBALS *pCG,
173 : : INCHI_IOSTREAM *out_file,
174 : : INCHI_IOS_STRING *strbuf,
175 : : ORIG_STRUCT *pOrigStruct,
176 : : INCHI_OUT_CTL *io,
177 : : char *pLF,
178 : : char *pTAB );
179 : :
180 : : static int OutputAUXINFO_PolymerInfo(CANON_GLOBALS *pCG,
181 : : INCHI_IOSTREAM *out_file,
182 : : INCHI_IOS_STRING *strbuf,
183 : : ORIG_STRUCT *pOrigStruct,
184 : : INCHI_OUT_CTL *io,
185 : : char *pLF,
186 : : char *pTAB);
187 : :
188 : : static int InternallyGetCanoNumsAndComponentNums(CANON_GLOBALS *pCG,
189 : : INCHI_IOS_STRING *strbuf,
190 : : INCHI_OUT_CTL *io,
191 : : int nat,
192 : : int *cano_nums,
193 : : int *compnt_nums);
194 : :
195 : : static int CountPseudoElementInFormula(const char *pseudo, char *s);
196 : : static int IsBondAtomNumsLesser(int *bond1, int *bond2);
197 : :
198 : : static void inchi_sort_int_pair_ascending(int *a, int *b);
199 : :
200 : : /* djb-rwth: removing redundant code */
201 : :
202 : : static void MergeZzInStrHillFormulaComponent(char *s);
203 : :
204 : : /*
205 : : Local constants
206 : : */
207 : : const char sCompDelim[] = ";"; /* component delimiter */
208 : : const char sIdenticalValues[] = "*"; /* identical component */
209 : : const char x_space[] = " ";
210 : :
211 : : /*
212 : : Output: words & additional tags
213 : : */
214 : : const char x_inchi[] = INCHI_NAME;
215 : : const char x_inchi_ver[] = "version"; /* "InChI.version"; */
216 : : const char x_curr_ver[] = INCHI_VERSION;
217 : : const char x_structure[] = "structure";
218 : : const char x_number[] = "number";
219 : : const char x_header[] = "id.name";
220 : : const char x_value[] = "id.value";
221 : : const char x_empty[] = "";
222 : : const char x_type[] = "type";
223 : : const char x_message[] = "message";
224 : : const char x_text[] = "value";
225 : : const char x_ferr[] = "fatal (aborted)";
226 : : const char x_err[] = "error (no InChI)";
227 : : const char x_warn[] = "warning";
228 : : const char x_basic[] = "identifier";
229 : : const char x_tautomeric[] = "mobile-H";
230 : : const char x_reconnected[] = "reconnected";
231 : : const char x_ver[] = "version";
232 : : const char x_type_alpha[] = "alpha";
233 : : const char x_type_numer[] = "numeric";
234 : : const char x_type_predec[] = "sct";
235 : : const char x_type_normal[] = "normal";
236 : : const char x_type_short[] = "compressed";
237 : : const char x_basic_layer[] = "basic";
238 : : const char x_aux_basic[] = "identifier.auxiliary-info";
239 : : const char x_aux_comm[] = "!-- This section is NOT a part of the identifier, it is not unique --";
240 : : const char x_ign_uu_sp2[] = "omit_undef_dbond";
241 : : const char x_ign_uu_sp3[] = "omit_undef_sp3";
242 : : const char x_line_opening[] = "<";
243 : : const char x_line_closing[] = "</";
244 : : const char x_close_line[] = ">";
245 : : const char x_abs[] = "1";
246 : : const char x_rel[] = "2";
247 : : const char x_rac[] = "3";
248 : :
249 : : typedef struct tagInchiTag
250 : : {
251 : : const char *szPlainLabel;
252 : : const char *szPlainComment;
253 : : const char *szXmlLabel;
254 : : int bAlwaysOutput;
255 : : } INCHI_TAG;
256 : :
257 : : /*
258 : : Identifier
259 : : */
260 : : const INCHI_TAG IdentLbl[] =
261 : : {
262 : : /* prefixes: may be combined in this order */
263 : : /* IL_FIXH_ORD, */ {"/", "fixed_H", "fixed-H", 0}, /* fixed H */
264 : : /* IL_ISOT_ORD, */ {"/", "isotopic", "isotopic", 0}, /* isotopic */
265 : : /* IL_STER_ORD, */ {"/", "stereo", "stereo", 0}, /* stereo */
266 : : /* items */
267 : : /* IL_VERS_ORD, */ {"", "version", "version", 1},
268 : : /* IL_FML__ORD, */ {"/", "formula", "formula", 1}, /* basic part formula */
269 : : /* IL_CONN_ORD, */ {"/c", "connections", "connections", 1},
270 : : /* IL_ALLH_ORD, */ {"/h", "H_atoms", "H", 1},
271 : : /* IL_CHRG_ORD, */ {"/q", "charge", "charge", 1},
272 : : /* IL_PROT_ORD, */ {"/p", "protons", "protons", 0},
273 : : /* stereo */
274 : : /* IL_DBND_ORD, */ {"/b", "dbond", "dbond", 0},
275 : : /* IL_SP3S_ORD, */ {"/t", "sp3", "sp3", 0},
276 : : /* IL_INVS_ORD, */ {"/m", "sp3:inverted", "abs.inverted", 0}, /* mirrored */
277 : : /* IL_TYPS_ORD, */ {"/s", "type (1=abs, 2=rel, 3=rac)", "type", 0}, /* stereo type */
278 : : /* isotopic */
279 : : /* IL_ATMS_ORD, */ {"/i", "atoms", "atoms", 1},
280 : : /* isotopic mobile H only */
281 : : /* IL_XCGA_ORD, */ {"/h", "exchangeable_H", "H-isotopic", 1},
282 : : /* fixed H only */
283 : : /* IL_FMLF_ORD, */ {"/f", "formula", "formula", 1}, /* fixed H formula */
284 : : /* IL_HFIX_ORD, */ {"/h", "H_fixed", "H-fixed", 1}, /* fixed-H */
285 : : /* IL_TRNS_ORD, */ {"/o", "transposition", "transposition", 0}, /* order */
286 : : /* IL_REC__ORD, */ {"/r", "reconnected bond(s) to metal(s) formula", "formula", 0}};
287 : :
288 : : /*
289 : :
290 : : Parsing plain text InChI (FML is a chemical formula)
291 : : ========================
292 : :
293 : : 1.12Beta/FML /i /f[FML] /i [/o] /rFML /i /f[FML] /i [/o] end
294 : : | | | | | | | | |
295 : : Labels | chqpbtms | hbtms | hqbtms | btms | chqpbtms | hbtms | hqbtms | btms |
296 : : inside: | | | | | | | | |
297 : : | non-iso- | iso- | fix- | iso- | non-iso- | iso- | fix- | iso- |
298 : : meaning: | topic | topic | ed H | topic | topic | topic | ed H | topic |
299 : : |----------+-------+--------+---------|----------+-------+--------+---------|
300 : : | mobile-H | fixed-H | mobile-H | fixed-H |
301 : : |----------+-------+--------+---------|----------+-------+--------+---------|
302 : : | | |
303 : : | normal or disconected metal | reconnected bonds to metal |
304 : : |_____________________________________|_____________________________________|
305 : :
306 : : meanings of h:
307 : :
308 : : /h - immobile H & mobile H group(s)
309 : : /i/h - exchangeable isotopic H (common)
310 : : /f/h - fixed-H
311 : : /f/i/h - never happens
312 : :
313 : : */
314 : : typedef enum tagIdentLblOrd
315 : : {
316 : : IL_FIXH_ORD,
317 : : IL_ISOT_ORD,
318 : : IL_STER_ORD,
319 : :
320 : : IL_VERS_ORD,
321 : : IL_FML__ORD,
322 : : IL_CONN_ORD,
323 : : IL_ALLH_ORD,
324 : : IL_CHRG_ORD,
325 : : IL_PROT_ORD,
326 : :
327 : : IL_DBND_ORD,
328 : : IL_SP3S_ORD,
329 : : IL_INVS_ORD,
330 : : IL_TYPS_ORD,
331 : :
332 : : IL_ATMS_ORD,
333 : :
334 : : IL_XCGA_ORD,
335 : :
336 : : IL_FMLF_ORD,
337 : : IL_HFIX_ORD,
338 : : IL_TRNS_ORD,
339 : : IL_REC__ORD,
340 : :
341 : : IL_MAX_ORD /* max number of tags */
342 : : } IDENT_LBL_ORD;
343 : :
344 : : typedef enum tagIdentLblBit
345 : : {
346 : : IL_FIXH = 1 << IL_FIXH_ORD,
347 : : IL_ISOT = 1 << IL_ISOT_ORD,
348 : : IL_STER = 1 << IL_STER_ORD,
349 : :
350 : : IL_VERS = 1 << IL_VERS_ORD,
351 : : IL_FML_ = 1 << IL_FML__ORD,
352 : : IL_CONN = 1 << IL_CONN_ORD,
353 : : IL_ALLH = 1 << IL_ALLH_ORD,
354 : : IL_CHRG = 1 << IL_CHRG_ORD,
355 : : IL_PROT = 1 << IL_PROT_ORD,
356 : :
357 : : IL_DBND = 1 << IL_DBND_ORD,
358 : : IL_SP3S = 1 << IL_SP3S_ORD,
359 : : IL_INVS = 1 << IL_INVS_ORD,
360 : : IL_TYPS = 1 << IL_TYPS_ORD,
361 : :
362 : : IL_ATMS = 1 << IL_ATMS_ORD,
363 : :
364 : : IL_XCGA = 1 << IL_XCGA_ORD,
365 : :
366 : : IL_FMLF = 1 << IL_FMLF_ORD,
367 : : IL_HFIX = 1 << IL_HFIX_ORD,
368 : : IL_TRNS = 1 << IL_TRNS_ORD,
369 : : IL_REC_ = 1 << IL_REC__ORD
370 : : } IDENT_LBL_BIT;
371 : :
372 : : /*
373 : : Aux Info constants
374 : : */
375 : : const INCHI_TAG AuxLbl[] =
376 : : {
377 : : /* prefixes may be combined in this order */
378 : : /* AL_FIXH_ORD, */ {"/", "fixed_H", "fixed-H", 0}, /* fixed-H */
379 : : /* AL_ISOT_ORD, */ {"/", "isotopic", "isotopic", 0}, /* isotopic */
380 : : /* AL_STER_ORD, */ {"/", "abs_stereo_inverted", "stereo.abs.inverted", 0}, /* inv abs sp3 stereo */
381 : : /* AL_REVR_ORD, */ {"/", "reversibility", "reversibility", 0}, /* reversibility */
382 : : /* items */
383 : : /* AL_VERS_ORD, */ {"", "version", "version", 1},
384 : : /* AL_NORM_ORD, */ {"/", "normalization_type", "norm-type", 1},
385 : : /* AL_ANBR_ORD, */ {"/N:", "original_atom_numbers", "atom.orig-nbr", 1},
386 : : /* AL_AEQU_ORD, */ {"/E:", "atom_equivalence", "atom.equivalence", 0},
387 : : /* AL_GEQU_ORD, */ {"/gE:", "group_equivalence", "group.equivalence", 0},
388 : : /* inv abs sp3 stereo */
389 : : /* AL_SP3I_ORD, */ {"/it:", "sp3", "sp3", 0},
390 : : /* AL_SP3N_ORD, */ {"/iN:", "original_atom_numbers", "atom.orig-nbr", 0},
391 : :
392 : : /* AL_CRV__ORD, */ {"/CRV:", "charge_radical_valence", "charges-rad-val", 0},
393 : : /* reversibility */
394 : : /* AL_ATMR_ORD, */ {"/rA:", "atoms", "atoms", 0},
395 : : /* AL_BNDR_ORD, */ {"/rB:", "bonds", "bonds", 0},
396 : : /* AL_XYZR_ORD, */ {"/rC:", "xyz", "xyz", 0},
397 : : /* fixed-H only */
398 : : /* AL_FIXN_ORD, */ {"/F:", "original_atom_numbers", "atom.orig-nbr", 1},
399 : : /* isotopic only */
400 : : /* AL_ISON_ORD, */ {"/I:", "original_atom_numbers", "atom.orig-nbr", 1},
401 : :
402 : : /* AL_REC__ORD, */ {"/R:", "reconnected bond(s) to metal(s) part", "", 1}};
403 : :
404 : : typedef enum tagAuxLblOrd
405 : : {
406 : : AL_FIXH_ORD,
407 : : AL_ISOT_ORD,
408 : : AL_STER_ORD,
409 : : AL_REVR_ORD,
410 : :
411 : : AL_VERS_ORD,
412 : : AL_NORM_ORD,
413 : : AL_ANBR_ORD,
414 : : AL_AEQU_ORD,
415 : : AL_GEQU_ORD,
416 : :
417 : : AL_SP3I_ORD,
418 : : AL_SP3N_ORD,
419 : :
420 : : AL_CRV__ORD,
421 : :
422 : : AL_ATMR_ORD,
423 : : AL_BNDR_ORD,
424 : : AL_XYZR_ORD,
425 : :
426 : : AL_FIXN_ORD,
427 : :
428 : : AL_ISON_ORD,
429 : :
430 : : AL_REC__ORD,
431 : :
432 : : AL_MAX_ORD /* max number of tags */
433 : : } AUX_LBL_ORD;
434 : :
435 : : typedef enum tagAuxLblBit
436 : : {
437 : : AL_FIXH = 1 << AL_FIXH_ORD,
438 : : AL_ISOT = 1 << AL_ISOT_ORD,
439 : : AL_STER = 1 << AL_STER_ORD,
440 : : AL_REVR = 1 << AL_REVR_ORD,
441 : :
442 : : AL_VERS = 1 << AL_VERS_ORD,
443 : : AL_NORM = 1 << AL_NORM_ORD,
444 : : AL_ANBR = 1 << AL_ANBR_ORD,
445 : : AL_AEQU = 1 << AL_AEQU_ORD,
446 : : AL_GEQU = 1 << AL_GEQU_ORD,
447 : :
448 : : AL_SP3I = 1 << AL_SP3I_ORD,
449 : : AL_SP3N = 1 << AL_SP3N_ORD,
450 : :
451 : : AL_CRV_ = 1 << AL_CRV__ORD,
452 : :
453 : : AL_ATMR = 1 << AL_ATMR_ORD,
454 : : AL_BNDR = 1 << AL_BNDR_ORD,
455 : : AL_XYZR = 1 << AL_XYZR_ORD,
456 : :
457 : : AL_FIXN = 1 << AL_FIXN_ORD,
458 : :
459 : : AL_ISON = 1 << AL_ISON_ORD,
460 : :
461 : : AL_REC_ = 1 << AL_REC__ORD
462 : : } AUX_LBL_BIT;
463 : :
464 : : /* const int MAX_TAG_NUM = inchi_max((short)IL_MAX_ORD, (short)AL_MAX_ORD); */ /* djb-rwth: fixing MSVC warning C5287 */
465 : :
466 : : char *szGetTag(const INCHI_TAG *Tag, int nTag, int bTag, char *szTag, int *bAlways, short tag_flag); /* djb-rwth: fixing GHI #160 */
467 : :
468 : : #define SP(N) (x_space + sizeof(x_space) - 1 - (N))
469 : :
470 : : #define NOT_YET_I2I_FOR_POLYMERS 40
471 : :
472 : : /****************************************************************************
473 : : Print error message (plain text)
474 : : ****************************************************************************/
475 : 0 : int OutputINChIPlainError(INCHI_IOSTREAM *out_file,
476 : : char *pErrorText,
477 : : int bError)
478 : : {
479 : : /* char szBuf[64]; */
480 : : const char *pErr;
481 : 0 : char *szErrorText = pErrorText;
482 : 0 : int ret = 0; /* djb-rwth: removing redundant variables */
483 : :
484 [ # # # ]: 0 : switch (bError)
485 : : {
486 : 0 : case _IS_WARNING:
487 : 0 : pErr = x_warn;
488 : 0 : break;
489 : 0 : case _IS_ERROR:
490 : 0 : pErr = x_err;
491 : 0 : break;
492 : 0 : default: /* _IS_FATAL */
493 : 0 : pErr = x_ferr;
494 : 0 : break;
495 : : }
496 : :
497 : : /* djb-rwth: removing redundant code */
498 : :
499 : 0 : inchi_ios_print(out_file,
500 : : "%s: %s=\"%s\" %s=\"%s\"",
501 : : x_message, x_type, pErr, x_text, szErrorText);
502 : : #ifdef TARGET_LIB_FOR_WINCHI
503 : : inchi_ios_print(out_file, "\n");
504 : : #endif
505 : 0 : ret = 1;
506 : :
507 : 0 : return ret;
508 : : }
509 : :
510 : : #ifndef OUT_TN /* defined in mode.h; quoted here for reference purposes only */
511 : :
512 : : #define OUT_N1 0 /* non-tautomeric only */
513 : : #define OUT_T1 1 /* tautomeric if present otherwise non-tautomeric */
514 : : #define OUT_NT 2 /* only non-taut representations of tautomeric */
515 : : #define OUT_TN 3 /* tautomeric if present otherwise non-tautomeric; \
516 : : sepatately output non-taut representations of tautomeric if present */
517 : : /* OUT_TN = OUT_T1 + OUT_NT */
518 : : #endif
519 : :
520 : : /****************************************************************************
521 : : Calculate equivalence mark (used to check for repeating (sub)layer(s) )
522 : : ****************************************************************************/
523 : 47 : const char *EquString(int EquVal)
524 : : {
525 : 47 : int bFrom = EquVal & (iiSTEREO | iiSTEREO_INV | iiNUMB | iiEQU);
526 : 47 : int bType = EquVal & (iitISO | iitNONTAUT);
527 : 47 : int bEq2 = EquVal & (iiEq2NONTAUT | iiEq2ISO | iiEq2INV);
528 : 47 : const char *r = "";
529 : :
530 : : #if (FIX_EMPTY_LAYER_BUG == 1)
531 : : int bEmpty = EquVal & iiEmpty;
532 : : if (bEmpty)
533 : : {
534 : : r = "e";
535 : : return r;
536 : : }
537 : : #endif
538 : :
539 [ - + - - : 47 : switch (bFrom)
- - ]
540 : : {
541 : :
542 : 0 : case iiSTEREO: /* ------------ Stereo --------------------*/
543 [ # # # # ]: 0 : switch (bType)
544 : : {
545 : 0 : case iitISO: /* iso main stereo =... */
546 [ # # ]: 0 : switch (bEq2)
547 : : {
548 : 0 : case 0:
549 : 0 : r = "m"; /* iso main stereo = main stereo */
550 : 0 : break;
551 : 0 : default:
552 : 0 : r = "??"; /* should not happen */
553 : 0 : break;
554 : : }
555 : 0 : break;
556 : 0 : case iitNONTAUT: /* non-taut stereo =... */
557 [ # # ]: 0 : switch (bEq2)
558 : : {
559 : 0 : case 0:
560 : 0 : r = "m"; /* non-taut stereo = main stereo */
561 : 0 : break;
562 : 0 : default:
563 : 0 : r = "??"; /* should not happen */
564 : 0 : break;
565 : : }
566 : 0 : break;
567 : 0 : case (iitNONTAUT | iitISO): /* iso non-taut stereo = ... */
568 [ # # # # ]: 0 : switch (bEq2)
569 : : {
570 : 0 : case 0:
571 : 0 : r = "m"; /* iso non-taut stereo = main stereo */
572 : 0 : break;
573 : 0 : case iiEq2ISO:
574 : 0 : r = "M"; /* iso non-taut stereo = main iso stereo */
575 : 0 : break;
576 : 0 : case iiEq2NONTAUT:
577 : 0 : r = "n"; /* iso non-taut stereo = non-taut stereo */
578 : 0 : break;
579 : 0 : default:
580 : 0 : r = "??"; /* should not happen */
581 : 0 : break;
582 : : }
583 : 0 : break;
584 : 0 : default:
585 : 0 : r = "??"; /* should not happen */
586 : 0 : break;
587 : : }
588 : 0 : break;
589 : :
590 : 47 : case iiSTEREO_INV: /*---------- Inverted Aux Stereo ------*/
591 [ + - ]: 47 : if (bEq2 & iiEq2INV)
592 : : { /* stereo = Inverted(another stereo) */
593 : 47 : bEq2 &= ~iiEq2INV;
594 [ + - - - : 47 : switch (bType)
- ]
595 : : {
596 : 47 : case 0: /* main = ...*/
597 [ + - - - : 47 : switch (bEq2)
- ]
598 : : {
599 : 47 : case 0:
600 : 47 : r = "im"; /* main = Inv(main) */
601 : 47 : break;
602 : 0 : case iiEq2ISO:
603 : 0 : r = "iM"; /* main = Inv(main iso) */
604 : 0 : break;
605 : 0 : case iiEq2NONTAUT:
606 : 0 : r = "in"; /* maim = Inv(non-taut) */
607 : 0 : break;
608 : 0 : case (iiEq2NONTAUT | iiEq2ISO):
609 : 0 : r = "iN"; /* maim = Inv(non-taut iso ) */
610 : 0 : break;
611 : 0 : default:
612 : 0 : r = "??"; /* should not happen */
613 : 0 : break;
614 : : }
615 : 47 : break;
616 : 0 : case iitISO: /* main iso = ...*/
617 [ # # # # : 0 : switch (bEq2)
# ]
618 : : {
619 : 0 : case 0:
620 : 0 : r = "im"; /* main iso = Inv(main) */
621 : 0 : break;
622 : 0 : case iiEq2ISO:
623 : 0 : r = "iM"; /* main iso = Inv(main iso) */
624 : 0 : break;
625 : 0 : case iiEq2NONTAUT:
626 : 0 : r = "in"; /* maim iso = Inv(non-taut) */
627 : 0 : break;
628 : 0 : case (iiEq2NONTAUT | iiEq2ISO):
629 : 0 : r = "iN"; /* maim = Inv(non-taut iso ) */
630 : 0 : break;
631 : 0 : default:
632 : 0 : r = "??"; /* should not happen */
633 : 0 : break;
634 : : }
635 : 0 : break;
636 : 0 : case iitNONTAUT: /* non-taut = ... */
637 [ # # # # : 0 : switch (bEq2)
# ]
638 : : {
639 : 0 : case 0:
640 : 0 : r = "im"; /* non-taut = Inv(main) */
641 : 0 : break;
642 : 0 : case iiEq2ISO:
643 : 0 : r = "iM"; /* non-taut = Inv(main iso) */
644 : 0 : break;
645 : 0 : case iiEq2NONTAUT:
646 : 0 : r = "in"; /* non-taut = Inv(non-taut) */
647 : 0 : break;
648 : 0 : case (iiEq2NONTAUT | iiEq2ISO):
649 : 0 : r = "iN"; /* non-taut = Inv(non-taut iso ) */
650 : 0 : break;
651 : 0 : default:
652 : 0 : r = "??"; /* should not happen */
653 : 0 : break;
654 : : }
655 : 0 : break;
656 : 0 : case (iitNONTAUT | iitISO):
657 [ # # # # : 0 : switch (bEq2)
# ]
658 : : {
659 : 0 : case 0:
660 : 0 : r = "im"; /* non-taut iso = Inv(main) */
661 : 0 : break;
662 : 0 : case iiEq2ISO:
663 : 0 : r = "iM"; /* non-taut iso = Inv(main iso) */
664 : 0 : break;
665 : 0 : case iiEq2NONTAUT:
666 : 0 : r = "in"; /* non-taut iso = Inv(non-taut) */
667 : 0 : break;
668 : 0 : case (iiEq2NONTAUT | iiEq2ISO):
669 : 0 : r = "iN"; /* non-taut iso = Inv(non-taut iso ) */
670 : 0 : break;
671 : 0 : default:
672 : 0 : r = "??"; /* should not happen */
673 : : }
674 : 0 : break;
675 : 0 : default:
676 : 0 : r = "??"; /* should not happen */
677 : 0 : break;
678 : : }
679 : : }
680 : : else
681 : : { /* Inv stereo = another (non-inverted) stereo */
682 : :
683 [ # # # # ]: 0 : switch (bType)
684 : : {
685 : 0 : case iitISO: /* main iso = ...*/
686 [ # # ]: 0 : switch (bEq2)
687 : : {
688 : 0 : case 0:
689 : 0 : r = "m"; /* main = (inverted aux) main */
690 : 0 : break;
691 : 0 : default:
692 : 0 : r = "??"; /* should not happen */
693 : 0 : break;
694 : : }
695 : 0 : break;
696 : 0 : case iitNONTAUT: /* non-taut = ... */
697 [ # # ]: 0 : switch (bEq2)
698 : : {
699 : 0 : case 0:
700 : 0 : r = "m"; /* non-taut = (inverted aux) main */
701 : 0 : break;
702 : 0 : default:
703 : 0 : r = "??"; /* should not happen */
704 : 0 : break;
705 : : }
706 : 0 : break;
707 : 0 : case (iitNONTAUT | iitISO): /* non-taut iso = ...*/
708 [ # # # # ]: 0 : switch (bEq2)
709 : : {
710 : 0 : case 0:
711 : 0 : r = "m"; /* non-taut iso = (inverted aux) main */
712 : 0 : break;
713 : 0 : case iiEq2ISO:
714 : 0 : r = "M"; /* non-taut iso = (inverted aux) main iso */
715 : 0 : break;
716 : 0 : case iiEq2NONTAUT:
717 : 0 : r = "n"; /* non-taut iso = (inverted aux) non-taut */
718 : 0 : break;
719 : 0 : default:
720 : 0 : r = "??"; /* should not happen */
721 : 0 : break;
722 : : }
723 : 0 : break;
724 : 0 : default:
725 : 0 : r = "??"; /* should not happen */
726 : 0 : break;
727 : : }
728 : : }
729 : 47 : break;
730 : :
731 : 0 : case (iiNUMB | iiSTEREO_INV): /*------------- Inv Stereo Numbering ------------*/
732 [ # # # # : 0 : switch (bType)
# ]
733 : : {
734 : 0 : case 0: /* inv stereo numb main = ...*/
735 [ # # ]: 0 : switch (bEq2)
736 : : {
737 : 0 : case 0:
738 : 0 : r = "m"; /* inv stereo numb main = main numb */
739 : 0 : break;
740 : 0 : default:
741 : 0 : r = "??"; /* should not happen */
742 : 0 : break;
743 : : }
744 : 0 : break;
745 : 0 : case iitISO: /* inv stereo iso numb main = ...*/
746 [ # # # # ]: 0 : switch (bEq2)
747 : : {
748 : 0 : case 0:
749 : 0 : r = "m"; /* inv stereo iso numb main = main numb */
750 : 0 : break;
751 : 0 : case iiEq2INV:
752 : 0 : r = "im"; /* inv stereo iso numb main = InvStereo(main) numb */
753 : 0 : break;
754 : 0 : case iiEq2ISO:
755 : 0 : r = "M"; /* inv stereo iso numb main = isotopic main numb */
756 : 0 : break;
757 : 0 : default:
758 : 0 : r = "??"; /* should not happen */
759 : 0 : break;
760 : : }
761 : 0 : break;
762 : 0 : case iitNONTAUT: /* inv stereo numb non-taut = ... */
763 [ # # # # ]: 0 : switch (bEq2)
764 : : {
765 : 0 : case 0:
766 : 0 : r = "m"; /* inv stereo numb non-taut = main numb */
767 : 0 : break;
768 : 0 : case iiEq2NONTAUT:
769 : 0 : r = "n"; /* inv stereo numb non-taut = non-taut numb */
770 : 0 : break;
771 : 0 : case iiEq2INV:
772 : 0 : r = "im"; /* inv stereo numb non-taut = InvStereo(main) numb */
773 : 0 : break;
774 : 0 : default:
775 : 0 : r = "??"; /* should not happen */
776 : 0 : break;
777 : : }
778 : 0 : break;
779 : 0 : case (iitNONTAUT | iitISO): /* inv stereo numb non-taut iso = ... */
780 [ # # # # : 0 : switch (bEq2)
# # # # ]
781 : : {
782 : 0 : case 0:
783 : 0 : r = "m"; /* inv stereo numb non-taut iso = main numb */
784 : 0 : break;
785 : 0 : case iiEq2ISO:
786 : 0 : r = "M"; /* inv stereo numb non-taut iso = main numb iso */
787 : 0 : break;
788 : 0 : case (iiEq2ISO | iiEq2INV):
789 : 0 : r = "iM"; /* inv stereo numb non-taut iso = InvStereo(main iso) numb */
790 : 0 : break;
791 : 0 : case iiEq2NONTAUT:
792 : 0 : r = "n"; /* inv stereo numb non-taut iso = non-taut numb */
793 : 0 : break;
794 : 0 : case (iiEq2NONTAUT | iiEq2ISO):
795 : 0 : r = "N"; /* inv stereo numb non-taut iso = non-taut iso numb */
796 : 0 : break;
797 : 0 : case iiEq2INV:
798 : 0 : r = "im"; /* inv stereo numb non-taut iso = InvStereo(main) numb */
799 : 0 : break;
800 : 0 : case (iiEq2NONTAUT | iiEq2INV):
801 : 0 : r = "in"; /* inv stereo numb non-taut iso = InvStereo(non-taut) numb ) */
802 : 0 : break;
803 : 0 : default:
804 : 0 : r = "??"; /* should not happen */
805 : 0 : break;
806 : : }
807 : 0 : break;
808 : 0 : default:
809 : 0 : r = "??"; /* should not happen */
810 : 0 : break;
811 : : }
812 : 0 : break;
813 : :
814 : 0 : case iiNUMB: /*------------- Canonical Numbering ------------*/
815 [ # # # # : 0 : switch (bType)
# ]
816 : : {
817 : 0 : case 0: /* numb main = ...*/
818 : 0 : r = "??"; /* should not happen */
819 : 0 : break;
820 : 0 : case iitISO: /* iso numb main = ...*/
821 [ # # ]: 0 : switch (bEq2)
822 : : {
823 : 0 : case 0:
824 : 0 : r = "m"; /* iso numb main = main numb */
825 : 0 : break;
826 : 0 : default:
827 : 0 : r = "??"; /* should not happen */
828 : : }
829 : 0 : break;
830 : 0 : case iitNONTAUT: /* numb non-taut = ... */
831 [ # # ]: 0 : switch (bEq2)
832 : : {
833 : 0 : case 0:
834 : 0 : r = "m"; /* numb non-taut = main numb */
835 : 0 : break;
836 : 0 : default:
837 : 0 : r = "??"; /* should not happen */
838 : : }
839 : 0 : break;
840 : 0 : case (iitNONTAUT | iitISO): /* numb non-taut iso = ... */
841 [ # # # # ]: 0 : switch (bEq2)
842 : : {
843 : 0 : case 0:
844 : 0 : r = "m"; /* numb non-taut iso = main numb */
845 : 0 : break;
846 : 0 : case iiEq2ISO:
847 : 0 : r = "M"; /* numb non-taut iso = main numb iso */
848 : 0 : break;
849 : 0 : case iiEq2NONTAUT:
850 : 0 : r = "n"; /* numb non-taut iso = non-taut numb */
851 : 0 : break;
852 : 0 : default:
853 : 0 : r = "??"; /* should not happen */
854 : 0 : break;
855 : : }
856 : 0 : break;
857 : 0 : default:
858 : 0 : r = "??"; /* should not happen */
859 : 0 : break;
860 : : }
861 : 0 : break;
862 : :
863 : 0 : case iiEQU: /*------------- Atom Equivalence ------------*/
864 [ # # # # : 0 : switch (bType)
# ]
865 : : {
866 : 0 : case 0: /* equivalence main = ...*/
867 : 0 : r = "??"; /* should not happen */
868 : 0 : break;
869 : 0 : case iitISO: /* equivalence main iso = ...*/
870 [ # # ]: 0 : switch (bEq2)
871 : : {
872 : 0 : case 0:
873 : 0 : r = "m"; /* equivalence main = main equ */
874 : 0 : break;
875 : 0 : default:
876 : 0 : r = "??"; /* should not happen */
877 : 0 : break;
878 : : }
879 : 0 : break;
880 : 0 : case iitNONTAUT: /* equivalence non-taut = ... */
881 [ # # ]: 0 : switch (bEq2)
882 : : {
883 : 0 : case 0:
884 : 0 : r = "m"; /* equivalence non-taut = main equ */
885 : 0 : break;
886 : 0 : default:
887 : 0 : r = "??"; /* should not happen */
888 : 0 : break;
889 : : }
890 : 0 : break;
891 : 0 : case (iitNONTAUT | iitISO): /* equivalence non-taut iso = ... */
892 [ # # # # ]: 0 : switch (bEq2)
893 : : {
894 : 0 : case 0:
895 : 0 : r = "m"; /* equivalence non-taut iso = main equ */
896 : 0 : break;
897 : 0 : case iiEq2ISO:
898 : 0 : r = "M"; /* equivalence non-taut iso = main iso equ */
899 : 0 : break;
900 : 0 : case iiEq2NONTAUT:
901 : 0 : r = "n"; /* equivalence non-taut iso = non-taut equ */
902 : 0 : break;
903 : 0 : default:
904 : 0 : r = "??"; /* should not happen */
905 : 0 : break;
906 : : }
907 : 0 : break;
908 : 0 : default:
909 : 0 : r = "??"; /* should not happen */
910 : 0 : break;
911 : : }
912 : 0 : break;
913 : 0 : default:
914 : 0 : r = "??"; /* should not happen */
915 : 0 : break;
916 : : }
917 : 47 : return r;
918 : : }
919 : :
920 : : #define OUT_NONTAUT OUT_NN /* was OUT_NT until 2004-04-07 */
921 : :
922 : : /****************************************************************************
923 : : OutputINChI2( ... ) is called from SortAndPrintINChI( ... )
924 : : ****************************************************************************/
925 : 197 : int OutputINChI2(CANON_GLOBALS *pCG,
926 : : INCHI_IOS_STRING *strbuf,
927 : : INCHI_SORT *pINChISortTautAndNonTaut2[][TAUT_NUM],
928 : : int INCHI_basic_or_INCHI_reconnected,
929 : : ORIG_ATOM_DATA *orig_inp_data,
930 : : ORIG_STRUCT *pOrigStruct,
931 : : INPUT_PARMS *ip,
932 : : int bDisconnectedCoord,
933 : : int bOutputType,
934 : : int bINChIOutputOptions,
935 : : int num_components2[],
936 : : int num_non_taut2[],
937 : : int num_taut2[],
938 : : INCHI_IOSTREAM *output_file,
939 : : INCHI_IOSTREAM *log_file,
940 : : int num_input_struct,
941 : : int *pSortPrintINChIFlags,
942 : : unsigned char save_opt_bits)
943 : : {
944 : 197 : int bINChIOutputOptions0 = bINChIOutputOptions & ~(INCHI_OUT_PLAIN_TEXT | INCHI_OUT_PLAIN_TEXT_COMMENTS);
945 : : int bINChIOutputOptionsCur;
946 : : int bCurOption, ret, i;
947 : :
948 : 197 : ret = 0;
949 : :
950 [ + + ]: 788 : for (i = 0; i < 3; i++)
951 : : {
952 [ + + + ]: 591 : switch (i)
953 : : {
954 : 197 : case 1:
955 : 197 : bCurOption = INCHI_OUT_PLAIN_TEXT;
956 : 197 : break;
957 : 197 : case 2:
958 : 197 : bCurOption = INCHI_OUT_PLAIN_TEXT_COMMENTS;
959 : 197 : break;
960 : 197 : default:
961 : 197 : continue;
962 : : }
963 [ + + ]: 394 : if (bINChIOutputOptions & bCurOption)
964 : : {
965 : 197 : bINChIOutputOptionsCur = bINChIOutputOptions0 | bCurOption;
966 [ - + ]: 197 : if (i != 1)
967 : : {
968 : 0 : bINChIOutputOptionsCur &= ~INCHI_OUT_TABBED_OUTPUT;
969 : : }
970 : 197 : ret |= OutputINChI1(pCG,
971 : : strbuf,
972 : : pINChISortTautAndNonTaut2,
973 : : INCHI_basic_or_INCHI_reconnected,
974 : : orig_inp_data,
975 : : pOrigStruct,
976 : : ip,
977 : : bDisconnectedCoord,
978 : : bOutputType,
979 : : bINChIOutputOptionsCur,
980 : : num_components2,
981 : : num_non_taut2,
982 : : num_taut2,
983 : : output_file,
984 : : log_file,
985 : : num_input_struct,
986 : : pSortPrintINChIFlags,
987 : : save_opt_bits);
988 : : }
989 : : }
990 : :
991 : 197 : return ret;
992 : : }
993 : :
994 : : /**
995 : : * @brief Main actual worker which serializes InChI to string. Called from OutputINChI2( ... ) and from itself.
996 : : *
997 : : * @param pCG Pointer to global canonicalization data.
998 : : * @param strbuf Pointer to the output string buffer.
999 : : * @param pINChISortTautAndNonTaut2 Array of pointers to INCHI_SORT structures for tautomeric and non-tautomeric forms.
1000 : : * @param INCHI_basic_or_INCHI_reconnected Flag indicating basic or reconnected InChI output.
1001 : : * @param orig_inp_data Pointer to original atom data.
1002 : : * @param pOrigStruct Pointer to the original structure data.
1003 : : * @param ip Pointer to input parameters.
1004 : : * @param bDisconnectedCoord Flag for disconnected metal coordination.
1005 : : * @param bOutputType Output type (tautomeric/non-tautomeric/both).
1006 : : * @param bINChIOutputOptions Bitmask of output options.
1007 : : * @param num_components2 Array of component counts for each structure type.
1008 : : * @param num_non_taut2 Array of non-tautomeric component counts.
1009 : : * @param num_taut2 Array of tautomeric component counts.
1010 : : * @param out_file Output stream for InChI string.
1011 : : * @param log_file Output stream for logging.
1012 : : * @param num_input_struct Number of input structures.
1013 : : * @param pSortPrintINChIFlags Pointer to flags controlling sorting and printing.
1014 : : * @param save_opt_bits Encoded bits for saved InChI creation options.
1015 : : * @return int
1016 : : */
1017 : 197 : int OutputINChI1( CANON_GLOBALS *pCG,
1018 : : INCHI_IOS_STRING *strbuf,
1019 : : INCHI_SORT *pINChISortTautAndNonTaut2[][TAUT_NUM],
1020 : : int INCHI_basic_or_INCHI_reconnected,
1021 : : ORIG_ATOM_DATA *orig_inp_data,
1022 : : ORIG_STRUCT *pOrigStruct,
1023 : : INPUT_PARMS *ip,
1024 : : int bDisconnectedCoord,
1025 : : int bOutputType,
1026 : : int bINChIOutputOptions,
1027 : : int num_components2[],
1028 : : int num_non_taut2[],
1029 : : int num_taut2[],
1030 : : INCHI_IOSTREAM *out_file,
1031 : : INCHI_IOSTREAM *log_file,
1032 : : int num_input_struct,
1033 : : int *pSortPrintINChIFlags,
1034 : : unsigned char save_opt_bits )
1035 : : {
1036 : : INCHI_OUT_CTL io;
1037 : : /*
1038 : : bINChIOutputOptions bits:
1039 : : INCHI_OUT_NO_AUX_INFO 0x0001 do not output Aux Info
1040 : : INCHI_OUT_SHORT_AUX_INFO 0x0002 output short version of Aux Info
1041 : : INCHI_OUT_ONLY_AUX_INFO 0x0004 output only Aux Info
1042 : : INCHI_OUT_EMBED_REC 0x0008 embed reconnected INChI into disconnected INChI
1043 : :
1044 : : bOutputType =
1045 : : TAUT_YES => tautomeric only (if no tautomeric components then no output;
1046 : : TAUT_NON => only non-tautomeric output (if no non-taut present then no output;
1047 : : TAUT_BOTH => tautomeric and non-tautomeric
1048 : : */
1049 : 197 : int i, j, ii, jj, /*ii2, jj2,*/ bEmbeddedOutputCalled = 0;
1050 : : int bTautIsoHNum, bTautIsoAt, bHasIsotopicAtoms[TAUT_NUM];
1051 : : int bStereoSp2[TAUT_NUM], bStereoSp3[TAUT_NUM];
1052 : : int bIsotopicStereoSp2[TAUT_NUM], bIsotopicStereoSp3[TAUT_NUM];
1053 : : int bStereoAbsInverted[TAUT_NUM], bIsotopicStereoAbsInverted[TAUT_NUM];
1054 : : int bStereoAbs[TAUT_NUM], bIsotopicStereoAbs[TAUT_NUM];
1055 : : int bTautomericAcid, bHardAddRemProton;
1056 : 197 : int bRequestedRacemicStereo = 0, bRequestedRelativeStereo = 0;
1057 : 197 : int npass = 0; /* djb-rwth: removing redundant variables */
1058 : 197 : int is_molecular_inorganic = 0;
1059 : :
1060 : : INCHI_SORT *is, *is2;
1061 : : INChI *pINChI /*, *pINChI2*/;
1062 : 197 : INChI_Aux *pINChI_Aux = NULL;
1063 : :
1064 : 197 : int ret = 0; /* 0 failed, 1 success */
1065 : 197 : int intermediate_result = 0;
1066 : 197 : int then_goto_repeat = 0;
1067 : : /* djb-rwth: removing redundant variables */
1068 : : int bHasIsoH;
1069 : : /* djb-rwth: removing redundant variables */
1070 : : int bTautAndNonTaut, bTautIsNonTaut;
1071 : : int nAtomsAllComp1, nAtomsAllComp2; /* v. 1.05 Total atoms in all components */
1072 : :
1073 : 197 : int bPlainText = 0 != (bINChIOutputOptions & (INCHI_OUT_PLAIN_TEXT | INCHI_OUT_PLAIN_TEXT_COMMENTS));
1074 : 197 : int bPlainTextCommnts = 0 != (bINChIOutputOptions & INCHI_OUT_PLAIN_TEXT_COMMENTS);
1075 : :
1076 : : char *pLF, *pTAB;
1077 : : #ifdef TARGET_LIB_FOR_WINCHI
1078 : : int silent = 1;
1079 : : #endif
1080 : :
1081 : 197 : int bFixTranspChargeBug = 0;
1082 : : #if (FIX_TRANSPOSITION_CHARGE_BUG == 1) /* 2008-01-02 */
1083 [ + - ]: 197 : if (INCHI_OUT_FIX_TRANSPOSITION_CHARGE_BUG & bINChIOutputOptions)
1084 : 197 : bFixTranspChargeBug = 1;
1085 : : #endif
1086 : :
1087 : 197 : io.bAbcNumbers = ip->bAbcNumbers;
1088 : :
1089 : 394 : io.ATOM_MODE = ((io.bAbcNumbers ? CT_MODE_ABC_NUMBERS : 0) | CT_MODE_ATOM_COUNTS | CT_MODE_NO_ORPHANS
1090 : : #if (EQL_H_NUM_TOGETHER == 1)
1091 [ - + ]: 197 : | CT_MODE_EQL_H_TOGETHER
1092 : : #endif
1093 : : #if (ABC_CT_NUM_CLOSURES == 1)
1094 [ - + - - ]: 197 : | (io.bAbcNumbers && ip->bCtPredecessors ? CT_MODE_ABC_NUM_CLOSURES : 0)
1095 : : #endif
1096 [ - + ]: 197 : | (ip->bCtPredecessors ? CT_MODE_PREDECESSORS : 0));
1097 : :
1098 [ - + ]: 197 : io.TAUT_MODE = (io.bAbcNumbers ? CT_MODE_ABC_NUMBERS : 0);
1099 : 197 : io.pSortPrintINChIFlags = pSortPrintINChIFlags;
1100 : 197 : io.num_components = num_components2[INCHI_basic_or_INCHI_reconnected];
1101 : 197 : io.pINChISortTautAndNonTaut = pINChISortTautAndNonTaut2[INCHI_basic_or_INCHI_reconnected];
1102 : 197 : io.pINChISort = io.pINChISortTautAndNonTaut[TAUT_YES];
1103 : 197 : io.pINChISort2 = io.pINChISortTautAndNonTaut[TAUT_YES];
1104 : 197 : io.bAlways = 0;
1105 : 197 : io.bUseMulipliers = 1;
1106 : 197 : io.bOmitRepetitions = 1;
1107 : 197 : io.bPlainTextTags = 2; /* 0 => no plain tags, 1=> plain text tags, 2=>plaintext tags without consecutive // */
1108 : 197 : io.bOutputType = bOutputType; /* remains constant */
1109 : 197 : io.bOutType = bOutputType; /* will change! */
1110 : 197 : io.bOverflow = 0;
1111 : 197 : io.bSecondNonTautPass = 0;
1112 : 197 : io.bNonTautIsoIdentifierNotEmpty = 0;
1113 : 197 : io.bNonTautNonIsoIdentifierNotEmpty = 0;
1114 : 197 : io.bNonTautIsIdenticalToTaut = 1;
1115 : 197 : io.bFhTag = 0;
1116 [ + - ]: 394 : io.nTag = bPlainTextCommnts ? 3 : bPlainText ? 2
1117 [ + - ]: 197 : : 0; /* tag type */
1118 : :
1119 [ + + ]: 197 : if (NULL == orig_inp_data)
1120 : : {
1121 : : /*intermediate_result = 1;
1122 : : goto exit_function;*/
1123 : 13 : io.n_zy = 0;
1124 : 13 : io.n_pzz = 0;
1125 : 13 : io.n_pzz = 0;
1126 : : }
1127 : : else
1128 : : {
1129 : 184 : io.n_zy = orig_inp_data->n_zy;
1130 : 184 : io.n_pzz = 0;
1131 [ + + ]: 184 : if (orig_inp_data->polymer)
1132 : : {
1133 : 24 : io.n_pzz = orig_inp_data->polymer->n_pzz;
1134 : : }
1135 : : }
1136 : :
1137 : : /*
1138 : : * @nnuk
1139 : : * The Molecular Inorganics subversion designator is structure-specific.
1140 : : * For structure input it is determined from the Molecular Inorganics
1141 : : * element classification when Molecular Inorganics processing is enabled.
1142 : : * For InChI-derived input, the subversion designator is preserved from
1143 : : * the input version prefix.
1144 : : */
1145 [ + + ]: 197 : if (ip->bMolecularInorganics)
1146 : : {
1147 : : #if ( READ_INCHI_STRING == 1 )
1148 [ + + ]: 196 : if (ip->bReadInChIOptions & (READ_INCHI_OUTPUT_INCHI | READ_INCHI_TO_STRUCTURE))
1149 : : {
1150 [ + + ]: 13 : if (ip->bReadInChIOptions & READ_INCHI_INPUT_MI)
1151 : : {
1152 : 3 : is_molecular_inorganic = 1;
1153 : : }
1154 : : }
1155 : : else
1156 : : #endif
1157 [ + - + - ]: 183 : if (orig_inp_data && orig_inp_data->at)
1158 : : {
1159 [ + + ]: 9083 : for (i = 0; i < orig_inp_data->num_inp_atoms; i++)
1160 : : {
1161 [ + + ]: 8966 : if (getElTypeforMolecularInorganics(orig_inp_data->at[i].el_number) != 0)
1162 : : {
1163 : 66 : is_molecular_inorganic = 1;
1164 : 66 : break;
1165 : : }
1166 : : }
1167 : : }
1168 : : }
1169 : :
1170 : 197 : io.bPolymers = ip->bPolymers;
1171 : :
1172 : : /* djb-rwth: removing redundant code */
1173 : :
1174 : : #ifdef TARGET_LIB_FOR_WINCHI
1175 : : /* @@@ From now on we will go with silent output; it ends on @@@ below */
1176 : : silent = 1;
1177 : : #endif
1178 : :
1179 : : /* Analyze layers, make adjustments and fixes, etc. */
1180 : :
1181 : 197 : set_line_separators(bINChIOutputOptions, &pLF, &pTAB);
1182 : 197 : memset(io.sDifSegs, DIFV_BOTH_EMPTY, sizeof(io.sDifSegs)); /* djb-rwth: memset_s C11/Annex K variant? */
1183 [ + - + - : 197 : if (!strbuf || !(strbuf->pStr) || strbuf->nAllocatedLength <= 0)
- + ]
1184 : : {
1185 : 0 : inchi_ios_eprint(log_file, "Cannot allocate output buffer. No output for structure #%d.%s%s%s%s\n",
1186 [ # # # # : 0 : num_input_struct, SDF_LBL_VAL(ip->pSdfLabel, ip->pSdfValue));
# # # # #
# # # # #
# # # # #
# # # #
# ]
1187 : 0 : return ret;
1188 : : }
1189 : :
1190 : : /* -- commented out to allow empty InChI --
1191 : : if (!io.num_components ) return 0;
1192 : : */
1193 : :
1194 [ + + ]: 591 : for (i = 0; i < TAUT_NUM; i++)
1195 : : {
1196 : 394 : bHasIsotopicAtoms[i] =
1197 : 394 : io.num_comp[i] =
1198 : 394 : bStereoSp2[i] =
1199 : 394 : bStereoSp3[i] =
1200 : 394 : bIsotopicStereoSp2[i] =
1201 : 394 : bIsotopicStereoSp3[i] =
1202 : 394 : io.bIsotopicOrigNumb[i] =
1203 : 394 : bStereoAbs[i] =
1204 : 394 : bIsotopicStereoAbs[i] =
1205 : 394 : bStereoAbsInverted[i] =
1206 : 394 : bIsotopicStereoAbsInverted[i] =
1207 : 394 : io.bRacemicStereo[i] =
1208 : 394 : io.bRelativeStereo[i] =
1209 : 394 : io.bIsotopicRacemicStereo[i] =
1210 : 394 : io.bIsotopicRelativeStereo[i] =
1211 : 394 : io.bAtomEqu[i] =
1212 : 394 : io.bTautEqu[i] =
1213 : 394 : io.bIsotopicAtomEqu[i] =
1214 : 394 : io.bIsotopicTautEqu[i] =
1215 : 394 : io.bInvStereo[i] =
1216 : 394 : io.bInvIsotopicStereo[i] =
1217 : 394 : io.bInvStereoOrigNumb[i] =
1218 : 394 : io.bInvIsotopicStereoOrigNumb[i] =
1219 : 394 : io.bIgn_UU_Sp3[i] =
1220 : 394 : io.bIgn_UU_Sp2[i] =
1221 : 394 : io.bIgn_UU_Sp3_Iso[i] =
1222 : 394 : io.bIgn_UU_Sp2_Iso[i] =
1223 : 394 : io.bChargesRadVal[i] =
1224 : 394 : io.bOrigCoord[i] = 0;
1225 : : }
1226 : :
1227 : : /* Find if it is isotopic */
1228 : 197 : io.bIsotopic =
1229 : 197 : io.bTautomeric =
1230 : 197 : io.bNonTautomeric =
1231 : 197 : bTautomericAcid =
1232 : 197 : bHardAddRemProton =
1233 : 197 : bTautIsoHNum =
1234 : 197 : bTautIsoAt =
1235 : 197 : bTautAndNonTaut =
1236 : 197 : bTautIsNonTaut = 0;
1237 : :
1238 : : /*
1239 : : x = bStereo, bStereoSp2, bStereoSp3, bStereoAbsInverted,
1240 : : bIsotopicStereo, bIsotopicStereoSp2, bIsotopicStereoSp3, bIsotopicStereoAbsInverted
1241 : :
1242 : : OUT_N1: x[TAUT_NON] refers to non-tautomeric only
1243 : : OUT_T1: x[TAUT_YES] refers to tautomeric if exists otherwise non-tautomeric
1244 : : OUT_NT: x[TAUT_NON] refers to non-taut representations of tautomeric
1245 : : OUT_TN: x[TAUT_YES] refers to tautomeric if exists otherwise non-tautomeric
1246 : : x[TAUT_NON] refers to non-taut representations of tautomeric
1247 : : */
1248 : :
1249 : 197 : memset(io.num_iso_H, 0, sizeof(io.num_iso_H)); /* djb-rwth: memset_s C11/Annex K variant? */
1250 : 197 : io.nNumRemovedProtons = 0;
1251 : : /* djb-rwth: removing redundant code */
1252 : 197 : bHasIsoH = 0;
1253 [ + - + - ]: 197 : io.bTautomericOutputAllowed = (io.bOutType == OUT_T1 || io.bOutType == OUT_TN);
1254 [ + - ]: 197 : io.pINChISort = io.pINChISortTautAndNonTaut[io.bTautomericOutputAllowed ? TAUT_YES : TAUT_NON];
1255 : 197 : is = io.pINChISort;
1256 : : /* djb-rwth: removing redundant variables/code */
1257 : :
1258 [ + - + + ]: 2749 : for (i = 0, is2 = io.pINChISortTautAndNonTaut[TAUT_NON]; i < io.num_components; i++, is++, is2 ? is2++ : NULL)
1259 : : {
1260 : :
1261 : 1276 : CompINChILayers(is, is2, io.sDifSegs, bFixTranspChargeBug);
1262 : :
1263 [ + - + - ]: 1276 : io.bNonTautIsIdenticalToTaut = io.bNonTautIsIdenticalToTaut && !CompINChITautVsNonTaut(is, is2, 1);
1264 : :
1265 [ + - + - ]: 1276 : if (is && (pINChI_Aux = is->pINChI_Aux[TAUT_YES]))
1266 : : {
1267 [ + + ]: 5104 : for (j = 0; j < NUM_H_ISOTOPES; j++)
1268 : : {
1269 : 3828 : bHasIsoH += abs(pINChI_Aux->nNumRemovedIsotopicH[j]);
1270 : 3828 : io.num_iso_H[j] += pINChI_Aux->nNumRemovedIsotopicH[j];
1271 : : }
1272 : 1276 : io.nNumRemovedProtons += pINChI_Aux->nNumRemovedProtons;
1273 : : /* djb-rwth: removing redundant code */
1274 : : }
1275 : :
1276 [ + - + - ]: 1276 : if (io.bTautomericOutputAllowed && is) /* djb-rwth: fixing a NULL pointer dereference */
1277 : : {
1278 : : /* Check for removed isotopic H */
1279 [ + + ]: 2552 : for (j = TAUT_YES; j < TAUT_NUM; j++)
1280 : : {
1281 [ - - - + : 1276 : switch (io.bOutType)
- ]
1282 : : {
1283 : 0 : case OUT_N1: /* x[TAUT_NON]: non-tautomeric only -- never happens */
1284 [ # # # # : 0 : jj = GET_II(io.bOutType, is);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
1285 [ # # ]: 0 : if (jj != j)
1286 : 0 : continue;
1287 : : /* djb-rwth: removing redundant code */
1288 : 0 : break;
1289 : 0 : case OUT_T1: /* x[TAUT_YES]: tautomeric if present otherwise non-tautomeric */
1290 [ # # # # : 0 : jj = GET_II(io.bOutType, is);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
1291 [ # # ]: 0 : if (jj != j)
1292 : 0 : continue;
1293 : : /* djb-rwth: removing redundant code */
1294 : 0 : break;
1295 : 0 : case OUT_NT: /* x[TAUT_NON]: only non-taut representations of tautomeric -- never happens */
1296 [ # # # # : 0 : jj = GET_II(io.bOutType, is);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
1297 [ # # ]: 0 : if (jj != j)
1298 : 0 : continue;
1299 : : /* djb-rwth: removing redundant code */
1300 : 0 : break;
1301 : : /* main path of control flow */
1302 : 1276 : case OUT_TN: /* x[TAUT_YES]: tautomeric if present otherwise non-tautomeric;
1303 : : * x[TAUT_NON]: non-taut only if tautomeric is present */
1304 [ + - + - : 1276 : jj = (j == TAUT_YES) ? GET_II(OUT_T1, is) : (j == TAUT_NON) ? GET_II(OUT_NT, is)
- + - - -
- - - - -
- - - - -
- - - ]
1305 [ # # ]: 0 : : -1;
1306 [ + - ]: 1276 : if (jj == TAUT_YES)
1307 : : {
1308 : : /* Fix12 */
1309 [ + + ]: 1276 : if (is->pINChI[jj]->lenTautomer > 0)
1310 : : {
1311 [ + - - + : 17 : bTautAndNonTaut += (!is->pINChI[jj]->bDeleted && HAS_N(is));
- - ]
1312 : : }
1313 : : else
1314 : : {
1315 : 1259 : bTautIsNonTaut++;
1316 : : }
1317 : : }
1318 [ - + ]: 1276 : if (jj < 0)
1319 : 0 : continue;
1320 : : /* djb-rwth: removing redundant code */
1321 : 1276 : break;
1322 : 0 : default:
1323 : 0 : continue;
1324 : : }
1325 [ - + ]: 1276 : if (jj != j)
1326 : 0 : continue;
1327 [ + - + - : 1276 : if ((pINChI = is->pINChI[jj]) && pINChI->nNumberOfAtoms > 0 && (pINChI_Aux = is->pINChI_Aux[jj]))
+ - ]
1328 : : {
1329 : 1276 : bTautIsoHNum += (pINChI_Aux->nNumRemovedIsotopicH[0] +
1330 : 1276 : pINChI_Aux->nNumRemovedIsotopicH[1] +
1331 : 1276 : pINChI_Aux->nNumRemovedIsotopicH[2]);
1332 [ + + - + ]: 1276 : bTautIsoAt += (pINChI->nNumberOfIsotopicAtoms > 0 || pINChI->nNumberOfIsotopicTGroups > 0);
1333 : : }
1334 : : }
1335 : : }
1336 : : }
1337 : :
1338 [ + + ]: 197 : io.sDifSegs[DIFL_M][DIFS_p_PROTONS] = io.nNumRemovedProtons ? DIFV_NEQ2PRECED : DIFV_BOTH_EMPTY;
1339 [ - + ]: 197 : io.sDifSegs[DIFL_MI][DIFS_h_H_ATOMS] = bHasIsoH ? DIFV_NEQ2PRECED : DIFV_BOTH_EMPTY;
1340 : :
1341 : 197 : MarkUnusedAndEmptyLayers(io.sDifSegs);
1342 : :
1343 [ + - + - ]: 197 : io.bNonTautIsIdenticalToTaut = io.bNonTautIsIdenticalToTaut && !bTautIsoHNum;
1344 : 197 : nAtomsAllComp1 = nAtomsAllComp2 = 0;
1345 : :
1346 [ + + ]: 1473 : for (i = 0, is = io.pINChISort; i < io.num_components; i++, is++)
1347 : : {
1348 : : int bCurIso, bCurHasIsoStereo /* Fix14 */, bCurTaut /*, bCurTaut2*/; /* djb-rwth: removing redundant variables */
1349 : : int bCompExists, bCurIsoHPos, bCurIsoHStereo;
1350 : : int bCurStereoSp2, bCurIsoStereoSp2, bCurStereoSp3, bCurIsoStereoSp3, bCurIsoStereoSp3Inv;
1351 : : int bCurRacemic, bCurRelative, bCurIsoRacemic, bCurIsoRelative;
1352 : 1276 : bCompExists = 0;
1353 : :
1354 [ + + ]: 3828 : for (j = TAUT_NON; j < TAUT_NUM; j++)
1355 : : {
1356 [ - - - + : 2552 : switch (io.bOutType)
- ]
1357 : : {
1358 : 0 : case OUT_N1:
1359 : : /* x[TAUT_NON]: non-tautomeric only */
1360 [ # # # # : 0 : jj = GET_II(io.bOutType, is);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
1361 [ # # ]: 0 : if (jj != j)
1362 : 0 : continue;
1363 : 0 : ii = TAUT_NON;
1364 : 0 : break;
1365 : 0 : case OUT_T1:
1366 : : /* x[TAUT_YES]: tautomeric if present otherwise non-tautomeric */
1367 [ # # # # : 0 : jj = GET_II(io.bOutType, is);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
1368 [ # # ]: 0 : if (jj != j)
1369 : 0 : continue;
1370 : 0 : ii = TAUT_YES;
1371 : 0 : break;
1372 : 0 : case OUT_NT:
1373 : : /* x[TAUT_NON]: only non-taut representations of tautomeric */
1374 [ # # # # : 0 : jj = GET_II(io.bOutType, is);
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # # #
# # # #
# ]
1375 [ # # ]: 0 : if (jj != j)
1376 : 0 : continue;
1377 : 0 : ii = TAUT_NON;
1378 : 0 : break;
1379 : : /* main control flow comes here: requested both mobile and fixed H results */
1380 : 2552 : case OUT_TN:
1381 : : /* x[TAUT_YES]: tautomeric if present otherwise non-tautomeric; */
1382 : : /* x[TAUT_NON]: non-taut only if tautomeric is present */
1383 [ + + + - : 5104 : jj = (j == TAUT_YES) ? GET_II(OUT_T1, is) : (j == TAUT_NON) ? GET_II(OUT_NT, is)
- + - - -
- + - + -
+ + - + -
- - - ]
1384 [ + - ]: 2552 : : -1;
1385 [ + + ]: 2552 : if (jj < 0)
1386 : : {
1387 : : /* Fix12 */
1388 [ - + - - : 1276 : if (bTautAndNonTaut && bTautIsNonTaut &&
- - ]
1389 [ # # # # : 0 : j == TAUT_NON && 0 <= (jj = GET_II(OUT_T1, is)) &&
# # # # #
# ]
1390 [ # # # # ]: 0 : !is->pINChI[jj]->bDeleted && !is->pINChI[jj]->lenTautomer)
1391 : : {
1392 : : ; /* the requested non-tautomeric component is in tautomeric position */
1393 : : /* (is->pINChI[TAUT_YES]); */
1394 : : /* process it also as non-tautomeric if Fixed-H layer was requested */
1395 : : }
1396 : : else
1397 : : {
1398 : 1276 : continue;
1399 : : }
1400 : : }
1401 : :
1402 : 1276 : ii = j; /* ii is what we wanted; jj is what we found (0 = TAUT_NON: fixed_H, 1 = TAUT_YES: mobile_H) */
1403 : :
1404 : : /* -- not used 2004-09-16 ---
1405 : : if ( is2 ) {
1406 : : jj2 = ( j == TAUT_YES )? GET_II(OUT_T1,is2) : ( j == TAUT_NON )? GET_II(OUT_NT,is2) : -1;
1407 : : if ( jj2 >= 0 ) {
1408 : : ii2 = j;
1409 : : } else {
1410 : : ii2 = -1;
1411 : : }
1412 : : } else {
1413 : : jj2 = ii2 = -1;
1414 : : }
1415 : : -----------------------------*/
1416 : 1276 : break;
1417 : :
1418 : 0 : default:
1419 : 0 : continue;
1420 : : }
1421 : :
1422 [ + - + - ]: 1276 : if ((pINChI = is->pINChI[jj]) && pINChI->nNumberOfAtoms > 0)
1423 : : {
1424 : : /*pINChI_Aux = is->pINChI_Aux[jj];*/
1425 : 1276 : bCompExists++;
1426 : :
1427 [ - + ]: 1276 : if (j == TAUT_NON)
1428 : 0 : nAtomsAllComp1 += pINChI->nNumberOfAtoms;
1429 [ + - ]: 1276 : else if (j == TAUT_YES)
1430 : 1276 : nAtomsAllComp2 += pINChI->nNumberOfAtoms;
1431 : :
1432 : 1276 : bCurTaut = (pINChI->lenTautomer > 0);
1433 [ + + - + ]: 1276 : bCurIso = (pINChI->nNumberOfIsotopicAtoms > 0 || pINChI->nNumberOfIsotopicTGroups > 0);
1434 [ + + + - : 1276 : bCurIsoHPos = ((pINChI->nPossibleLocationsOfIsotopicH && pINChI->nPossibleLocationsOfIsotopicH[0] > 1) || pINChI->lenTautomer > 1); /* djb-rwth: addressing LLVM warning */
+ + ]
1435 : : /* present isotopic H + their possible positions AND/OR isotopic atoms */
1436 [ + + + - : 1276 : bCurIsoHStereo = (bCurIsoHPos && (bTautIsoHNum || bTautIsoAt)) || bCurIso; /* djb-rwth: addressing LLVM warning */
+ - + + ]
1437 [ + - - + ]: 1276 : if (jj == j && pINChI->bDeleted)
1438 : : {
1439 : 0 : io.num_comp[j]--;
1440 [ # # ]: 0 : if (bCurTaut)
1441 : : {
1442 : 0 : io.bTautomeric |= 1; /* tautomeric representation is present */
1443 [ # # # # ]: 0 : io.bNonTautomeric |= HAS_N(is);
1444 : : }
1445 : 0 : io.bIsotopic |= bCurIso;
1446 : 0 : continue; /* deleted H(+) in tautomeric representation */
1447 : : }
1448 : :
1449 [ + + + + ]: 1276 : bCurStereoSp2 = pINChI->Stereo && (pINChI->Stereo->nNumberOfStereoBonds > 0);
1450 : :
1451 : 1276 : bCurHasIsoStereo =
1452 [ + + + + ]: 1276 : bCurStereoSp3 = pINChI->Stereo && (pINChI->Stereo->nNumberOfStereoCenters > 0);
1453 : :
1454 [ + + + - : 1276 : bCurIsoStereoSp2 = bCurIsoHStereo && pINChI->StereoIsotopic && (pINChI->StereoIsotopic->nNumberOfStereoBonds > 0);
- + ]
1455 [ + + + - : 1276 : bCurIsoStereoSp3 = bCurIsoHStereo && pINChI->StereoIsotopic && (pINChI->StereoIsotopic->nNumberOfStereoCenters > 0);
+ + ]
1456 [ + + + - ]: 1276 : bCurIsoStereoSp3Inv = bCurIsoStereoSp3 && pINChI->StereoIsotopic->nCompInv2Abs; /* inversion changes sp3 stereo */
1457 : 1276 : bRequestedRacemicStereo |= (0 != (pINChI->nFlags & INCHI_FLAG_RAC_STEREO));
1458 : 1276 : bRequestedRelativeStereo |= (0 != (pINChI->nFlags & INCHI_FLAG_REL_STEREO));
1459 : :
1460 : : /* Check whether isotopic stereo is same as non-isotopic; if same than do not output isotopic stereo */
1461 [ + + - + ]: 1276 : if (bCurStereoSp2 && bCurIsoStereoSp2)
1462 : : {
1463 : 0 : bCurIsoStereoSp2 = !Eql_INChI_Stereo(pINChI->Stereo, EQL_SP2, pINChI->StereoIsotopic, EQL_SP2, 0);
1464 : : }
1465 [ + + + + ]: 1276 : if (bCurStereoSp3 && bCurIsoStereoSp3)
1466 : : {
1467 : : /* bCurIsoStereoSp3=0 means (iso stereo sp3) = (non-iso stereo sp3) or (iso stereo sp3) = Inv(non-iso stereo sp3) */
1468 : 2 : bCurIsoStereoSp3 = !Eql_INChI_Stereo(pINChI->Stereo, EQL_SP3, pINChI->StereoIsotopic, EQL_SP3,
1469 [ + - - + ]: 2 : (pINChI->nFlags & INCHI_FLAG_RAC_STEREO) || (pINChI->nFlags & INCHI_FLAG_REL_STEREO));
1470 [ + - ]: 2 : if (!bCurIsoStereoSp3)
1471 : : {
1472 : : /* Inversion changes iso sp3 differently from non-iso sp3 Fix11 */
1473 : 2 : bCurIsoStereoSp3Inv &= (pINChI->StereoIsotopic->nCompInv2Abs != pINChI->Stereo->nCompInv2Abs);
1474 : : }
1475 : : }
1476 : :
1477 [ - + - - ]: 1276 : bCurRelative = bRequestedRelativeStereo && bCurStereoSp3;
1478 : : #if (REL_RAC_STEREO_IGN_1_SC == 1)
1479 : : bCurRelative = bCurRelative &&
1480 : : (pINChI->Stereo->nNumberOfStereoCenters > 1) &&
1481 : : (pINChI->Stereo->nCompInv2Abs != 0) &&
1482 : : #endif
1483 : :
1484 [ - + - - : 1276 : bCurIsoRelative = bRequestedRelativeStereo && (bCurIsoStereoSp3 || bCurIsoStereoSp3Inv);
- - ]
1485 : : #if (REL_RAC_STEREO_IGN_1_SC == 1)
1486 : : bCurIsoRelative = bCurIsoRelative &&
1487 : : (pINChI->StereoIsotopic->nNumberOfStereoCenters > 1) &&
1488 : : (pINChI->StereoIsotopic->nCompInv2Abs != 0) &&
1489 : : #endif
1490 : :
1491 [ - + - - ]: 1276 : bCurRacemic = bRequestedRacemicStereo && bCurStereoSp3;
1492 : : #if (REL_RAC_STEREO_IGN_1_SC == 1)
1493 : : bCurRacemic = bCurRacemic &&
1494 : : (pINChI->Stereo->nCompInv2Abs != 0) &&
1495 : : (pINChI->Stereo->nNumberOfStereoCenters > 0)
1496 : : ? pINChI->Stereo->nNumberOfStereoCenters
1497 : : : 0;
1498 : : #endif
1499 : :
1500 [ - + - - : 1276 : bCurIsoRacemic = bRequestedRacemicStereo && (bCurIsoStereoSp3 || bCurIsoStereoSp3Inv);
- - ]
1501 : : #if (REL_RAC_STEREO_IGN_1_SC == 1)
1502 : : bCurIsoRacemic = bCurIsoRacemic &
1503 : : (pINChI->StereoIsotopic->nCompInv2Abs != 0) &&
1504 : : (pINChI->StereoIsotopic->nNumberOfStereoCenters > 0)
1505 : : ? pINChI->StereoIsotopic->nNumberOfStereoCenters
1506 : : : 0;
1507 : : #endif
1508 [ - + ]: 1276 : if (bRequestedRelativeStereo)
1509 : : {
1510 [ # # # # : 0 : bCurStereoSp3 = bCurRelative || (bCurStereoSp3 && (pINChI->Stereo->nNumberOfStereoCenters > 1)); /* Fix11 */ /* djb-rwth: addressing LLVM warning */
# # ]
1511 [ # # ]: 0 : bCurIsoStereoSp3 = bCurIsoRelative ? bCurIsoStereoSp3 : 0;
1512 : : }
1513 : : else
1514 : : {
1515 [ - + ]: 1276 : if (bRequestedRacemicStereo)
1516 : : {
1517 [ # # # # : 0 : bCurStereoSp3 = bCurRacemic > 1 || (bCurStereoSp3 && (pINChI->Stereo->nNumberOfStereoCenters > 1)); /* Fix11 */ /* djb-rwth: addressing LLVM warning */
# # ]
1518 [ # # ]: 0 : bCurIsoStereoSp3 = bCurIsoRacemic > 1 ? bCurIsoStereoSp3 : 0;
1519 : : }
1520 : : }
1521 : : /* djb-rwth: removing redundant code */
1522 : :
1523 : 1276 : io.bIsotopic |= bCurIso;
1524 : 1276 : bHasIsotopicAtoms[ii] |= bCurIso;
1525 : 1276 : bStereoSp2[ii] |= bCurStereoSp2;
1526 : 1276 : bStereoSp3[ii] |= bCurStereoSp3;
1527 [ + + + + ]: 1276 : io.bIgn_UU_Sp3[ii] |= !bCurStereoSp3 && (pINChI->nFlags & INCHI_FLAG_SC_IGN_ALL_UU);
1528 [ + + - + ]: 1276 : io.bIgn_UU_Sp2[ii] |= !bCurStereoSp2 && (pINChI->nFlags & INCHI_FLAG_SB_IGN_ALL_UU);
1529 : 1276 : bIsotopicStereoSp2[ii] |= bCurIsoStereoSp2;
1530 : 1276 : bIsotopicStereoSp3[ii] |= bCurIsoStereoSp3;
1531 [ + + - + ]: 1276 : io.bIgn_UU_Sp3_Iso[ii] |= !bCurIsoStereoSp3 && (pINChI->nFlags & INCHI_FLAG_SC_IGN_ALL_ISO_UU);
1532 [ + - - + ]: 1276 : io.bIgn_UU_Sp2_Iso[ii] |= !bCurIsoStereoSp2 && (pINChI->nFlags & INCHI_FLAG_SB_IGN_ALL_ISO_UU);
1533 [ + + + + ]: 1276 : bStereoAbs[ii] |= bCurStereoSp3 && (pINChI->Stereo->nCompInv2Abs != 0);
1534 : :
1535 [ + + + + ]: 1276 : bStereoAbsInverted[ii] |= bCurStereoSp3 && (pINChI->Stereo->nCompInv2Abs < 0);
1536 : :
1537 : : /* Fix08: missing isotopic inverted flag if isotopic = inverted non-isotopic */
1538 [ + + - + : 2550 : bIsotopicStereoAbsInverted[ii] |= (bCurIsoStereoSp3 && (pINChI->StereoIsotopic->nCompInv2Abs < 0)) ||
+ - ]
1539 [ + + + - ]: 1274 : (!bCurIsoStereoSp3 && pINChI->StereoIsotopic && pINChI->Stereo &&
1540 [ + + ]: 7 : pINChI->StereoIsotopic->nCompInv2Abs &&
1541 [ - + ]: 2 : pINChI->StereoIsotopic->nCompInv2Abs != pINChI->Stereo->nCompInv2Abs); /* djb-rwth: addressing LLVM warnings */
1542 : :
1543 : : /* Fix 11: missing /s1 if only isotopic stereo is inverted */
1544 [ + + - + : 2550 : bIsotopicStereoAbs[ii] |= (bCurIsoStereoSp3 && (pINChI->StereoIsotopic->nCompInv2Abs != 0)) ||
+ - ]
1545 [ + + + - ]: 1274 : (!bCurIsoStereoSp3 && pINChI->StereoIsotopic && pINChI->Stereo &&
1546 [ + + ]: 7 : pINChI->StereoIsotopic->nCompInv2Abs &&
1547 [ - + ]: 2 : pINChI->StereoIsotopic->nCompInv2Abs != pINChI->Stereo->nCompInv2Abs); /* djb-rwth: addressing LLVM warnings */
1548 : :
1549 : 1276 : io.bRelativeStereo[ii] |= bCurRelative;
1550 : 1276 : io.bIsotopicRelativeStereo[ii] |= bCurIsoRelative;
1551 : 1276 : io.bRacemicStereo[ii] |= bCurRacemic;
1552 : 1276 : io.bIsotopicRacemicStereo[ii] |= bCurIsoRacemic;
1553 : :
1554 : 1276 : bTautomericAcid |= (0 != (pINChI->nFlags & INCHI_FLAG_ACID_TAUT));
1555 : 1276 : bHardAddRemProton |= (0 != (pINChI->nFlags & INCHI_FLAG_HARD_ADD_REM_PROTON));
1556 [ + + ]: 1276 : if (bCurTaut)
1557 : : {
1558 : 17 : io.bTautomeric |= 1; /* tautomeric representation is present */
1559 : : /* does tautomeric structure have also a non-tautomeric repesentation? */
1560 [ - + - - ]: 17 : io.bNonTautomeric |= HAS_N(is);
1561 : : }
1562 : :
1563 : : /* Auxiliary info */
1564 [ + + + - ]: 1276 : if (!(bINChIOutputOptions & INCHI_OUT_NO_AUX_INFO) && (pINChI_Aux = is->pINChI_Aux[jj]))
1565 : : {
1566 : : /* detect presence of constitutional equivalence onfo */
1567 : 1260 : int bCurEqu, bCurTautEqu = 0, bCurIsoEqu = 0, bCurIsoTautEqu = 0; /* Fix15-disabled */
1568 : 1260 : io.bAtomEqu[ii] |= (bCurEqu = bHasEquString(pINChI_Aux->nConstitEquNumbers,
1569 : : pINChI_Aux->nNumberOfAtoms)); /* djb-rwth: ignoring LLVM warning: variable used to store function return value */
1570 [ + + ]: 1260 : if (bCurTaut)
1571 : : {
1572 : 14 : io.bTautEqu[ii] |= (bCurTautEqu = bHasEquString(pINChI_Aux->nConstitEquTGroupNumbers,
1573 : : pINChI_Aux->nNumberOfTGroups)); /* djb-rwth: ignoring LLVM warning: variable used to store function return value */
1574 : : }
1575 [ + + ]: 1260 : if (bCurIso)
1576 : : {
1577 : 6 : io.bIsotopicAtomEqu[ii] |= (bCurIsoEqu = bHasEquString(pINChI_Aux->nConstitEquIsotopicNumbers,
1578 : : pINChI_Aux->nNumberOfAtoms)) /*|| bCurEqu*/; /* djb-rwth: ignoring LLVM warning: variable used to store function return value */
1579 [ - + ]: 6 : if (bCurTaut)
1580 : : {
1581 : 0 : io.bIsotopicTautEqu[ii] |= (bCurIsoTautEqu = bHasEquString(pINChI_Aux->nConstitEquIsotopicTGroupNumbers,
1582 : : pINChI_Aux->nNumberOfTGroups)) /*|| bCurTautEqu*/; /* djb-rwth: ignoring LLVM warning: variable used to store function return value */
1583 : : }
1584 : : /* non-zero if isotopic numbering for inverted isotopic stereo is different */
1585 : 6 : io.bIsotopicOrigNumb[ii] |= bCurHasIsoStereo && /* Fix14 */
1586 [ + - ]: 2 : pINChI_Aux->nOrigAtNosInCanonOrdInv &&
1587 [ + + + - ]: 10 : pINChI_Aux->nIsotopicOrigAtNosInCanonOrd &&
1588 : 2 : (0 != memcmp(pINChI_Aux->nOrigAtNosInCanonOrdInv,
1589 : 2 : pINChI_Aux->nIsotopicOrigAtNosInCanonOrd,
1590 [ - + ]: 2 : sizeof(pINChI_Aux->nOrigAtNosInCanonOrdInv[0]) * pINChI_Aux->nNumberOfAtoms));
1591 : : }
1592 : : /* Inverted stereo */
1593 [ + + + + ]: 1260 : if (bCurStereoSp3 && pINChI->Stereo->nCompInv2Abs)
1594 : : {
1595 : 60 : io.bInvStereo[ii] |= 1;
1596 : 60 : io.bInvStereoOrigNumb[ii] |= pINChI_Aux->nOrigAtNosInCanonOrd &&
1597 [ + - + - ]: 120 : pINChI_Aux->nOrigAtNosInCanonOrdInv &&
1598 : 60 : (0 != memcmp(pINChI_Aux->nOrigAtNosInCanonOrd,
1599 : 60 : pINChI_Aux->nOrigAtNosInCanonOrdInv,
1600 [ - + ]: 60 : sizeof(pINChI_Aux->nOrigAtNosInCanonOrd[0]) * pINChI_Aux->nNumberOfAtoms));
1601 : : }
1602 : :
1603 : : /* Inverted isotopic stereo */
1604 [ + + + - ]: 1260 : if (bCurIsoStereoSp3 && pINChI->StereoIsotopic->nCompInv2Abs)
1605 : : {
1606 : 2 : io.bInvIsotopicStereo[ii] |= 1;
1607 : :
1608 : 2 : io.bInvIsotopicStereoOrigNumb[ii] |= pINChI_Aux->nIsotopicOrigAtNosInCanonOrd &&
1609 [ + - + - ]: 4 : pINChI_Aux->nIsotopicOrigAtNosInCanonOrdInv &&
1610 : 2 : (0 != memcmp(pINChI_Aux->nIsotopicOrigAtNosInCanonOrd,
1611 : 2 : pINChI_Aux->nIsotopicOrigAtNosInCanonOrdInv,
1612 [ - + ]: 2 : sizeof(pINChI_Aux->nIsotopicOrigAtNosInCanonOrd[0]) * pINChI_Aux->nNumberOfAtoms));
1613 : : }
1614 : :
1615 [ + - + + ]: 1260 : if (pINChI_Aux->OrigInfo && bHasOrigInfo(pINChI_Aux->OrigInfo, pINChI_Aux->nNumberOfAtoms))
1616 : : {
1617 : 37 : io.bChargesRadVal[ii] |= 1;
1618 : : }
1619 : : }
1620 : :
1621 [ + + ]: 1276 : if (ip->bEnhancedStereo)
1622 : : {
1623 : 57 : set_EnhancedStereo_t_m_layers(orig_inp_data, pINChI, pINChI_Aux);
1624 : : }
1625 : : }
1626 : : }
1627 [ + - ]: 1276 : if (bCompExists)
1628 : : {
1629 [ + + ]: 3828 : for (j = TAUT_NON; j < TAUT_NUM; j++)
1630 : : {
1631 : 2552 : io.num_comp[j]++;
1632 : : }
1633 : : }
1634 : : }
1635 [ + + ]: 197 : if (io.bTautomeric /*&& bTautomericAcid*/) /* "&& bTautomericAcid" commented out 2004-06-02 */
1636 : : {
1637 : 13 : io.bTautomeric += bTautomericAcid; /* long-range tautomerism */
1638 [ - + ]: 13 : io.bTautomeric += (bHardAddRemProton ? 4 : 0);
1639 : : }
1640 [ + - - + ]: 197 : if (bRequestedRacemicStereo || bRequestedRelativeStereo)
1641 : : {
1642 : : /* do not output inverted stereo info */
1643 [ # # ]: 0 : for (i = 0; i < TAUT_NUM; i++)
1644 : : {
1645 : : /* Fix11 */
1646 : 0 : bStereoAbsInverted[i] =
1647 : 0 : bStereoAbs[i] =
1648 : 0 : io.bInvStereo[i] =
1649 : 0 : io.bInvStereoOrigNumb[i] = 0;
1650 : : /* io.bIsotopicRelativeStereo[i]=0 may happen because iso stereo is same or inverted non-iso stereo */
1651 : 0 : bIsotopicStereoAbsInverted[i] =
1652 : 0 : bIsotopicStereoAbs[i] =
1653 : 0 : io.bInvIsotopicStereo[i] =
1654 : 0 : io.bInvIsotopicStereoOrigNumb[i] = 0;
1655 : : }
1656 : : }
1657 : :
1658 [ + - ]: 394 : io.iCurTautMode = io.bOutType == OUT_N1 ? TAUT_NON : /* only non-taut */
1659 : :
1660 : 197 : io.bOutType == OUT_T1 ? TAUT_YES
1661 [ + - ]: 394 : : /* tautomeric if present, otherwise non-tautomeric */
1662 : 197 : io.bOutType == OUT_NT ? TAUT_NON
1663 [ + - ]: 394 : : /* only non-taut representations of tautomeric */
1664 : 197 : io.bOutType == OUT_TN ? TAUT_YES
1665 [ + - ]: 197 : : /* tautomeric if present otherwise non-tautomeric; */
1666 : : -1; /* separately output non-taut representations of tautomeric if present */
1667 : :
1668 [ - + ]: 197 : if (io.iCurTautMode < 0)
1669 : : {
1670 : 0 : return 0; /* error */
1671 : : }
1672 : :
1673 : : /* Now print out */
1674 : :
1675 : 197 : io.bOverflow = 0;
1676 : 197 : io.num_components = io.num_comp[io.iCurTautMode];
1677 : : /* djb-rwth: removing redundant code */
1678 : :
1679 [ - + ]: 197 : if (bINChIOutputOptions & INCHI_OUT_ONLY_AUX_INFO)
1680 : : {
1681 : 0 : goto output_aux_info;
1682 : : }
1683 : :
1684 : 197 : io.nCurINChISegment = DIFL_M;
1685 : :
1686 : : /* InChI output: version prefix */
1687 [ - + - - ]: 197 : if (INCHI_basic_or_INCHI_reconnected == INCHI_BAS || !(bINChIOutputOptions & INCHI_OUT_EMBED_REC))
1688 : : {
1689 : 197 : int is_beta = 0;
1690 : 197 : int nAtomsAllComp = inchi_max(nAtomsAllComp1, nAtomsAllComp2);
1691 : :
1692 : : #if ( READ_INCHI_STRING == 1 )
1693 [ + + ]: 197 : if (ip->bReadInChIOptions & (READ_INCHI_OUTPUT_INCHI | READ_INCHI_TO_STRUCTURE))
1694 : : {
1695 [ + + ]: 13 : if (ip->bReadInChIOptions & READ_INCHI_INPUT_BETA)
1696 : : {
1697 : 2 : is_beta = 1;
1698 : : }
1699 : : }
1700 : : else
1701 : : #endif
1702 [ + + ]: 184 : if (is_molecular_inorganic)
1703 : : {
1704 : : /*
1705 : : * Molecular Inorganics is a Beta feature in this release.
1706 : : */
1707 : 66 : is_beta = 1;
1708 : : }
1709 : :
1710 [ - + ]: 197 : if (nAtomsAllComp > NORMALLY_ALLOWED_INP_MAX_ATOMS)
1711 : : {
1712 : : /* v. 1.05 for LargeMolecules */
1713 : 0 : is_beta = 1;
1714 : : }
1715 [ + + + + ]: 197 : if (pOrigStruct && pOrigStruct->polymer)
1716 : : {
1717 : : /* v. 1.05 for Polymers */
1718 : 24 : is_beta = 1;
1719 : : }
1720 : : /* specifically put 'B' for empty structure InChI */
1721 : : /* if "Polymers" or "LargeMolecules" requested */
1722 [ + + + - : 173 : else if (!pOrigStruct && (ip->bLargeMolecules || ip->bPolymers))
- + ]
1723 : : {
1724 : 0 : is_beta = 1;
1725 : : }
1726 [ + + - + ]: 173 : else if (pOrigStruct && pOrigStruct->n_zy)
1727 : : {
1728 : 0 : is_beta = 1;
1729 : : }
1730 [ + + ]: 173 : else if (ip->bEnhancedStereo)
1731 : : {
1732 : 47 : is_beta = 1;
1733 : : }
1734 : :
1735 : 197 : OutputINCHI_VersionAndKind(out_file, strbuf, bINChIOutputOptions, is_beta, is_molecular_inorganic, pLF, pTAB);
1736 : : }
1737 : :
1738 : : /* InChI output: atoms */
1739 : 197 : intermediate_result = OutputINCHI_MainLayerFormula(pCG, out_file, strbuf,
1740 : : num_components2,
1741 : : &INCHI_basic_or_INCHI_reconnected,
1742 : : &io, pLF, pTAB);
1743 [ - + ]: 197 : if (intermediate_result != 0)
1744 : 0 : goto exit_function;
1745 : :
1746 : : /* InChI output: connection table */
1747 : 197 : intermediate_result = OutputINCHI_MainLayerConnections(pCG, out_file, strbuf, num_components2,
1748 : : &INCHI_basic_or_INCHI_reconnected,
1749 : : &io, pLF, pTAB);
1750 [ - + ]: 197 : if (intermediate_result != 0)
1751 : 0 : goto exit_function;
1752 : :
1753 : : /* InChI output: hydrogens (with tautomeric info) */
1754 : 197 : intermediate_result = OutputINCHI_MainLayerHydrogens(pCG, out_file, strbuf, num_components2,
1755 : : &INCHI_basic_or_INCHI_reconnected,
1756 : : &io, pLF, pTAB);
1757 [ - + ]: 197 : if (intermediate_result != 0)
1758 : 0 : goto exit_function;
1759 : :
1760 : 197 : io.bFhTag = 0;
1761 : 197 : npass = 0;
1762 : :
1763 : 197 : repeat_INChI_output:
1764 : :
1765 : : /* InChI output: charge and removed protons */
1766 : 197 : intermediate_result = OutputINCHI_ChargeAndRemovedAddedProtonsLayers(pCG, out_file, strbuf,
1767 : : &io, pLF, pTAB);
1768 [ - + ]: 197 : if (intermediate_result != 0)
1769 : 0 : goto exit_function;
1770 : :
1771 : : /* InChI output: polymer layer */
1772 [ + - ]: 197 : if (npass == 0)
1773 : : {
1774 : 197 : intermediate_result = OutputINCHI_PolymerLayer(pCG, out_file, strbuf,
1775 : : &INCHI_basic_or_INCHI_reconnected,
1776 : : orig_inp_data, pOrigStruct,
1777 : : &io, pLF, pTAB);
1778 [ - + ]: 197 : if (intermediate_result != 0)
1779 : 0 : goto exit_function;
1780 : : }
1781 : :
1782 : : /* InChI output: stereo (non-isotopic) */
1783 [ + + ]: 197 : if (ip->bEnhancedStereo) {
1784 : 47 : intermediate_result = OutputINCHI_StereoLayer_EnhancedStereo( pCG, out_file, strbuf, &io, orig_inp_data, pLF, pTAB );
1785 : : } else {
1786 : 150 : intermediate_result = OutputINCHI_StereoLayer( pCG, out_file, strbuf, &io, pLF, pTAB );
1787 : : }
1788 [ - + ]: 197 : if (intermediate_result != 0)
1789 : 0 : goto exit_function;
1790 : :
1791 : : /* Switch from M to MI or from F to FI */
1792 : 197 : io.nCurINChISegment++;
1793 : :
1794 : : /* InChI output: isotopic */
1795 : 197 : intermediate_result = OutputINCHI_IsotopicLayer(pCG, out_file, strbuf,
1796 : : &INCHI_basic_or_INCHI_reconnected,
1797 : : &io, pLF, pTAB);
1798 : :
1799 [ - + ]: 197 : if (intermediate_result != 0)
1800 : : {
1801 : 0 : goto exit_function;
1802 : : }
1803 : :
1804 : : /*
1805 : : At this point the INChI part of the output has been done.
1806 : : If this INChI is tautomeric and non-tautomeric results exist,
1807 : : then we need to output non-tautomeric data:
1808 : : fixed H
1809 : : stereo
1810 : : isotopic
1811 : : isotopic stereo
1812 : : */
1813 : :
1814 : : /* InChI output: FixedH and sublayers */
1815 : 197 : intermediate_result = OutputINCHI_FixedHLayerWithSublayers(pCG, out_file, strbuf,
1816 : : &INCHI_basic_or_INCHI_reconnected,
1817 : : &io, pLF, pTAB,
1818 : : &then_goto_repeat);
1819 [ - + ]: 197 : if (intermediate_result != 0)
1820 : : {
1821 : 0 : goto exit_function;
1822 : : }
1823 [ - + ]: 197 : if (then_goto_repeat)
1824 : : {
1825 : 0 : npass++;
1826 : 0 : goto repeat_INChI_output;
1827 : : }
1828 : :
1829 : : /*
1830 : : InChI output: reconnected structure
1831 : : */
1832 : :
1833 : 197 : bEmbeddedOutputCalled = 0;
1834 [ + + + - ]: 197 : if (bDisconnectedCoord && INCHI_basic_or_INCHI_reconnected == INCHI_BAS &&
1835 [ + - - + ]: 1 : (bINChIOutputOptions & INCHI_OUT_EMBED_REC) && num_components2[INCHI_REC])
1836 : : {
1837 : : int nRet;
1838 : 0 : bEmbeddedOutputCalled = 1;
1839 : :
1840 : : /* output blank line before /R: in case of bPlainTextCommnts=1 */
1841 : 0 : inchi_ios_print_nodisplay(out_file, "%s", pLF);
1842 : : /* end of disconnected INChI output */
1843 : :
1844 : 0 : nRet = OutputINChI1(pCG,
1845 : : strbuf,
1846 : : pINChISortTautAndNonTaut2,
1847 : : INCHI_REC,
1848 : : orig_inp_data,
1849 : : pOrigStruct,
1850 : : ip,
1851 : : 0 /*bDisconnectedCoord*/,
1852 : : bOutputType,
1853 : : bINChIOutputOptions | INCHI_OUT_NO_AUX_INFO,
1854 : : num_components2,
1855 : : num_non_taut2,
1856 : : num_taut2,
1857 : : out_file,
1858 : : log_file,
1859 : : num_input_struct,
1860 : : pSortPrintINChIFlags,
1861 : : save_opt_bits);
1862 : :
1863 [ # # ]: 0 : if (!nRet)
1864 : : {
1865 : 0 : goto exit_function; /* error */
1866 : : }
1867 : : }
1868 : :
1869 : : /* InChI output: save InChI creation options if requested */
1870 [ + - ]: 197 : if (!bEmbeddedOutputCalled &&
1871 [ - + ]: 197 : (bINChIOutputOptions & INCHI_OUT_SAVEOPT) &&
1872 [ # # ]: 0 : (0 == (bINChIOutputOptions & INCHI_OUT_STDINCHI)) /* not std-InChI output */
1873 : : )
1874 : : {
1875 : : char let1, let2;
1876 : 0 : GetSaveOptLetters(save_opt_bits, &let1, &let2);
1877 : 0 : inchi_ios_print_nodisplay(out_file, "\\%c%c", let1, let2);
1878 : : }
1879 [ + - + - ]: 197 : if (!bEmbeddedOutputCalled && !bPlainTextCommnts)
1880 : : { /* plain text comment earlier ended with LF */
1881 : 394 : inchi_ios_print_nodisplay(out_file, "%s%s",
1882 [ - + - - ]: 197 : (!num_components2[0] && !num_components2[1]) ? "//" : "", /* empty InChI=// */
1883 [ + + ]: 197 : (bINChIOutputOptions & INCHI_OUT_NO_AUX_INFO) ? "\n" : pTAB);
1884 : : /* end of INChI= output */
1885 : : }
1886 : :
1887 : 197 : inchi_strbuf_reset(strbuf);
1888 : :
1889 : : #ifdef TARGET_LIB_FOR_WINCHI
1890 : : /* @@@ Here we end up with silent output: display previously hidden output */
1891 : : if (inchi_ios_flush_not_displayed(out_file) != -1)
1892 : : silent = 0;
1893 : : #endif
1894 : :
1895 : 197 : output_aux_info:
1896 : :
1897 : : /* Output Aux Info */
1898 : :
1899 : 197 : io.bFhTag = 0;
1900 [ + + ]: 197 : if ((bINChIOutputOptions & INCHI_OUT_NO_AUX_INFO) == 0)
1901 : : {
1902 : :
1903 : 184 : io.num_components = io.num_comp[io.iCurTautMode];
1904 : :
1905 : : /* AuxInfo: header and normalization type */
1906 : 184 : intermediate_result = OutputAUXINFO_HeaderAndNormalization_type(pCG, out_file, strbuf,
1907 : : bINChIOutputOptions,
1908 : : &INCHI_basic_or_INCHI_reconnected,
1909 : : num_components2,
1910 : : &io, pLF, pTAB);
1911 [ + - ]: 184 : if (intermediate_result != 0)
1912 : 0 : goto exit_function;
1913 : :
1914 : 184 : repeat_INChI_Aux_output:
1915 : :
1916 : : /* AuxInfo: original atom numbers and symmetry numbers (constit. equivalence /E: ) */
1917 : 184 : intermediate_result = OutputAUXINFO_OriginalNumbersAndEquivalenceClasses(pCG, out_file, strbuf,
1918 : : num_components2,
1919 : : &io, pLF, pTAB);
1920 [ - + ]: 184 : if (intermediate_result != 0)
1921 : 0 : goto exit_function;
1922 : :
1923 : : /* AuxInfo: tautomeric groups equivalence */
1924 : 184 : intermediate_result = OutputAUXINFO_TautomericGroupsEquivalence(pCG, out_file, strbuf, &io);
1925 [ - + ]: 184 : if (intermediate_result != 0)
1926 : 0 : goto exit_function;
1927 : :
1928 : : /* AuxInfo: stereo data */
1929 : 184 : intermediate_result = OutputAUXINFO_Stereo(pCG, out_file, strbuf, &io, pLF, pTAB);
1930 [ + - ]: 184 : if (intermediate_result != 0)
1931 : 0 : goto exit_function;
1932 : :
1933 : 184 : repeat_INChI_Aux_Iso_output:
1934 : : /* AuxInfo: isotopic info */
1935 : 184 : intermediate_result = OutputAUXINFO_IsotopicInfo(pCG, out_file, strbuf,
1936 : : &INCHI_basic_or_INCHI_reconnected,
1937 : : &io, pLF, pTAB);
1938 [ - + ]: 184 : if (intermediate_result != 0)
1939 : : {
1940 : 0 : goto exit_function;
1941 : : }
1942 : :
1943 : : /*
1944 : : At this point the INChI_Aux part of the output has been completed.
1945 : : If this INChI is tautomeric and non-tautomeric results exist,
1946 : : then we need to output non-tautomeric auxilialy data
1947 : : (same as above excluding tautomeric information).
1948 : : Currently, this is enabled for xml output only
1949 : : */
1950 : :
1951 [ + - + + : 184 : if (io.bOutType == OUT_TN && io.bTautomeric && io.bNonTautomeric &&
- + ]
1952 : : /* Check whether the Fixed-H layer is empty */
1953 [ # # # # ]: 0 : (*pSortPrintINChIFlags & ((INCHI_basic_or_INCHI_reconnected == INCHI_BAS) ? FLAG_SORT_PRINT_NO_NFIX_H_BAS : FLAG_SORT_PRINT_NO_NFIX_H_REC)) &&
1954 [ # # # # ]: 0 : (*pSortPrintINChIFlags & ((INCHI_basic_or_INCHI_reconnected == INCHI_BAS) ? FLAG_SORT_PRINT_NO_IFIX_H_BAS : FLAG_SORT_PRINT_NO_IFIX_H_REC)))
1955 : : {
1956 : 0 : io.bNonTautomeric = 0; /* bNonTautIdentifierNotEmpty == 0 => no fixed H info 02-10-2995 */
1957 : : }
1958 : :
1959 [ + - + + : 184 : if (io.bOutType == OUT_TN && io.bTautomeric && io.bNonTautomeric)
- + ]
1960 : : {
1961 : : /* add the second (non-tautomeric) output */
1962 : 0 : io.bOutType = OUT_NONTAUT;
1963 : 0 : io.iCurTautMode = TAUT_NON;
1964 : 0 : io.pINChISort = io.pINChISortTautAndNonTaut[TAUT_NON];
1965 : 0 : io.bSecondNonTautPass = 1;
1966 : 0 : io.num_components = io.num_comp[io.iCurTautMode];
1967 : 0 : io.bFhTag = AL_FIXH;
1968 : 0 : inchi_strbuf_reset(strbuf); /*pStr[io.tot_len=0] = '\0';*/
1969 : :
1970 : : /* if InChI Fixed-H isotopic is empty then do not output corresponding AuxInfo */
1971 [ # # ]: 0 : if (!(*pSortPrintINChIFlags &
1972 [ # # ]: 0 : ((INCHI_basic_or_INCHI_reconnected == INCHI_BAS) ? FLAG_SORT_PRINT_NO_NFIX_H_BAS : FLAG_SORT_PRINT_NO_NFIX_H_REC)))
1973 : : {
1974 : 0 : npass++;
1975 : 0 : goto repeat_INChI_Aux_output;
1976 : : }
1977 : : else
1978 : : {
1979 : 0 : npass++;
1980 : 0 : goto repeat_INChI_Aux_Iso_output;
1981 : : }
1982 : : }
1983 : : else
1984 : : {
1985 [ - + - - : 184 : if (io.bOutType == OUT_NONTAUT && io.bOutputType == OUT_TN && io.bTautomeric && io.bNonTautomeric)
- - - - ]
1986 : : {
1987 : : /* the second (non-taut) output has been done; restore variables */
1988 : 0 : io.bOutType = OUT_TN;
1989 : 0 : io.iCurTautMode = TAUT_YES;
1990 : 0 : io.pINChISort = io.pINChISortTautAndNonTaut[TAUT_YES];
1991 : 0 : io.bSecondNonTautPass = 0;
1992 : : /* set correct num components for the reversibility info 02-10-2005 */
1993 : 0 : io.num_components = io.num_comp[io.iCurTautMode];
1994 : 0 : io.bFhTag = 0;
1995 : : }
1996 : : }
1997 : :
1998 : : /* Charges, radicals, unusual valences */
1999 : 184 : intermediate_result = OutputAUXINFO_ChargesRadicalsAndUnusualValences(pCG, out_file, strbuf, &io, pLF, pTAB);
2000 [ - + ]: 184 : if (intermediate_result != 0)
2001 : : {
2002 : 0 : goto exit_function;
2003 : : }
2004 : :
2005 : : /* Output the original input structure -- quick fix */
2006 : 184 : intermediate_result = OutputAUXINFO_ReversibilityInfo(pCG, out_file, strbuf, pOrigStruct, &io, pLF, pTAB);
2007 [ - + ]: 184 : if (intermediate_result != 0)
2008 : : {
2009 : 0 : goto exit_function;
2010 : : }
2011 : :
2012 : : /* Output polymeric Aux Info */
2013 : 184 : intermediate_result = OutputAUXINFO_PolymerInfo(pCG, out_file, strbuf, pOrigStruct, &io, pLF, pTAB);
2014 [ - + ]: 184 : if (intermediate_result != 0)
2015 : : {
2016 : 0 : goto exit_function;
2017 : : }
2018 : :
2019 : : /*
2020 : : Output INChI_Aux of the reconnected structure
2021 : : */
2022 : :
2023 : 184 : bEmbeddedOutputCalled = 0;
2024 [ + + + - : 184 : if (bDisconnectedCoord && INCHI_basic_or_INCHI_reconnected == INCHI_BAS && (bINChIOutputOptions & INCHI_OUT_EMBED_REC) &&
+ - ]
2025 [ - + - - ]: 1 : num_components2[INCHI_REC] && !(bINChIOutputOptions & INCHI_OUT_NO_AUX_INFO))
2026 : : {
2027 : : int nRet;
2028 : 0 : bEmbeddedOutputCalled = 1;
2029 : 0 : inchi_ios_print(out_file, "%s", pLF);
2030 : :
2031 : 0 : nRet = OutputINChI1(pCG,
2032 : : strbuf,
2033 : : pINChISortTautAndNonTaut2,
2034 : : INCHI_REC,
2035 : : NULL,
2036 : : NULL,
2037 : : ip,
2038 : : 0 /*bDisconnectedCoord*/,
2039 : : bOutputType,
2040 : : INCHI_OUT_ONLY_AUX_INFO | bINChIOutputOptions,
2041 : : num_components2,
2042 : : num_non_taut2,
2043 : : num_taut2,
2044 : : out_file,
2045 : : log_file,
2046 : : num_input_struct,
2047 : : pSortPrintINChIFlags,
2048 : : save_opt_bits);
2049 : :
2050 [ # # ]: 0 : if (!nRet)
2051 : : {
2052 : 0 : goto exit_function; /* error */
2053 : : }
2054 : : }
2055 : :
2056 : : /* Close INChI_Aux */
2057 [ + - + - ]: 184 : if (!bEmbeddedOutputCalled && !bPlainTextCommnts)
2058 : : {
2059 [ - + - - ]: 184 : inchi_ios_print(out_file, "%s\n", (!num_components2[0] && !num_components2[1]) ? "//" : "");
2060 : : /* plain text comment earlier ended with LF */
2061 : : }
2062 : :
2063 : : /* in wINChI window, separate AuxInfo: from InChIKey: with blank line */
2064 : 184 : inchi_ios_print(out_file, "%s",
2065 [ - + ]: 184 : (bINChIOutputOptions & INCHI_OUT_WINCHI_WINDOW) ? "\n" : "");
2066 : : } /* end of output AuxInfo */
2067 : :
2068 : 197 : ret = 1;
2069 : :
2070 : 197 : exit_function:
2071 : :
2072 : : #ifdef TARGET_LIB_FOR_WINCHI
2073 : : /* @@@ If for any error we get here silent, display previously hidden output */
2074 : : if (silent)
2075 : : {
2076 : : /*
2077 : : if ( !inchi_ios_flush_not_displayed( out_file ) != -1 )
2078 : : silent = 0;
2079 : : */
2080 : : silent = 0;
2081 : : }
2082 : : #endif
2083 : :
2084 [ - + ]: 197 : if (io.bOverflow)
2085 : : {
2086 : 0 : inchi_ios_print(out_file, "\nFATAL ERROR: Output buffer overflow\n");
2087 : : }
2088 : :
2089 [ - + ]: 197 : if (intermediate_result)
2090 : : {
2091 : 0 : ret = 0;
2092 : 0 : inchi_ios_eprint(log_file, "InChI serialization error for structure #%d.%s%s%s%s\n",
2093 [ # # # # : 0 : num_input_struct, SDF_LBL_VAL(ip->pSdfLabel, ip->pSdfValue));
# # # # #
# # # # #
# # # # #
# # # #
# ]
2094 : : }
2095 : :
2096 : 197 : return ret;
2097 : : } /* OutputINChI1 */
2098 : :
2099 : : /****************************************************************************/
2100 : 2276 : char *szGetTag(const INCHI_TAG *Tag,
2101 : : int nTag,
2102 : : int bTag,
2103 : : char *szTag,
2104 : : int *bAlways,
2105 : : short tag_flag)
2106 : : {
2107 : : int i, j, bit, num, len;
2108 [ + + ]: 2276 : const int MAX_TAG_NUM = tag_flag ? (int)IL_MAX_ORD : (int)AL_MAX_ORD; /* djb-rwth: fixing GHI #160 */
2109 [ + - + - ]: 2276 : if (0 < nTag && nTag < 3)
2110 : : {
2111 : : /* no plain text comments: pick up the last tag */
2112 [ + + ]: 44060 : for (i = 0, j = -1, bit = 1; i < MAX_TAG_NUM; i++, bit <<= 1)
2113 : : {
2114 [ + + ]: 41784 : if (bTag & bit)
2115 : : {
2116 : 3057 : j = i;
2117 : : }
2118 : : }
2119 [ + - ]: 2276 : if (j >= 0)
2120 : : {
2121 : : #if USE_BCF
2122 : : int stl1, stl2, dstsz;
2123 : : stl1 = strlen(Tag[j].szXmlLabel) + 1;
2124 : : stl2 = strlen(Tag[j].szPlainLabel) + 1;
2125 : : dstsz = max_3(stl1, stl2, 5);
2126 : : strcpy_s(szTag, dstsz, nTag == 1 ? Tag[j].szXmlLabel : nTag == 2 ? Tag[j].szPlainLabel
2127 : : : "???"); /* djb-rwth: function replaced with its safe C11 variant */
2128 : : #else
2129 [ - + + - ]: 2276 : strcpy(szTag, nTag == 1 ? Tag[j].szXmlLabel : nTag == 2 ? Tag[j].szPlainLabel : "???"); /* djb-rwth: addressing coverity ID #499488 -- when nTag == 2, the "???" is avoided, which is correct */
2130 : : #endif
2131 [ - + ]: 2276 : if (nTag != 2)
2132 : : {
2133 : 0 : *bAlways = Tag[j].bAlwaysOutput;
2134 : : }
2135 : 2276 : return szTag;
2136 : : }
2137 : : }
2138 [ # # ]: 0 : else if (nTag == 3)
2139 : : {
2140 : : /* plain text with comments */
2141 : 0 : szTag[0] = '{';
2142 : 0 : szTag[1] = '\0';
2143 [ # # ]: 0 : for (i = 0, j = -1, bit = 1, num = 0; i < MAX_TAG_NUM; i++, bit <<= 1)
2144 : : {
2145 [ # # ]: 0 : if (bTag & bit)
2146 : : {
2147 : 0 : j = i;
2148 [ # # ]: 0 : if (num++)
2149 : : {
2150 : 0 : strcat(szTag, ":");
2151 : : }
2152 : 0 : strcat(szTag, Tag[i].szPlainComment);
2153 : : }
2154 : : }
2155 [ # # ]: 0 : if (num)
2156 : : {
2157 : 0 : strcat(szTag, "}");
2158 : 0 : num = (int)strlen(Tag[j].szPlainLabel);
2159 : 0 : len = (int)strlen(szTag);
2160 [ # # ]: 0 : if (len)
2161 : : {
2162 : 0 : memmove(szTag + num, szTag, (long long)len + 1); /* djb-rwth: cast operator added */
2163 : 0 : memcpy(szTag, Tag[j].szPlainLabel, num);
2164 : : }
2165 : : else
2166 : : {
2167 : 0 : strcpy(szTag, Tag[j].szPlainLabel);
2168 : : }
2169 : 0 : *bAlways = Tag[j].bAlwaysOutput;
2170 : : }
2171 : : else
2172 : : {
2173 : 0 : strcpy(szTag, "???");
2174 : : }
2175 : 0 : return szTag;
2176 : : }
2177 : :
2178 : 0 : strcpy(szTag, "???");
2179 : 0 : return szTag;
2180 : : }
2181 : :
2182 : : /* djb-rwth: removing redundant code */
2183 : :
2184 : : /****************************************************************************
2185 : : str_LineEnd( ... )
2186 : :
2187 : : First, checks if buffer overflow; then:
2188 : : if ind < 0 (common usage, plain text output)
2189 : : sets terminating '\0' in pStr,
2190 : : optionally adds leading tag (e.g., '/' or "/c" )
2191 : : *obsolete* if ind >=0 XML output
2192 : :
2193 : : ****************************************************************************/
2194 : 1354 : int str_LineEnd(const char *tag,
2195 : : int *bOverflow,
2196 : : INCHI_IOS_STRING *buf,
2197 : : int ind,
2198 : : int bPlainTextTags)
2199 : : {
2200 : : /* djb-rwth: removing redundant variables */
2201 : : int tag_len;
2202 : :
2203 : : /* check buffer overflow */
2204 [ - + ]: 1354 : if (*bOverflow)
2205 : : {
2206 : 0 : return 1;
2207 : : }
2208 : :
2209 [ + - ]: 1354 : if (ind < 0)
2210 : : {
2211 : : /* Plain text */
2212 : : /* insert plain text tag if:
2213 : : (a) pStr has non-zero length, or
2214 : : (b) ind < -1
2215 : : */
2216 [ + + - + ]: 1354 : if (buf->pStr[0] || ind < -1)
2217 : : {
2218 [ + - ]: 1352 : tag_len = bPlainTextTags ? (int)strlen(tag) : 0;
2219 [ + + ]: 1352 : if (tag_len > 0)
2220 : : {
2221 : 1168 : int n_added = tag_len + 2 + 2;
2222 : 1168 : inchi_strbuf_update(buf, n_added);
2223 : :
2224 : 1168 : memmove(buf->pStr + tag_len, buf->pStr, (long long)buf->nUsedLength + 1); /* djb-rwth: cast operator added */
2225 : : /* NB: trailing 0 is also memmoved */
2226 : 1168 : memcpy(buf->pStr, tag, tag_len);
2227 : :
2228 : : /* to be sure... */
2229 : 1168 : buf->nUsedLength = strlen(buf->pStr);
2230 : : }
2231 : : }
2232 : : }
2233 : :
2234 : 1354 : return 0;
2235 : : }
2236 : :
2237 : : /****************************************************************************/
2238 : 18716 : int CleanOrigCoord(MOL_COORD szCoord, int delim)
2239 : : {
2240 : : #define MIN_BOND_LENGTH (1.0e-6)
2241 : : char szVal[LEN_COORD + 1];
2242 : : MOL_COORD szBuf;
2243 : : char *q;
2244 : 18716 : int len, last, fst, dec_pnt, num_zer = 0, len_buf = 0, e;
2245 : : int k, i;
2246 : : double coord;
2247 : :
2248 [ + + ]: 74864 : for (k = 0; k < NUM_COORD * LEN_COORD; k += LEN_COORD)
2249 : : {
2250 : 56148 : memcpy(szVal, szCoord + k, LEN_COORD);
2251 : 56148 : szVal[LEN_COORD] = '\0';
2252 : 56148 : lrtrim(szVal, &len);
2253 : 56148 : coord = inchi_strtod(szVal, (const char **)&q); /* GH #100 */
2254 [ + + ]: 56148 : if (MIN_BOND_LENGTH > fabs(coord))
2255 : : {
2256 : 33358 : strcpy(szVal, "0");
2257 : 33358 : len = 1;
2258 : 33358 : num_zer++;
2259 : : }
2260 : : else
2261 : : {
2262 : 22790 : len = (int)(q - szVal);
2263 : : /* last = (last mantissa digit position + 1) */
2264 [ + + + - ]: 22790 : if ((q = strchr(szVal, 'e')) || (q = strchr(szVal, 'E')) ||
2265 [ + - - + ]: 22786 : (q = strchr(szVal, 'd')) || (q = strchr(szVal, 'D')))
2266 : : {
2267 : : /* floating point */
2268 : 4 : last = q - szVal;
2269 : : /* remove (+) and leading zeroes from the exponent */
2270 : 4 : e = (int)strtol(szVal + last + 1, &q, 10); /* exponent */
2271 [ + + ]: 4 : if (e)
2272 : : {
2273 : : /* new exp; update the length */
2274 : 2 : len = last + 1 + sprintf(szVal + last + 1, "%d", e); /* print exp without leading zeroes and '+' */
2275 : : }
2276 : : else
2277 : : {
2278 : : /* exponent is zero */
2279 : 2 : len = last;
2280 : : }
2281 : : }
2282 : : else
2283 : : {
2284 : 22786 : last = len;
2285 : : }
2286 : : /* fst = (first mantissa digit); fst=1 if the sign is present, otherwise 0 */
2287 [ + - + + ]: 22790 : fst = (szVal[0] != '.' && !isdigit(UCINT szVal[0]));
2288 : : /* dec_pnt = (decimal point position) or last */
2289 [ + + ]: 22790 : if ((q = strchr(szVal, '.'))) /* djb-rwth: addressing LLVM warning */
2290 : : {
2291 : 14756 : dec_pnt = (int)(q - szVal);
2292 : : }
2293 : : else
2294 : : {
2295 : 8034 : dec_pnt = last;
2296 : : }
2297 : 22790 : last -= 1; /* last mantissa digit position */
2298 : : /* remove trailing zeroes in the range dec_pnt+1..last-1 */
2299 [ + + + + ]: 24739 : for (i = last; dec_pnt < i && '0' == szVal[i]; i--)
2300 : : ;
2301 [ + + ]: 22790 : if (i == dec_pnt)
2302 : : {
2303 : 328 : i--; /* remove decimal point, too */
2304 : : }
2305 [ + + ]: 22790 : if (i < last)
2306 : : {
2307 : 627 : memmove(szVal + i + 1, szVal + last + 1, (long long)len - (long long)last); /* djb-rwth: cast operator added */
2308 : 627 : len -= last - i;
2309 : : }
2310 : : /* remove leading zeroes */
2311 [ + - + + ]: 25719 : for (i = fst; i < len && '0' == szVal[i]; i++)
2312 : : {
2313 : : ;
2314 : : }
2315 [ + + + - : 22790 : if ((i > fst) && (len - fst <= LEN_COORD + 1 - i) && (len - fst <= LEN_COORD + 1 - fst)) /* djb-rwth: fixing GHI #138 */
+ - ]
2316 : : {
2317 : 2929 : memmove(szVal + fst, szVal + i, (long long)len - (long long)fst); /* djb-rwth: cast operator added */
2318 : 2929 : len -= i - fst;
2319 : : }
2320 : : }
2321 [ + + + - ]: 56148 : if (len_buf && (len_buf < (int)sizeof(MOL_COORD)))
2322 : : {
2323 : : #pragma warning(push)
2324 : : #pragma warning(disable : 6386)
2325 : 37432 : szBuf[len_buf++] = delim;
2326 : : #pragma warning(pop)
2327 : : }
2328 [ - + ]: 56148 : if (len_buf >= (int)sizeof(MOL_COORD)) /* djb-rwth: fixing coverity ID #499520 */
2329 : : {
2330 : 0 : len_buf = (int)sizeof(MOL_COORD) - 1;
2331 : 0 : len = 0;
2332 : : }
2333 : 56148 : memcpy(szBuf + len_buf, szVal, len); /* does not copy zero termination*/
2334 : 56148 : len_buf += len;
2335 : : }
2336 : : /* zero termination */
2337 [ + - ]: 18716 : if (len_buf < (int)sizeof(MOL_COORD))
2338 : : {
2339 : 18716 : memset(szBuf + len_buf, 0, sizeof(MOL_COORD) - len_buf); /* djb-rwth: memset_s C11/Annex K variant? */
2340 : : }
2341 : :
2342 : 18716 : memcpy(szCoord, szBuf, sizeof(MOL_COORD));
2343 : :
2344 : 18716 : return num_zer;
2345 : : #undef MIN_BOND_LENGTH
2346 : : }
2347 : :
2348 : : /****************************************************************************/
2349 : 791 : int WriteOrigCoord(int num_inp_atoms,
2350 : : MOL_COORD *szMolCoord,
2351 : : int *i,
2352 : : char *szBuf,
2353 : : int buf_len)
2354 : : {
2355 : :
2356 : : int j, num_zer, len, cur_len;
2357 : : char *p;
2358 : : MOL_COORD szCurCoord;
2359 : 791 : cur_len = 0;
2360 [ + + ]: 19277 : for (j = *i; j < num_inp_atoms;)
2361 : : {
2362 : 18716 : memcpy(szCurCoord, szMolCoord[j], sizeof(szCurCoord));
2363 : 18716 : num_zer = CleanOrigCoord(szCurCoord, ',');
2364 [ + + ]: 18716 : if (NUM_COORD == num_zer)
2365 : : {
2366 : 190 : len = 0;
2367 : : }
2368 : : else
2369 : : {
2370 [ + - ]: 18526 : if ((p = (char *)memchr(szCurCoord, '\0', sizeof(szCurCoord)))) /* djb-rwth: addressing LLVM warning */
2371 : : {
2372 : 18526 : len = (int)(p - szCurCoord);
2373 : : }
2374 : : else
2375 : : {
2376 : 0 : len = sizeof(szCurCoord);
2377 : : }
2378 : : }
2379 [ + + ]: 18716 : if (len + cur_len + 1 < buf_len)
2380 : : {
2381 [ + + ]: 18486 : if (len)
2382 : : {
2383 : 18296 : memcpy(szBuf + cur_len, szCurCoord, len * sizeof(szBuf[0]));
2384 : : }
2385 : 18486 : szBuf[cur_len += len] = ';';
2386 : 18486 : cur_len++;
2387 : 18486 : j++;
2388 : : }
2389 : : else
2390 : : {
2391 : 230 : break;
2392 : : }
2393 : : }
2394 : 791 : szBuf[cur_len] = '\0';
2395 : 791 : *i = j; /* next item */
2396 : :
2397 : 791 : return cur_len;
2398 : : }
2399 : :
2400 : : /****************************************************************************
2401 : : WriteOrigAtoms
2402 : :
2403 : : number of atoms
2404 : : [c|n] chiral/nonchiral
2405 : :
2406 : : Element
2407 : : #valence
2408 : : +/-[charge>1]
2409 : : .#rad (#rad=1, 2, 3: singlet, doulet, triplet)
2410 : : [.]i#iso_mass
2411 : : [.]{o|e|u|?} atom parity = {1:2:3:4}
2412 : : [.]h[#of 1H>1]
2413 : : [.]d[#of 2H>1]
2414 : : [.]t[#of 3H>1]
2415 : :
2416 : : Note: . occurs only once and only if radical or 1-character element
2417 : : ****************************************************************************/
2418 : 586 : int WriteOrigAtoms(CANON_GLOBALS *pCG,
2419 : : int num_inp_atoms,
2420 : : inp_ATOM *at,
2421 : : int *i,
2422 : : char *szBuf,
2423 : : int buf_len,
2424 : : STRUCT_DATA *sd)
2425 : : {
2426 : : int j, k, n, len, len0, cur_len, val, bonds_val, mw, parity, num_trans, is_ok, b_self;
2427 : : static const char szIsoH[] = "hdt";
2428 : : char szCurAtom[32];
2429 : : AT_NUMB nNeighOrder[MAXVAL], neigh;
2430 : :
2431 : 586 : cur_len = 0;
2432 [ + + ]: 586 : if (0 == *i)
2433 : : {
2434 : 380 : cur_len = sprintf(szBuf, "%d%s", num_inp_atoms,
2435 [ + + ]: 380 : (sd->bChiralFlag & FLAG_INP_AT_CHIRAL) ? "c" : (sd->bChiralFlag & FLAG_INP_AT_NONCHIRAL) ? "n"
2436 [ + + ]: 362 : : "");
2437 : : }
2438 [ + + ]: 19088 : for (j = *i; j < num_inp_atoms;)
2439 : : {
2440 : : /* tetrahedral parity treatment */
2441 : 18518 : parity = 0;
2442 : 18518 : num_trans = 0;
2443 [ - + ]: 18518 : if (at[j].p_parity)
2444 : : {
2445 : : /* verify neighbors */
2446 : 0 : is_ok = 1;
2447 : 0 : b_self = 0;
2448 [ # # ]: 0 : for (n = 0, k = 0; n < MAX_NUM_STEREO_ATOM_NEIGH; n++)
2449 : : {
2450 : 0 : neigh = at[j].p_orig_at_num[n] - 1;
2451 [ # # ]: 0 : if (is_in_the_list(at[j].neighbor, neigh, at[j].valence) &&
2452 [ # # ]: 0 : at[neigh].orig_at_number == at[j].p_orig_at_num[n])
2453 : : {
2454 : : /* real neighbor */
2455 : 0 : nNeighOrder[k++] = at[j].p_orig_at_num[n];
2456 : : }
2457 : : else
2458 : : {
2459 [ # # # # ]: 0 : if ((int)neigh == j && at[neigh].orig_at_number == at[j].p_orig_at_num[n])
2460 : : {
2461 : : /* central atom is a neighbor */
2462 : 0 : num_trans = n; /* move this neighbor to 0 position permutation parity */
2463 : 0 : b_self++;
2464 : : }
2465 : : else
2466 : : {
2467 : 0 : is_ok = 0;
2468 : 0 : break;
2469 : : }
2470 : : }
2471 : : }
2472 [ # # # # : 0 : if (is_ok && b_self <= 1 && b_self + k == MAX_NUM_STEREO_ATOM_NEIGH)
# # ]
2473 : : {
2474 : 0 : num_trans += insertions_sort(pCG, nNeighOrder, k, sizeof(nNeighOrder[0]), comp_AT_RANK);
2475 [ # # # # ]: 0 : if (ATOM_PARITY_WELL_DEF(at[j].p_parity))
2476 : : {
2477 : 0 : parity = 2 - (num_trans + at[j].p_parity) % 2;
2478 : : }
2479 : : else
2480 : : {
2481 [ # # # # ]: 0 : if (ATOM_PARITY_ILL_DEF(at[j].p_parity))
2482 : : {
2483 : 0 : parity = at[j].p_parity;
2484 : : }
2485 : : else
2486 : : {
2487 : : ; /* invalid atom parity */
2488 : : }
2489 : : }
2490 : : }
2491 : : else
2492 : : {
2493 : : ; /* add error message here */
2494 : : }
2495 : : }
2496 : :
2497 : 18518 : len = len0 = (int)strlen(at[j].elname);
2498 : :
2499 : 18518 : memcpy(szCurAtom, at[j].elname, len);
2500 : 18518 : bonds_val = nBondsValenceInpAt(at + j, NULL, NULL);
2501 : :
2502 [ + + ]: 18518 : if ((val = needed_unusual_el_valence(at[j].el_number, at[j].charge, at[j].radical,
2503 : 18518 : at[j].chem_bonds_valence, bonds_val, at[j].num_H, at[j].valence)) ||
2504 [ + + + - : 18440 : at[j].charge || at[j].radical || at[j].iso_atw_diff || NUM_ISO_H(at, j) || parity)
+ + + - -
+ ]
2505 : : {
2506 : : /* valence */
2507 [ + + ]: 150 : if (val)
2508 : : {
2509 : 78 : len += sprintf(szCurAtom + len, "%d", val > 0 ? val : 0);
2510 : : }
2511 : : /* charge */
2512 [ + + ]: 150 : if ((val = at[j].charge)) /* djb-rwth: addressing LLVM warning */
2513 : : {
2514 [ + + ]: 98 : szCurAtom[len++] = val > 0 ? '+' : '-';
2515 [ + + ]: 98 : if ((val = abs(val)) > 1)
2516 : : {
2517 : 20 : len += sprintf(szCurAtom + len, "%d", val);
2518 : : }
2519 : : }
2520 : : /* radical */
2521 [ - + ]: 150 : if ((val = at[j].radical)) /* djb-rwth: addressing LLVM warning */
2522 : : {
2523 : 0 : len += sprintf(szCurAtom + len, ".%d", val);
2524 : : }
2525 : : /* isotopic shift */
2526 [ + + ]: 150 : if ((val = at[j].iso_atw_diff)) /* djb-rwth: addressing LLVM warning */
2527 : : {
2528 : 16 : mw = get_atomic_mass_from_elnum(at[j].el_number);
2529 [ - + ]: 16 : if (val == 1)
2530 : 0 : val = mw;
2531 [ + + ]: 16 : else if (val > 0)
2532 : 12 : val = mw + val - 1;
2533 : : else
2534 : 4 : val = mw + val;
2535 : :
2536 [ + + ]: 16 : len += sprintf(szCurAtom + len, "%si%d", len == len0 ? "." : "", val);
2537 : : }
2538 : : /* parity */
2539 [ - + ]: 150 : if (parity)
2540 : : {
2541 [ # # # # ]: 0 : len += sprintf(szCurAtom + len, "%s%s", len == len0 ? "." : "",
2542 : : parity == AB_PARITY_ODD ? "o" : parity == AB_PARITY_EVEN ? "e"
2543 [ # # ]: 0 : : parity == AB_PARITY_UNKN ? "u"
2544 [ # # ]: 0 : : parity == AB_PARITY_UNDF ? "?"
2545 [ # # ]: 0 : : "");
2546 : : }
2547 : : /* implicit isotopic H */
2548 [ - + ]: 150 : if (NUM_ISO_H(at, j))
2549 : : {
2550 [ # # ]: 0 : for (k = 0; k < NUM_H_ISOTOPES; k++)
2551 : : {
2552 [ # # ]: 0 : if ((val = at[j].num_iso_H[k])) /* djb-rwth: addressing LLVM warning */
2553 : : {
2554 [ # # ]: 0 : len += sprintf(szCurAtom + len, "%s%c", len == len0 ? "." : "", szIsoH[k]);
2555 [ # # ]: 0 : if (val > 1)
2556 : : {
2557 : 0 : len += sprintf(szCurAtom + len, "%d", val);
2558 : : }
2559 : : }
2560 : : }
2561 : : }
2562 : : }
2563 : :
2564 [ + + ]: 18518 : if (len + cur_len < buf_len)
2565 : : {
2566 : 18502 : memcpy(szBuf + cur_len, szCurAtom, len);
2567 : 18502 : cur_len += len;
2568 : 18502 : j++;
2569 : : }
2570 : : else
2571 : : {
2572 : 16 : break;
2573 : : }
2574 : 18502 : szBuf[cur_len] = '\0';
2575 : 18502 : *i = j;
2576 : : }
2577 : :
2578 : 586 : return cur_len;
2579 : : }
2580 : :
2581 : : /****************************************************************************
2582 : : WriteOrigBonds( ... )
2583 : :
2584 : : Output bonds in ascending order of the neighboring atom original numbers
2585 : :
2586 : : <bonds> bpA;bpAbpA... </bonds>
2587 : :
2588 : : b = bond type:
2589 : : =============
2590 : : w = undefined stereo, double
2591 : : s = single
2592 : : d = double
2593 : : t = triple
2594 : : a = aromatic
2595 : : p = up from the current atom to the neighbor
2596 : : P = uP from the neighbor to the current atom
2597 : : v = undefined stereo Either, single from the current atom to the neighbor
2598 : : V = undefined stereo Either, single from the neighbor to the current atom
2599 : : n = down from the current atom to the neighbor
2600 : : N = dowN from the neighbor to the current atom
2601 : :
2602 : : p = bond parity:
2603 : : ================
2604 : : - = odd
2605 : : + = even
2606 : : u = unknown
2607 : : ? = undefined
2608 : : = no parity (empty)
2609 : :
2610 : :
2611 : : A = neighbor orig. atom number
2612 : : ===============
2613 : : neighbor orig. atom number < number of the current atom
2614 : : Number of the current atom: 2 until first ";", 3 until 2nd ";", etc.
2615 : : ****************************************************************************/
2616 : 611 : int WriteOrigBonds(CANON_GLOBALS *pCG,
2617 : : int num_inp_atoms,
2618 : : inp_ATOM *at,
2619 : : int *i,
2620 : : char *szBuf,
2621 : : int buf_len,
2622 : : STRUCT_DATA *sd)
2623 : : {
2624 : 611 : int j, k, k2, kk, len, cur_len, j2 = 0, bond_stereo, bond_char, bond_parity, bond_parityNM, num_trans; /* djb-rwth: ignoring LLVM warning: variable used to store function return value */
2625 : : char szCurBonds[7 * MAXVAL + 2]; /* num_neigh*(1 byte bond type + 2 bytes for bond parity up to 4 digits per neighbor number) + at the end one ';' */
2626 : : AT_RANK nNeighOrder[MAXVAL];
2627 : : int chain_len, pnxt_atom, pinxt2cur, pinxt_sb_parity_ord;
2628 : : int chain_len2, pnxt_atom2, pinxt2cur2, pinxt_sb_parity_ord2, m1, m2;
2629 : : int pcur_atom, picur2nxt, picur_sb_parity_ord;
2630 : :
2631 : 611 : cur_len = 0;
2632 [ + + ]: 18733 : for (j = *i; j < num_inp_atoms;)
2633 : : {
2634 : 18215 : len = 0;
2635 [ + + ]: 18215 : if (at[j].valence >= 1) /* djb-rwth: changing condition to avoid garbage values */
2636 : : {
2637 [ + + ]: 48385 : for (k = 0; k < at[j].valence; k++)
2638 : : {
2639 : 32186 : nNeighOrder[k] = k;
2640 : : }
2641 : 16199 : pCG->m_pn_RankForSort = at[j].neighbor;
2642 : 16199 : num_trans = insertions_sort(pCG, nNeighOrder, at[j].valence, sizeof(nNeighOrder[0]), CompRank); /* djb-rwth: ignoring LLVM warning: variable used to store function return value */
2643 : : }
2644 : : else
2645 : : {
2646 : 2016 : num_trans = 0; /* djb-rwth: ignoring LLVM warning: variable used to store function return value */
2647 : 2016 : nNeighOrder[0] = 0;
2648 : : }
2649 [ + + ]: 50401 : for (kk = 0; kk < at[j].valence; kk++)
2650 : : {
2651 : 32186 : k = nNeighOrder[kk];
2652 : 32186 : j2 = at[j].neighbor[k];
2653 : 32186 : bond_parity = 0;
2654 : 32186 : bond_parityNM = 0;
2655 [ + + ]: 32186 : if (j2 < j)
2656 : : {
2657 : 16277 : bond_stereo = at[j].bond_stereo[k];
2658 [ + + + - : 16277 : switch (at[j].bond_type[k])
+ ]
2659 : : {
2660 : 16113 : case BOND_TYPE_SINGLE:
2661 [ + + - + : 16113 : switch (bond_stereo)
- - + ]
2662 : : {
2663 : 28 : case STEREO_SNGL_UP:
2664 : 28 : bond_char = 'p';
2665 : 28 : break;
2666 : 298 : case -STEREO_SNGL_UP:
2667 : 298 : bond_char = 'P';
2668 : 298 : break;
2669 : 0 : case STEREO_SNGL_DOWN:
2670 : 0 : bond_char = 'n';
2671 : 0 : break;
2672 : 70 : case -STEREO_SNGL_DOWN:
2673 : 70 : bond_char = 'N';
2674 : 70 : break;
2675 : : #if (FIX_EITHER_STEREO_IN_AUX_INFO == 1)
2676 : 0 : case STEREO_SNGL_EITHER:
2677 : 0 : bond_char = 'v';
2678 : 0 : break;
2679 : 0 : case -STEREO_SNGL_EITHER:
2680 : 0 : bond_char = 'V';
2681 : 0 : break;
2682 : : #else
2683 : : case STEREO_SNGL_EITHER:
2684 : : case -STEREO_SNGL_EITHER:
2685 : : bond_char = 'v';
2686 : : break;
2687 : : #endif
2688 : 15717 : default:
2689 : 15717 : bond_char = 's';
2690 : 15717 : break;
2691 : : }
2692 : 16113 : break;
2693 : 114 : case BOND_TYPE_DOUBLE:
2694 [ + + ]: 114 : switch (bond_stereo)
2695 : : {
2696 : 2 : case STEREO_DBLE_EITHER:
2697 : : case -STEREO_DBLE_EITHER:
2698 : 2 : bond_char = 'w';
2699 : 2 : break;
2700 : 112 : default:
2701 : 112 : bond_char = 'd';
2702 : 112 : break;
2703 : : }
2704 : 114 : break;
2705 : 4 : case BOND_TYPE_TRIPLE:
2706 : 4 : bond_char = 't';
2707 : 4 : break;
2708 : 0 : case BOND_TYPE_ALTERN:
2709 : 0 : bond_char = 'a';
2710 : 0 : break;
2711 : 46 : default:
2712 : 46 : bond_char = 's';
2713 : 46 : break;
2714 : : }
2715 : : /* check for allene/cumulene */
2716 : 16277 : k2 = (int)(is_in_the_list(at[j2].neighbor, (AT_NUMB)j, at[j2].valence) - at[j2].neighbor);
2717 : 16277 : chain_len = chain_len2 = 0;
2718 [ - + ]: 16277 : if (at[j].sb_parity[0])
2719 : : {
2720 [ # # # # ]: 0 : for (m1 = 0; m1 < MAX_NUM_STEREO_BONDS && at[j].sb_parity[m1]; m1++)
2721 : : {
2722 [ # # ]: 0 : if (k == at[j].sb_ord[m1])
2723 : : {
2724 : 0 : chain_len = get_opposite_sb_atom(at, j, k,
2725 : : &pnxt_atom, &pinxt2cur, &pinxt_sb_parity_ord);
2726 : 0 : break;
2727 : : }
2728 : : }
2729 : : }
2730 [ - + ]: 16277 : if (at[j2].sb_parity[0])
2731 : : {
2732 [ # # # # ]: 0 : for (m2 = 0; m2 < MAX_NUM_STEREO_BONDS && at[j2].sb_parity[m2]; m2++)
2733 : : {
2734 [ # # ]: 0 : if (k2 == at[j2].sb_ord[m2])
2735 : : {
2736 : 0 : chain_len2 = get_opposite_sb_atom(at, j2, k2,
2737 : : &pnxt_atom2, &pinxt2cur2, &pinxt_sb_parity_ord2);
2738 : 0 : break;
2739 : : }
2740 : : }
2741 : : }
2742 [ - + - - : 16277 : if ((chain_len == 1 && chain_len2 == 1) || /* regular stereobond */
- + ]
2743 [ # # ]: 0 : (chain_len > 1 && j > pnxt_atom)) /* djb-rwth: addressing LLVM warnings */
2744 : 0 : {
2745 : : /* j is a cumulene endpoint */
2746 : : int m;
2747 : 0 : pcur_atom = j; /* pcur_atom > pnxt_atom */
2748 : 0 : picur2nxt = k;
2749 : 0 : picur_sb_parity_ord = -1;
2750 [ # # # # ]: 0 : for (m = 0; m < MAX_NUM_STEREO_BONDS && at[pcur_atom].sb_parity[m]; m++)
2751 : : {
2752 [ # # ]: 0 : if (at[pcur_atom].sb_ord[m] == k)
2753 : : {
2754 : 0 : picur_sb_parity_ord = m;
2755 : 0 : break;
2756 : : }
2757 : : }
2758 : : /* djb-rwth: removing redundant code */
2759 : : }
2760 : : else
2761 : : {
2762 [ - + - - ]: 16277 : if (chain_len2 > 1 && j2 > pnxt_atom2)
2763 : 0 : { /* j2 is a cumulene endpoint */
2764 : : int m;
2765 : 0 : pcur_atom = j2;
2766 : 0 : picur2nxt = k2;
2767 : 0 : pnxt_atom = pnxt_atom2;
2768 : 0 : pinxt2cur = pinxt2cur2;
2769 : 0 : pinxt_sb_parity_ord = pinxt_sb_parity_ord2;
2770 : 0 : picur_sb_parity_ord = -1;
2771 [ # # # # ]: 0 : for (m = 0; m < MAX_NUM_STEREO_BONDS && at[pcur_atom].sb_parity[m]; m++)
2772 : : {
2773 [ # # ]: 0 : if (at[pcur_atom].sb_ord[m] == k2)
2774 : 0 : picur_sb_parity_ord = m;
2775 : : }
2776 : 0 : chain_len = chain_len2;
2777 : : /* djb-rwth: removing redundant code */
2778 : : }
2779 : : else
2780 : : {
2781 : 16277 : chain_len = 0; /* djb-rwth: removing redundant code */
2782 : : }
2783 : : }
2784 : : /*len += sprintf( szCurBonds + len, "%c%d", bond_char, val+1);*/
2785 [ - + ]: 16277 : if (chain_len)
2786 : : {
2787 : : /* both atoms belong to a stereo bond */
2788 : : int kc;
2789 : 0 : int p1 = 0, p2, p1NM = 0, p2NM, neigh, neigh1, neigh2, bHasMetal, bWellDef; /* djb-rwth: initialising p1 and p1NM */
2790 : : int bNeighSwitched1, bNeighSwitched2;
2791 : :
2792 : : /* djb-rwth: avoiding buffer overrun as picur_sb_parity_ord == -1 is possible */
2793 [ # # ]: 0 : if (picur_sb_parity_ord >= 0)
2794 : : {
2795 : 0 : p1 = SB_PARITY_1(at[pcur_atom].sb_parity[picur_sb_parity_ord]);
2796 : 0 : p1NM = SB_PARITY_2(at[pcur_atom].sb_parity[picur_sb_parity_ord]);
2797 : : }
2798 : :
2799 : 0 : p2 = SB_PARITY_1(at[pnxt_atom].sb_parity[pinxt_sb_parity_ord]);
2800 : 0 : p2NM = SB_PARITY_2(at[pnxt_atom].sb_parity[pinxt_sb_parity_ord]);
2801 : :
2802 [ # # # # : 0 : bWellDef = ATOM_PARITY_WELL_DEF(p1) && ATOM_PARITY_WELL_DEF(p2);
# # # # ]
2803 [ # # # # : 0 : bHasMetal = ATOM_PARITY_WELL_DEF(p1NM) && ATOM_PARITY_WELL_DEF(p2NM);
# # # # ]
2804 : :
2805 : 0 : bNeighSwitched1 = bNeighSwitched2 = 0;
2806 : :
2807 [ # # # # ]: 0 : if (bWellDef || bHasMetal)
2808 : : {
2809 : :
2810 : 0 : neigh1 = num_inp_atoms;
2811 [ # # ]: 0 : for (kc = 0; kc < at[pcur_atom].valence; kc++)
2812 : : {
2813 [ # # ]: 0 : if (kc == picur2nxt)
2814 : 0 : continue;
2815 : 0 : neigh = at[pcur_atom].neighbor[kc];
2816 [ # # # # ]: 0 : if (bHasMetal && is_el_a_metal(at[neigh].el_number))
2817 : 0 : continue;
2818 [ # # ]: 0 : if (neigh < neigh1)
2819 : 0 : neigh1 = neigh;
2820 : : }
2821 [ # # ]: 0 : if (neigh1 < num_inp_atoms)
2822 : : {
2823 : 0 : bNeighSwitched1 = (neigh1 != at[pcur_atom].neighbor[(int)at[pcur_atom].sn_ord[picur_sb_parity_ord]]);
2824 : : }
2825 : : else
2826 : : {
2827 : 0 : AddErrorMessage(sd->pStrErrStruct, "Cannot find 0D stereobond neighbor");
2828 : : /*
2829 : : sd->nStructReadError = 99;
2830 : : sd->nErrorType = _IS_ERROR;
2831 : : */
2832 : : }
2833 : :
2834 : 0 : neigh2 = num_inp_atoms;
2835 [ # # ]: 0 : for (kc = 0; kc < at[pnxt_atom].valence; kc++)
2836 : : {
2837 [ # # ]: 0 : if (kc == pinxt2cur)
2838 : 0 : continue;
2839 : 0 : neigh = at[pnxt_atom].neighbor[kc];
2840 [ # # # # ]: 0 : if (bHasMetal && is_el_a_metal(at[neigh].el_number))
2841 : 0 : continue;
2842 [ # # ]: 0 : if (neigh < neigh2)
2843 : 0 : neigh2 = neigh;
2844 : : }
2845 [ # # ]: 0 : if (neigh2 < num_inp_atoms)
2846 : : {
2847 : 0 : bNeighSwitched2 = (neigh2 != at[pnxt_atom].neighbor[(int)at[pnxt_atom].sn_ord[pinxt_sb_parity_ord]]);
2848 : : }
2849 : : else
2850 : : {
2851 : 0 : AddErrorMessage(sd->pStrErrStruct, "Cannot find 0D stereobond neighbor");
2852 : : /*
2853 : : sd->nStructReadError = 99;
2854 : : sd->nErrorType = _IS_ERROR;
2855 : : */
2856 : : }
2857 : :
2858 [ # # # # ]: 0 : if (neigh1 < num_inp_atoms && neigh2 < num_inp_atoms)
2859 : : {
2860 [ # # # # : 0 : if (ATOM_PARITY_WELL_DEF(p1) && ATOM_PARITY_WELL_DEF(p2))
# # # # ]
2861 : : {
2862 : 0 : bond_parity = 2 - (p1 + p2 + bNeighSwitched1 + bNeighSwitched2) % 2;
2863 : : }
2864 : : else
2865 : : {
2866 : 0 : bond_parity = inchi_min(p1, p2);
2867 : : }
2868 : :
2869 [ # # ]: 0 : if (bHasMetal)
2870 : : {
2871 : 0 : bond_parityNM = 2 - (p1NM + p2NM + bNeighSwitched1 + bNeighSwitched2) % 2;
2872 : : }
2873 : : else
2874 : : {
2875 [ # # # # ]: 0 : if (p1NM && p2NM)
2876 : : {
2877 : 0 : bond_parityNM = inchi_min(p1NM, p2NM);
2878 : : }
2879 : : }
2880 : : }
2881 : : }
2882 : : else
2883 : : {
2884 [ # # # # ]: 0 : if (p1 && p2)
2885 : : {
2886 : 0 : bond_parity = inchi_min(p1, p2);
2887 : : }
2888 [ # # # # ]: 0 : if (p1NM && p2NM)
2889 : : {
2890 : 0 : bond_parityNM = inchi_min(p1NM, p2NM);
2891 : : }
2892 [ # # # # ]: 0 : if (bond_parityNM && !bond_parity)
2893 : : {
2894 : 0 : bond_parity = AB_PARITY_UNDF;
2895 : : }
2896 : : }
2897 : : }
2898 : :
2899 [ + - + - ]: 48831 : len += sprintf(szCurBonds + len, "%c%s%s%d",
2900 : : bond_char,
2901 : :
2902 : : (bond_parity == AB_PARITY_ODD) ? "-" : (bond_parity == AB_PARITY_EVEN) ? "+"
2903 [ + - ]: 32554 : : (bond_parity == AB_PARITY_UNKN) ? "u"
2904 [ + - ]: 32554 : : (bond_parity == AB_PARITY_UNDF) ? "?"
2905 [ - + ]: 16277 : : "",
2906 : :
2907 : : (bond_parityNM == AB_PARITY_ODD) ? "-" : (bond_parityNM == AB_PARITY_EVEN) ? "+"
2908 [ + - ]: 32554 : : (bond_parityNM == AB_PARITY_UNKN) ? "u"
2909 [ + - ]: 32554 : : (bond_parityNM == AB_PARITY_UNDF) ? "?"
2910 [ - + ]: 16277 : : "",
2911 : :
2912 : : j2 + 1);
2913 : : }
2914 : : }
2915 [ + + ]: 18215 : if (len + cur_len + 2 < buf_len)
2916 : : {
2917 : 18122 : memcpy(szBuf + cur_len, szCurBonds, len);
2918 : 18122 : cur_len += len;
2919 : 18122 : szBuf[cur_len++] = ';';
2920 : 18122 : j++;
2921 : : }
2922 : : else
2923 : : {
2924 : 93 : break;
2925 : : }
2926 : : }
2927 : 611 : szBuf[cur_len] = '\0';
2928 [ + - ]: 611 : *i = num_inp_atoms > 0 ? j : 0;
2929 : :
2930 : 611 : return cur_len;
2931 : : }
2932 : :
2933 : : #define ORIG_STR_BUFLEN (7 * MAXVAL + 2) /* > 7*MAXVAL+2 = 142 */
2934 : :
2935 : : /****************************************************************************
2936 : : Fill out original input structure
2937 : : ****************************************************************************/
2938 : 190 : int OrigStruct_FillOut(CANON_GLOBALS *pCG,
2939 : : ORIG_ATOM_DATA *orig_inp_data,
2940 : : ORIG_STRUCT *pOrigStruct,
2941 : : STRUCT_DATA *sd)
2942 : : {
2943 : : char szBuf[ORIG_STR_BUFLEN];
2944 : : int i, len, len_coord, len_atoms, len_bonds;
2945 : :
2946 : 190 : pOrigStruct->polymer = NULL;
2947 : 190 : pOrigStruct->v3000 = NULL;
2948 : :
2949 : 190 : pOrigStruct->n_zy = orig_inp_data->n_zy;
2950 : : /* Coordinates */
2951 : 190 : len_coord = i = 0;
2952 : :
2953 [ + + ]: 190 : if (orig_inp_data->szCoord)
2954 : : {
2955 : :
2956 [ + + ]: 604 : while ((len = WriteOrigCoord(orig_inp_data->num_inp_atoms,
2957 : : orig_inp_data->szCoord, &i, szBuf, sizeof(szBuf)))) /* djb-rwth: addressing LLVM warning */
2958 : : {
2959 : 417 : len_coord += len;
2960 : : }
2961 : 187 : pOrigStruct->szCoord = (char *)inchi_malloc(((long long)len_coord + 1) * sizeof(pOrigStruct->szCoord[0])); /* djb-rwth: cast operator added */
2962 : 187 : i = 0;
2963 [ + - + - ]: 374 : if (pOrigStruct->szCoord &&
2964 : 187 : len_coord == WriteOrigCoord(orig_inp_data->num_inp_atoms,
2965 : 187 : orig_inp_data->szCoord, &i, pOrigStruct->szCoord, len_coord + 1) &&
2966 [ + - ]: 187 : i == orig_inp_data->num_inp_atoms)
2967 : : {
2968 : : /* success */
2969 [ + - ]: 187 : if (orig_inp_data->szCoord)
2970 : : {
2971 [ + - ]: 187 : inchi_free(orig_inp_data->szCoord);
2972 : 187 : orig_inp_data->szCoord = NULL;
2973 : : }
2974 : : }
2975 : : else
2976 : : {
2977 : 0 : return -1;
2978 : : }
2979 : : }
2980 : :
2981 : : /* Atoms */
2982 : 190 : len_atoms = i = 0;
2983 [ + + ]: 396 : while ((len = WriteOrigAtoms(pCG, orig_inp_data->num_inp_atoms,
2984 : : orig_inp_data->at, &i, szBuf, sizeof(szBuf), sd))) /* djb-rwth: addressing LLVM warning */
2985 : : {
2986 : 206 : len_atoms += len;
2987 [ - + ]: 206 : if (!orig_inp_data->num_inp_atoms)
2988 : 0 : break;
2989 : : }
2990 : 190 : pOrigStruct->szAtoms = (char *)inchi_malloc(((long long)len_atoms + 1) * sizeof(pOrigStruct->szAtoms[0])); /* djb-rwth: cast operator added */
2991 : 190 : i = 0;
2992 [ + - + - ]: 380 : if (pOrigStruct->szAtoms &&
2993 : 190 : len_atoms == WriteOrigAtoms(pCG, orig_inp_data->num_inp_atoms,
2994 : 190 : orig_inp_data->at, &i, pOrigStruct->szAtoms, len_atoms + 1, sd) &&
2995 [ + - ]: 190 : i == orig_inp_data->num_inp_atoms)
2996 : : {
2997 : : ; /* success */
2998 : : }
2999 : : else
3000 : : {
3001 : 0 : return -1;
3002 : : }
3003 : :
3004 : : /* Bonds */
3005 : 190 : len_bonds = 0;
3006 : 190 : i = 1;
3007 [ + + ]: 421 : while ((len = WriteOrigBonds(pCG, orig_inp_data->num_inp_atoms,
3008 : : #if (FIX_CURE53_ISSUE_OOB_ALREADY_HAVE_THIS_MESSAGE == 1)
3009 : : orig_inp_data->at, &i, szBuf, sizeof(szBuf), sd))) /* djb-rwth: addressing LLVM warning */
3010 : : #else
3011 : : orig_inp_data->at, &i, szBuf, sizeof(szBuf), NULL)))
3012 : : #endif
3013 : : {
3014 : 231 : len_bonds += len;
3015 [ - + ]: 231 : if (!orig_inp_data->num_inp_atoms)
3016 : : {
3017 : 0 : break;
3018 : : }
3019 : : }
3020 : :
3021 : 190 : pOrigStruct->szBonds = (char *)inchi_malloc(((long long)len_bonds + 2) * sizeof(pOrigStruct->szBonds[0])); /* djb-rwth: cast operator added */
3022 : 190 : i = 1;
3023 : :
3024 [ + - + - ]: 380 : if (pOrigStruct->szBonds &&
3025 : 190 : len_bonds == WriteOrigBonds(pCG, orig_inp_data->num_inp_atoms,
3026 : 190 : orig_inp_data->at, &i, pOrigStruct->szBonds, len_bonds + 2, sd) &&
3027 [ + - ]: 190 : i == orig_inp_data->num_inp_atoms)
3028 : : {
3029 : : ; /* success */
3030 : : }
3031 : : else
3032 : : {
3033 : 0 : return -1;
3034 : : }
3035 : 190 : pOrigStruct->num_atoms = orig_inp_data->num_inp_atoms;
3036 : :
3037 : : /* Extensions of v. 1.05 */
3038 [ + + + - : 190 : if (orig_inp_data->polymer != NULL && orig_inp_data->polymer->n > 0 && orig_inp_data->valid_polymer)
+ - ]
3039 : : {
3040 : 24 : pOrigStruct->polymer = orig_inp_data->polymer;
3041 : : /* pointer copy, do not free after use! */
3042 : : }
3043 [ + + ]: 190 : if (orig_inp_data->v3000 != NULL)
3044 : : {
3045 : 80 : pOrigStruct->v3000 = orig_inp_data->v3000;
3046 : : /* pointer copy, do not free after use! */
3047 : : }
3048 : :
3049 : 190 : return 0;
3050 : : }
3051 : :
3052 : : /****************************************************************************/
3053 : 190 : void OrigStruct_Free(ORIG_STRUCT *pOrigStruct)
3054 : : {
3055 [ + - ]: 190 : if (pOrigStruct)
3056 : : {
3057 [ + - ]: 190 : if (pOrigStruct->szAtoms)
3058 : : {
3059 [ + - ]: 190 : inchi_free(pOrigStruct->szAtoms);
3060 : : }
3061 [ + - ]: 190 : if (pOrigStruct->szBonds)
3062 : : {
3063 [ + - ]: 190 : inchi_free(pOrigStruct->szBonds);
3064 : : }
3065 [ + + ]: 190 : if (pOrigStruct->szCoord)
3066 : : {
3067 [ + - ]: 187 : inchi_free(pOrigStruct->szCoord);
3068 : : }
3069 : :
3070 : : /* For
3071 : :
3072 : : OAD_Polymer *polymer;
3073 : : OAD_V3000 *v3000;
3074 : :
3075 : : we used shallow (pointer) copy of analogs from orig_inp_data, so do not free these here */
3076 : :
3077 : : /*memset( pOrigStruct, 0, sizeof(*pOrigStruct) );*/
3078 : 190 : pOrigStruct->szAtoms = NULL;
3079 : 190 : pOrigStruct->szBonds = NULL;
3080 : 190 : pOrigStruct->szCoord = NULL;
3081 : : }
3082 : 190 : }
3083 : :
3084 : : /****************************************************************************
3085 : : GetSaveOptLetters
3086 : :
3087 : : Get the two letters encoding the saved InChI creation options.
3088 : :
3089 : : The first one encodes RecMet/FixedH/SUU/SLUUD options.
3090 : : Each of options is a binary switch {ON,OFF}, so it totals to 2*2*2*2=16 values
3091 : : which are encoded by capital letters 'A' through 'P'.
3092 : :
3093 : : The second character encodes experimental (InChI 1 extension)
3094 : : options KET and 15T.
3095 : : Each of these options is a binary switch ON/OFF, so there are 2*2=4 combinations,
3096 : : currently encoded by 'A' through 'D'.
3097 : : Note that anything but 'A' here would indicate "extended" InChI 1
3098 : : Also, there is a reservation for future needs: the 2nd memo char
3099 : : may accommodate two more ON/OFF
3100 : : ****************************************************************************/
3101 : 0 : void GetSaveOptLetters(unsigned char save_opt_bits, char *let1, char *let2)
3102 : : {
3103 : 0 : const char a2p[] = "ABCDEFGHIJKLMNOP";
3104 : : /* SaveOptBits layout: {unused|unused|Ket|15T|RecMet|FixedH|SUU|SLUUD} */
3105 : 0 : *let1 = a2p[(size_t)(save_opt_bits & 0x0f)];
3106 : 0 : *let2 = a2p[(size_t)((save_opt_bits & 0x30) >> 4)];
3107 : 0 : }
3108 : :
3109 : : /****************************************************************************
3110 : : Set line separators dependent on requested output mode
3111 : : ****************************************************************************/
3112 : 197 : void set_line_separators(int bINChIOutputOptions, char **pLF, char **pTAB)
3113 : : {
3114 : 197 : int bPlainTextCommnts = 0 != (bINChIOutputOptions & INCHI_OUT_PLAIN_TEXT_COMMENTS);
3115 : :
3116 [ - + ]: 197 : *pLF = (char *)(bPlainTextCommnts ? "\n" : "\0");
3117 : :
3118 : : #if (!defined(TARGET_API_LIB) && !defined(TARGET_LIB_FOR_WINCHI))
3119 : : {
3120 : : int bPlainText = 0 != (bINChIOutputOptions & (INCHI_OUT_PLAIN_TEXT | INCHI_OUT_PLAIN_TEXT_COMMENTS));
3121 : : int bPlainTabbedOutput = 0 != (bINChIOutputOptions & INCHI_OUT_TABBED_OUTPUT) &&
3122 : : bPlainText && !bPlainTextCommnts;
3123 : :
3124 : : *pTAB = bPlainTabbedOutput ? (char*)"\t" : (char*)"\n";
3125 : : }
3126 : : #else
3127 : 197 : *pTAB = "\n";
3128 : : #endif
3129 : :
3130 : 197 : return;
3131 : : }
3132 : :
3133 : : /****************************************************************************
3134 : : Output InChI: InChI version prefix
3135 : : ****************************************************************************/
3136 : 197 : int OutputINCHI_VersionAndKind(INCHI_IOSTREAM *out_file,
3137 : : INCHI_IOS_STRING *strbuf,
3138 : : int bINChIOutputOptions,
3139 : : int is_beta,
3140 : : int is_molecular_inorganic,
3141 : : char *pLF,
3142 : : char *pTAB)
3143 : : {
3144 : 197 : inchi_ios_print_nodisplay(out_file, "%s%s=%s", pLF, INCHI_NAME, pLF);
3145 : :
3146 : 197 : inchi_strbuf_reset(strbuf);
3147 : 197 : inchi_strbuf_printf(strbuf, "%s", x_curr_ver);
3148 : :
3149 : : /*
3150 : : * (@nnuk)
3151 : : * The calculation class designator is:
3152 : : * S = Standard
3153 : : * B = Beta
3154 : : * N = non-standard
3155 : : *
3156 : : * Molecular Inorganics adds the subversion designator 'B'.
3157 : : *
3158 : : * Non-standard takes precedence over Beta because use of a non-standard
3159 : : * option makes the resulting InChI non-standard irrespective of any
3160 : : * experimental feature that would otherwise require the Beta designator.
3161 : : */
3162 [ + + ]: 197 : if (!(bINChIOutputOptions & INCHI_OUT_STDINCHI))
3163 : : {
3164 : 8 : inchi_strbuf_printf(strbuf, "N");
3165 : : }
3166 [ + + ]: 189 : else if (is_beta)
3167 : : {
3168 : 139 : inchi_strbuf_printf(strbuf, "B");
3169 : : }
3170 : : else
3171 : : {
3172 : 50 : inchi_strbuf_printf(strbuf, "S");
3173 : : }
3174 : :
3175 [ + + ]: 197 : if (is_molecular_inorganic)
3176 : : {
3177 : 69 : inchi_strbuf_printf(strbuf, "B");
3178 : : }
3179 : :
3180 : 197 : inchi_ios_print_nodisplay(out_file, "%s%s", strbuf->pStr, pLF);
3181 : :
3182 : 197 : return 0;
3183 : : }
3184 : :
3185 : : /****************************************************************************
3186 : : Output InChI: main layer - formula, connections and hydrogens
3187 : : (incl. tautomeric info == mobile H)
3188 : : ***************************************************************************/
3189 : 197 : int OutputINCHI_MainLayerFormula(CANON_GLOBALS *pCG,
3190 : : INCHI_IOSTREAM *out_file,
3191 : : INCHI_IOS_STRING *strbuf,
3192 : : int num_components2[],
3193 : : int *INCHI_basic_or_INCHI_reconnected,
3194 : : INCHI_OUT_CTL *io,
3195 : : char *pLF,
3196 : : char *pTAB)
3197 : : {
3198 : :
3199 : : /* constitution ( dot-disconnected Hill formulas: <formula> ) */
3200 : :
3201 [ - + - - ]: 197 : if (num_components2[0] || num_components2[1])
3202 : : {
3203 [ - + ]: 197 : szGetTag(IdentLbl, io->nTag, io->bTag1 = *INCHI_basic_or_INCHI_reconnected == INCHI_REC ? IL_REC_ : IL_FML_, io->szTag1, &io->bAlways, 1);
3204 : 197 : inchi_strbuf_reset(strbuf);
3205 : 197 : io->tot_len = str_HillFormula(io->pINChISort, strbuf, &io->bOverflow, io->bOutType,
3206 : : io->num_components, io->bUseMulipliers);
3207 : :
3208 [ - + ]: 197 : if (str_LineEnd(io->szTag1, &io->bOverflow, strbuf, -1, 1))
3209 : : {
3210 : 0 : return 1;
3211 : : }
3212 [ + + - + ]: 197 : if (io->n_pzz > 0 && io->n_zy > 0)
3213 : : {
3214 : 0 : int retm = MergeZzInHillFormula(strbuf);
3215 [ # # ]: 0 : if (0 != retm)
3216 : : {
3217 : 0 : return -1;
3218 : : }
3219 : : }
3220 : 197 : inchi_ios_print_nodisplay(out_file, "%s%s", strbuf->pStr, pLF);
3221 : : }
3222 : :
3223 : : LOG_NO_ARGS("\n#################### (L3318:ichiprt1.c) ##########################\n");
3224 : : LOG_MULT_ARGS("This is the Chemical formula : %s\n", strbuf->pStr);
3225 : : LOG_NO_ARGS("####################################################################\n");
3226 : :
3227 : 197 : return 0;
3228 : : }
3229 : :
3230 : : /****************************************************************************/
3231 : 197 : int OutputINCHI_MainLayerConnections(CANON_GLOBALS *pCG,
3232 : : INCHI_IOSTREAM *out_file,
3233 : : INCHI_IOS_STRING *strbuf,
3234 : : int num_components2[],
3235 : : int *INCHI_basic_or_INCHI_reconnected,
3236 : : INCHI_OUT_CTL *io,
3237 : : char *pLF,
3238 : : char *pTAB)
3239 : : {
3240 : : /* connections ( semicolon/dot-disconnected connection tables ) */
3241 : :
3242 : 197 : szGetTag(IdentLbl, io->nTag, io->bTag1 = IL_CONN, io->szTag1, &io->bAlways, 1);
3243 : 197 : inchi_strbuf_reset(strbuf);
3244 : 197 : io->tot_len = 0;
3245 : 197 : io->tot_len2 = str_Connections(pCG, io->pINChISort, strbuf, &io->bOverflow, io->bOutType,
3246 : : io->ATOM_MODE, io->num_components, io->bUseMulipliers);
3247 : :
3248 : : /* current version does not output empty (";;;;") connectivity */
3249 : :
3250 [ + + ]: 197 : if (io->tot_len != io->tot_len2)
3251 : : { /* 2004-06-30: never output empty connection table */
3252 : 124 : io->tot_len = io->tot_len2;
3253 [ - + ]: 124 : if (str_LineEnd(io->szTag1, &io->bOverflow, strbuf, -2, io->bPlainTextTags))
3254 : : {
3255 : 0 : return 1; /* pStr overfow */
3256 : : }
3257 : 124 : inchi_ios_print_nodisplay(out_file, "%s%s", strbuf->pStr, pLF);
3258 : : }
3259 : :
3260 : : LOG_NO_ARGS("\n##################### (L3357:ichiprt1.c) #########################\n");
3261 : : LOG_MULT_ARGS("This is the Connection Layer : %s\n", strbuf->pStr);
3262 : : LOG_NO_ARGS("####################################################################\n");
3263 : :
3264 : 197 : return 0;
3265 : : }
3266 : :
3267 : : /****************************************************************************/
3268 : 197 : int OutputINCHI_MainLayerHydrogens(CANON_GLOBALS *pCG,
3269 : : INCHI_IOSTREAM *out_file,
3270 : : INCHI_IOS_STRING *strbuf,
3271 : : int num_components2[],
3272 : : int *INCHI_basic_or_INCHI_reconnected,
3273 : : INCHI_OUT_CTL *io,
3274 : : char *pLF,
3275 : : char *pTAB)
3276 : : {
3277 : :
3278 : : /* hydrogen atoms (do not output empty) */
3279 : :
3280 [ + + ]: 197 : if (INCHI_SEGM_FILL == INChI_SegmentAction(io->sDifSegs[io->nCurINChISegment][DIFS_h_H_ATOMS]))
3281 : : {
3282 : 153 : szGetTag(IdentLbl, io->nTag, io->bTag1 = IL_ALLH, io->szTag1, &io->bAlways, 1);
3283 : 153 : inchi_strbuf_reset(strbuf);
3284 : 153 : io->tot_len = 0;
3285 : 153 : io->tot_len2 = str_H_atoms(io->pINChISort, strbuf, &io->bOverflow, io->bOutType,
3286 : : io->ATOM_MODE, io->TAUT_MODE,
3287 : : io->num_components, io->bUseMulipliers);
3288 [ + - ]: 153 : if (io->tot_len != io->tot_len2)
3289 : : { /* 2004-06-21: never output empty */
3290 : 153 : io->tot_len = io->tot_len2;
3291 [ - + ]: 153 : if (str_LineEnd(io->szTag1, &io->bOverflow, strbuf, -2, 1))
3292 : : {
3293 : 0 : return 1;
3294 : : }
3295 : 153 : inchi_ios_print_nodisplay(out_file, "%s%s", strbuf->pStr, pLF);
3296 : : }
3297 : : }
3298 : :
3299 : : LOG_NO_ARGS("\n###################### (L3396:ichiprt1.c) ########################\n");
3300 : : LOG_MULT_ARGS("This is the Hydrogen Layer : %s\n", strbuf->pStr);
3301 : : LOG_NO_ARGS("####################################################################\n");
3302 : :
3303 : 197 : return 0;
3304 : : }
3305 : :
3306 : : /****************************************************************************
3307 : : Output InChI: charge and removed protons layers
3308 : : ****************************************************************************/
3309 : 197 : int OutputINCHI_ChargeAndRemovedAddedProtonsLayers(CANON_GLOBALS *pCG,
3310 : : INCHI_IOSTREAM *out_file,
3311 : : INCHI_IOS_STRING *strbuf,
3312 : : INCHI_OUT_CTL *io,
3313 : : char *pLF,
3314 : : char *pTAB)
3315 : : {
3316 : :
3317 : : /* charge */
3318 : :
3319 : 197 : io->nSegmAction = INChI_SegmentAction(io->sDifSegs[io->nCurINChISegment][DIFS_q_CHARGE]);
3320 [ + + ]: 197 : if (io->nSegmAction)
3321 : : {
3322 : 26 : szGetTag(IdentLbl, io->nTag, io->bTag1 = IL_CHRG | io->bFhTag, io->szTag1, &io->bAlways, 1);
3323 : 26 : inchi_strbuf_reset(strbuf);
3324 : 26 : io->tot_len = 0;
3325 [ + - ]: 26 : if (INCHI_SEGM_FILL == io->nSegmAction)
3326 : : {
3327 : 26 : io->tot_len = str_Charge2(io->pINChISort, io->pINChISort2,
3328 : : strbuf, &io->bOverflow, io->bOutType, io->num_components,
3329 : : io->bSecondNonTautPass, io->bOmitRepetitions, io->bUseMulipliers);
3330 : 26 : io->bNonTautNonIsoIdentifierNotEmpty += io->bSecondNonTautPass;
3331 : : }
3332 [ - + ]: 26 : if (str_LineEnd(io->szTag1, &io->bOverflow, strbuf, -io->nSegmAction, io->bPlainTextTags))
3333 : : {
3334 : 0 : return 1;
3335 : : }
3336 : 26 : inchi_ios_print_nodisplay(out_file, "%s%s", strbuf->pStr, pLF);
3337 : : }
3338 : :
3339 : : /* removed protons */
3340 : :
3341 [ + - + - ]: 197 : if (io->iCurTautMode == TAUT_YES && !io->bSecondNonTautPass)
3342 : : {
3343 : :
3344 : 197 : io->nSegmAction = INChI_SegmentAction(io->sDifSegs[io->nCurINChISegment][DIFS_p_PROTONS]);
3345 [ + + ]: 197 : if (io->nSegmAction)
3346 : : {
3347 : 11 : szGetTag(IdentLbl, io->nTag, io->bTag1 = IL_PROT | io->bFhTag, io->szTag1, &io->bAlways, 1);
3348 : 11 : inchi_strbuf_reset(strbuf);
3349 : 11 : io->tot_len = 0;
3350 : 11 : inchi_strbuf_printf(strbuf, "%+d", io->nNumRemovedProtons);
3351 [ - + ]: 11 : if (str_LineEnd(io->szTag1, &io->bOverflow, strbuf, -io->nSegmAction, io->bPlainTextTags))
3352 : : {
3353 : 0 : return 1;
3354 : : }
3355 : 11 : inchi_ios_print_nodisplay(out_file, "%s%s", strbuf->pStr, pLF);
3356 : : }
3357 : : else
3358 : : {
3359 [ - + ]: 186 : if (io->bPlainTextTags == 1)
3360 : 0 : inchi_ios_print_nodisplay(out_file, "/");
3361 : : }
3362 : : }
3363 : :
3364 : 197 : return 0;
3365 : : }
3366 : :
3367 : : /**
3368 : : * @brief Output InChI: stereo layer with sublayers.
3369 : : *
3370 : : * @param pCG Pointer to the CANON_GLOBALS structure containing global canonicalization data.
3371 : : * @param out_file Pointer to the INCHI_IOSTREAM output stream where the stereo layer will be written.
3372 : : * @param strbuf Pointer to an INCHI_IOS_STRING buffer used for string formatting and output.
3373 : : * @param io Pointer to the INCHI_OUT_CTL structure containing output control and state information.
3374 : : * @param pLF Pointer to a string used as the line feed (end-of-line) character(s).
3375 : : * @param pTAB Pointer to a string used as the tab or separator character(s).
3376 : : * @return Returns 0 on success, or a non-zero error code on failure.
3377 : : */
3378 : 150 : int OutputINCHI_StereoLayer( CANON_GLOBALS *pCG,
3379 : : INCHI_IOSTREAM *out_file,
3380 : : INCHI_IOS_STRING *strbuf,
3381 : : INCHI_OUT_CTL *io,
3382 : : char *pLF,
3383 : : char *pTAB )
3384 : : {
3385 : :
3386 [ + + + + ]: 299 : if (INChI_SegmentAction( io->sDifSegs[io->nCurINChISegment][DIFS_b_SBONDS] ) ||
3387 [ + - ]: 287 : INChI_SegmentAction( io->sDifSegs[io->nCurINChISegment][DIFS_t_SATOMS] ) ||
3388 [ - + ]: 276 : INChI_SegmentAction( io->sDifSegs[io->nCurINChISegment][DIFS_m_SP3INV] ) ||
3389 : 138 : INChI_SegmentAction( io->sDifSegs[io->nCurINChISegment][DIFS_s_STYPE] ))
3390 : : {
3391 : :
3392 : : /* stereo */
3393 : :
3394 : 12 : szGetTag(IdentLbl, io->nTag, io->bTag1 = IL_STER | io->bFhTag, io->szTag1, &io->bAlways, 1);
3395 : :
3396 : : /* sp2 */
3397 : :
3398 [ + + ]: 12 : if ((io->nSegmAction = INChI_SegmentAction( io->sDifSegs[io->nCurINChISegment][DIFS_b_SBONDS] )))
3399 : : {
3400 : 1 : szGetTag(IdentLbl, io->nTag, io->bTag2 = io->bTag1 | IL_DBND, io->szTag2, &io->bAlways, 1);
3401 : 1 : inchi_strbuf_reset(strbuf);
3402 : 1 : io->tot_len = 0;
3403 [ + - ]: 1 : if (INCHI_SEGM_FILL == io->nSegmAction)
3404 : : {
3405 : 1 : io->tot_len = str_Sp2( io->pINChISort, io->pINChISort2, strbuf, &io->bOverflow,
3406 : : io->bOutType, io->TAUT_MODE, io->num_components,
3407 : : io->bSecondNonTautPass, io->bOmitRepetitions, io->bUseMulipliers );
3408 : :
3409 : 1 : io->bNonTautNonIsoIdentifierNotEmpty += io->bSecondNonTautPass;
3410 : : }
3411 : :
3412 [ - + ]: 1 : if (str_LineEnd(io->szTag2, &io->bOverflow, strbuf, -io->nSegmAction, io->bPlainTextTags))
3413 : : {
3414 : 0 : return 1;
3415 : : }
3416 : 1 : inchi_ios_print_nodisplay(out_file, "%s%s", strbuf->pStr, pLF);
3417 : : }
3418 : : else
3419 : : {
3420 [ - + ]: 11 : if (io->bPlainTextTags == 1)
3421 : : {
3422 : 0 : inchi_ios_print_nodisplay(out_file, "/"); /* sp2 */
3423 : : }
3424 : : }
3425 : :
3426 : : /* sp3 */
3427 : :
3428 : : /* t-layer */
3429 [ + + ]: 12 : if ((io->nSegmAction = INChI_SegmentAction( io->sDifSegs[io->nCurINChISegment][DIFS_t_SATOMS] ))) /* djb-rwth: addressing LLVM warning */
3430 : : {
3431 [ + - - + ]: 11 : io->bRelRac = io->bRelativeStereo[io->iCurTautMode] || io->bRacemicStereo[io->iCurTautMode];
3432 : 11 : szGetTag(IdentLbl, io->nTag, io->bTag2 = io->bTag1 | IL_SP3S, io->szTag2, &io->bAlways, 1);
3433 : 11 : inchi_strbuf_reset(strbuf);
3434 : 11 : io->tot_len = 0;
3435 [ + - ]: 11 : if (INCHI_SEGM_FILL == io->nSegmAction)
3436 : : {
3437 : 11 : io->tot_len = str_Sp3( io->pINChISort, io->pINChISort2, strbuf, &io->bOverflow,
3438 : : io->bOutType, io->TAUT_MODE, io->num_components, io->bRelRac,
3439 : : io->bSecondNonTautPass, io->bOmitRepetitions, io->bUseMulipliers );
3440 : :
3441 : 11 : io->bNonTautNonIsoIdentifierNotEmpty += io->bSecondNonTautPass;
3442 : : }
3443 : :
3444 [ - + ]: 11 : if (str_LineEnd(io->szTag2, &io->bOverflow, strbuf, -io->nSegmAction, io->bPlainTextTags))
3445 : : {
3446 : 0 : return 2;
3447 : : }
3448 : 11 : inchi_ios_print_nodisplay(out_file, "%s%s", strbuf->pStr, pLF);
3449 : : }
3450 : : else
3451 : : {
3452 [ - + ]: 1 : if (io->bPlainTextTags == 1)
3453 : : {
3454 : 0 : inchi_ios_print_nodisplay( out_file, "/" ); /* sp3 */
3455 : : }
3456 : : }
3457 : :
3458 : : /* m-layer */
3459 [ + + ]: 12 : if ((io->nSegmAction = INChI_SegmentAction( io->sDifSegs[io->nCurINChISegment][DIFS_m_SP3INV] ))) /* djb-rwth: addressing LLVM warning */
3460 : : {
3461 : 10 : szGetTag(IdentLbl, io->nTag, io->bTag2 = io->bTag1 | IL_INVS, io->szTag2, &io->bAlways, 1);
3462 : 10 : inchi_strbuf_reset(strbuf);
3463 : 10 : io->tot_len = 0;
3464 [ + - ]: 10 : if (INCHI_SEGM_FILL == io->nSegmAction)
3465 : : {
3466 : 10 : io->tot_len = str_StereoAbsInv( io->pINChISort, strbuf,
3467 : : &io->bOverflow, io->bOutType, io->num_components );
3468 : 10 : io->bNonTautNonIsoIdentifierNotEmpty += io->bSecondNonTautPass;
3469 : : }
3470 : :
3471 [ - + ]: 10 : if (str_LineEnd(io->szTag2, &io->bOverflow, strbuf, -io->nSegmAction, io->bPlainTextTags))
3472 : : {
3473 : 0 : return 3;
3474 : : }
3475 : 10 : inchi_ios_print_nodisplay(out_file, "%s%s", strbuf->pStr, pLF);
3476 : : }
3477 : : else
3478 : : {
3479 [ - + ]: 2 : if (io->bPlainTextTags == 1)
3480 : : {
3481 : 0 : inchi_ios_print_nodisplay(out_file, "/"); /* stereo-abs-inv */
3482 : : }
3483 : : }
3484 : :
3485 : : /* stereo type */
3486 : :
3487 : : /* s-layer */
3488 [ + + ]: 12 : if ((io->nSegmAction = INChI_SegmentAction( io->sDifSegs[io->nCurINChISegment][DIFS_s_STYPE] )))
3489 : : {
3490 [ + - ]: 20 : const char *p_stereo = io->bRelativeStereo[io->iCurTautMode] ? x_rel : io->bRacemicStereo[io->iCurTautMode] ? x_rac
3491 [ - + ]: 10 : : x_abs;
3492 : 10 : szGetTag(IdentLbl, io->nTag, io->bTag2 = io->bTag1 | IL_TYPS, io->szTag2, &io->bAlways, 1);
3493 : 10 : inchi_strbuf_reset(strbuf);
3494 : 10 : io->tot_len = 0;
3495 [ + - ]: 10 : if (INCHI_SEGM_FILL == io->nSegmAction)
3496 : : {
3497 : 10 : (io->tot_len) += MakeDelim(p_stereo, strbuf, &io->bOverflow);
3498 : 10 : io->bNonTautNonIsoIdentifierNotEmpty += io->bSecondNonTautPass;
3499 : : }
3500 [ - + ]: 10 : if (str_LineEnd(io->szTag2, &io->bOverflow, strbuf, -io->nSegmAction, io->bPlainTextTags))
3501 : : {
3502 : 0 : return 1;
3503 : : }
3504 : 10 : inchi_ios_print_nodisplay(out_file, "%s%s", strbuf->pStr, pLF);
3505 : : }
3506 [ - + ]: 12 : if (io->bPlainTextTags == 1)
3507 : : {
3508 : 0 : inchi_ios_print_nodisplay(out_file, "/"); /* no abs, inv or racemic stereo */
3509 : : }
3510 : : }
3511 : : else
3512 : : {
3513 [ - + ]: 138 : if (io->bPlainTextTags == 1)
3514 : : {
3515 : 0 : inchi_ios_print_nodisplay( out_file, "////" ); /* sp2, sp3, abs-inv, stereo.type */
3516 : : }
3517 : : }
3518 : :
3519 : 150 : return 0;
3520 : : }
3521 : :
3522 : : /**
3523 : : * @brief Output InChI: stereo layer with sublayers for enhanced stereochemistry (absolute, relative, racemic).
3524 : : *
3525 : : * @param pCG Pointer to the CANON_GLOBALS structure containing global canonicalization data.
3526 : : * @param out_file Pointer to the INCHI_IOSTREAM output stream where the stereo layer will be written.
3527 : : * @param strbuf Pointer to an INCHI_IOS_STRING buffer used for string formatting and output.
3528 : : * @param io Pointer to the INCHI_OUT_CTL structure containing output control and state information.
3529 : : * @param orig_inp_data Pointer to the ORIG_ATOM_DATA containing e.g. atom information.
3530 : : * @param pLF Pointer to a string used as the line feed (end-of-line) character(s).
3531 : : * @param pTAB Pointer to a string used as the tab or separator character(s).
3532 : : * @return Returns 0 on success, or a non-zero error code on failure.
3533 : : */
3534 : 47 : int OutputINCHI_StereoLayer_EnhancedStereo(
3535 : : CANON_GLOBALS *pCG,
3536 : : INCHI_IOSTREAM *out_file,
3537 : : INCHI_IOS_STRING *strbuf,
3538 : : INCHI_OUT_CTL *io,
3539 : : ORIG_ATOM_DATA *orig_inp_data,
3540 : : char *pLF,
3541 : : char *pTAB )
3542 : : {
3543 : :
3544 [ + - + + ]: 94 : if (INChI_SegmentAction( io->sDifSegs[io->nCurINChISegment][DIFS_b_SBONDS] ) ||
3545 [ + - ]: 52 : INChI_SegmentAction( io->sDifSegs[io->nCurINChISegment][DIFS_t_SATOMS] ) ||
3546 [ - + ]: 10 : INChI_SegmentAction( io->sDifSegs[io->nCurINChISegment][DIFS_m_SP3INV] ) ||
3547 : 5 : INChI_SegmentAction( io->sDifSegs[io->nCurINChISegment][DIFS_s_STYPE] ))
3548 : : {
3549 : :
3550 : : /* stereo */
3551 : :
3552 : 42 : szGetTag( IdentLbl, io->nTag, io->bTag1 = IL_STER | io->bFhTag, io->szTag1, &io->bAlways, 1 );
3553 : :
3554 : : /* sp2 */
3555 : :
3556 [ - + ]: 42 : if ((io->nSegmAction = INChI_SegmentAction( io->sDifSegs[io->nCurINChISegment][DIFS_b_SBONDS] )))
3557 : : {
3558 : 0 : szGetTag( IdentLbl, io->nTag, io->bTag2 = io->bTag1 | IL_DBND, io->szTag2, &io->bAlways, 1 );
3559 : 0 : inchi_strbuf_reset( strbuf );
3560 : 0 : io->tot_len = 0;
3561 [ # # ]: 0 : if (INCHI_SEGM_FILL == io->nSegmAction)
3562 : : {
3563 : 0 : io->tot_len = str_Sp2( io->pINChISort, io->pINChISort2, strbuf, &io->bOverflow,
3564 : : io->bOutType, io->TAUT_MODE, io->num_components,
3565 : : io->bSecondNonTautPass, io->bOmitRepetitions, io->bUseMulipliers );
3566 : :
3567 : 0 : io->bNonTautNonIsoIdentifierNotEmpty += io->bSecondNonTautPass;
3568 : : }
3569 : :
3570 [ # # ]: 0 : if (str_LineEnd( io->szTag2, &io->bOverflow, strbuf, -io->nSegmAction, io->bPlainTextTags ))
3571 : : {
3572 : 0 : return 1;
3573 : : }
3574 : 0 : inchi_ios_print_nodisplay( out_file, "%s%s", strbuf->pStr, pLF );
3575 : : }
3576 : : else
3577 : : {
3578 [ - + ]: 42 : if (io->bPlainTextTags == 1)
3579 : : {
3580 : 0 : inchi_ios_print_nodisplay( out_file, "/" ); /* sp2 */
3581 : : }
3582 : : }
3583 : :
3584 : : /* sp3 */
3585 : :
3586 : : /* t-layer */
3587 [ + - ]: 42 : if ((io->nSegmAction = INChI_SegmentAction( io->sDifSegs[io->nCurINChISegment][DIFS_t_SATOMS] ))) /* djb-rwth: addressing LLVM warning */
3588 : : {
3589 [ + - - + ]: 42 : io->bRelRac = io->bRelativeStereo[io->iCurTautMode] || io->bRacemicStereo[io->iCurTautMode];
3590 : 42 : szGetTag( IdentLbl, io->nTag, io->bTag2 = io->bTag1 | IL_SP3S, io->szTag2, &io->bAlways, 1 );
3591 : 42 : inchi_strbuf_reset( strbuf );
3592 : 42 : io->tot_len = 0;
3593 [ + - ]: 42 : if (INCHI_SEGM_FILL == io->nSegmAction)
3594 : : {
3595 : 42 : io->tot_len = str_Sp3( io->pINChISort, io->pINChISort2, strbuf, &io->bOverflow,
3596 : : io->bOutType, io->TAUT_MODE, io->num_components, io->bRelRac,
3597 : : io->bSecondNonTautPass, io->bOmitRepetitions, io->bUseMulipliers );
3598 : :
3599 : 42 : io->bNonTautNonIsoIdentifierNotEmpty += io->bSecondNonTautPass;
3600 : : }
3601 : :
3602 [ - + ]: 42 : if (str_LineEnd( io->szTag2, &io->bOverflow, strbuf, -io->nSegmAction, io->bPlainTextTags ))
3603 : : {
3604 : 0 : return 2;
3605 : : }
3606 : 42 : inchi_ios_print_nodisplay( out_file, "%s%s", strbuf->pStr, pLF );
3607 : : }
3608 : : else
3609 : : {
3610 [ # # ]: 0 : if (io->bPlainTextTags == 1)
3611 : : {
3612 : 0 : inchi_ios_print_nodisplay( out_file, "/" ); /* sp3 */
3613 : : }
3614 : : }
3615 : :
3616 : : /* m-layer */
3617 [ + - ]: 42 : if ((io->nSegmAction = INChI_SegmentAction( io->sDifSegs[io->nCurINChISegment][DIFS_m_SP3INV] ))) /* djb-rwth: addressing LLVM warning */
3618 : : {
3619 : 42 : szGetTag( IdentLbl, io->nTag, io->bTag2 = io->bTag1 | IL_INVS, io->szTag2, &io->bAlways, 1 );
3620 : 42 : inchi_strbuf_reset( strbuf );
3621 : 42 : io->tot_len = 0;
3622 [ + - ]: 42 : if (INCHI_SEGM_FILL == io->nSegmAction)
3623 : : {
3624 : 42 : io->tot_len = str_StereoAbsInv( io->pINChISort, strbuf,
3625 : : &io->bOverflow, io->bOutType, io->num_components );
3626 : 42 : io->bNonTautNonIsoIdentifierNotEmpty += io->bSecondNonTautPass;
3627 : : }
3628 : :
3629 [ - + ]: 42 : if (str_LineEnd( io->szTag2, &io->bOverflow, strbuf, -io->nSegmAction, io->bPlainTextTags ))
3630 : : {
3631 : 0 : return 3;
3632 : : }
3633 : 42 : inchi_ios_print_nodisplay( out_file, "%s%s", strbuf->pStr, pLF );
3634 : : }
3635 : : else
3636 : : {
3637 [ # # ]: 0 : if (io->bPlainTextTags == 1)
3638 : : {
3639 : 0 : inchi_ios_print_nodisplay( out_file, "/" ); /* stereo-abs-inv */
3640 : : }
3641 : : }
3642 : :
3643 : : /* stereo type */
3644 : :
3645 : : /* s-layer */
3646 [ + - ]: 42 : if ((io->nSegmAction = INChI_SegmentAction( io->sDifSegs[io->nCurINChISegment][DIFS_s_STYPE] )))
3647 : : {
3648 [ + - ]: 84 : const char *p_stereo = io->bRelativeStereo[io->iCurTautMode] ? x_rel :
3649 [ - + ]: 42 : io->bRacemicStereo[io->iCurTautMode] ? x_rac : x_abs;
3650 : :
3651 : 42 : szGetTag( IdentLbl, io->nTag, io->bTag2 = io->bTag1 | IL_TYPS, io->szTag2, &io->bAlways, 1 );
3652 : 42 : inchi_strbuf_reset( strbuf ); io->tot_len = 0;
3653 : :
3654 : 42 : io->tot_len = 0;
3655 [ + - ]: 42 : if (INCHI_SEGM_FILL == io->nSegmAction)
3656 : : {
3657 : : /* no input structure (-InChI2InChI) or no V3000 collections */
3658 [ + - + - ]: 42 : if (orig_inp_data && orig_inp_data->v3000 &&
3659 [ + + ]: 42 : (orig_inp_data->v3000->n_steabs > 0 ||
3660 [ + + ]: 20 : orig_inp_data->v3000->n_sterel > 0 ||
3661 [ + + ]: 16 : orig_inp_data->v3000->n_sterac > 0)) {
3662 : 36 : io->tot_len += MakeSlayerString(
3663 : : orig_inp_data,
3664 : : io->pINChISort,
3665 : : strbuf,
3666 : : io->bOutType,
3667 : : io->num_components,
3668 : : io->TAUT_MODE,
3669 : : &io->bOverflow
3670 : 36 : );
3671 : : } else {
3672 : 6 : ( io->tot_len ) += MakeDelim( p_stereo, strbuf, &io->bOverflow );
3673 : : }
3674 : :
3675 : 42 : io->bNonTautNonIsoIdentifierNotEmpty += io->bSecondNonTautPass;
3676 : : }
3677 [ - + ]: 42 : if (str_LineEnd( io->szTag2, &io->bOverflow, strbuf, -io->nSegmAction, io->bPlainTextTags ))
3678 : : {
3679 : 0 : return 1;
3680 : : }
3681 : 42 : inchi_ios_print_nodisplay( out_file, "%s%s", strbuf->pStr, pLF );
3682 : : }
3683 [ - + ]: 42 : if (io->bPlainTextTags == 1)
3684 : : {
3685 : 0 : inchi_ios_print_nodisplay( out_file, "/" ); /* no abs, inv or racemic stereo */
3686 : : }
3687 : : }
3688 : : else
3689 : : {
3690 [ - + ]: 5 : if (io->bPlainTextTags == 1)
3691 : : {
3692 : 0 : inchi_ios_print_nodisplay( out_file, "////" ); /* sp2, sp3, abs-inv, stereo.type */
3693 : : }
3694 : : }
3695 : :
3696 : 47 : return 0;
3697 : : }
3698 : :
3699 : : /****************************************************************************
3700 : : Output InChI: isotopic layer and sublayers
3701 : : ****************************************************************************/
3702 : 197 : int OutputINCHI_IsotopicLayer( CANON_GLOBALS *pCG,
3703 : : INCHI_IOSTREAM *out_file,
3704 : : INCHI_IOS_STRING *strbuf,
3705 : : int *INCHI_basic_or_INCHI_reconnected,
3706 : : INCHI_OUT_CTL *io,
3707 : : char *pLF,
3708 : : char *pTAB )
3709 : : {
3710 : :
3711 [ + + ]: 197 : if (INChI_SegmentAction(io->sDifSegs[io->nCurINChISegment][DIFS_i_IATOMS]))
3712 : : {
3713 : : /* isotopic #1: composition -- atoms -- do not output in xml if empty */
3714 : 6 : szGetTag(IdentLbl, io->nTag, io->bTag1 = IL_ISOT | io->bFhTag, io->szTag1, &io->bAlways, 1);
3715 : : /* isotopic atoms without mobile H.
3716 : : * Fixed 2004-06-15: always output if not bXml. Note:
3717 : : * Previous condition if( bHasIsotopicAtoms[io->iCurTautMode] || bIsotopic && !bXml)
3718 : : * did not optput /i in case of only mobile isotopic H
3719 : : */
3720 [ + - ]: 6 : if ((io->nSegmAction = INChI_SegmentAction(io->sDifSegs[io->nCurINChISegment][DIFS_i_IATOMS]))) /* djb-rwth: addressing LLVM warning */
3721 : : {
3722 : 6 : szGetTag(IdentLbl, io->nTag, io->bTag2 = io->bTag1 | IL_ATMS, io->szTag2, &io->bAlways, 1);
3723 : 6 : inchi_strbuf_reset(strbuf);
3724 : 6 : io->tot_len = 0;
3725 : : /*if ( bHasIsotopicAtoms[io->iCurTautMode] )*/
3726 [ + - ]: 6 : if (INCHI_SEGM_FILL == io->nSegmAction)
3727 : : {
3728 : 6 : io->tot_len2 = str_IsoAtoms(io->pINChISort, io->pINChISort2, strbuf, &io->bOverflow,
3729 : : io->bOutType, io->TAUT_MODE, io->num_components, io->bAbcNumbers,
3730 : : io->bSecondNonTautPass, io->bOmitRepetitions, io->bUseMulipliers);
3731 : 6 : io->bNonTautIsoIdentifierNotEmpty += io->bSecondNonTautPass;
3732 : : }
3733 : : else
3734 : : {
3735 : 0 : io->tot_len2 = io->tot_len;
3736 : : }
3737 : :
3738 : 6 : io->tot_len = io->tot_len2;
3739 [ - + ]: 6 : if (str_LineEnd(io->szTag2, &io->bOverflow, strbuf, -io->nSegmAction, io->bPlainTextTags))
3740 : : {
3741 : 0 : return 1;
3742 : : }
3743 : 6 : inchi_ios_print_nodisplay(out_file, "%s%s", strbuf->pStr, pLF);
3744 : : }
3745 : :
3746 : : /* isotopic #1a: composition -- exchangeable isotopic H (mobile H only) */
3747 : : /*if ( !io->bSecondNonTautPass && bHasIsoH )*/
3748 [ - + ]: 6 : if ((io->nSegmAction = INChI_SegmentAction(io->sDifSegs[io->nCurINChISegment][DIFS_h_H_ATOMS]))) /* djb-rwth: addressing LLVM warning */
3749 : : {
3750 : 0 : szGetTag(IdentLbl, io->nTag, io->bTag2 = io->bTag1 | IL_XCGA, io->szTag2, &io->bAlways, 1);
3751 : 0 : inchi_strbuf_reset(strbuf);
3752 : 0 : io->tot_len = 0;
3753 : 0 : (io->tot_len) += MakeIsoHString(io->num_iso_H, strbuf, io->TAUT_MODE, &io->bOverflow);
3754 : 0 : io->bNonTautIsoIdentifierNotEmpty += io->bSecondNonTautPass;
3755 [ # # ]: 0 : if (str_LineEnd(io->szTag2, &io->bOverflow, strbuf, -io->nSegmAction, io->bPlainTextTags))
3756 : : {
3757 : 0 : return 2;
3758 : : }
3759 : 0 : inchi_ios_print_nodisplay(out_file, "%s%s", strbuf->pStr, pLF);
3760 : : }
3761 : :
3762 : : /***************************************************
3763 : : *
3764 : : * Isotopic stereo
3765 : : *
3766 : : ***************************************************/
3767 : :
3768 : : /*if ( bIsotopicStereo[io->iCurTautMode] )*/
3769 [ + - + + ]: 12 : if (INChI_SegmentAction(io->sDifSegs[io->nCurINChISegment][DIFS_b_SBONDS]) ||
3770 [ + - ]: 10 : INChI_SegmentAction(io->sDifSegs[io->nCurINChISegment][DIFS_t_SATOMS]) ||
3771 [ - + ]: 8 : INChI_SegmentAction(io->sDifSegs[io->nCurINChISegment][DIFS_m_SP3INV]) ||
3772 : 4 : INChI_SegmentAction(io->sDifSegs[io->nCurINChISegment][DIFS_s_STYPE]))
3773 : : {
3774 : : /* stereo */
3775 : 2 : szGetTag(IdentLbl, io->nTag, io->bTag2 = io->bTag1 | IL_STER, io->szTag2, &io->bAlways, 1);
3776 : :
3777 : : /************************
3778 : : isotopic #2: sp2
3779 : : ************************/
3780 : : /*if ( bIsotopicStereoSp2[io->iCurTautMode] )*/
3781 [ - + ]: 2 : if ((io->nSegmAction = INChI_SegmentAction(io->sDifSegs[io->nCurINChISegment][DIFS_b_SBONDS]))) /* djb-rwth: addressing LLVM warning */
3782 : : {
3783 : 0 : szGetTag(IdentLbl, io->nTag, io->bTag3 = io->bTag2 | IL_DBND, io->szTag3, &io->bAlways, 1);
3784 : 0 : inchi_strbuf_reset(strbuf);
3785 : 0 : io->tot_len = 0;
3786 [ # # ]: 0 : if (INCHI_SEGM_FILL == io->nSegmAction)
3787 : : {
3788 : 0 : io->tot_len = str_IsoSp2(io->pINChISort, io->pINChISort2, strbuf, &io->bOverflow,
3789 : : io->bOutType, io->TAUT_MODE, io->num_components,
3790 : : io->bSecondNonTautPass, io->bOmitRepetitions, io->bUseMulipliers);
3791 : 0 : io->bNonTautIsoIdentifierNotEmpty += io->bSecondNonTautPass;
3792 : : }
3793 [ # # ]: 0 : if (str_LineEnd(io->szTag3, &io->bOverflow, strbuf, -io->nSegmAction, io->bPlainTextTags))
3794 : : {
3795 : 0 : return 3;
3796 : : }
3797 : 0 : inchi_ios_print_nodisplay(out_file, "%s%s", strbuf->pStr, pLF);
3798 : : }
3799 : : else
3800 : : {
3801 [ - + ]: 2 : if (io->bPlainTextTags == 1)
3802 : 0 : inchi_ios_print_nodisplay(out_file, "/"); /* iso sp2 */
3803 : : }
3804 : :
3805 : : /************************
3806 : : isotopic #3: sp3
3807 : : ************************/
3808 : : /*if ( bIsotopicStereoSp3[io->iCurTautMode] )*/
3809 [ + - ]: 2 : if ((io->nSegmAction = INChI_SegmentAction(io->sDifSegs[io->nCurINChISegment][DIFS_t_SATOMS]))) /* djb-rwth: addressing LLVM warning */
3810 : : {
3811 [ + - - + ]: 2 : io->bRelRac = io->bIsotopicRelativeStereo[io->iCurTautMode] || io->bIsotopicRacemicStereo[io->iCurTautMode];
3812 : :
3813 : 2 : szGetTag(IdentLbl, io->nTag, io->bTag3 = io->bTag2 | IL_SP3S, io->szTag3, &io->bAlways, 1);
3814 : 2 : inchi_strbuf_reset(strbuf);
3815 : 2 : io->tot_len = 0;
3816 [ + - ]: 2 : if (INCHI_SEGM_FILL == io->nSegmAction)
3817 : : {
3818 : 2 : io->tot_len = str_IsoSp3(io->pINChISort, io->pINChISort2, strbuf, &io->bOverflow,
3819 : : io->bOutType, io->TAUT_MODE, io->num_components, io->bRelRac,
3820 : : io->bSecondNonTautPass, io->bOmitRepetitions, io->bUseMulipliers);
3821 : 2 : io->bNonTautIsoIdentifierNotEmpty += io->bSecondNonTautPass;
3822 : : }
3823 [ - + ]: 2 : if (str_LineEnd(io->szTag3, &io->bOverflow, strbuf, -io->nSegmAction, io->bPlainTextTags))
3824 : : {
3825 : 0 : return 5;
3826 : : }
3827 : 2 : inchi_ios_print_nodisplay(out_file, "%s%s", strbuf->pStr, pLF);
3828 : : }
3829 : : else
3830 : : {
3831 [ # # ]: 0 : if (io->bPlainTextTags == 1)
3832 : : {
3833 : 0 : inchi_ios_print_nodisplay(out_file, "/"); /* iso-sp3 */
3834 : : }
3835 : : }
3836 : :
3837 : : /* isotopic #4: abs inverted */
3838 [ + - ]: 2 : if ((io->nSegmAction = INChI_SegmentAction(io->sDifSegs[io->nCurINChISegment][DIFS_m_SP3INV]))) /* djb-rwth: addressing LLVM warning */
3839 : : {
3840 : 2 : szGetTag(IdentLbl, io->nTag, io->bTag3 = io->bTag2 | IL_INVS, io->szTag3, &io->bAlways, 1);
3841 : 2 : inchi_strbuf_reset(strbuf);
3842 : 2 : io->tot_len = 0;
3843 [ + - ]: 2 : if (INCHI_SEGM_FILL == io->nSegmAction)
3844 : : {
3845 : 2 : io->tot_len = str_IsoStereoAbsInv(io->pINChISort, strbuf,
3846 : : &io->bOverflow, io->bOutType, io->num_components);
3847 : 2 : io->bNonTautIsoIdentifierNotEmpty += io->bSecondNonTautPass;
3848 : : }
3849 [ - + ]: 2 : if (str_LineEnd(io->szTag3, &io->bOverflow, strbuf, -io->nSegmAction, io->bPlainTextTags))
3850 : : {
3851 : 0 : return 5;
3852 : : }
3853 : 2 : inchi_ios_print_nodisplay(out_file, "%s%s", strbuf->pStr, pLF);
3854 : : }
3855 : : else
3856 : : {
3857 [ # # ]: 0 : if (io->bPlainTextTags == 1)
3858 : : {
3859 : 0 : inchi_ios_print_nodisplay(out_file, "/");
3860 : : }
3861 : : }
3862 : :
3863 : : /* isotopic #5: stereo type. Do not output if it has already been output in non-iso */
3864 [ + - ]: 2 : if ((io->nSegmAction = INChI_SegmentAction(io->sDifSegs[io->nCurINChISegment][DIFS_s_STYPE]))) /* djb-rwth: addressing LLVM warning */
3865 : : {
3866 [ + - ]: 4 : const char *p_stereo = io->bIsotopicRelativeStereo[io->iCurTautMode] ? x_rel : io->bIsotopicRacemicStereo[io->iCurTautMode] ? x_rac
3867 [ - + ]: 2 : : x_abs;
3868 : 2 : szGetTag(IdentLbl, io->nTag, io->bTag3 = io->bTag2 | IL_TYPS, io->szTag3, &io->bAlways, 1);
3869 : 2 : inchi_strbuf_reset(strbuf);
3870 : 2 : io->tot_len = 0;
3871 [ + - ]: 2 : if (INCHI_SEGM_FILL == io->nSegmAction)
3872 : : {
3873 : 2 : io->tot_len += MakeDelim(p_stereo, strbuf, &io->bOverflow);
3874 : 2 : io->bNonTautIsoIdentifierNotEmpty += io->bSecondNonTautPass;
3875 : : }
3876 [ - + ]: 2 : if (str_LineEnd(io->szTag3, &io->bOverflow, strbuf, -io->nSegmAction, io->bPlainTextTags))
3877 : : {
3878 : 0 : return 6;
3879 : : }
3880 : 2 : inchi_ios_print_nodisplay(out_file, "%s%s", strbuf->pStr, pLF);
3881 : : }
3882 [ - + ]: 2 : if (io->bPlainTextTags == 1)
3883 : : {
3884 : 0 : inchi_ios_print_nodisplay(out_file, "/"); /* no abs, inv or racemic stereo */
3885 : : }
3886 : : }
3887 : : else
3888 : : {
3889 : : /* no isotopic stereo */
3890 [ - + ]: 4 : if (io->bPlainTextTags == 1)
3891 : : {
3892 : 0 : inchi_ios_print_nodisplay(out_file, "////"); /* sp3, sp2, abs-inv, stereo.type */
3893 : : }
3894 : : }
3895 : : }
3896 : : else
3897 : : {
3898 [ - + ]: 191 : if (io->bPlainTextTags == 1)
3899 : : {
3900 : 0 : inchi_ios_print_nodisplay(out_file, "///"); /* isotopic composition, sp2, sp3 */
3901 : : }
3902 [ - + ]: 191 : if (io->bPlainTextTags == 1)
3903 : : {
3904 : 0 : inchi_ios_print_nodisplay(out_file, "//"); /* inv or racemic stereo */
3905 : : }
3906 : : }
3907 : :
3908 : : #if (CANON_FIXH_TRANS == 1)
3909 [ - + - - : 197 : if (io->bOutType == OUT_NONTAUT && io->bOutputType == OUT_TN && io->bSecondNonTautPass &&
- - - - ]
3910 : 0 : INCHI_SEGM_FILL == INChI_SegmentAction(io->sDifSegs[DIFL_F][DIFS_o_TRANSP]))
3911 : : {
3912 : : /* find and print non-tautomeric components transposition, if non-trivial */
3913 : : AT_NUMB *nTrans_n, *nTrans_s;
3914 : :
3915 [ # # ]: 0 : if (0 < bin_AuxTautTrans(io->pINChISort, io->pINChISort2, &nTrans_n, &nTrans_s, io->bOutType, io->num_components))
3916 : : {
3917 : : /* a non-trivial transposition does exist; output start tag */
3918 : 0 : szGetTag(IdentLbl, io->nTag, io->bTag1 = IL_TRNS | io->bFhTag, io->szTag1, &io->bAlways, 1);
3919 : 0 : inchi_strbuf_reset(strbuf);
3920 : 0 : io->tot_len = 0;
3921 : : /* print the transposition, cycle after cycle */
3922 : 0 : io->tot_len = str_AuxTautTrans(pCG, nTrans_n, nTrans_s, strbuf,
3923 : : &io->bOverflow, io->TAUT_MODE, io->num_components);
3924 : 0 : io->bNonTautIsoIdentifierNotEmpty += io->bSecondNonTautPass;
3925 [ # # ]: 0 : if (str_LineEnd(io->szTag1, &io->bOverflow, strbuf, -1, io->bPlainTextTags))
3926 : : {
3927 : 0 : return 7;
3928 : : }
3929 : 0 : inchi_ios_print_nodisplay(out_file, "%s%s", strbuf->pStr, pLF);
3930 : : /* detected transposition */
3931 : 0 : (*io->pSortPrintINChIFlags) |=
3932 [ # # ]: 0 : (*INCHI_basic_or_INCHI_reconnected == INCHI_BAS) ? FLAG_SORT_PRINT_TRANSPOS_BAS : FLAG_SORT_PRINT_TRANSPOS_REC;
3933 : : }
3934 : : else
3935 : : {
3936 [ # # ]: 0 : if (io->bPlainTextTags == 1)
3937 : : {
3938 : 0 : inchi_ios_print_nodisplay(out_file, "/");
3939 : : }
3940 : : }
3941 : : }
3942 : : #endif
3943 : :
3944 : 197 : return 0;
3945 : : }
3946 : :
3947 : : /****************************************************************************
3948 : : Output InChI: FixedH layer and related sublayers
3949 : : ****************************************************************************/
3950 : 197 : int OutputINCHI_FixedHLayerWithSublayers(CANON_GLOBALS *pCG,
3951 : : INCHI_IOSTREAM *out_file,
3952 : : INCHI_IOS_STRING *strbuf,
3953 : : int *INCHI_basic_or_INCHI_reconnected,
3954 : : INCHI_OUT_CTL *io,
3955 : : char *pLF,
3956 : : char *pTAB,
3957 : : int *then_goto_repeat)
3958 : : {
3959 : :
3960 : 197 : *then_goto_repeat = 0;
3961 : :
3962 [ + - ]: 197 : if (io->bOutType == OUT_TN &&
3963 [ + - ]: 197 : !(io->bSecondNonTautPass) &&
3964 [ + - ]: 197 : io->bNonTautIsIdenticalToTaut &&
3965 [ + + ]: 197 : io->bTautomeric &&
3966 [ - + ]: 13 : io->bNonTautomeric)
3967 : : {
3968 : : /* Fixed-H layer is empty in the Identifier */
3969 : 0 : (*io->pSortPrintINChIFlags) |=
3970 [ # # ]: 0 : (*INCHI_basic_or_INCHI_reconnected == INCHI_BAS) ? FLAG_SORT_PRINT_NO_NFIX_H_BAS : FLAG_SORT_PRINT_NO_NFIX_H_REC;
3971 : 0 : (*io->pSortPrintINChIFlags) |=
3972 [ # # ]: 0 : (*INCHI_basic_or_INCHI_reconnected == INCHI_BAS) ? FLAG_SORT_PRINT_NO_IFIX_H_BAS : FLAG_SORT_PRINT_NO_IFIX_H_REC;
3973 : : }
3974 : :
3975 [ + - ]: 197 : if (io->bOutType == OUT_TN &&
3976 [ - + - - ]: 197 : !io->bNonTautIsIdenticalToTaut && /* added 2004-10-04 Fix16 */
3977 : : #ifdef OLD_ITEM_DISCOVERY
3978 : : io->bTautomeric &&
3979 : : io->bNonTautomeric &&
3980 : : #endif
3981 : 0 : INChI_SegmentAction(io->sDifSegs[DIFL_F][DIFS_f_FORMULA])
3982 : : /* special case: removed isolated H(+): */
3983 : : /* || io->iCurTautMode == TAUT_YES && num_comp[TAUT_YES] < num_comp[TAUT_NON] &&
3984 : : 0 < num_comp[TAUT_NON]*/
3985 : : )
3986 : :
3987 : : {
3988 : : /* add the second (non-tautomeric) output */
3989 : 0 : io->bOutType = OUT_NONTAUT; /* pick up only non-tautomeric representation of tautomeric */
3990 : 0 : io->iCurTautMode = TAUT_NON;
3991 : 0 : io->pINChISort = io->pINChISortTautAndNonTaut[TAUT_NON];
3992 : 0 : io->bSecondNonTautPass = 1;
3993 : 0 : io->nCurINChISegment = DIFL_F;
3994 : 0 : io->num_components = io->num_comp[io->iCurTautMode]; /* number of components could change due to removal of isolated H(+) from tautomeric */
3995 : 0 : io->bFhTag = IL_FIXH;
3996 : 0 : szGetTag(IdentLbl, io->nTag, io->bTag1 = io->bFhTag, io->szTag1, &io->bAlways, 1);
3997 : : /***** constitution non-taut: dot-disconnected Hill formulas: <formula> -- only if different */
3998 : 0 : szGetTag(IdentLbl, io->nTag, io->bTag1 = IL_FMLF | io->bFhTag, io->szTag1, &io->bAlways, 1);
3999 : 0 : inchi_strbuf_reset(strbuf);
4000 : 0 : io->tot_len = 0;
4001 : 0 : io->nSegmAction = INChI_SegmentAction(io->sDifSegs[io->nCurINChISegment][DIFS_f_FORMULA]);
4002 [ # # ]: 0 : if (INCHI_SEGM_FILL == io->nSegmAction)
4003 : : {
4004 : 0 : io->tot_len2 = str_HillFormula2(io->pINChISort, io->pINChISort2,
4005 : : strbuf, &io->bOverflow, io->bOutType,
4006 : : io->num_components, io->bUseMulipliers);
4007 [ # # # # ]: 0 : if (io->n_pzz > 0 && io->n_zy > 0)
4008 : : {
4009 : 0 : MergeZzInHillFormula(strbuf);
4010 : : }
4011 : 0 : io->bNonTautNonIsoIdentifierNotEmpty += io->bSecondNonTautPass;
4012 : : }
4013 : : else
4014 : : {
4015 : 0 : io->tot_len2 = io->tot_len;
4016 : : }
4017 : 0 : io->tot_len = io->tot_len2;
4018 [ # # ]: 0 : if (str_LineEnd(io->szTag1, &io->bOverflow, strbuf, -io->nSegmAction, io->bPlainTextTags))
4019 : : {
4020 : 0 : return 1;
4021 : : }
4022 : 0 : inchi_ios_print_nodisplay(out_file, "%s%s", strbuf->pStr, pLF);
4023 : :
4024 : 0 : io->nSegmAction = INChI_SegmentAction(io->sDifSegs[io->nCurINChISegment][DIFS_h_H_ATOMS]);
4025 : :
4026 [ # # ]: 0 : if (INCHI_SEGM_FILL == io->nSegmAction)
4027 : : {
4028 : 0 : szGetTag(IdentLbl, io->nTag, io->bTag1 = IL_HFIX | io->bFhTag, io->szTag1, &io->bAlways, 1);
4029 : 0 : inchi_strbuf_reset(strbuf);
4030 : 0 : io->tot_len = 0; /* open H-fixed */
4031 : : /* output the second non-tautomeric item: fixed H -- do not output in xml if empty */
4032 : 0 : io->tot_len2 = str_FixedH_atoms(io->pINChISort, strbuf,
4033 : : &io->bOverflow, io->bOutType, io->ATOM_MODE,
4034 : : io->num_components, io->bUseMulipliers);
4035 : 0 : io->tot_len = io->tot_len2;
4036 [ # # ]: 0 : if (str_LineEnd(io->szTag1, &io->bOverflow, strbuf, -io->nSegmAction, io->bPlainTextTags))
4037 : : {
4038 : 0 : return 2;
4039 : : }
4040 : 0 : inchi_ios_print_nodisplay(out_file, "%s%s", strbuf->pStr, pLF);
4041 : 0 : io->bNonTautNonIsoIdentifierNotEmpty += io->bSecondNonTautPass;
4042 : : }
4043 : 0 : *then_goto_repeat = 1;
4044 : 0 : return 0;
4045 : : }
4046 : :
4047 : : else
4048 : : {
4049 [ - + - - : 197 : if (io->bOutType == OUT_NONTAUT && io->bOutputType == OUT_TN && io->bSecondNonTautPass /* && io->bTautomeric && io->bNonTautomeric*/)
- - ]
4050 : : {
4051 : : /* the second (non-taut) output has been done; restore variables */
4052 : 0 : io->bOutType = OUT_TN;
4053 : 0 : io->iCurTautMode = TAUT_YES;
4054 : 0 : io->pINChISort = io->pINChISortTautAndNonTaut[TAUT_YES];
4055 : 0 : io->bSecondNonTautPass = 0;
4056 : 0 : io->num_components = io->num_comp[io->iCurTautMode];
4057 [ # # ]: 0 : if (!io->bNonTautNonIsoIdentifierNotEmpty)
4058 : : {
4059 : : /* Fixed-H layer is empty in the Identifier */
4060 [ # # ]: 0 : (*io->pSortPrintINChIFlags) |= (*INCHI_basic_or_INCHI_reconnected == INCHI_BAS) ? FLAG_SORT_PRINT_NO_NFIX_H_BAS : FLAG_SORT_PRINT_NO_NFIX_H_REC;
4061 : : }
4062 [ # # ]: 0 : if (!io->bNonTautIsoIdentifierNotEmpty)
4063 : : {
4064 : : /* Fixed-H layer is empty in the Identifier */
4065 [ # # ]: 0 : (*io->pSortPrintINChIFlags) |= (*INCHI_basic_or_INCHI_reconnected == INCHI_BAS) ? FLAG_SORT_PRINT_NO_IFIX_H_BAS : FLAG_SORT_PRINT_NO_IFIX_H_REC;
4066 : : }
4067 : 0 : io->bFhTag = 0;
4068 : : }
4069 : : }
4070 : :
4071 : 197 : return 0;
4072 : : }
4073 : :
4074 : : /****************************************************************************
4075 : : Output InChI: polymer layer
4076 : : ****************************************************************************/
4077 : 197 : static int OutputINCHI_PolymerLayer(CANON_GLOBALS *pCG,
4078 : : INCHI_IOSTREAM *out_file,
4079 : : INCHI_IOS_STRING *strbuf,
4080 : : int *INCHI_basic_or_INCHI_reconnected,
4081 : : ORIG_ATOM_DATA *orig_inp_data,
4082 : : ORIG_STRUCT *pOrigStruct,
4083 : : INCHI_OUT_CTL *io,
4084 : : char *pLF,
4085 : : char *pTAB)
4086 : : {
4087 : 197 : int i, err = 0;
4088 : 197 : int nunits2 = 0;
4089 : 197 : int n_used_stars = 0;
4090 : 197 : int *cano_nums = NULL, *compnt_nums = NULL, *unum = NULL, *old_stars = NULL;
4091 : 197 : OAD_PolymerUnit *u = NULL;
4092 : 197 : OAD_PolymerUnit **units2 = NULL;
4093 : 197 : OAD_Polymer *p = NULL;
4094 : 197 : OAD_AtProps *aprops = NULL;
4095 : : int nat, num_inp_bonds;
4096 : 197 : inp_ATOM *at = NULL;
4097 : 197 : int is_inchi2inchi = 0;
4098 : :
4099 [ + + ]: 197 : if (!orig_inp_data)
4100 : : {
4101 : 13 : goto exit_function;
4102 : : }
4103 : :
4104 : 184 : at = orig_inp_data->at;
4105 : 184 : nat = orig_inp_data->num_inp_atoms;
4106 : 184 : num_inp_bonds = orig_inp_data->num_inp_bonds;
4107 : :
4108 : :
4109 [ + - + + ]: 184 : if (pOrigStruct && !pOrigStruct->polymer)
4110 : : {
4111 : 160 : return 0;
4112 : : }
4113 : :
4114 [ + - ]: 24 : if (pOrigStruct)
4115 : : {
4116 : 24 : p = pOrigStruct->polymer;
4117 [ - + - - : 24 : is_inchi2inchi = !pOrigStruct->szAtoms && !pOrigStruct->szBonds && !pOrigStruct->szCoord;
- - ]
4118 : :
4119 [ - + ]: 24 : if (is_inchi2inchi)
4120 : : {
4121 : 0 : err = NOT_YET_I2I_FOR_POLYMERS;
4122 : 0 : goto exit_function;
4123 : : }
4124 : :
4125 : : /*OAD_Polymer_DebugTrace( p );*/
4126 : :
4127 : : /* Get canonical numbers and numbers-of-components for each original atom */
4128 : 24 : cano_nums = (int *)inchi_calloc((long long)pOrigStruct->num_atoms + 1, sizeof(int)); /* djb-rwth: cast operator added */
4129 [ - + ]: 24 : if (!cano_nums)
4130 : : {
4131 : 0 : err = 1;
4132 : 0 : goto exit_function;
4133 : : }
4134 : 24 : compnt_nums = (int *)inchi_calloc((long long)pOrigStruct->num_atoms + 1, sizeof(int)); /* djb-rwth: cast operator added */
4135 [ - + ]: 24 : if (!compnt_nums)
4136 : : {
4137 : 0 : err = 2;
4138 : 0 : goto exit_function;
4139 : : }
4140 : 24 : err = InternallyGetCanoNumsAndComponentNums(pCG,
4141 : : strbuf,
4142 : : io,
4143 : : pOrigStruct->num_atoms,
4144 : : cano_nums,
4145 : : compnt_nums);
4146 [ - + ]: 24 : if (err != 0)
4147 : : {
4148 : 0 : err = 3;
4149 : 0 : goto exit_function;
4150 : : }
4151 : :
4152 : : /* Set atom properties for sorting */
4153 : 24 : aprops = (OAD_AtProps *)inchi_calloc((long long)nat + 1, sizeof(OAD_AtProps)); /* djb-rwth: cast operator added */
4154 : : /* nat + 1: add extra element for possibe 1-based indexing */
4155 [ - + ]: 24 : if (!aprops)
4156 : : {
4157 : : /* djb-rwth: avoiding memory leak */
4158 [ # # ]: 0 : if (cano_nums)
4159 : : {
4160 [ # # ]: 0 : inchi_free(cano_nums);
4161 : : }
4162 [ # # ]: 0 : if (compnt_nums)
4163 : : {
4164 [ # # ]: 0 : inchi_free(compnt_nums);
4165 : : }
4166 [ # # ]: 0 : if (aprops)
4167 : : {
4168 [ # # ]: 0 : inchi_free(aprops);
4169 : : }
4170 : 0 : return 0;
4171 : : }
4172 : :
4173 : : /* Note that aprops[] is in orig_atoms domain (0-based) and */
4174 : : /* u (from units) are in cano_nums domain (1-based) */
4175 : : /* Supply non-NULL cano_nums to adjust the domains (base will be adjusted at place) */
4176 : 24 : OAD_Polymer_SetAtProps(p, at, nat, &num_inp_bonds, aprops, cano_nums);
4177 : :
4178 : : /* Make a working copy of polymer units data: units2 is a copy */
4179 : : /* of original polymer units (p->units) with atomic numbers changed */
4180 : : /* to curr canonical ones; atoms in alists sorted; atoms in blists */
4181 : : /* and blists themselves sorted */
4182 : 24 : units2 = (OAD_PolymerUnit **)inchi_calloc(p->n, sizeof(OAD_PolymerUnit *));
4183 : :
4184 [ - + ]: 24 : if (NULL == units2)
4185 : : {
4186 : 0 : err = 3;
4187 : 0 : goto exit_function;
4188 : : }
4189 : 24 : memset(units2, 0, sizeof(*units2)); /* djb-rwth: memset_s C11/Annex K variant? */
4190 : :
4191 : 24 : old_stars = (int *)inchi_calloc(pOrigStruct->polymer->n_pzz, sizeof(int));
4192 [ - + ]: 24 : if (NULL == old_stars)
4193 : : {
4194 : 0 : err = 3;
4195 : 0 : goto exit_function;
4196 : : }
4197 [ + + ]: 60 : for (i = 0; i < pOrigStruct->polymer->n_pzz; i++)
4198 : : {
4199 : 36 : old_stars[i] = pOrigStruct->polymer->pzz[i];
4200 : : }
4201 : :
4202 [ + + ]: 48 : for (i = 0; i < p->n; i++)
4203 : : {
4204 : 24 : units2[i] = OAD_PolymerUnit_CreateCopy(p->units[i]);
4205 [ - + ]: 24 : if (NULL == units2[i]) /* djb-rwth: unresolved issue -- revision required? -- units2 properly allocated, and loop index well defined */
4206 : : {
4207 : 0 : err = 4;
4208 : 0 : goto exit_function;
4209 : : }
4210 : 24 : nunits2 = i + 1;
4211 : : }
4212 : :
4213 : : /* unum contains numbers of units (0..p->n) as they go */
4214 : : /* when sorted by alist's in lexicographic order */
4215 : 24 : unum = (int *)inchi_calloc(p->n, sizeof(int));
4216 [ - + ]: 24 : if (NULL == unum)
4217 : : {
4218 : 0 : err = 4;
4219 : 0 : goto exit_function;
4220 : : }
4221 : :
4222 : 24 : err = OAD_Polymer_PrepareWorkingSet(p, cano_nums, compnt_nums, units2, unum);
4223 : :
4224 [ - + ]: 24 : if (err != 0)
4225 : : {
4226 : 0 : err = 5;
4227 : 0 : goto exit_function;
4228 : : }
4229 : :
4230 : : /* Prepare polymer substring */
4231 : :
4232 : : /* Mark layer beginning */
4233 : 24 : inchi_strbuf_printf(strbuf, "%s", "/z");
4234 : :
4235 : : /* Print polymer units data */
4236 : 24 : n_used_stars = 0;
4237 [ + + ]: 48 : for (i = 0; i < p->n; i++)
4238 : : {
4239 : : /* For each unit u ... */
4240 : 24 : u = units2[unum[i]];
4241 : : /* djb-rwth: addressing coverity ID #499574 -- all NULL checks already done above */
4242 : 24 : err = OutputINCHI_PolymerLayer_SingleUnit(u,
4243 : : io->bPolymers,
4244 : 24 : pOrigStruct->polymer->n_pzz,
4245 : : &n_used_stars, aprops,
4246 : : cano_nums,
4247 : : orig_inp_data,
4248 : : pOrigStruct, strbuf);
4249 [ - + ]: 24 : if (err)
4250 : : {
4251 : 0 : goto exit_function;
4252 : : }
4253 [ - + ]: 24 : if (i < p->n - 1)
4254 : : {
4255 : 0 : inchi_strbuf_printf(strbuf, ";");
4256 : : }
4257 : : }
4258 : 24 : inchi_ios_print_nodisplay(out_file, "%s%s", strbuf->pStr, pLF);
4259 : :
4260 : : LOG_NO_ARGS("\n******************* (L4184:ichiprt1.c) ********************\n");
4261 : : LOG_MULT_ARGS("Polymer Layer start: %s\n", strbuf->pStr);
4262 : : LOG_NO_ARGS("\n***********************************************************\n");
4263 : :
4264 : 37 : exit_function:
4265 [ + + ]: 37 : if (cano_nums)
4266 : : {
4267 [ + - ]: 24 : inchi_free(cano_nums);
4268 : : }
4269 [ + + ]: 37 : if (compnt_nums)
4270 : : {
4271 [ + - ]: 24 : inchi_free(compnt_nums);
4272 : : }
4273 [ + + ]: 37 : if (aprops)
4274 : : {
4275 [ + - ]: 24 : inchi_free(aprops);
4276 : : }
4277 [ + + ]: 37 : if (unum)
4278 : : {
4279 [ + - ]: 24 : inchi_free(unum);
4280 : : }
4281 [ + + ]: 37 : if (units2)
4282 : : {
4283 [ + + ]: 48 : for (i = 0; i < nunits2; i++)
4284 : : {
4285 : 24 : OAD_PolymerUnit_Free(units2[i]);
4286 : : }
4287 [ + - ]: 24 : inchi_free(units2);
4288 : : }
4289 [ + + ]: 37 : if (old_stars)
4290 : : {
4291 [ + + ]: 60 : for (i = 0; i < pOrigStruct->polymer->n_pzz; i++)
4292 : 36 : pOrigStruct->polymer->pzz[i] = old_stars[i];
4293 [ + - ]: 24 : inchi_free(old_stars);
4294 : : }
4295 : : }
4296 : 37 : return err;
4297 : : }
4298 : :
4299 : : /****************************************************************************
4300 : : Output InChI: polymer layer, single CRU data
4301 : : ****************************************************************************/
4302 : 24 : static int OutputINCHI_PolymerLayer_SingleUnit(OAD_PolymerUnit *u,
4303 : : int bPolymers,
4304 : : int total_star_atoms,
4305 : : int *n_used_stars,
4306 : : OAD_AtProps *aprops,
4307 : : int *cano_nums,
4308 : : ORIG_ATOM_DATA *orig_inp_data,
4309 : : ORIG_STRUCT *pOrigStruct,
4310 : : INCHI_IOS_STRING *strbuf)
4311 : : {
4312 : 24 : int j, k, tmp, a1 = 0, a2 = 0, a3 = 0, a4 = 0, b, curr_star_num;
4313 : 24 : int err = 0;
4314 : 24 : OAD_Polymer *p = orig_inp_data->polymer;
4315 : 24 : inp_ATOM *at = orig_inp_data->at;
4316 : :
4317 : : /* print unit type and subtype */
4318 : 24 : inchi_strbuf_printf(strbuf, "%-d%-d%-d-", u->type, u->subtype, u->conn);
4319 : :
4320 : : /* print unit atoms */
4321 : 24 : print_sequence_of_nums_compressing_ranges(u->na, u->alist, strbuf);
4322 : :
4323 : : /* Print the crossing bonds or frame-shiftable pattern */
4324 [ - + ]: 24 : if (u->nb > 2)
4325 : : {
4326 : : /* not supported yet, too many bonds in SBL */
4327 : 0 : err = 12;
4328 : 0 : goto exit_function;
4329 : : }
4330 : :
4331 : : /* Print crossing bonds "(cap1-partner1,cap2-partner2)" */
4332 [ + + + - : 24 : if (u->nb == 2 && (!u->cyclizable || !u->cyclized))
+ + ]
4333 : 16 : {
4334 : 16 : int swap = 0;
4335 : 16 : a1 = u->blist[0];
4336 : 16 : a2 = u->blist[1];
4337 : 16 : a3 = u->blist[2];
4338 : 16 : a4 = u->blist[3];
4339 : :
4340 [ - + ]: 16 : if (is_in_the_ilist( u->alist, a1, u->na ))
4341 : : {
4342 : 0 : tmp = a2;
4343 : 0 : a2 = a1;
4344 : 0 : a1 = tmp;
4345 : : }
4346 [ - + ]: 16 : if (is_in_the_ilist(u->alist, a3, u->na))
4347 : : {
4348 : 0 : tmp = a4;
4349 : 0 : a4 = a3;
4350 : 0 : a3 = tmp;
4351 : : }
4352 : :
4353 : : /* Always print first the crossing bond pointing to more senior CRU end ("head") */
4354 [ - + ]: 16 : if (bPolymers == POLYMERS_LEGACY)
4355 : : {
4356 : : /* old, v. 1.05 */
4357 : : /* The first printed is the crossing bond with higher canonical number of the cap */
4358 : 0 : swap = a3 < a1;
4359 : : }
4360 : : else
4361 : : {
4362 : : /* new in v. 1.06 */
4363 : : /* The first printed is the crossing bond pointing to more senior CRU end ("head") */
4364 : 16 : swap = (OAD_Polymer_IsFirstAtomRankLower(a2, a4, aprops) == 1);
4365 : : }
4366 : :
4367 [ + + ]: 16 : if (swap)
4368 : : {
4369 : 14 : inchi_strbuf_printf(strbuf, "(%-d-%-d,%-d-%-d)", a3, a4, a1, a2);
4370 : : }
4371 : : else
4372 : : {
4373 : 2 : inchi_strbuf_printf(strbuf, "(%-d-%-d,%-d-%-d)", a1, a2, a3, a4);
4374 : : }
4375 : : }
4376 : :
4377 [ - + + + : 8 : else if (u->nb <= 2 && (u->cyclizable || u->nbkbonds > 0))
+ - ]
4378 : : {
4379 : : /* Print frame-shiftable pattern "cap1,cap2-(b1a1,b1a2, b2a1,b2a2, ... )" */
4380 : : /* where b1, b2, ... are CRU bonds potentially invilved in frame shift */
4381 : :
4382 : : /* Get actual star atoms numbers from all-units pool */
4383 : : /* NB: ordered according to already established in units2/unum */
4384 [ - + - - ]: 6 : if (u->cap1 > 0 || u->cap2 > 0)
4385 : : {
4386 : 6 : int n_expl_H = 0, pos = 0;
4387 : 6 : char *sza = pOrigStruct->szAtoms;
4388 [ + + ]: 60 : while (sza[pos])
4389 : : {
4390 [ - + ]: 54 : if (sza[pos] == 'H')
4391 : : {
4392 [ # # # # ]: 0 : if (isupper(UCINT sza[pos + 1]) || !sza[pos + 1]) /* if ( next_c is Uppercase or NUL ) */
4393 : : {
4394 : 0 : n_expl_H++;
4395 : : }
4396 [ # # ]: 0 : if (!sza[pos + 1])
4397 : : {
4398 : 0 : break;
4399 : : }
4400 : : }
4401 : 54 : pos++;
4402 : : }
4403 : :
4404 [ + - ]: 6 : if (u->cap1 > 0)
4405 : : {
4406 : 6 : curr_star_num = pOrigStruct->num_atoms - n_expl_H - total_star_atoms + *n_used_stars + 1;
4407 [ - + ]: 6 : if (curr_star_num > pOrigStruct->num_atoms)
4408 : : {
4409 : 0 : err = 11;
4410 : 0 : goto exit_function;
4411 : : }
4412 : 6 : a1 = curr_star_num;
4413 : 6 : (*n_used_stars)++;
4414 : : }
4415 [ + - ]: 6 : if (u->cap2 > 0)
4416 : : {
4417 : 6 : curr_star_num = pOrigStruct->num_atoms - n_expl_H - total_star_atoms + *n_used_stars + 1;
4418 [ - + ]: 6 : if (curr_star_num > pOrigStruct->num_atoms)
4419 : : {
4420 : 0 : err = 11;
4421 : 0 : goto exit_function;
4422 : : }
4423 : 6 : a2 = curr_star_num;
4424 : 6 : (*n_used_stars)++;
4425 : : }
4426 : : }
4427 : : /* a1 and a2 are number of star atoms associated (but actually */
4428 : : /* disconnected at this moment ) with SRU head and tail atoms */
4429 : 6 : inchi_strbuf_printf(strbuf, "(%-d,%-d-", a1, a2);
4430 : :
4431 [ - + ]: 6 : if (u->cyclizable == CLOSING_SRU_DIRADICAL)
4432 : : {
4433 : 0 : inchi_strbuf_printf(strbuf, "%-d)", u->end_atom1);
4434 : : }
4435 [ - + ]: 6 : else if (u->cyclizable == CLOSING_SRU_HIGHER_ORDER_BOND)
4436 : : {
4437 : 0 : a3 = u->end_atom1;
4438 : 0 : a4 = u->end_atom2;
4439 : 0 : inchi_sort_int_pair_ascending(&a3, &a4);
4440 : : /* if ( a3 > a4 ) { tmp = a4; a4 = a3; a3 = tmp; }*/
4441 : 0 : inchi_strbuf_printf(strbuf, "%-d.%-d)", a3, a4);
4442 : : }
4443 [ - + ]: 6 : else if (u->cyclizable == CLOSING_SRU_RING)
4444 : : {
4445 [ + - ]: 6 : if (u->nbkbonds == 0)
4446 : : {
4447 : : /* last resort */
4448 : 6 : a3 = u->end_atom1;
4449 : 6 : a4 = u->end_atom2;
4450 : 6 : inchi_sort_int_pair_ascending(&a3, &a4);
4451 : : /* if ( a3 > a4 ) { tmp = a4; a4 = a3; a3 = tmp; } */
4452 : 6 : inchi_strbuf_printf(strbuf, "%-d,%-d)", a3, a4);
4453 : : }
4454 : : else
4455 : : {
4456 : : /* Sort all backbone bonds in min-at-number order */
4457 [ # # ]: 0 : for (b = 1; b < u->nbkbonds; b++)
4458 : : {
4459 : 0 : int *tmp_psbond = u->bkbonds[b];
4460 : 0 : j = b - 1;
4461 [ # # # # ]: 0 : while (j >= 0 && IsBondAtomNumsLesser(u->bkbonds[j], tmp_psbond) > 0)
4462 : : {
4463 : 0 : u->bkbonds[j + 1] = u->bkbonds[j];
4464 : 0 : j--;
4465 : : }
4466 : 0 : u->bkbonds[j + 1] = tmp_psbond;
4467 : : }
4468 : :
4469 [ # # # # ]: 0 : if (p->treat == POLYMERS_MODERN || p->treat == POLYMERS_LEGACY_PLUS)
4470 : : {
4471 : : /* was #if DO_POLYMER_FRAME_SHIFT_AT_STRUCT_TO_INCHI_CONVERSION==1 */
4472 : : /* was: OAD_PolymerUnit_ReorderPolymerFrameShiftLinks( u, orig_inp_data, aprops, cano_nums );
4473 : : OAD_Polymer_DebugTrace(p);*/
4474 : :
4475 : : /* Find senior link and move it to the beginning of list
4476 : : If necessary, swap atoms in link so that the first
4477 : : points to SRU head and the next to SRU tail
4478 : :
4479 : : The net result of ordering is as follows:
4480 : : at1,at2, at3,at4, at5,at6, ...
4481 : : here
4482 : : at1, at2 is the most senior bond, and at1 is more senior than at2
4483 : : all other pairs at3,at4, at5,at6, ... are sorted just in increasing
4484 : : order of first number in pair, then second one, e.g.: at3<at4; at3<=at5
4485 : : (and if at3==at5 then at4<at6)
4486 : : */
4487 : :
4488 [ # # # # : 0 : if (p->frame_shift_scheme != FSS_NONE && u->nbkbonds >= 1 && u->cap1 >= 1 && u->cap2 >= 1)
# # # # ]
4489 : : {
4490 [ # # ]: 0 : if (OAD_PolymerUnit_SetReopeningDetails(u, at))
4491 : : {
4492 : : /* Find senior backbone bond and move it to the beginning of list */
4493 : : {
4494 : : int senior_bond, bond0at1, bond0at2;
4495 : 0 : OAD_PolymerUnit_SortBackboneBondsAndSetSeniors(u, at, aprops, &senior_bond);
4496 [ # # ]: 0 : if (senior_bond)
4497 : : {
4498 : 0 : bond0at1 = u->bkbonds[0][0];
4499 : 0 : bond0at2 = u->bkbonds[0][1];
4500 : 0 : u->bkbonds[0][0] = u->bkbonds[senior_bond][0];
4501 : 0 : u->bkbonds[0][1] = u->bkbonds[senior_bond][1];
4502 : 0 : u->end_atom1 = u->bkbonds[0][0];
4503 : 0 : u->end_atom2 = u->bkbonds[0][1];
4504 : 0 : u->bkbonds[senior_bond][0] = bond0at1;
4505 : 0 : u->bkbonds[senior_bond][1] = bond0at2;
4506 : : }
4507 : : }
4508 : : }
4509 : : }
4510 : : /* p->really_do_frame_shift = 0; */
4511 : : }
4512 : :
4513 [ # # ]: 0 : for (k = 0; k < u->nbkbonds; k++)
4514 : : {
4515 : 0 : a3 = u->bkbonds[k][0];
4516 : 0 : a4 = u->bkbonds[k][1];
4517 : : /*if ( a3 > a4 ) { tmp = a4; a4 = a3; a3 = tmp; }*/
4518 [ # # ]: 0 : inchi_strbuf_printf(strbuf, "%-d,%-d%-c", a3, a4, k == u->nbkbonds - 1 ? ')' : ',');
4519 : : }
4520 : : }
4521 : : }
4522 : : }
4523 : :
4524 : 2 : exit_function:
4525 : :
4526 : 24 : return err;
4527 : : }
4528 : :
4529 : : /****************************************************************************
4530 : : Output AuxInfo: header and normalization type
4531 : : ****************************************************************************/
4532 : 184 : int OutputAUXINFO_HeaderAndNormalization_type(CANON_GLOBALS *pCG,
4533 : : INCHI_IOSTREAM *out_file,
4534 : : INCHI_IOS_STRING *strbuf,
4535 : : int bINChIOutputOptions,
4536 : : int *INCHI_basic_or_INCHI_reconnected,
4537 : : int num_components2[],
4538 : : INCHI_OUT_CTL *io,
4539 : : char *pLF,
4540 : : char *pTAB)
4541 : : {
4542 : : /* AuxInfo header */
4543 [ + - ]: 184 : if (*INCHI_basic_or_INCHI_reconnected == INCHI_BAS)
4544 : : {
4545 : 184 : inchi_strbuf_printf(strbuf, "AuxInfo="); /* in wINChI window, separate INChI: from AuxInfo: with blank line */
4546 : 184 : inchi_ios_print(out_file, "%s%s%s",
4547 : : /* blank line before AuxInfo in winchi window unless it is an annotation */
4548 [ - + ]: 184 : (bINChIOutputOptions & INCHI_OUT_WINCHI_WINDOW) ? "\n" : "",
4549 : : strbuf->pStr, pLF);
4550 : 184 : szGetTag(AuxLbl, io->nTag, io->bTag1 = AL_VERS, io->szTag1, &io->bAlways, 0);
4551 : 184 : inchi_strbuf_reset(strbuf);
4552 : 184 : io->tot_len = 0;
4553 : 184 : inchi_strbuf_printf(strbuf, "%s", x_curr_ver);
4554 : : /* avoid leading slash in plain output */
4555 [ - + ]: 184 : if (str_LineEnd(io->szTag1, &io->bOverflow, strbuf, -1, io->bPlainTextTags))
4556 : : {
4557 : 0 : return 1;
4558 : : }
4559 : 184 : inchi_ios_print(out_file, "%s%s", strbuf->pStr, pLF);
4560 : : }
4561 : : else
4562 : : {
4563 [ # # ]: 0 : if (*INCHI_basic_or_INCHI_reconnected == INCHI_REC)
4564 : : {
4565 : 0 : szGetTag(AuxLbl, io->nTag, io->bTag1 = AL_REC_, io->szTag1, &io->bAlways, 0);
4566 : 0 : inchi_ios_print(out_file, "%s%s", io->szTag1, pLF);
4567 : : }
4568 : : }
4569 : :
4570 : : /* AuxInfo normalization type */
4571 [ - + - - ]: 184 : if (num_components2[0] || num_components2[1])
4572 : : {
4573 : 184 : szGetTag(AuxLbl, io->nTag, io->bTag1 = AL_NORM, io->szTag1, &io->bAlways, 0);
4574 : 184 : inchi_strbuf_reset(strbuf);
4575 : 184 : io->tot_len = 0;
4576 [ + + + - ]: 184 : inchi_strbuf_printf(strbuf, "%d", (io->bTautomeric && io->bTautomericOutputAllowed) ? io->bTautomeric : 0);
4577 [ - + ]: 184 : if (str_LineEnd(io->szTag1, &io->bOverflow, strbuf, -1, io->bPlainTextTags))
4578 : : {
4579 : 0 : return 1;
4580 : : }
4581 : 184 : inchi_ios_print(out_file, "%s%s", strbuf->pStr, pLF);
4582 : : }
4583 : :
4584 : 184 : return 0;
4585 : : }
4586 : :
4587 : : /****************************************************************************
4588 : : Output AuxInfo: original atom numbers and symmetry numbers (constit. equivalence /E: )
4589 : : ****************************************************************************/
4590 : 184 : int OutputAUXINFO_OriginalNumbersAndEquivalenceClasses(CANON_GLOBALS *pCG,
4591 : : INCHI_IOSTREAM *out_file,
4592 : : INCHI_IOS_STRING *strbuf,
4593 : : int num_components2[],
4594 : : INCHI_OUT_CTL *io,
4595 : : char *pLF,
4596 : : char *pTAB)
4597 : : {
4598 : : /* Original atom numbers in order of canonical numbers */
4599 [ - + - - ]: 184 : if (num_components2[0] || num_components2[1])
4600 : : {
4601 : 368 : szGetTag(AuxLbl, io->nTag,
4602 [ - + ]: 184 : io->bTag1 = (io->bSecondNonTautPass ? AL_FIXN : AL_ANBR) | io->bFhTag, io->szTag1, &io->bAlways, 0);
4603 : 184 : inchi_strbuf_reset(strbuf);
4604 : 184 : io->tot_len = 0;
4605 : : /* Original numbering output */
4606 : 184 : io->tot_len = str_AuxNumb(pCG, io->pINChISort, io->pINChISort2,
4607 : : strbuf, &io->bOverflow,
4608 : : io->bOutType, io->TAUT_MODE, io->num_components,
4609 : : io->bSecondNonTautPass, io->bOmitRepetitions);
4610 : :
4611 [ - + ]: 184 : if (str_LineEnd(io->szTag1, &io->bOverflow, strbuf, -1, io->bPlainTextTags))
4612 : : {
4613 : 0 : return 1;
4614 : : }
4615 : 184 : inchi_ios_print(out_file, "%s%s", strbuf->pStr, pLF);
4616 : : }
4617 : :
4618 : : /*
4619 : : Symmetry numbers (constit. equivalence) /E:
4620 : : */
4621 [ + + ]: 184 : if (io->bAtomEqu[io->iCurTautMode])
4622 : : {
4623 : : /* aux equ atoms */
4624 : : /* 1. Compare to tautomeric equivalence (in case of second, non-taut, pass only) */
4625 : : /* 2. Compare to the previous component if (1) failed to find equivalence */
4626 : 43 : szGetTag(AuxLbl, io->nTag, io->bTag1 = AL_AEQU | io->bFhTag, io->szTag1, &io->bAlways, 0);
4627 : 43 : inchi_strbuf_reset(strbuf);
4628 : 43 : io->tot_len = 0;
4629 : 43 : io->tot_len = str_AuxEqu(io->pINChISort, io->pINChISort2,
4630 : : strbuf, &io->bOverflow, io->bOutType, io->TAUT_MODE,
4631 : : io->num_components, io->bSecondNonTautPass,
4632 : : io->bOmitRepetitions, io->bUseMulipliers);
4633 : :
4634 [ - + ]: 43 : if (str_LineEnd(io->szTag1, &io->bOverflow, strbuf, -1, io->bPlainTextTags))
4635 : : {
4636 : 0 : return 1;
4637 : : }
4638 : 43 : inchi_ios_print(out_file, "%s%s", strbuf->pStr, pLF);
4639 : : }
4640 : : else
4641 : : {
4642 [ - + ]: 141 : if (io->bPlainTextTags == 1)
4643 : : {
4644 : 0 : inchi_ios_print(out_file, "/");
4645 : : }
4646 : : }
4647 : :
4648 : 184 : return 0;
4649 : : }
4650 : :
4651 : : /****************************************************************************
4652 : : Output AuxInfo: tautomeric groups equivalence
4653 : : ****************************************************************************/
4654 : 184 : int OutputAUXINFO_TautomericGroupsEquivalence(CANON_GLOBALS *pCG,
4655 : : INCHI_IOSTREAM *out_file,
4656 : : INCHI_IOS_STRING *strbuf,
4657 : : INCHI_OUT_CTL *io)
4658 : : {
4659 [ + - + + : 184 : if (io->bTautomericOutputAllowed && io->bTautomeric && io->bTautEqu[io->iCurTautMode] && !io->bSecondNonTautPass)
+ + + - ]
4660 : : {
4661 : : /*-- Tautomeric groups constitutional equivalence */
4662 : :
4663 : : /*-- aux tgroup equ */
4664 : 2 : szGetTag(AuxLbl, io->nTag, io->bTag1 = AL_GEQU | io->bFhTag, io->szTag1, &io->bAlways, 0);
4665 : 2 : inchi_strbuf_reset(strbuf);
4666 : 2 : io->tot_len = 0;
4667 : 2 : io->tot_len = str_AuxTgroupEqu(io->pINChISort,
4668 : : strbuf, &io->bOverflow, io->bOutType, io->TAUT_MODE,
4669 : : io->num_components, io->bUseMulipliers);
4670 [ - + ]: 2 : if (str_LineEnd(io->szTag1, &io->bOverflow, strbuf, -1, io->bPlainTextTags))
4671 : : {
4672 : 0 : return 1;
4673 : : }
4674 : 2 : inchi_ios_print(out_file, "%s", strbuf->pStr);
4675 : : }
4676 : : else
4677 : : {
4678 [ + - + + ]: 182 : if (io->bTautomericOutputAllowed && io->bTautomeric)
4679 : : {
4680 [ - + ]: 9 : if (io->bPlainTextTags == 1)
4681 : : {
4682 : 0 : inchi_ios_print(out_file, "/");
4683 : : }
4684 : : }
4685 : : }
4686 : :
4687 : 184 : return 0;
4688 : : }
4689 : :
4690 : : /****************************************************************************
4691 : : Output AuxInfo: stereo info
4692 : : ****************************************************************************/
4693 : 184 : int OutputAUXINFO_Stereo(CANON_GLOBALS *pCG,
4694 : : INCHI_IOSTREAM *out_file,
4695 : : INCHI_IOS_STRING *strbuf,
4696 : : INCHI_OUT_CTL *io,
4697 : : char *pLF,
4698 : : char *pTAB)
4699 : : {
4700 : : /*-- Inverted stereo -- sp3 only + canonical numbering
4701 : : */
4702 [ + + ]: 184 : if (io->bInvStereo[io->iCurTautMode])
4703 : : {
4704 : 51 : szGetTag(AuxLbl, io->nTag, io->bTag1 = AL_STER | io->bFhTag, io->szTag1, &io->bAlways, 0);
4705 : : /*-- inverted sp3 start tag */
4706 : 51 : szGetTag(AuxLbl, io->nTag, io->bTag2 = io->bTag1 | AL_SP3I, io->szTag2, &io->bAlways, 0);
4707 : 51 : inchi_strbuf_reset(strbuf);
4708 : 51 : io->tot_len = 0;
4709 : 51 : io->tot_len = str_AuxInvSp3(io->pINChISort, io->pINChISort2, strbuf,
4710 : : &io->bOverflow, io->bOutType, io->TAUT_MODE, io->num_components,
4711 : : io->bSecondNonTautPass, io->bOmitRepetitions, io->bUseMulipliers);
4712 [ - + ]: 51 : if (str_LineEnd(io->szTag2, &io->bOverflow, strbuf, -1, io->bPlainTextTags))
4713 : 0 : return 1;
4714 : 51 : inchi_ios_print(out_file, "%s%s", strbuf->pStr, pLF);
4715 : :
4716 : : /*-- inverted sp3 canonical numbering */
4717 [ - + ]: 51 : if (io->bInvStereoOrigNumb[io->iCurTautMode])
4718 : : {
4719 : 0 : szGetTag(AuxLbl, io->nTag, io->bTag2 = io->bTag1 | AL_SP3N, io->szTag2, &io->bAlways, 0);
4720 : 0 : inchi_strbuf_reset(strbuf);
4721 : 0 : io->tot_len = 0;
4722 : :
4723 : 0 : io->tot_len = str_AuxInvSp3Numb(pCG, io->pINChISort, io->pINChISort2,
4724 : : strbuf, &io->bOverflow, io->bOutType,
4725 : : io->TAUT_MODE, io->num_components,
4726 : : io->bSecondNonTautPass, io->bOmitRepetitions);
4727 : :
4728 [ # # ]: 0 : if (str_LineEnd(io->szTag2, &io->bOverflow, strbuf, -1, io->bPlainTextTags))
4729 : : {
4730 : 0 : return 1;
4731 : : }
4732 : 0 : inchi_ios_print(out_file, "%s%s", strbuf->pStr, pLF);
4733 : : }
4734 : : else
4735 : : {
4736 [ - + ]: 51 : if (io->bPlainTextTags == 1)
4737 : 0 : inchi_ios_print(out_file, "/");
4738 : : }
4739 : : }
4740 : : else
4741 : : {
4742 [ - + ]: 133 : if (io->bPlainTextTags == 1)
4743 : : {
4744 : 0 : inchi_ios_print(out_file, "//");
4745 : : }
4746 : : /* Inverted stereo -- sp3 only + canonical numbering */
4747 : : }
4748 : :
4749 : 184 : return 0;
4750 : : }
4751 : :
4752 : : /****************************************************************************
4753 : : Output AuxInfo: isotopic info
4754 : : ****************************************************************************/
4755 : 184 : int OutputAUXINFO_IsotopicInfo(CANON_GLOBALS *pCG,
4756 : : INCHI_IOSTREAM *out_file,
4757 : : INCHI_IOS_STRING *strbuf,
4758 : : int *INCHI_basic_or_INCHI_reconnected,
4759 : : INCHI_OUT_CTL *io,
4760 : : char *pLF,
4761 : : char *pTAB)
4762 : : {
4763 : : int i;
4764 : :
4765 : : /* if InChI Fixed-H isotopic is empty, then do not output corresponding AuxInfo */
4766 : :
4767 [ - + ]: 184 : i = io->bSecondNonTautPass &&
4768 [ # # # # ]: 0 : (*io->pSortPrintINChIFlags & ((*INCHI_basic_or_INCHI_reconnected == INCHI_BAS) ? FLAG_SORT_PRINT_NO_IFIX_H_BAS : FLAG_SORT_PRINT_NO_IFIX_H_REC));
4769 : :
4770 [ + + + - ]: 184 : if (io->bIsotopic && !i &&
4771 [ + - ]: 6 : (io->bIsotopicOrigNumb[io->iCurTautMode] ||
4772 [ + - ]: 6 : io->bIsotopicAtomEqu[io->iCurTautMode] ||
4773 [ + - - + : 6 : (io->bTautomericOutputAllowed && io->bTautomeric && io->bIsotopicTautEqu[io->iCurTautMode]) ||
- - ]
4774 [ + + + - : 6 : (io->bInvIsotopicStereo[io->iCurTautMode] && (io->bIgn_UU_Sp3_Iso[io->iCurTautMode])) || io->bIgn_UU_Sp2_Iso[io->iCurTautMode])) /* djb-rwth: addressing LLVM warnings */
- + ]
4775 : : {
4776 : : /*-- isotopic aux info header */
4777 : 0 : szGetTag(AuxLbl, io->nTag, io->bTag1 = AL_ISOT | io->bFhTag, io->szTag1, &io->bAlways, 0);
4778 : 0 : inchi_strbuf_reset(strbuf); /* pStr[io->tot_len = 0] = '\0'; */
4779 : : /*-- Original atom numbers in order of isotopic canonical numbers */
4780 : 0 : szGetTag(AuxLbl, io->nTag, io->bTag2 = io->bTag1 | AL_ISON, io->szTag2, &io->bAlways, 0);
4781 [ # # ]: 0 : if (io->bIsotopicOrigNumb[io->iCurTautMode])
4782 : : {
4783 : 0 : inchi_strbuf_reset(strbuf);
4784 : 0 : io->tot_len = 0;
4785 : 0 : io->tot_len = str_AuxIsoNumb(pCG, io->pINChISort, io->pINChISort2,
4786 : : strbuf, &io->bOverflow, io->bOutType,
4787 : : io->TAUT_MODE, io->num_components,
4788 : : io->bSecondNonTautPass, io->bOmitRepetitions);
4789 [ # # ]: 0 : if (str_LineEnd(io->szTag2, &io->bOverflow, strbuf, -1, io->bPlainTextTags))
4790 : : {
4791 : 0 : return 1;
4792 : : }
4793 : 0 : inchi_ios_print(out_file, "%s%s", strbuf->pStr, pLF);
4794 : : }
4795 : : else
4796 : : {
4797 : : /*if ( io->bPlainTextTags == 1 ) inchi_ios_print( out_file, "/" );*/
4798 : 0 : inchi_ios_print(out_file, "%s%s", io->szTag2, pLF); /* mark isotopic output */
4799 : : }
4800 : :
4801 : : /*-- Isotopic symmetry */
4802 [ # # ]: 0 : if (io->bIsotopicAtomEqu[io->iCurTautMode])
4803 : : {
4804 : : /*-- atoms */
4805 : 0 : szGetTag(AuxLbl, io->nTag, io->bTag2 = io->bTag1 | AL_AEQU, io->szTag2, &io->bAlways, 0);
4806 : 0 : inchi_strbuf_reset(strbuf);
4807 : 0 : io->tot_len = 0;
4808 : 0 : io->tot_len = str_AuxIsoEqu(io->pINChISort, io->pINChISort2,
4809 : : strbuf,
4810 : : &io->bOverflow, io->bOutType, io->TAUT_MODE, io->num_components,
4811 : : io->bSecondNonTautPass, io->bOmitRepetitions, io->bUseMulipliers);
4812 [ # # ]: 0 : if (str_LineEnd(io->szTag2, &io->bOverflow, strbuf, -2 /*was -1: Fix15*/, io->bPlainTextTags))
4813 : : {
4814 : 0 : return 1;
4815 : : }
4816 : 0 : inchi_ios_print(out_file, "%s%s", strbuf->pStr, pLF);
4817 : : }
4818 : : else
4819 : : {
4820 [ # # ]: 0 : if (io->bPlainTextTags == 1)
4821 : : {
4822 : 0 : inchi_ios_print(out_file, "/");
4823 : : }
4824 : : }
4825 : :
4826 : : /*-- Tautomeric groups, isotopic */
4827 [ # # # # : 0 : if (io->bTautomericOutputAllowed && io->bTautomeric && io->bIsotopicTautEqu[io->iCurTautMode])
# # ]
4828 : : {
4829 : : /*-- Isotopic tautomeric groups equivalence */
4830 : 0 : szGetTag(AuxLbl, io->nTag, io->bTag2 = io->bTag1 | AL_GEQU, io->szTag2, &io->bAlways, 0);
4831 : 0 : inchi_strbuf_reset(strbuf);
4832 : 0 : io->tot_len = 0;
4833 : 0 : io->tot_len = str_AuxIsoTgroupEqu(io->pINChISort,
4834 : : strbuf, &io->bOverflow,
4835 : : io->bOutType, io->TAUT_MODE, io->num_components,
4836 : : io->bOmitRepetitions, io->bUseMulipliers);
4837 [ # # ]: 0 : if (str_LineEnd(io->szTag2, &io->bOverflow, strbuf, -2 /*was -1: Fix15*/, io->bPlainTextTags))
4838 : : {
4839 : 0 : return 1;
4840 : : }
4841 : 0 : inchi_ios_print(out_file, "%s%s", strbuf->pStr, pLF);
4842 : : }
4843 : : else
4844 : : {
4845 [ # # # # ]: 0 : if (io->bTautomericOutputAllowed && io->bTautomeric)
4846 : : {
4847 [ # # ]: 0 : if (io->bPlainTextTags == 1)
4848 : : {
4849 : 0 : inchi_ios_print(out_file, "/");
4850 : : }
4851 : : }
4852 : : }
4853 : : /*-- Isotopic inverted stereo */
4854 [ # # ]: 0 : if (io->bInvIsotopicStereo[io->iCurTautMode])
4855 : : {
4856 : 0 : szGetTag(AuxLbl, io->nTag, io->bTag2 = io->bTag1 | AL_STER, io->szTag2, &io->bAlways, 0);
4857 : : /*-- inverted isotopic sp3 start tag */
4858 : 0 : szGetTag(AuxLbl, io->nTag, io->bTag3 = io->bTag2 | AL_SP3I, io->szTag3, &io->bAlways, 0);
4859 : 0 : inchi_strbuf_reset(strbuf);
4860 : 0 : io->tot_len = 0;
4861 : 0 : io->tot_len = str_AuxInvIsoSp3(io->pINChISort, io->pINChISort2,
4862 : : strbuf, &io->bOverflow,
4863 : : io->bOutType, io->TAUT_MODE, io->num_components,
4864 : : io->bSecondNonTautPass, io->bOmitRepetitions, io->bUseMulipliers);
4865 [ # # ]: 0 : if (str_LineEnd(io->szTag3, &io->bOverflow, strbuf, -1, io->bPlainTextTags))
4866 : : {
4867 : 0 : return 1;
4868 : : }
4869 : 0 : inchi_ios_print(out_file, "%s", strbuf->pStr);
4870 : : /*-- inverted isotopic sp3 canonical numbering */
4871 [ # # ]: 0 : if (io->bInvIsotopicStereoOrigNumb[io->iCurTautMode])
4872 : : {
4873 : 0 : szGetTag(AuxLbl, io->nTag, io->bTag3 = io->bTag2 | AL_SP3N, io->szTag3, &io->bAlways, 0);
4874 : 0 : inchi_strbuf_reset(strbuf);
4875 : 0 : io->tot_len = 0;
4876 : 0 : io->tot_len = str_AuxInvIsoSp3Numb(pCG, io->pINChISort, io->pINChISort2,
4877 : : strbuf, &io->bOverflow,
4878 : : io->bOutType, io->TAUT_MODE,
4879 : : io->num_components,
4880 : : io->bSecondNonTautPass,
4881 : : io->bOmitRepetitions);
4882 : :
4883 [ # # ]: 0 : if (str_LineEnd(io->szTag3, &io->bOverflow, strbuf, -1, io->bPlainTextTags))
4884 : : {
4885 : 0 : return 1;
4886 : : }
4887 : 0 : inchi_ios_print(out_file, "%s%s", strbuf->pStr, pLF);
4888 : : }
4889 : : else
4890 : : {
4891 [ # # ]: 0 : if (io->bPlainTextTags == 1)
4892 : : {
4893 : 0 : inchi_ios_print(out_file, "/");
4894 : : }
4895 : : }
4896 : : }
4897 : : else
4898 : : {
4899 [ # # ]: 0 : if (io->bPlainTextTags == 1)
4900 : : {
4901 : 0 : inchi_ios_print(out_file, "//");
4902 : : }
4903 : : }
4904 : : /*-- totally omitted undefined/unknown isotopic stereo */
4905 : : } /* Aux info isotopic */
4906 : :
4907 : 184 : return 0;
4908 : : }
4909 : :
4910 : : /****************************************************************************
4911 : : Output AuxInfo: charges, radicals, unusual valences
4912 : : ****************************************************************************/
4913 : 184 : int OutputAUXINFO_ChargesRadicalsAndUnusualValences(CANON_GLOBALS *pCG,
4914 : : INCHI_IOSTREAM *out_file,
4915 : : INCHI_IOS_STRING *strbuf,
4916 : : INCHI_OUT_CTL *io,
4917 : : char *pLF,
4918 : : char *pTAB)
4919 : : {
4920 [ + - + + ]: 184 : if (!io->bSecondNonTautPass && io->bChargesRadVal[io->iCurTautMode])
4921 : : {
4922 : : /* aux equ atoms */
4923 : : /* 1. Compare to tautomeric equivalence (in case of second, non-taut, pass only) */
4924 : : /* 2. Compare to the previous component if (1) failed to find equivalence */
4925 : 25 : szGetTag(AuxLbl, io->nTag, io->bTag1 = AL_CRV_ | io->bFhTag, io->szTag1, &io->bAlways, 0);
4926 : :
4927 : 25 : inchi_strbuf_reset(strbuf);
4928 : 25 : io->tot_len = 0;
4929 : :
4930 : 25 : io->tot_len = str_AuxChargeRadVal(io->pINChISort, strbuf,
4931 : : &io->bOverflow, io->bOutType, io->TAUT_MODE,
4932 : : io->num_components, io->bUseMulipliers);
4933 : :
4934 [ - + ]: 25 : if (str_LineEnd(io->szTag1, &io->bOverflow, strbuf, -1, io->bPlainTextTags))
4935 : : {
4936 : 0 : return 1;
4937 : : }
4938 : :
4939 : 25 : inchi_ios_print(out_file, "%s%s", strbuf->pStr, pLF);
4940 : : }
4941 : :
4942 : 184 : return 0;
4943 : : }
4944 : :
4945 : : /****************************************************************************
4946 : : Output AuxInfo: reversibility info (to restore orig. structure)
4947 : : ****************************************************************************/
4948 : 184 : int OutputAUXINFO_ReversibilityInfo(CANON_GLOBALS *pCG,
4949 : : INCHI_IOSTREAM *out_file,
4950 : : INCHI_IOS_STRING *strbuf,
4951 : : ORIG_STRUCT *pOrigStruct,
4952 : : INCHI_OUT_CTL *io,
4953 : : char *pLF,
4954 : : char *pTAB)
4955 : : {
4956 [ + - + - ]: 184 : if (!io->bSecondNonTautPass &&
4957 [ + - ]: 184 : pOrigStruct && pOrigStruct->num_atoms &&
4958 [ + - + - : 184 : pOrigStruct->szAtoms && pOrigStruct->szBonds && pOrigStruct->szCoord)
+ - ]
4959 : : {
4960 : : int length, cur_pos, line_len, last_pos, nMaxLineLen;
4961 : : char *p;
4962 : 184 : nMaxLineLen = inchi_min(80, strbuf->nAllocatedLength); /* restrict line length to 80 characters */
4963 : :
4964 : 184 : szGetTag(AuxLbl, io->nTag, io->bTag1 = AL_REVR | io->bFhTag, io->szTag1, &io->bAlways, 0);
4965 : :
4966 : : /* Atoms /A: */
4967 : 184 : szGetTag(AuxLbl, io->nTag, io->bTag2 = io->bTag1 | AL_ATMR, io->szTag2, &io->bAlways, 0);
4968 : 184 : inchi_strbuf_reset(strbuf);
4969 : 184 : inchi_ios_print(out_file, "%s%s", io->szTag2, strbuf->pStr);
4970 : 184 : p = pOrigStruct->szAtoms;
4971 : 184 : length = (int)strlen(p);
4972 : 184 : io->tot_len = strbuf->nUsedLength;
4973 : 184 : line_len = nMaxLineLen - io->tot_len;
4974 [ + + ]: 464 : for (cur_pos = 0; cur_pos < length; cur_pos = last_pos)
4975 : : {
4976 [ + + ]: 280 : if (length - cur_pos >= line_len)
4977 : : {
4978 : 96 : last_pos = cur_pos + line_len;
4979 : : /* search backward for the nearest first atom letter (always uppercase) */
4980 [ + - - + ]: 96 : while (cur_pos < last_pos && !isupper(UCINT p[last_pos]))
4981 : : {
4982 : 0 : last_pos--;
4983 : : }
4984 : : }
4985 : : else
4986 : : {
4987 : 184 : last_pos = length;
4988 : : }
4989 [ + - ]: 280 : if (last_pos > cur_pos)
4990 : : {
4991 : 280 : memcpy(strbuf->pStr + strbuf->nUsedLength, p + cur_pos, (long long)last_pos - (long long)cur_pos); /* djb-rwth: cast operators added */
4992 : 280 : strbuf->pStr[strbuf->nUsedLength + last_pos - cur_pos] = '\0';
4993 : : /*strbuf->nUsedLength = strbuf->nUsedLength + last_pos - cur_pos;*/
4994 : :
4995 : : if (1) /* always show "Zy" as "Zz" */
4996 : : {
4997 : 280 : char *pzy, *pstart = strbuf->pStr + strbuf->nUsedLength;
4998 [ + + ]: 282 : while ((pzy = strstr(pstart, "Zy"))) /* djb-rwth: addressing LLVM warning */
4999 : : {
5000 : 2 : *(++pzy) = 'z';
5001 : 2 : pstart = pzy;
5002 : : }
5003 : : }
5004 : :
5005 [ + - ]: 280 : inchi_ios_print(out_file, "%s%s", strbuf->pStr, io->bPlainTextTags ? "" : "\n");
5006 : : }
5007 : : else
5008 : : {
5009 : 0 : break;
5010 : : }
5011 : : }
5012 [ - + ]: 184 : if (pLF[0])
5013 : : {
5014 : 0 : inchi_ios_print(out_file, "%s", pLF);
5015 : : }
5016 : :
5017 : 184 : inchi_strbuf_reset(strbuf);
5018 : :
5019 : : /* Bonds /B: */
5020 : 184 : szGetTag(AuxLbl, io->nTag, io->bTag2 = io->bTag1 | AL_BNDR, io->szTag2, &io->bAlways, 0);
5021 : 184 : inchi_strbuf_reset(strbuf);
5022 : 184 : inchi_ios_print(out_file, "%s%s", io->szTag2, strbuf->pStr);
5023 : :
5024 : 184 : p = pOrigStruct->szBonds;
5025 : 184 : length = (int)strlen(p);
5026 : 184 : line_len = nMaxLineLen - io->tot_len;
5027 [ + + ]: 766 : for (cur_pos = 0; cur_pos < length; cur_pos = last_pos)
5028 : : {
5029 [ + + ]: 582 : if (length - cur_pos >= line_len)
5030 : : {
5031 : 448 : last_pos = cur_pos + line_len - 1;
5032 : : /* search backward for the nearest first bond delimiter ";" */
5033 [ + - + + ]: 488 : while (cur_pos < last_pos && p[last_pos] != ';')
5034 : : {
5035 : 40 : last_pos--;
5036 : : }
5037 [ + - ]: 448 : if (cur_pos < last_pos)
5038 : : {
5039 : 448 : last_pos++; /* include ';' at the end of the line */
5040 : : }
5041 : : }
5042 : : else
5043 : : {
5044 : 134 : last_pos = length;
5045 : : }
5046 [ + - ]: 582 : if (last_pos > cur_pos)
5047 : : {
5048 : 582 : memcpy(strbuf->pStr, p + cur_pos, (long long)last_pos - (long long)cur_pos); /* djb-rwth: cast operators added */
5049 : 582 : strbuf->pStr[last_pos - cur_pos] = '\0';
5050 : 582 : strbuf->nUsedLength = last_pos - cur_pos;
5051 [ + - ]: 582 : inchi_ios_print(out_file, "%s%s", strbuf->pStr, io->bPlainTextTags ? "" : "\n");
5052 : 582 : inchi_strbuf_reset(strbuf);
5053 : : }
5054 : : else
5055 : : {
5056 : 0 : break;
5057 : : }
5058 : : }
5059 [ - + ]: 184 : if (pLF[0])
5060 : : {
5061 : 0 : inchi_ios_print(out_file, "%s", pLF);
5062 : : }
5063 : :
5064 : : /* Coordinates /C: */
5065 : 184 : szGetTag(AuxLbl, io->nTag, io->bTag2 = io->bTag1 | AL_XYZR, io->szTag2, &io->bAlways, 0);
5066 : 184 : inchi_strbuf_reset(strbuf);
5067 : 184 : inchi_ios_print(out_file, "%s%s", io->szTag2, strbuf->pStr);
5068 : :
5069 : 184 : p = pOrigStruct->szCoord;
5070 : 184 : length = (int)strlen(p);
5071 : 184 : line_len = nMaxLineLen - io->tot_len;
5072 [ + + ]: 1548 : for (cur_pos = 0; cur_pos < length; cur_pos = last_pos)
5073 : : {
5074 [ + + ]: 1364 : if (length - cur_pos >= line_len)
5075 : : {
5076 : 1180 : last_pos = cur_pos + line_len - 1;
5077 : : /* search backward for the nearest first coord. delimiter ";" */
5078 [ + - + + ]: 6497 : while (cur_pos < last_pos && p[last_pos] != ';')
5079 : : {
5080 : 5317 : last_pos--;
5081 : : }
5082 [ + - ]: 1180 : if (cur_pos < last_pos)
5083 : : {
5084 : 1180 : last_pos++; /* include ';' at the end of the line */
5085 : : }
5086 : : }
5087 : : else
5088 : : {
5089 : 184 : last_pos = length;
5090 : : }
5091 [ + - ]: 1364 : if (last_pos > cur_pos)
5092 : : {
5093 : 1364 : memcpy(strbuf->pStr, p + cur_pos, (long long)last_pos - (long long)cur_pos); /* djb-rwth: cast operator added */
5094 : 1364 : strbuf->pStr[last_pos - cur_pos] = '\0';
5095 : 1364 : strbuf->nUsedLength = last_pos - cur_pos;
5096 [ + - ]: 1364 : inchi_ios_print(out_file, "%s%s", strbuf->pStr, io->bPlainTextTags ? "" : "\n");
5097 : 1364 : inchi_strbuf_reset(strbuf);
5098 : : }
5099 : : else
5100 : : {
5101 : 0 : break;
5102 : : }
5103 : : }
5104 : :
5105 [ - + ]: 184 : if (pLF[0])
5106 : : {
5107 : 0 : inchi_ios_print(out_file, "%s", pLF);
5108 : : }
5109 : : }
5110 : :
5111 : 184 : return 0;
5112 : : }
5113 : :
5114 : : /* "%f" of a double needs at most 317 chars (DBL_MAX) */
5115 : : #define LEN_DBL_STR 320
5116 : :
5117 : : /****************************************************************************/
5118 : : /* GH #100: print one number as "%f" with '.' decimal point, e.g. "5.042700" */
5119 : 128 : static const char *DotDecimalStr(double x, char *buf)
5120 : : {
5121 : 128 : snprintf(buf, LEN_DBL_STR, "%f", x);
5122 : 128 : inchi_dot_decimal(buf);
5123 : 128 : return buf;
5124 : : }
5125 : :
5126 : : /****************************************************************************/
5127 : 184 : int OutputAUXINFO_PolymerInfo(CANON_GLOBALS *pCG,
5128 : : INCHI_IOSTREAM *out_file,
5129 : : INCHI_IOS_STRING *strbuf,
5130 : : ORIG_STRUCT *pOrigStruct,
5131 : : INCHI_OUT_CTL *io,
5132 : : char *pLF,
5133 : : char *pTAB)
5134 : : {
5135 : : int k, i, q;
5136 : : OAD_Polymer *p;
5137 : : OAD_PolymerUnit *u;
5138 : : char szNum[LEN_DBL_STR];
5139 : :
5140 [ - + ]: 184 : if (!pOrigStruct)
5141 : : {
5142 : 0 : return 0;
5143 : : }
5144 : 184 : p = pOrigStruct->polymer;
5145 [ + + ]: 184 : if (!p)
5146 : : {
5147 : 160 : return 0;
5148 : : }
5149 : :
5150 : 24 : inchi_strbuf_reset(strbuf);
5151 : :
5152 : 24 : inchi_ios_print(out_file, "/Z:");
5153 : :
5154 : : /* Print polymer units data */
5155 [ + + ]: 48 : for (i = 0; i < p->n; i++)
5156 : : {
5157 : : /* For each unit u ... */
5158 : 24 : u = p->units[i];
5159 : :
5160 : : /* print kinds of unit */
5161 : 24 : inchi_strbuf_printf(strbuf, "%-d%-d%-d-", u->type, u->subtype, u->conn);
5162 [ + + ]: 24 : inchi_strbuf_printf(strbuf, "%-s-", u->smt[0] ? u->smt : "n");
5163 : :
5164 : : /* Print unit atoms */
5165 : 24 : print_sequence_of_nums_compressing_ranges(u->na, u->alist, strbuf);
5166 : :
5167 : : /* Print bonds from unit to otside */
5168 [ + + ]: 24 : if (u->nb > 0)
5169 : : {
5170 : 22 : inchi_strbuf_printf(strbuf, "(");
5171 [ + + ]: 88 : for (k = 0; k < 2 * u->nb - 1; k++)
5172 : : {
5173 : 66 : inchi_strbuf_printf(strbuf, "%-d,", u->blist[k]);
5174 : : }
5175 : 22 : inchi_strbuf_printf(strbuf, "%-d)", u->blist[2 * u->nb - 1]);
5176 : : }
5177 : :
5178 [ + + ]: 24 : if (fabs(-fabs(u->xbr1[0]) + 777777.777) > 1.e-7)
5179 : : {
5180 : 16 : inchi_strbuf_printf(strbuf, "[");
5181 [ + + ]: 64 : for (q = 0; q < 3; q++)
5182 : : {
5183 : 48 : inchi_strbuf_printf(strbuf, "%s,", DotDecimalStr(u->xbr1[q], szNum)); /* GH #100 */
5184 : : }
5185 : 16 : inchi_strbuf_printf(strbuf, "%s]", DotDecimalStr(u->xbr1[3], szNum)); /* GH #100 */
5186 : : }
5187 [ + + ]: 24 : if (fabs(-fabs(u->xbr2[0]) + 777777.777) > 1.e-7)
5188 : : {
5189 : 16 : inchi_strbuf_printf(strbuf, "[");
5190 [ + + ]: 64 : for (q = 0; q < 3; q++)
5191 : : {
5192 : 48 : inchi_strbuf_printf(strbuf, "%s,", DotDecimalStr(u->xbr2[q], szNum)); /* GH #100 */
5193 : : }
5194 : 16 : inchi_strbuf_printf(strbuf, "%s]", DotDecimalStr(u->xbr2[3], szNum)); /* GH #100 */
5195 : : }
5196 : :
5197 [ - + ]: 24 : if (i < p->n - 1)
5198 : : {
5199 : 0 : inchi_strbuf_printf(strbuf, ";");
5200 : : }
5201 : : }
5202 : :
5203 : 24 : inchi_ios_print(out_file, "%s%s", strbuf->pStr, pLF);
5204 : :
5205 : 24 : return 0;
5206 : : }
5207 : :
5208 : : /****************************************************************************/
5209 : 0 : int IsBondAtomNumsLesser(int *bond1, int *bond2)
5210 : : {
5211 : 0 : int min1 = inchi_min(bond1[0], bond1[1]);
5212 : 0 : int min2 = inchi_min(bond2[0], bond2[1]);
5213 : 0 : int max1 = inchi_max(bond1[0], bond1[1]);
5214 : 0 : int max2 = inchi_max(bond2[0], bond2[1]);
5215 : :
5216 [ # # ]: 0 : if (min1 < min2)
5217 : : {
5218 : 0 : return -1;
5219 : : }
5220 [ # # ]: 0 : if (min1 > min2)
5221 : : {
5222 : 0 : return 1;
5223 : : }
5224 [ # # ]: 0 : if (min1 == min2)
5225 : : {
5226 [ # # ]: 0 : if (max1 < max2)
5227 : : {
5228 : 0 : return -1;
5229 : : }
5230 [ # # ]: 0 : if (max1 > max2)
5231 : : {
5232 : 0 : return 1;
5233 : : }
5234 : : }
5235 : :
5236 : 0 : return 0;
5237 : : }
5238 : :
5239 : : /****************************************************************************/
5240 : 6 : void EditINCHI_HidePolymerZz(INCHI_IOSTREAM *out, int n_pzz, int n_zy)
5241 : : {
5242 : 6 : char *s = out->s.pStr, *s0, *buf = NULL;
5243 : 6 : char prev_layer_symbol = '0';
5244 : : int i, j, ii, nzz,
5245 : 6 : nzz1 = 0, nslash = 0, ncopied = 0,
5246 : 6 : start = 0, skip = 0, is_in_z_layer = 0,
5247 : 6 : eol_was_consumed = 0, pre_eol = 0,
5248 : 6 : nonprt_sym = 0, nonprt_prev = 0;
5249 : :
5250 [ - + ]: 6 : if (n_zy > 0)
5251 : : {
5252 : : /* We have some placeholder pseudo atoms which should not be removed below (if anyway they are allowed) */
5253 [ # # ]: 0 : if (n_pzz == 0)
5254 : : {
5255 : : /* Have nothing to remove, just exit */
5256 : 0 : return;
5257 : : }
5258 : : /* Have both polymer-related and placeholder pseudo atoms */
5259 [ # # ]: 0 : if (n_pzz < 2)
5260 : : {
5261 : : /* Something strange, should not arrive here, cowardly exit */
5262 : 0 : return;
5263 : : }
5264 : : }
5265 : :
5266 : : /* Ensure that polymeric layer is present */
5267 [ - + ]: 6 : if (!strstr(s, "/z"))
5268 : : {
5269 : 0 : return;
5270 : : }
5271 : 6 : s0 = strstr(s, INCHI_NAME INCHI_NAM_VER_DELIM);
5272 [ - + ]: 6 : if (!s0)
5273 : : {
5274 : 0 : return;
5275 : : }
5276 : :
5277 : : #if 0
5278 : : nzz1 = CountPseudoElementInFormula("Zz", s0 + strlen("InChI=1B/"));
5279 : : if (nzz1 == 0)
5280 : : {
5281 : : return;
5282 : : }
5283 : : if (nzz1 != (n_pzz + n_zy))
5284 : : {
5285 : : /* Something strange, should not arrive here, cowardly exit */
5286 : : return;
5287 : : }
5288 : : #endif
5289 : 6 : nzz1 = n_pzz;
5290 : :
5291 : : /* OK, we must hide n_pzz Zz's*/
5292 : 6 : buf = (char *)inchi_calloc((long long)out->s.nUsedLength + 1, sizeof(char)); /* djb-rwth: cast operator added */
5293 [ - + ]: 6 : if (!buf)
5294 : : {
5295 : 0 : return;
5296 : : }
5297 : :
5298 : : /* Consume '\n' temporarily */
5299 [ + - ]: 6 : if (s[out->s.nUsedLength - 1] == '\n')
5300 : : {
5301 : 6 : s[out->s.nUsedLength - 1] = '\0';
5302 : 6 : out->s.nUsedLength--;
5303 : 6 : eol_was_consumed = 1;
5304 : : }
5305 : :
5306 : 6 : start = s0 - s;
5307 : 6 : nzz = nzz1;
5308 : 6 : is_in_z_layer = skip = 0;
5309 [ + - ]: 1764 : for (i = start; i < out->s.nUsedLength; i++)
5310 : : {
5311 : 1764 : pre_eol = (i == out->s.nUsedLength - 1);
5312 [ + + + - : 1764 : nonprt_sym = s[i] == '\n' || s[i] == '\r' || s[i] == '\t';
- + ]
5313 : :
5314 [ + + ]: 1764 : if (!skip)
5315 : : {
5316 : 1740 : buf[ncopied] = s[i];
5317 : 1740 : ncopied++;
5318 [ + + - + ]: 1740 : if (nonprt_sym && nonprt_prev)
5319 : : {
5320 : 0 : continue;
5321 : : }
5322 : : }
5323 : 1764 : nonprt_prev = nonprt_sym;
5324 : :
5325 [ + + + + ]: 1764 : if (is_in_z_layer && !skip)
5326 : : {
5327 [ + + ]: 84 : if (s[i] == '(')
5328 : : {
5329 : : /* Software version 1.07 : skip pattern "(cap,cap-bkbonds)" but not "(cap-end, cap-end)" */
5330 : : const char *q;
5331 : 6 : const char *p = out->s.pStr + i + 1;
5332 : 6 : AT_NUMB ia = (AT_NUMB)inchi_strtol(p, &q, 10); /* make compiler happy: */ /* djb-rwth: removing redundant code; ignoring LLVM warning: variable used to store function return value */
5333 [ + - ]: 6 : if (*q != '-')
5334 : : {
5335 : 6 : skip = 1;
5336 : : }
5337 : : }
5338 : : }
5339 [ + + + - ]: 1680 : else if (is_in_z_layer && skip)
5340 : : {
5341 [ + + ]: 24 : if (s[i] == '-')
5342 : : {
5343 : 6 : skip = 0;
5344 : : }
5345 : : }
5346 : :
5347 [ + + + + : 1764 : if (s[i] == '/' || pre_eol || nonprt_sym)
+ + ]
5348 : : {
5349 [ + + ]: 78 : if (is_in_z_layer)
5350 : : {
5351 : 6 : is_in_z_layer = 0;
5352 : : }
5353 : :
5354 [ + + ]: 78 : if (s[i] == '/')
5355 : : {
5356 : 66 : nslash++;
5357 : : }
5358 : :
5359 [ + + + + ]: 78 : if (nslash == 2 ||
5360 [ + - - + ]: 72 : (nslash == 1 && pre_eol) ||
5361 : : (prev_layer_symbol == 'f'))
5362 : : {
5363 [ + - ]: 6 : if (nzz)
5364 : : {
5365 : : /* eat Zz's */
5366 : 6 : ii = i;
5367 [ - + ]: 6 : if (pre_eol)
5368 : : {
5369 : 0 : ii = i + 1;
5370 : : }
5371 [ + - + - ]: 6 : if (s[ii - 1] == 'z' && s[ii - 2] == 'Z')
5372 : : {
5373 : 6 : ncopied -= 2;
5374 [ + - ]: 12 : for (j = ii - 3; j >= 0; j--)
5375 : : {
5376 [ + + ]: 12 : if (s[j] == '.')
5377 : : {
5378 : 6 : break;
5379 : : }
5380 : 6 : ncopied--;
5381 : : }
5382 : 6 : ncopied--;
5383 [ + - ]: 6 : if (!pre_eol)
5384 : : {
5385 : 6 : buf[ncopied - 1] = '/';
5386 : : }
5387 : : else
5388 : : {
5389 : 0 : buf[ncopied - 1] = '\0';
5390 : : }
5391 : : }
5392 : : }
5393 : : }
5394 [ + + + - : 72 : else if (nslash > 2 || pre_eol || s[i] == '\n')
- + ]
5395 : : {
5396 [ + - ]: 66 : if (nzz)
5397 : : {
5398 [ + - + - ]: 66 : if (prev_layer_symbol != 'p' &&
5399 [ + - ]: 66 : prev_layer_symbol != 's' &&
5400 [ + + ]: 66 : prev_layer_symbol != 'f' &&
5401 : : prev_layer_symbol != 'z')
5402 : : {
5403 : : /* eat nzz last ; if any */
5404 : 60 : int n_eaten = 0;
5405 : 60 : char eatable = ';';
5406 [ - + ]: 60 : if (prev_layer_symbol == 'm')
5407 : : {
5408 : 0 : eatable = '.';
5409 : : }
5410 : 60 : ii = i;
5411 [ + + ]: 60 : if (pre_eol)
5412 : : {
5413 : 6 : ii = i + 1;
5414 : : }
5415 [ + - ]: 114 : for (j = ii - 1; j >= 0; j--)
5416 : : {
5417 [ + + + - ]: 114 : if (s[j] == eatable && n_eaten < nzz)
5418 : : {
5419 : 54 : ncopied--;
5420 : 54 : n_eaten++;
5421 : : }
5422 : : else
5423 : : {
5424 : : break;
5425 : : }
5426 : : }
5427 [ + + ]: 60 : if (!pre_eol)
5428 : : {
5429 [ - + ]: 54 : if (s[i] == '\n')
5430 : : {
5431 : 0 : buf[ncopied - 1] = '\n';
5432 : : }
5433 : : else
5434 : : {
5435 : 54 : buf[ncopied - 1] = '/';
5436 : : }
5437 : : }
5438 : : else
5439 : : {
5440 : 6 : buf[ncopied] = '\0';
5441 : 6 : break;
5442 : : }
5443 : : }
5444 : : }
5445 : : }
5446 : :
5447 : 72 : prev_layer_symbol = s[i + 1];
5448 [ + + ]: 72 : if (s[i + 1] == 'r')
5449 : : {
5450 [ + - + - ]: 18 : if (i + 3 < out->s.nUsedLength && s[i + 3] == ':')
5451 : : {
5452 : : /* ra: rB; rC: in AuxInfo */
5453 : : ;
5454 : : }
5455 : : else
5456 : : {
5457 : : /* reconnected layer */
5458 : 0 : nslash = 1;
5459 : : /* nzz = nzz2; paranoidal */
5460 : : }
5461 : : }
5462 [ + + ]: 54 : else if (s[i + 1] == 'z')
5463 : : {
5464 : 6 : is_in_z_layer = 1;
5465 : : }
5466 : : }
5467 : : }
5468 : :
5469 : 6 : out->s.nUsedLength = 0;
5470 [ + - ]: 6 : inchi_ios_print_nodisplay(out, "%s%s", buf, eol_was_consumed ? "\n" : "");
5471 [ + - ]: 6 : inchi_free(buf);
5472 : :
5473 : 6 : return;
5474 : : }
5475 : :
5476 : : /****************************************************************************/
5477 : 0 : int CountPseudoElementInFormula(const char *pseudo, char *s) /* djb-rwth: ignoring LLVM warning: function used */
5478 : : {
5479 : 0 : int npseudo = 0, mult = 1, index = 1, new_component = 1;
5480 : : const char *p, *q;
5481 : 0 : char prev = '/';
5482 : :
5483 : : /*
5484 : : format is
5485 : : [sequence of] [.[int_mult[Zz[int_index]]]]
5486 : : */
5487 : :
5488 [ # # ]: 0 : if (!s)
5489 : : {
5490 : 0 : return 0;
5491 : : }
5492 : :
5493 : 0 : p = s;
5494 [ # # ]: 0 : while (*p)
5495 : : /*for (p = s ; *p; p++)*/
5496 : : {
5497 [ # # ]: 0 : if (*p == '/')
5498 : : {
5499 : : /* end of formula layer */
5500 : 0 : break;
5501 : : }
5502 [ # # ]: 0 : else if (*p == '.')
5503 : : {
5504 : : /* start of new component subformula */
5505 : 0 : new_component = 1;
5506 : 0 : prev = *p;
5507 : 0 : p++;
5508 : 0 : continue;
5509 : : }
5510 : :
5511 [ # # ]: 0 : if (new_component)
5512 : : {
5513 : 0 : new_component = 0;
5514 [ # # ]: 0 : if (isdigit(*p))
5515 : : {
5516 : 0 : mult = (int)inchi_strtol(p, &q, 10);
5517 : 0 : p = q;
5518 : 0 : prev = *q--;
5519 : 0 : continue;
5520 : : }
5521 : : else
5522 : : {
5523 : 0 : mult = 1;
5524 : : }
5525 [ # # ]: 0 : if (!mult)
5526 : : {
5527 : 0 : break;
5528 : : }
5529 : : }
5530 [ # # # # ]: 0 : else if (*p == pseudo[1] && prev == pseudo[0])
5531 : : {
5532 : 0 : q = p++;
5533 [ # # # # ]: 0 : if (*q && isdigit(*q))
5534 : : {
5535 : 0 : index = (int)inchi_strtol(q, &p, 10);
5536 : : }
5537 : : else
5538 : : {
5539 : 0 : index = 1;
5540 : 0 : p = q;
5541 : : }
5542 : 0 : npseudo += mult * index;
5543 : : }
5544 : 0 : prev = *p;
5545 : 0 : p++;
5546 : : }
5547 : :
5548 : 0 : return npseudo;
5549 : : }
5550 : :
5551 : : /****************************************************************************
5552 : : Get canonical numbers and component numbers for each original atom
5553 : : NB: cano_nums[orig_num] - in orig_nums order,
5554 : : compnt_nums[cano_num] - in cano_nums order
5555 : : NB': orig_nums are 1-based
5556 : : cano_nums are 0-based
5557 : : compnt_nums are 1-based
5558 : : ****************************************************************************/
5559 : 24 : int InternallyGetCanoNumsAndComponentNums(CANON_GLOBALS *pCG,
5560 : : INCHI_IOS_STRING *strbuf,
5561 : : INCHI_OUT_CTL *io,
5562 : : int nat,
5563 : : int *cano_nums,
5564 : : int *compnt_nums)
5565 : : {
5566 : : int orig_num, cano_num, icompnt, i, k, ndigit, err;
5567 : : char c, cnum[8];
5568 : :
5569 [ + - + - : 24 : if (!cano_nums || !compnt_nums || !strbuf->pStr)
- + ]
5570 : : {
5571 : 0 : return 1;
5572 : : }
5573 : :
5574 : 24 : inchi_strbuf_reset(strbuf);
5575 : 24 : io->tot_len = str_AuxNumb(pCG, io->pINChISort, io->pINChISort2,
5576 : : strbuf, &io->bOverflow, io->bOutType,
5577 : : io->TAUT_MODE, io->num_components,
5578 : : io->bSecondNonTautPass, io->bOmitRepetitions);
5579 [ + + ]: 184 : for (i = 0; i < nat; i++)
5580 : : {
5581 : 160 : compnt_nums[i] = -1;
5582 : 160 : cano_nums[i + 1] = -1;
5583 : : }
5584 : :
5585 : 24 : ndigit = 0;
5586 : 24 : err = 0;
5587 : : /* djb-rwth: removing redundant code */
5588 : 24 : icompnt = 1;
5589 : 24 : cano_num = 0;
5590 [ + - ]: 344 : for (k = 0; k <= strbuf->nUsedLength; k++)
5591 : : {
5592 : 344 : c = strbuf->pStr[k];
5593 [ + + + + : 344 : if (c == ',' || c == ';' || c == '\0')
+ + ]
5594 : : {
5595 : 160 : cnum[ndigit] = '\0';
5596 : 160 : orig_num = atoi(cnum);
5597 : 160 : cano_nums[orig_num] = cano_num;
5598 : 160 : compnt_nums[cano_num] = icompnt;
5599 : 160 : cnum[0] = '\0';
5600 : 160 : ndigit = 0;
5601 : 160 : cano_num++;
5602 [ + + ]: 160 : if (c == ';')
5603 : : {
5604 : 12 : icompnt++;
5605 : : }
5606 [ + + ]: 160 : if (c == '\0')
5607 : : {
5608 : 24 : break;
5609 : : }
5610 : 136 : continue;
5611 : : }
5612 [ + - ]: 184 : else if (isdigit(c))
5613 : : {
5614 : 184 : cnum[ndigit] = c;
5615 : 184 : ndigit++;
5616 : : }
5617 : : else
5618 : : {
5619 : 0 : err = 2;
5620 : 0 : goto exit_function;
5621 : : }
5622 : : }
5623 : :
5624 : 0 : exit_function:
5625 : 24 : inchi_strbuf_reset(strbuf);
5626 : :
5627 : 24 : return err;
5628 : : }
5629 : :
5630 : : /***************************************************************************/
5631 : 0 : int MergeZzInHillFormula(INCHI_IOS_STRING *strbuf)
5632 : : {
5633 : 0 : char *p, *scopy = NULL, *stmp = NULL, *pend = NULL, *p0 = NULL; /* djb-rwth: removing redundant variables */
5634 : : size_t sublen; /* djb-rwth: removing redundant variables */
5635 : :
5636 [ # # # # ]: 0 : if (!strbuf->pStr || strbuf->nUsedLength < 1)
5637 : : {
5638 : 0 : return 0;
5639 : : }
5640 : 0 : scopy = (char *)inchi_calloc((long long)strbuf->nAllocatedLength + 1, sizeof(char)); /* djb-rwth: cast operator added */
5641 [ # # ]: 0 : if (!scopy)
5642 : : {
5643 [ # # ]: 0 : inchi_free(scopy); /* djb-rwth: avoiding memory leak */
5644 : 0 : return -1; /* failed */
5645 : : }
5646 : 0 : memcpy(scopy, strbuf->pStr, strbuf->nAllocatedLength);
5647 : 0 : stmp = (char *)inchi_calloc((long long)strbuf->nAllocatedLength + 1, sizeof(char)); /* djb-rwth: cast operator added */
5648 [ # # ]: 0 : if (!stmp)
5649 : : {
5650 [ # # ]: 0 : inchi_free(scopy); /* djb-rwth: avoiding memory leak */
5651 : 0 : return -1; /* failed */
5652 : : }
5653 : :
5654 : 0 : inchi_strbuf_reset(strbuf);
5655 : 0 : p0 = scopy;
5656 : 0 : p = p0;
5657 : : do
5658 : : {
5659 : : /* djb-rwth: removing redundant code */
5660 : 0 : pend = strchr(p, '.');
5661 [ # # ]: 0 : if (!pend)
5662 : : {
5663 : 0 : pend = strchr(p, '\0');
5664 : : }
5665 : 0 : sublen = pend - p;
5666 : 0 : memcpy(stmp, p, sublen);
5667 : 0 : stmp[sublen] = '\0';
5668 : 0 : MergeZzInStrHillFormulaComponent(stmp);
5669 [ # # ]: 0 : if (stmp)
5670 : : {
5671 : 0 : inchi_strbuf_printf(strbuf, "%-s%-c", stmp, *pend);
5672 : : }
5673 : : /* djb-rwth: removing redundant code */
5674 [ # # # # ]: 0 : } while (*pend && (p = pend + 1));
5675 : :
5676 [ # # ]: 0 : if (scopy)
5677 : : {
5678 [ # # ]: 0 : inchi_free(scopy);
5679 : : }
5680 [ # # ]: 0 : if (stmp)
5681 : : {
5682 [ # # ]: 0 : inchi_free(stmp);
5683 : : }
5684 : :
5685 : 0 : return 0;
5686 : : }
5687 : :
5688 : : /***************************************************************************/
5689 : 0 : void MergeZzInStrHillFormulaComponent(char *s)
5690 : : {
5691 : 0 : char *pz = strstr(s, "Zz");
5692 [ # # ]: 0 : if (pz)
5693 : : {
5694 : 0 : int n = 1, offset;
5695 : 0 : char *pz2 = pz + 2, *pd = pz + 2;
5696 [ # # # # ]: 0 : if (*pd && (isdigit(*pd)))
5697 : : {
5698 : 0 : n = strtol(pd, &pz2, 10);
5699 : : }
5700 : 0 : pz2 = strstr(pz2, "Zz");
5701 [ # # ]: 0 : if (pz2)
5702 : : {
5703 : 0 : int n2 = 1;
5704 : 0 : char *pd2 = pz2 + 2;
5705 [ # # # # ]: 0 : if (*pd2 && (isdigit(*pd2)))
5706 : : {
5707 : 0 : n2 = strtol(pd2, &pz2, 10);
5708 : : }
5709 : 0 : n += n2;
5710 : 0 : offset = (int)(pd - s);
5711 : 0 : sprintf(s + offset, "%d", n);
5712 : : }
5713 : : }
5714 : 0 : return;
5715 : : }
5716 : :
5717 : : /****************************************************************************/
5718 : 6 : static void inchi_sort_int_pair_ascending(int *a, int *b)
5719 : : {
5720 : : int tmp;
5721 [ - + ]: 6 : if (*a > *b)
5722 : : {
5723 : 0 : tmp = *b;
5724 : 0 : *b = *a;
5725 : 0 : *a = tmp;
5726 : : }
5727 : :
5728 : 6 : return;
5729 : : }
|