~ubuntu-branches/debian/stretch/openbabel/stretch

« back to all changes in this revision

Viewing changes to src/formats/inchi/ichiparm.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2008-07-22 23:54:58 UTC
  • mfrom: (3.1.10 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080722235458-3o606czluviz4akx
Tags: 2.2.0-2
* Upload to unstable.
* debian/control: Updated descriptions.
* debian/patches/gauss_cube_format.patch: New patch, makes the 
  gaussian cube format available again.
* debian/rules (DEB_DH_MAKESHLIBS_ARGS_libopenbabel3): Removed.
* debian/rules (DEB_CONFIGURE_EXTRA_FLAGS): Likewise.
* debian/libopenbabel3.install: Adjust formats directory to single 
  version hierarchy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * International Union of Pure and Applied Chemistry (IUPAC)
3
 
 * International Chemical Identifier (InChI)
4
 
 * Version 1
5
 
 * Software version 1.01
6
 
 * May 16, 2006
7
 
 * Developed at NIST
8
 
 */
9
 
 
10
 
int DetectInputINChIFileType( FILE **inp_file, INPUT_PARMS *ip, const char *fmode );
11
 
 
12
 
/*****************************************************************************************/
13
 
int ReadCommandLineParms( int argc, const char *argv[], INPUT_PARMS *ip, char *szSdfDataValue,
14
 
                          unsigned long *ulDisplTime, int bReleaseVersion, INCHI_FILE *log_file )
15
 
{
16
 
    int i, k, c;
17
 
    const char *q;
18
 
    unsigned long ul;
19
 
    int           nFontSize    = -9;
20
 
    int           nMode        = 0;
21
 
    int           nReleaseMode = nMode | (REQ_MODE_BASIC | REQ_MODE_TAUT | REQ_MODE_ISO | REQ_MODE_STEREO);
22
 
#if( MIN_SB_RING_SIZE > 0 )
23
 
    int           nMinDbRinSize = MIN_SB_RING_SIZE, mdbr=0;
24
 
#endif
25
 
    /*int           bNotRecognized=0;*/
26
 
    char          szNameSuffix[32], szOutputPath[512];
27
 
    int           bNameSuffix, bOutputPath;
28
 
    int           bMergeAllInputStructures;
29
 
    int           bDisconnectSalts       = (DISCONNECT_SALTS==1);
30
 
    int           bDoNotAddH             = 0;
31
 
 
32
 
#ifdef INCHI_LIB
33
 
    int           bVer1Options           = 0;
34
 
    int           bReconnectCoord        = 1;
35
 
    int           bDisconnectCoord       = 1;
36
 
    int           bINChIOutputOptions     = INCHI_OUT_EMBED_REC; /* embed reconnected & output full aux info */
37
 
    int           bCompareComponents     = CMP_COMPONENTS;
38
 
#else
39
 
    int           bVer1Options           = 1;
40
 
    int           bReconnectCoord        = (RECONNECT_METALS==1);
41
 
    int           bDisconnectCoord       = (DISCONNECT_METALS==1);
42
 
    int           bINChIOutputOptions     = ((EMBED_REC_METALS_INCHI==1)? INCHI_OUT_EMBED_REC   : 0);
43
 
                                            /*| INCHI_OUT_NO_AUX_INFO INCHI_OUT_SHORT_AUX_INFO*/
44
 
    int           bCompareComponents     = 0;
45
 
#endif
46
 
 
47
 
    int           bDisconnectCoordChkVal = (CHECK_METAL_VALENCE == 1);
48
 
    int           bMovePositiveCharges   = (MOVE_CHARGES==1);
49
 
    int           bAcidTautomerism       = (DISCONNECT_SALTS==1)? (TEST_REMOVE_S_ATOMS==1? 2:1):0;
50
 
    int           bUnchargedAcidTaut     = (CHARGED_SALTS_ONLY==0);
51
 
    int           bMergeSaltTGroups      = (DISCONNECT_SALTS==1);
52
 
    int           bDisplayCompositeResults = 0;
53
 
 
54
 
#define VER100_DEFAULT_MODE    (REQ_MODE_TAUT | REQ_MODE_ISO | REQ_MODE_STEREO |\
55
 
                                REQ_MODE_SB_IGN_ALL_UU | REQ_MODE_SC_IGN_ALL_UU)
56
 
 
57
 
    INCHI_MODE     bVer1DefaultMode       = VER100_DEFAULT_MODE;
58
 
    const char   *ext[MAX_NUM_PATHS+1];
59
 
    const char   *pArg;
60
 
    double        t;
61
 
    int           bRecognizedOption;
62
 
    int           bDisplay = 0;
63
 
    int           bNoStructLabels = 0;
64
 
    int           bOutputMolfileOnly = 0;
65
 
    int           bOutputMolfileDT = 0;
66
 
    int           bOutputMolfileSplit = 0;
67
 
    int           bForcedChiralFlag = 0;
68
 
#if( READ_INCHI_STRING == 1 )
69
 
    int           bDisplayIfRestoreWarnings = 0;
70
 
#endif
71
 
#ifdef INCHI_LIB
72
 
    int           bXml = INCHI_OUT_XML;
73
 
#else
74
 
    int           bXml = INCHI_OUT_PLAIN_TEXT;
75
 
#endif
76
 
    int bTgFlagVariableProtons = 1;
77
 
    int bTgFlagHardAddRenProtons = 1;
78
 
#ifdef STEREO_WEDGE_ONLY
79
 
    int bPointedEdgeStereo = STEREO_WEDGE_ONLY; /*   NEWPS TG_FLAG_POINTED_EDGE_STEREO*/
80
 
#endif
81
 
#if( FIX_ADJ_RAD == 1 )
82
 
    int bFixAdjacentRad = 0;
83
 
#endif
84
 
#if( ADD_PHOSPHINE_STEREO == 1 )
85
 
    int bAddPhosphineStereo = 0;
86
 
#endif
87
 
#if( ADD_ARSINE_STEREO == 1 )
88
 
    int bAddArsineStereo = 0;
89
 
#endif
90
 
    int bFixSp3bug        = 0;
91
 
 
92
 
 
93
 
    ext[0] = ".mol";
94
 
    ext[1] = bVer1Options? ".txt" : ".ich";
95
 
    ext[2] = ".log";
96
 
    ext[3] = ".prb";
97
 
    ext[4] = "";
98
 
 
99
 
#if( MAX_NUM_PATHS < 4 )
100
 
  #error Wrong initialization
101
 
#endif
102
 
 
103
 
    /*  init table parms */
104
 
    memset ( ip, 0, sizeof(*ip) );
105
 
#ifndef INCHI_ANSI_ONLY
106
 
    strcpy( ip->tdp.ReqShownFoundTxt[ilSHOWN], "Shown" );
107
 
    ip->dp.sdp.tdp = &ip->tdp;
108
 
    ip->dp.pdp     = &ip->pdp;
109
 
#endif
110
 
    memset( szNameSuffix, 0, sizeof(szNameSuffix) );
111
 
    bNameSuffix = 0;
112
 
    memset(szOutputPath, 0, sizeof(szOutputPath) );
113
 
    bOutputPath = 0;
114
 
    bMergeAllInputStructures = 0;
115
 
 
116
 
    *ulDisplTime  = 0;
117
 
#ifdef INCHI_LIBRARY
118
 
    ip->msec_MaxTime = 0;      /*  milliseconds, default = unlimited in libinchi */
119
 
#else
120
 
    ip->msec_MaxTime = 60000;  /*  milliseconds, default = 60 sec */
121
 
#endif
122
 
 
123
 
    if ( bReleaseVersion ) {
124
 
 
125
 
        /*  normal */
126
 
        /*ip->bINChIOutputOptions |= INCHI_OUT_PLAIN_TEXT;*/
127
 
        /*ip->bXml = 1;*/
128
 
        ip->bAbcNumbers = 0;
129
 
        ip->bCtPredecessors = 0;
130
 
        /*
131
 
         -- testing --
132
 
        ip->bXml = 0;
133
 
        ip->bAbcNumbers = 1;
134
 
        */
135
 
    } else {
136
 
        /*bXml = INCHI_OUT_PLAIN_TEXT;*/
137
 
        nReleaseMode = 0;
138
 
    }
139
 
 
140
 
    if ( bVer1Options ) {
141
 
        bNameSuffix = 1;
142
 
        szNameSuffix[0] = '\0';
143
 
    }
144
 
 
145
 
 
146
 
#if( ACD_LABS_VERSION == 1 ) /* { */
147
 
/*
148
 
  -- Files --
149
 
  ip->path[0] => Input               -I
150
 
  ip->path[1] => Output (INChI)       -O
151
 
  ip->path[2] => Log                 -L
152
 
  ip->path[3] => Problem structures
153
 
  ip->path[4] => Errors file (ACD(   -E
154
 
 
155
 
*/
156
 
        for ( i = 1; i < argc; i ++ ) {
157
 
            if ( *argv[i] !memicmp( argv[i], "-I", 2) ) {
158
 
                ip->num_paths += !ip->path[0];
159
 
                ip->path[0] = _strdup( argv[i] + 2 );
160
 
            } else
161
 
            if ( *argv[i] !memicmp( argv[i], "-O", 2) ) {
162
 
                ip->num_paths += !ip->path[1];
163
 
                ip->path[1] = _strdup( argv[i] + 2 );
164
 
            } else
165
 
            if ( *argv[i] !memicmp( argv[i], "-L", 2) ) {
166
 
                ip->num_paths += !ip->path[2];
167
 
                ip->path[2] = _strdup( argv[i] + 2 );
168
 
            } else
169
 
            if ( *argv[i] !memicmp( argv[i], "-E", 2) ) {
170
 
                ip->path[4] = _strdup( argv[i] + 2 );
171
 
            } else
172
 
            if ( *argv[i] !stricmp( argv[i], "-Z" ) ) {
173
 
                sprintf( stdout, "%s version %s\n", INCHI_NAME, INCHI_VERSION );
174
 
                return -1;
175
 
            }
176
 
        }
177
 
 
178
 
#else /* } ACD_LABS_VERSION { */
179
 
 
180
 
    for ( i = 1; i < argc; i ++ ) {
181
 
        if ( bVer1Options && INCHI_OPTION_PREFX == argv[i][0] && ':' == argv[i][1] && !argv[i][2] ) {
182
 
            bVer1Options &= ~1;  /* turn off ver 1 options mode */
183
 
        } else
184
 
        if ( !(bVer1Options & 1) && INCHI_OPTION_PREFX == argv[i][0] && INCHI_OPTION_PREFX != argv[i][1] )
185
 
        {
186
 
            /*============== Version 0.9xx Beta options & INCHI_LIB ==================*/
187
 
            /***************************************************************/
188
 
            /*                                                             */
189
 
            /*       Version 0.9xx Beta  and INCHI_LIB (GUI) options       */
190
 
            /*                                                             */
191
 
            /***************************************************************/
192
 
 
193
 
            pArg = argv[i]+1;
194
 
 
195
 
            /* parameter */
196
 
            if ( INPUT_NONE == ip->nInputType && !stricmp( pArg, "MOL" ) ) {
197
 
                ip->nInputType = INPUT_MOLFILE;
198
 
            } else
199
 
            if ( INPUT_NONE == ip->nInputType && !stricmp( pArg, "SDF" ) ) {
200
 
                ip->nInputType = INPUT_MOLFILE;
201
 
            } else
202
 
            if ( INPUT_NONE == ip->nInputType &&
203
 
                (!memicmp( pArg, "SDF", 3 )) &&
204
 
                ( pArg[3] == ':' ) ) {
205
 
                k = 0;
206
 
                mystrncpy( ip->szSdfDataHeader, pArg+4, MAX_SDF_HEADER+1 );
207
 
                LtrimRtrim( ip->szSdfDataHeader, &k );
208
 
                if ( k ) {
209
 
                    ip->pSdfLabel  = ip->szSdfDataHeader;
210
 
                    ip->pSdfValue  = szSdfDataValue;
211
 
                    ip->nInputType = INPUT_SDFILE;
212
 
                } else {
213
 
                    ip->pSdfLabel  = NULL;
214
 
                    ip->pSdfValue  = NULL;
215
 
                    ip->nInputType = INPUT_MOLFILE;
216
 
                }
217
 
            } else
218
 
#if( ADD_CMLPP == 1 )
219
 
            if ( INPUT_NONE == ip->nInputType && !stricmp( pArg, "CML" )  ) {
220
 
                 /* CMLfile label */
221
 
                ip->nInputType = INPUT_CMLFILE;
222
 
            } else
223
 
#endif
224
 
            if ( !memicmp( pArg, "START:", 6 ) ) {
225
 
                ip->first_struct_number = strtol(pArg+6, NULL, 10);
226
 
            } else
227
 
            if ( !memicmp( pArg, "END:", 4 ) ) {
228
 
                ip->last_struct_number = strtol(pArg+4, NULL, 10);
229
 
            } else /*  RSB: */
230
 
            if ( !memicmp( pArg, "RSB:", 4 ) ) {
231
 
                mdbr = (int)strtol(pArg+4, NULL, 10);
232
 
            } else
233
 
            if ( !memicmp( pArg, "DISCONSALT:", 11 ) ) {
234
 
                bDisconnectSalts = (0 != strtol(pArg+11, NULL, 10));
235
 
            } else
236
 
            if ( !memicmp( pArg, "DISCONMETAL:", 12 ) ) {
237
 
                bDisconnectCoord = (0 != strtol(pArg+12, NULL, 10));
238
 
            } else
239
 
            if ( !memicmp( pArg, "RECONMETAL:", 11 ) ) {
240
 
                bReconnectCoord = (0 != strtol(pArg+11, NULL, 10));
241
 
            } else
242
 
            if ( !memicmp( pArg, "DISCONMETALCHKVAL:", 18 ) ) {
243
 
                bDisconnectCoordChkVal = (0 != strtol(pArg+18, NULL, 10));
244
 
            } else
245
 
            if ( !memicmp( pArg, "MOVEPOS:", 8 ) ) {
246
 
                bMovePositiveCharges = (0 != strtol(pArg+8, NULL, 10));
247
 
            } else
248
 
            if ( !memicmp( pArg, "MERGESALTTG:", 12 ) ) {
249
 
                bMergeSaltTGroups = (0 != strtol(pArg+12, NULL, 10));
250
 
            } else
251
 
            if ( !memicmp( pArg, "UNCHARGEDACIDS:", 15) ) {
252
 
                bUnchargedAcidTaut = (0 != strtol(pArg+15, NULL, 16));;
253
 
            } else
254
 
            if ( !memicmp( pArg, "ACIDTAUT:", 9 ) ) {
255
 
                bAcidTautomerism = c = (int)strtol(pArg+9, NULL, 10);
256
 
                if ( 0 <= c && c <= 2 )  bAcidTautomerism = c;
257
 
                /*else bNotRecognized = 2*bReleaseVersion;*/
258
 
            } else
259
 
            if ( !memicmp( pArg, "O:", 2 ) ) {
260
 
                bNameSuffix = 1;
261
 
                strncpy(szNameSuffix, pArg+2, sizeof(szNameSuffix)-1);
262
 
            } else
263
 
            if ( !memicmp( pArg, "OP:", 3 ) ) {
264
 
                bOutputPath = 1;
265
 
                strncpy(szOutputPath, pArg+3, sizeof(szOutputPath)-1);
266
 
            } else
267
 
            if ( !stricmp( pArg, "ALT" ) ) {
268
 
                ip->bAbcNumbers = 1;
269
 
            } else
270
 
            if ( !stricmp( pArg, "SCT" ) ) {
271
 
                ip->bCtPredecessors = 1;
272
 
            } else
273
 
 
274
 
            if ( !stricmp( pArg, "CMP" ) ) {
275
 
                bCompareComponents = CMP_COMPONENTS;
276
 
            } else
277
 
            if ( !stricmp( pArg, "CMPNONISO" ) ) {
278
 
                bCompareComponents = CMP_COMPONENTS | CMP_COMPONENTS_NONISO;
279
 
            } else
280
 
            if ( !stricmp( pArg, "SREL" ) ) {
281
 
                if ( nMode & REQ_MODE_RACEMIC_STEREO ) {
282
 
                    nMode ^= REQ_MODE_RACEMIC_STEREO;
283
 
                }
284
 
                if ( nMode & REQ_MODE_CHIR_FLG_STEREO ) {
285
 
                    nMode ^= REQ_MODE_CHIR_FLG_STEREO;
286
 
                }
287
 
                nMode |= REQ_MODE_RELATIVE_STEREO;
288
 
                nMode |= REQ_MODE_STEREO;
289
 
            } else
290
 
            if ( !stricmp( pArg, "SRAC" ) ) {
291
 
                if ( nMode & REQ_MODE_RELATIVE_STEREO ) {
292
 
                    nMode ^= REQ_MODE_RELATIVE_STEREO;
293
 
                }
294
 
                if ( nMode & REQ_MODE_CHIR_FLG_STEREO ) {
295
 
                    nMode ^= REQ_MODE_CHIR_FLG_STEREO;
296
 
                }
297
 
                nMode |= REQ_MODE_RACEMIC_STEREO;
298
 
                nMode |= REQ_MODE_STEREO;
299
 
            } else
300
 
            if ( !stricmp( pArg, "SUCF" ) ) {
301
 
                if ( nMode & REQ_MODE_RELATIVE_STEREO ) {
302
 
                    nMode ^= REQ_MODE_RELATIVE_STEREO;
303
 
                }
304
 
                if ( nMode & REQ_MODE_RACEMIC_STEREO ) {
305
 
                    nMode ^= REQ_MODE_RACEMIC_STEREO;
306
 
                }
307
 
                nMode |= REQ_MODE_CHIR_FLG_STEREO;    /* stereo defined by the Chiral flag */
308
 
                nMode |= REQ_MODE_STEREO;
309
 
            } else
310
 
            if ( !stricmp( pArg, "ChiralFlagON" ) ) { /* used only with /SUCF */
311
 
                bForcedChiralFlag &= ~FLAG_SET_INP_AT_NONCHIRAL;
312
 
                bForcedChiralFlag |= FLAG_SET_INP_AT_CHIRAL;
313
 
            } else
314
 
            if ( !stricmp( pArg, "ChiralFlagOFF" ) ) { /* used only with /SUCF */
315
 
                bForcedChiralFlag &= ~FLAG_SET_INP_AT_CHIRAL;
316
 
                bForcedChiralFlag |= FLAG_SET_INP_AT_NONCHIRAL;
317
 
            } else
318
 
            if ( !stricmp( pArg, "NOUUSB" ) ) {
319
 
                nMode |= REQ_MODE_SB_IGN_ALL_UU;
320
 
            } else
321
 
            if ( !stricmp( pArg, "NOUUSC" ) ) {
322
 
                nMode |= REQ_MODE_SC_IGN_ALL_UU;
323
 
            } else
324
 
            if ( !stricmp( pArg, "SDFID" ) ) {
325
 
                ip->bGetSdfileId = 1;
326
 
            } else
327
 
            if ( !stricmp( pArg, "XML" ) ) {
328
 
                bXml &= ~INCHI_OUT_PLAIN_TEXT;
329
 
                bXml |=  INCHI_OUT_XML;
330
 
                /*bNotRecognized = 2*bReleaseVersion;*/
331
 
            } else
332
 
            if ( !stricmp( pArg, "PLAIN" ) ) {
333
 
                bXml |=  INCHI_OUT_PLAIN_TEXT;
334
 
                bXml &= ~INCHI_OUT_XML;
335
 
            } else
336
 
#if( !defined(INCHI_LIBRARY) && !defined(INCHI_LIB) )
337
 
            if ( !stricmp( pArg, "Tabbed" ) ) {
338
 
                bXml |=  INCHI_OUT_TABBED_OUTPUT;
339
 
            } else
340
 
#endif
341
 
            if ( !stricmp( pArg, "ANNPLAIN" ) ) {
342
 
                bXml |=   INCHI_OUT_PLAIN_TEXT_COMMENTS;
343
 
                bXml &=  ~INCHI_OUT_XML_TEXT_COMMENTS;
344
 
            } else
345
 
            if ( !stricmp( pArg, "ANNXML" ) ) {
346
 
                bXml |=   INCHI_OUT_XML_TEXT_COMMENTS;
347
 
                bXml &=  ~INCHI_OUT_PLAIN_TEXT_COMMENTS;
348
 
            } else
349
 
            if ( !stricmp( pArg, "DONOTADDH" ) ) {
350
 
                bDoNotAddH = 1;
351
 
            } else
352
 
            if ( !memicmp( pArg, "AUXINFO:", 8 ) && isdigit(UCINT pArg[8]) ) {
353
 
                k = strtol(pArg+8, NULL, 10);
354
 
                if ( k == 0 ) {
355
 
                    bINChIOutputOptions |= INCHI_OUT_NO_AUX_INFO;  /* no aux info */
356
 
                    bINChIOutputOptions &= ~INCHI_OUT_SHORT_AUX_INFO;
357
 
                } else
358
 
                if ( k == 1 ) {
359
 
                    bINChIOutputOptions &= ~(INCHI_OUT_NO_AUX_INFO | INCHI_OUT_SHORT_AUX_INFO); /* include full aux info */
360
 
                } else
361
 
                if ( k == 2 ) {
362
 
                    bINChIOutputOptions &= ~INCHI_OUT_NO_AUX_INFO; /* include short aux info */
363
 
                    bINChIOutputOptions |= INCHI_OUT_SHORT_AUX_INFO;
364
 
                } else {
365
 
                    bINChIOutputOptions = k;  /* override everything */
366
 
                }
367
 
            } else
368
 
            if ( !stricmp( pArg, "MERGE" ) ) {
369
 
                bMergeAllInputStructures = 1;
370
 
            } else
371
 
            if ( !stricmp( pArg, "PGO" ) ) {
372
 
                ip->bSaveAllGoodStructsAsProblem = 1;
373
 
            } else
374
 
            if ( !stricmp( pArg, "DCR" ) ) {
375
 
                bDisplayCompositeResults = 1;
376
 
            } else
377
 
            if ( !stricmp( pArg, "DSB" ) ) {
378
 
                nMode |= REQ_MODE_NO_ALT_SBONDS;
379
 
            } else
380
 
            if ( !stricmp( pArg, "NOHDR" ) ) {
381
 
                 bNoStructLabels = 1;
382
 
            } else
383
 
            if ( !stricmp( pArg, "NoVarH" ) ) {
384
 
                 bTgFlagVariableProtons = 0;
385
 
            } else
386
 
            if ( !stricmp( pArg, "NoADP" ) ) {
387
 
                 bTgFlagHardAddRenProtons = 0;
388
 
            } else
389
 
            if ( !stricmp( pArg, "FixSp3bug" ) ) {
390
 
                 bFixSp3bug = 1;
391
 
            } else
392
 
#ifdef STEREO_WEDGE_ONLY
393
 
            if ( !stricmp( pArg, "NEWPS" ) ) {
394
 
                 bPointedEdgeStereo = 1;
395
 
            } else
396
 
#endif
397
 
#if( ADD_PHOSPHINE_STEREO == 1 )
398
 
            if ( !stricmp( pArg, "SPXYZ" ) ) {
399
 
                 bAddPhosphineStereo = 1;
400
 
            } else
401
 
#endif
402
 
#if( ADD_ARSINE_STEREO == 1 )
403
 
            if ( !stricmp( pArg, "SASXYZ" ) ) {
404
 
                 bAddArsineStereo = 1;
405
 
            } else
406
 
#endif
407
 
 
408
 
            if ( !stricmp( pArg, "PW" ) ) {
409
 
                ip->bSaveWarningStructsAsProblem = 1;
410
 
            } else {
411
 
                for ( k = 0 /*1*/; c=pArg[k]; k ++ ) {
412
 
                    c = toupper( c );
413
 
                    switch ( c ) {
414
 
                    case 'D':
415
 
                        bDisplay |= 1;
416
 
                        if ( pArg[k+1] == 'C' || pArg[k+1] == 'c' ) {
417
 
                            k++;
418
 
                            ip->bDisplayEachComponentINChI = 1;
419
 
                        }
420
 
                    case 'W':
421
 
                        t = strtod( pArg+k+1, (char**)&q ); /*  cast deliberately discards 'const' qualifier */
422
 
                        if ( q > pArg+k && errno == ERANGE || t < 0.0 || t*1000.0 > (double)ULONG_MAX) {
423
 
                            ul = 0;
424
 
                        } else {
425
 
                            ul = (unsigned long)(t*1000.0);
426
 
                        }
427
 
                        if ( q > pArg+k ) {
428
 
                            k = q - pArg - 1; /* k will be incremented by the for() cycle */
429
 
                            switch( c ) {
430
 
                                case 'D':
431
 
                                    *ulDisplTime = ul;
432
 
                                    break;
433
 
                                case 'W':
434
 
                                    ip->msec_MaxTime = ul;
435
 
                                    break;
436
 
                            }
437
 
                        }
438
 
                        break;
439
 
                    case 'F':
440
 
                        c =  (int)strtol( pArg+k+1, (char**)&q, 10 ); /*  cast deliberately discards 'const' qualifier */
441
 
                        if ( q > pArg+k ) {
442
 
                            k = q - pArg - 1;
443
 
                            if ( abs(c) > 5 ) {
444
 
                                nFontSize = -c;  /* font size 5 or less is too small */
445
 
                            }
446
 
                        }
447
 
                        break;
448
 
                    case 'B':
449
 
                        nMode |= REQ_MODE_BASIC;
450
 
                        nReleaseMode = 0;
451
 
                        /*bNotRecognized = bReleaseVersion;*/
452
 
                        break;
453
 
                    case 'T':
454
 
                        nMode |= REQ_MODE_TAUT;
455
 
                        nReleaseMode = 0;
456
 
                        /*bNotRecognized = bReleaseVersion;*/
457
 
                        break;
458
 
                    case 'I':
459
 
                        nMode |= REQ_MODE_ISO;
460
 
                        nReleaseMode = 0;
461
 
                        /*bNotRecognized = bReleaseVersion;*/
462
 
                        break;
463
 
                    case 'N':
464
 
                        nMode |= REQ_MODE_NON_ISO;
465
 
                        nReleaseMode = 0;
466
 
                        /*bNotRecognized = bReleaseVersion;*/
467
 
                        break;
468
 
                    case 'S':
469
 
                        nMode |= REQ_MODE_STEREO;
470
 
                        nReleaseMode = 0;
471
 
                        /*bNotRecognized = bReleaseVersion;*/
472
 
                        break;
473
 
                    case 'E':
474
 
                        if ( nReleaseMode & REQ_MODE_STEREO ) {
475
 
                            nReleaseMode ^= REQ_MODE_STEREO;
476
 
                        }
477
 
                        break;
478
 
#ifndef INCHI_LIB
479
 
                    default:
480
 
                        my_fprintf(log_file, "Unrecognized option: \"%c\".\n", c);
481
 
#endif
482
 
                    }
483
 
                    /*
484
 
                    if ( bNotRecognized && bNotRecognized == bReleaseVersion ) {
485
 
                        my_fprintf(stderr, "Unrecognized option: \"%c\".\n", c);
486
 
                        bNotRecognized = 0;
487
 
                    }
488
 
                    */
489
 
                }
490
 
            }
491
 
            /*
492
 
            if ( bNotRecognized && bNotRecognized == 2*bReleaseVersion ) {
493
 
               my_fprintf(stderr, "Unrecognized option: \"%s\".\n", argv[i]);
494
 
               bNotRecognized = 0;
495
 
            }
496
 
            */
497
 
        } else
498
 
        if ( (bVer1Options & 1) && INCHI_OPTION_PREFX == argv[i][0] && argv[i][1] ) {
499
 
            /***************************************************************/
500
 
            /*                                                             */
501
 
            /*                    Version 1.00 Beta options                */
502
 
            /*                                                             */
503
 
            /***************************************************************/
504
 
            bRecognizedOption = 2;
505
 
            pArg = argv[i] + 1;
506
 
#ifdef CML_DEBUG
507
 
            printf ("1 argv %d %s\n", i, argv[i]);
508
 
#endif
509
 
 
510
 
            bVer1Options += 2;
511
 
            /* always on: REQ_MODE_TAUT | REQ_MODE_ISO | REQ_MODE_STEREO */
512
 
            if ( !stricmp( pArg, "FIXEDH" ) ) {
513
 
                bVer1DefaultMode |= REQ_MODE_BASIC;  /* If tautomeric then tautomeric only */
514
 
            } else
515
 
            if ( !stricmp( pArg, "SNON" ) ) {
516
 
                bVer1DefaultMode &= ~REQ_MODE_STEREO; /* no stereo */
517
 
                nMode &= ~(REQ_MODE_RACEMIC_STEREO | REQ_MODE_RELATIVE_STEREO | REQ_MODE_CHIR_FLG_STEREO);
518
 
            } else
519
 
            if ( (!stricmp( pArg, "SABS" ) )) {
520
 
                bVer1DefaultMode |= REQ_MODE_STEREO;  /* abs stereo (default) */
521
 
                nMode &= ~(REQ_MODE_RACEMIC_STEREO | REQ_MODE_RELATIVE_STEREO | REQ_MODE_CHIR_FLG_STEREO);
522
 
            } else
523
 
            if ( !stricmp( pArg, "SREL" ) ) {
524
 
                bVer1DefaultMode |= REQ_MODE_STEREO;  /* relative stereo */
525
 
                nMode &= ~(REQ_MODE_RACEMIC_STEREO | REQ_MODE_CHIR_FLG_STEREO);
526
 
                nMode |= REQ_MODE_RELATIVE_STEREO;
527
 
            } else  /* REQ_MODE_CHIR_FLG_STEREO */
528
 
            if ( !stricmp( pArg, "SRAC" ) ) {
529
 
                bVer1DefaultMode |= REQ_MODE_STEREO;  /* racemic stereo */
530
 
                nMode &= ~(REQ_MODE_RELATIVE_STEREO | REQ_MODE_CHIR_FLG_STEREO);
531
 
                nMode |= REQ_MODE_RACEMIC_STEREO;
532
 
            } else
533
 
            if ( !stricmp( pArg, "SUCF" ) ) {
534
 
                bVer1DefaultMode |= REQ_MODE_STEREO;  /* stereo defined by the Chiral flag */
535
 
                nMode &= ~(REQ_MODE_RELATIVE_STEREO | REQ_MODE_RACEMIC_STEREO);
536
 
                nMode |= REQ_MODE_CHIR_FLG_STEREO;
537
 
            } else
538
 
            if ( !stricmp( pArg, "ChiralFlagON" ) ) { /* used only with /SUCF */
539
 
                bForcedChiralFlag &= ~FLAG_SET_INP_AT_NONCHIRAL;
540
 
                bForcedChiralFlag |= FLAG_SET_INP_AT_CHIRAL;
541
 
            } else
542
 
            if ( !stricmp( pArg, "ChiralFlagOFF" ) ) { /* used only with /SUCF */
543
 
                bForcedChiralFlag &= ~FLAG_SET_INP_AT_CHIRAL;
544
 
                bForcedChiralFlag |= FLAG_SET_INP_AT_NONCHIRAL;
545
 
            } else
546
 
            if ( !stricmp( pArg, "SUU" ) ) {       /* include omitted undef/unkn stereo */
547
 
                bVer1DefaultMode &= ~(REQ_MODE_SB_IGN_ALL_UU | REQ_MODE_SC_IGN_ALL_UU);
548
 
            } else
549
 
            if ( !stricmp( pArg, "FixSp3bug" ) ) {
550
 
                 bFixSp3bug = 1;
551
 
            } else
552
 
#ifdef STEREO_WEDGE_ONLY
553
 
            if ( !stricmp( pArg, "NEWPS" ) ) {
554
 
                 bPointedEdgeStereo = 1;
555
 
            } else
556
 
#endif
557
 
#if( ADD_PHOSPHINE_STEREO == 1 )
558
 
            if ( !stricmp( pArg, "SPXYZ" ) ) {
559
 
                 bAddPhosphineStereo = 1;
560
 
            } else
561
 
#endif
562
 
#if( ADD_ARSINE_STEREO == 1 )
563
 
            if ( !stricmp( pArg, "SASXYZ" ) ) {
564
 
                 bAddArsineStereo = 1;
565
 
            } else
566
 
#endif
567
 
            if ( !stricmp( pArg, "RECMET" ) ) {    /* do reconnect metals */
568
 
                bReconnectCoord = 1;
569
 
            } else
570
 
            if ( !stricmp( pArg, "AUXNONE" ) ) {    /* no aux. info */
571
 
                bINChIOutputOptions |= INCHI_OUT_NO_AUX_INFO;  /* no aux info */
572
 
                bINChIOutputOptions &= ~INCHI_OUT_SHORT_AUX_INFO;
573
 
            } else
574
 
            if ( !stricmp( pArg, "AUXFULL" ) || !stricmp( pArg, "AUXMAX" ) ) {     /* full aux info */
575
 
                bINChIOutputOptions &= ~(INCHI_OUT_NO_AUX_INFO | INCHI_OUT_SHORT_AUX_INFO); /* include short aux info */
576
 
            } else
577
 
            if ( !stricmp( pArg, "AUXMIN" ) ) {     /* minimal aux info */
578
 
                bINChIOutputOptions &= ~INCHI_OUT_NO_AUX_INFO; /* include short aux info */
579
 
                bINChIOutputOptions |= INCHI_OUT_SHORT_AUX_INFO;
580
 
            } else
581
 
            if ( !stricmp( pArg, "DONOTADDH" ) ) {
582
 
                bDoNotAddH = 1;
583
 
            } else
584
 
            if ( !stricmp( pArg, "D" ) ) {          /* display the structures */
585
 
                bDisplay |= 1;
586
 
            } else
587
 
#if( READ_INCHI_STRING == 1 )
588
 
            if ( !stricmp( pArg, "DDSRC" ) ) {
589
 
                bDisplayIfRestoreWarnings = 1;  /* InChI->Structure debugging: Display Debug Structure Restore Components */
590
 
            }
591
 
            else
592
 
#endif
593
 
            if ( !stricmp( pArg, "NOLABELS" ) ) {
594
 
                 bNoStructLabels = 1;
595
 
            } else
596
 
            if ( !stricmp( pArg, "WarnOnEmptyStructure" ) ) {
597
 
                 ip->bAllowEmptyStructure = 1;
598
 
            } else
599
 
            if ( !stricmp( pArg, "NoVarH" ) ) {
600
 
                 bTgFlagVariableProtons = 0;
601
 
            } else
602
 
            if ( !stricmp( pArg, "NoADP" ) ) {
603
 
                 bTgFlagHardAddRenProtons = 0;
604
 
            } else
605
 
            if ( !stricmp( pArg, "COMPRESS" ) ) {
606
 
                ip->bAbcNumbers = 1;
607
 
                ip->bCtPredecessors = 1;             /* compressed output */
608
 
            } else
609
 
            if ( !stricmp( pArg, "FULL" ) ) {
610
 
                bVer1DefaultMode       = VER100_DEFAULT_MODE;
611
 
                nMode                = 0;
612
 
                bReconnectCoord      = 1;            /* full output */
613
 
                bINChIOutputOptions   = ((EMBED_REC_METALS_INCHI==1)? INCHI_OUT_EMBED_REC   : 0) | INCHI_OUT_SHORT_AUX_INFO;
614
 
                ip->bCtPredecessors  = 0;
615
 
                ip->bAbcNumbers      = 0;
616
 
                bXml                 |=  INCHI_OUT_PLAIN_TEXT | INCHI_OUT_PLAIN_TEXT_COMMENTS;
617
 
                bXml                 &= ~(INCHI_OUT_XML | INCHI_OUT_XML_TEXT_COMMENTS);
618
 
            } else
619
 
            if ( !stricmp( pArg, "MIN" ) ) {
620
 
                bVer1DefaultMode     = VER100_DEFAULT_MODE;
621
 
                nMode                = 0;
622
 
                bReconnectCoord      = 1;            /* minimal output */
623
 
                bINChIOutputOptions   = ((EMBED_REC_METALS_INCHI==1)? INCHI_OUT_EMBED_REC   : 0) | INCHI_OUT_NO_AUX_INFO;            /* minimal compressed output */
624
 
                ip->bCtPredecessors  = 1;
625
 
                ip->bAbcNumbers      = 1;
626
 
                bXml                |= INCHI_OUT_PLAIN_TEXT | INCHI_OUT_PLAIN_TEXT_COMMENTS;
627
 
                bXml                &= ~(INCHI_OUT_XML | INCHI_OUT_XML_TEXT_COMMENTS);
628
 
            } else
629
 
#if( READ_INCHI_STRING == 1 )
630
 
            if ( !stricmp( pArg, "InChI2InChI" )  ) {
631
 
                 /* Read InChI Identifiers and output InChI Identifiers */
632
 
                ip->nInputType = INPUT_INCHI;
633
 
                ip->bReadInChIOptions |= READ_INCHI_OUTPUT_INCHI;
634
 
                ip->bReadInChIOptions &= ~READ_INCHI_TO_STRUCTURE;
635
 
            } else
636
 
            if ( !stricmp( pArg, "SplitInChI" )  ) {
637
 
                 /* Split InChI Identifiers into components */
638
 
                ip->bReadInChIOptions |= READ_INCHI_SPLIT_OUTPUT;
639
 
            } else
640
 
            if ( !stricmp( pArg, "InChI2Struct" )  ) {
641
 
                 /* Split InChI Identifiers into components */
642
 
                ip->bReadInChIOptions |= READ_INCHI_TO_STRUCTURE;
643
 
                ip->bReadInChIOptions &= ~READ_INCHI_OUTPUT_INCHI;
644
 
                ip->nInputType = INPUT_INCHI;
645
 
            } else
646
 
            if ( !stricmp( pArg, "KeepBalanceP" )  ) {
647
 
                 /* When spliting InChI Identifiers into components: */
648
 
                 /* If MobileH output then add p to each component;  */
649
 
                 /* Otherwise add one more component containing balance */
650
 
                 /* of protons and exchangeable isotopic H */
651
 
                ip->bReadInChIOptions |= READ_INCHI_KEEP_BALANCE_P;
652
 
            } else
653
 
#endif
654
 
            if ( /* INPUT_NONE == ip->nInputType &&*/
655
 
                !memicmp( pArg, "SDF:", 4 )  ) {
656
 
                 /* SDfile label */
657
 
                k = 0;
658
 
                mystrncpy( ip->szSdfDataHeader, pArg+4, MAX_SDF_HEADER+1 );
659
 
                LtrimRtrim( ip->szSdfDataHeader, &k );
660
 
                if ( k ) {
661
 
                    ip->pSdfLabel  = ip->szSdfDataHeader;
662
 
                    ip->pSdfValue  = szSdfDataValue;
663
 
                    if ( INPUT_NONE == ip->nInputType ) {
664
 
                        ip->nInputType = INPUT_SDFILE;
665
 
                    }
666
 
                } else {
667
 
                    ip->pSdfLabel  = NULL;
668
 
                    ip->pSdfValue  = NULL;
669
 
                    if ( INPUT_NONE == ip->nInputType ) {
670
 
                        ip->nInputType = INPUT_MOLFILE;
671
 
                    }
672
 
                }
673
 
            } else
674
 
#if( ADD_CMLPP == 1 )
675
 
            if ( INPUT_NONE == ip->nInputType && !stricmp( pArg, "CML" )  ) {
676
 
                 /* CMLfile label */
677
 
                ip->nInputType = INPUT_CMLFILE;
678
 
            } else
679
 
#endif
680
 
            /*============= Default options =============*/
681
 
            if ( !stricmp( pArg, "RECMET-" ) ) {     /* do not reconnect metals (default) */
682
 
                bReconnectCoord = 0;
683
 
            } else
684
 
            if ( !stricmp( pArg, "OUTPUTSDF" ) ) {  /* output SDfile */
685
 
                bOutputMolfileOnly = 1;
686
 
            } else
687
 
            if ( !stricmp( pArg, "SdfAtomsDT" ) ) {  /* output isotopes H as D and T in SDfile */
688
 
                bOutputMolfileDT = 1;
689
 
            } else                                    
690
 
            if ( !stricmp( pArg, "SdfSplit" ) ) {  /* Split single Molfiles into disconnected components */
691
 
                bOutputMolfileSplit = 1;
692
 
            } else
693
 
            if ( !stricmp( pArg, "STDIO" ) ) {
694
 
                bNameSuffix = 0;
695
 
            } else
696
 
            if ( !stricmp( pArg, "DCR" ) ) {
697
 
                bDisplayCompositeResults = 1;
698
 
            } else
699
 
#if( FIX_ADJ_RAD == 1 )
700
 
            if ( !stricmp( pArg, "FixRad" ) ) {
701
 
                bFixAdjacentRad = 1;
702
 
            } else
703
 
#endif
704
 
            /*============= Additional options ==========*/
705
 
            /* Tautomer perception off */
706
 
            if ( !stricmp( pArg, "EXACT" ) ) {
707
 
                bVer1DefaultMode |= REQ_MODE_BASIC;
708
 
            } else
709
 
            if ( !stricmp( pArg, "MOLFILENUMBER" ) ) {
710
 
                ip->bGetMolfileNumber |= 1;
711
 
            } else
712
 
            if ( !stricmp( pArg, "OutputPLAIN" ) ) {
713
 
                bXml |=  INCHI_OUT_PLAIN_TEXT;
714
 
                bXml &= ~INCHI_OUT_XML;
715
 
            } else
716
 
#if( !defined(INCHI_LIBRARY) && !defined(INCHI_LIB) )
717
 
            if ( !stricmp( pArg, "Tabbed" ) ) {
718
 
                bXml |=  INCHI_OUT_TABBED_OUTPUT;
719
 
            } else
720
 
#endif
721
 
            if ( !stricmp( pArg, "OutputXML" ) ) {
722
 
                bXml |= INCHI_OUT_XML;
723
 
                bXml &= ~INCHI_OUT_PLAIN_TEXT;
724
 
            } else
725
 
            if ( !stricmp( pArg, "OutputANNPLAIN" ) ) {
726
 
                bXml |=   INCHI_OUT_PLAIN_TEXT_COMMENTS;
727
 
                bXml &=  ~INCHI_OUT_XML_TEXT_COMMENTS;
728
 
                bXml |=   INCHI_OUT_WINCHI_WINDOW; /* debug */
729
 
            } else
730
 
            if ( !stricmp( pArg, "OutputANNXML" ) ) {
731
 
                bXml |=   INCHI_OUT_XML_TEXT_COMMENTS;
732
 
                bXml &=  ~INCHI_OUT_PLAIN_TEXT_COMMENTS;
733
 
            } else
734
 
            if ( !stricmp( pArg, "ONLYEXACT" ) || !stricmp( pArg, "ONLYFIXEDH" ) ) {
735
 
                bVer1DefaultMode |=  REQ_MODE_BASIC;
736
 
                bVer1DefaultMode &= ~REQ_MODE_TAUT;
737
 
            } else
738
 
            if ( !stricmp( pArg, "ONLYNONISO" ) ) {
739
 
                bVer1DefaultMode |=  REQ_MODE_NON_ISO;
740
 
                bVer1DefaultMode &= ~REQ_MODE_ISO;
741
 
            } else
742
 
            if ( !stricmp( pArg, "TAUT" ) ) {
743
 
                bVer1DefaultMode &= ~REQ_MODE_BASIC;
744
 
                bVer1DefaultMode |= REQ_MODE_TAUT;
745
 
            } else
746
 
            if ( !stricmp( pArg, "ONLYRECMET" ) ) {  /* do not disconnect metals */
747
 
                bDisconnectCoord = 0;
748
 
            } else
749
 
            if ( !stricmp( pArg, "ONLYRECSALT" ) ) {  /* do not disconnect salts */
750
 
                bDisconnectSalts = 0;
751
 
            } else
752
 
            if ( !memicmp( pArg, "START:", 6 ) ) {
753
 
                ip->first_struct_number = strtol(pArg+6, NULL, 10);
754
 
            } else
755
 
            if ( !memicmp( pArg, "END:", 4 ) ) {
756
 
                ip->last_struct_number = strtol(pArg+4, NULL, 10);
757
 
            } else /*  RSB: */
758
 
            if ( !memicmp( pArg, "RSB:", 4 )) {
759
 
                mdbr = (int)strtol(pArg+4, NULL, 10);
760
 
            } else
761
 
            if ( !stricmp( pArg, "EQU" ) ) {
762
 
                bCompareComponents = CMP_COMPONENTS;
763
 
            } else
764
 
            if ( !stricmp( pArg, "EQUNONISO" ) ) {
765
 
                bCompareComponents = CMP_COMPONENTS | CMP_COMPONENTS_NONISO;
766
 
            } else
767
 
            if ( !memicmp( pArg, "OP:", 3 ) ) {
768
 
                bOutputPath = 1;
769
 
                strncpy(szOutputPath, pArg+3, sizeof(szOutputPath)-1);
770
 
            } else
771
 
            /*============== Char+Value options ==============*/
772
 
            if ( !memicmp( pArg, "W", 1 ) && (t = strtod( pArg+1, (char**)&q ), q > pArg+1) ) {
773
 
                if ( errno == ERANGE || t < 0.0 || t*1000.0 > (double)ULONG_MAX)  {
774
 
                    ul = 0;
775
 
                } else {
776
 
                    ul = (unsigned long)(t*1000.0);  /* max. time per structure */
777
 
                }
778
 
                ip->msec_MaxTime = ul;
779
 
            } else
780
 
            if ( !memicmp( pArg, "F", 1 ) && (c =  (int)strtol( pArg+1, (char**)&q, 10 ), q > pArg+1) ) {
781
 
                nFontSize = -c;                      /* struct. display font size */
782
 
            } else {
783
 
                bRecognizedOption = 0;
784
 
#ifndef INCHI_LIB
785
 
                my_fprintf(log_file, "Unrecognized option: \"%s\".\n", pArg);
786
 
#endif
787
 
            }
788
 
            bVer1Options |= bRecognizedOption;
789
 
        } else
790
 
        if ( ip->num_paths < MAX_NUM_PATHS ) {
791
 
            char *sz;
792
 
            if ( argv[i] && argv[i][0] ) {
793
 
                if ( sz = (char*)inchi_malloc( (strlen(argv[i]) + 1)*sizeof(sz[0])) ) {
794
 
                    strcpy( sz, argv[i] );
795
 
                }
796
 
#ifdef CML_DEBUG
797
 
                printf ("1 path %d argv %d %s\n", ip -> num_paths, i, argv [i]);
798
 
#endif
799
 
                   ip->path[ip->num_paths++] = sz;
800
 
            }
801
 
        }
802
 
    }
803
 
 
804
 
 
805
 
    if ( bNameSuffix || bOutputPath ) {
806
 
        const char *p = NULL;
807
 
        char       *r = NULL;
808
 
        char       *sz;
809
 
        int  len;
810
 
        /*  find the 1st path */
811
 
        for ( i = 0; i < MAX_NUM_PATHS; i ++ ) {
812
 
            if ( !p && ip->path[i] && ip->path[i][0] ) {
813
 
                p = ip->path[i];
814
 
                break;
815
 
            }
816
 
        }
817
 
        /* fix output path */
818
 
        if ( bOutputPath && szOutputPath[0] && p ) {
819
 
            /* remove last slash */
820
 
            len = strlen(szOutputPath);
821
 
            if ( len > 0 && szOutputPath[len-1] != INCHI_PATH_DELIM ) {
822
 
                szOutputPath[len++] = INCHI_PATH_DELIM;
823
 
                szOutputPath[len]   = '\0';
824
 
            }
825
 
            if ( len > 0 && (r = (char *)strrchr( p, INCHI_PATH_DELIM ) ) && r[1] ) {
826
 
                strcat( szOutputPath, r+1 );
827
 
                p = szOutputPath;
828
 
            }
829
 
        }        /*  add missing paths */
830
 
        for ( i = 0; p && i < MAX_NUM_PATHS; i ++ ) {
831
 
            if ( ip->path[i] && !stricmp( ip->path[i], "NUL" ) ) {
832
 
                inchi_free( (char *)ip->path[i] ); /* cast deliberately const qualifier */
833
 
                ip->path[i] = NULL;
834
 
            } else
835
 
            if ( !ip->path[i] || !ip->path[i][0] ) {
836
 
                len = strlen( p ) + strlen(szNameSuffix) + strlen( ext[i] );
837
 
                if ( sz = (char*)inchi_malloc( (len+1)*sizeof(sz[0]) ) ) {
838
 
                    strcpy( sz, p );
839
 
                    strcat( sz, szNameSuffix );
840
 
                    strcat( sz, ext[i] );
841
 
                    ip->num_paths++;
842
 
                }
843
 
                ip->path[i] =sz;
844
 
            }
845
 
        }
846
 
    }
847
 
 
848
 
#endif  /* } NOT ACD_LABS_VERSION */
849
 
 
850
 
 
851
 
#if( READ_INCHI_STRING == 1 )
852
 
    if ( INPUT_INCHI == ip->nInputType ) {
853
 
        bCompareComponents                 = 0;
854
 
        /*bDisplayCompositeResults           = 0;*/
855
 
        bOutputMolfileOnly                 = 0;
856
 
        /*bNoStructLabels                    = 1;*/
857
 
        bINChIOutputOptions  |= INCHI_OUT_NO_AUX_INFO;
858
 
        bINChIOutputOptions  &= ~INCHI_OUT_SHORT_AUX_INFO;
859
 
        bINChIOutputOptions  &= ~INCHI_OUT_ONLY_AUX_INFO;
860
 
        ip->bDisplayIfRestoreWarnings = bDisplayIfRestoreWarnings;
861
 
 
862
 
        if ( !(bINChIOutputOptions &
863
 
            
864
 
             (INCHI_OUT_SDFILE_ONLY          |
865
 
              INCHI_OUT_XML                  |
866
 
              INCHI_OUT_PLAIN_TEXT           |
867
 
              INCHI_OUT_PLAIN_TEXT_COMMENTS  |
868
 
              INCHI_OUT_XML_TEXT_COMMENTS    
869
 
                                             ) ) ) {
870
 
 
871
 
            bINChIOutputOptions |= INCHI_OUT_PLAIN_TEXT;
872
 
        }
873
 
    }
874
 
#endif
875
 
 
876
 
 
877
 
    if ( bVer1Options ) {
878
 
        nMode |= bVer1DefaultMode;
879
 
    } else
880
 
    if ( bReleaseVersion ) {
881
 
        nMode |= nReleaseMode;
882
 
    }
883
 
 
884
 
#if( defined(INCHI_ANSI_ONLY) || defined(INCHI_LIB) )
885
 
    if ( bCompareComponents && !(bDisplay & 1) ) {
886
 
        bCompareComponents = 0;
887
 
    }
888
 
#endif
889
 
    /*  Save original options */
890
 
    /* nOrigMode = nMode; */
891
 
#ifndef INCHI_ANSI_ONLY
892
 
    ip->dp.sdp.nFontSize         = nFontSize;
893
 
    ip->dp.sdp.ulDisplTime       = *ulDisplTime;
894
 
    ip->bDisplay                 = bDisplay;
895
 
#ifdef INCHI_LIB
896
 
    ip->bDisplayCompositeResults = bDisplay;
897
 
#else
898
 
    ip->bDisplayCompositeResults = bDisplayCompositeResults;
899
 
#endif
900
 
#else
901
 
    ip->bDisplayEachComponentINChI = 0;
902
 
    bCompareComponents            = 0;
903
 
#endif
904
 
    ip->bMergeAllInputStructures = bMergeAllInputStructures;
905
 
    ip->bDoNotAddH               = bDoNotAddH;
906
 
    /*  set default options */
907
 
    if ( !nMode || nMode == REQ_MODE_STEREO ) {
908
 
        /*  requested all output */
909
 
        nMode |= (REQ_MODE_BASIC | REQ_MODE_TAUT | REQ_MODE_ISO | REQ_MODE_NON_ISO | REQ_MODE_STEREO);
910
 
    } else {
911
 
        if ( !(nMode & (REQ_MODE_BASIC | REQ_MODE_TAUT)) ) {
912
 
            nMode |= (REQ_MODE_BASIC | REQ_MODE_TAUT);
913
 
        }
914
 
        if ( (nMode & REQ_MODE_STEREO) && !(nMode & (REQ_MODE_ISO | REQ_MODE_NON_ISO)) ) {
915
 
            nMode |= (REQ_MODE_ISO | REQ_MODE_NON_ISO);
916
 
        }
917
 
    }
918
 
    /*  if the user requested isotopic then unconditionally add non-isotopic output. */
919
 
    if ( nMode & REQ_MODE_ISO ) {
920
 
        nMode |= REQ_MODE_NON_ISO;
921
 
    }
922
 
#if( MIN_SB_RING_SIZE > 0 )
923
 
    if ( mdbr ) {
924
 
        nMinDbRinSize = mdbr;
925
 
    }
926
 
    nMode |= (nMinDbRinSize << REQ_MODE_MIN_SB_RING_SHFT) & REQ_MODE_MIN_SB_RING_MASK;
927
 
#endif
928
 
    /*  input file */
929
 
    if ( ip->nInputType == INPUT_NONE && ip->num_paths > 0 ) {
930
 
        ip->nInputType = INPUT_MOLFILE; /*  default */
931
 
#if( ADD_CMLPP == 1 )
932
 
        {
933
 
            const char *p;
934
 
            if ( ip->path[0] && ( p = strrchr(ip->path[0], '.' ) ) &&
935
 
                 !stricmp( p, ".cml") ) {
936
 
                ip->nInputType = INPUT_CMLFILE;
937
 
            }
938
 
        }
939
 
#endif
940
 
    }
941
 
    ip->nMode = nMode;
942
 
    if ( (bCompareComponents & CMP_COMPONENTS) && (nMode & REQ_MODE_BASIC) ) {
943
 
        bCompareComponents |= CMP_COMPONENTS_NONTAUT; /* compare non-tautomeric */
944
 
    }
945
 
    ip->bCompareComponents = bCompareComponents;
946
 
 
947
 
    ip->bINChIOutputOptions = bINChIOutputOptions | (bOutputMolfileOnly? INCHI_OUT_SDFILE_ONLY : 0);
948
 
    if ( bOutputMolfileOnly ) {
949
 
        bXml &= ~(INCHI_OUT_XML                 | INCHI_OUT_PLAIN_TEXT |
950
 
                  INCHI_OUT_PLAIN_TEXT_COMMENTS | INCHI_OUT_XML_TEXT_COMMENTS | INCHI_OUT_TABBED_OUTPUT);
951
 
#if( SDF_OUTPUT_DT == 1 )
952
 
        ip->bINChIOutputOptions |= bOutputMolfileDT?    INCHI_OUT_SDFILE_ATOMS_DT : 0;
953
 
        ip->bINChIOutputOptions |= bOutputMolfileSplit? INCHI_OUT_SDFILE_SPLIT : 0;
954
 
#endif
955
 
    }
956
 
    if ( bXml & INCHI_OUT_XML ) {
957
 
        bXml &= ~(INCHI_OUT_PLAIN_TEXT | INCHI_OUT_XML_TEXT_COMMENTS | INCHI_OUT_TABBED_OUTPUT);
958
 
    }
959
 
#ifdef INCHI_LIB
960
 
    if ( !(bDisplay & 1) ) {
961
 
        bXml &= ~(INCHI_OUT_PLAIN_TEXT_COMMENTS | INCHI_OUT_XML_TEXT_COMMENTS); /* do not ouput comments in wINChI text file results */
962
 
    } else {
963
 
        bXml |= INCHI_OUT_WINCHI_WINDOW;
964
 
    }
965
 
#endif
966
 
    ip->bINChIOutputOptions |= bXml;
967
 
    ip->bNoStructLabels     = bNoStructLabels;
968
 
 
969
 
    if ( bForcedChiralFlag ) {
970
 
        ip->bChiralFlag = bForcedChiralFlag;
971
 
    }
972
 
 
973
 
    /*******************************************/
974
 
    /*       tautomeric/salts settings         */
975
 
    /*******************************************/
976
 
 
977
 
    ip->bTautFlags     = 0;   /* initialize */
978
 
    ip->bTautFlagsDone = 0;   /* initialize */
979
 
 
980
 
    /* find regular tautomerism */
981
 
    ip->bTautFlags |= TG_FLAG_TEST_TAUT__ATOMS;
982
 
    /* disconnect salts */
983
 
    ip->bTautFlags |= bDisconnectSalts?         TG_FLAG_DISCONNECT_SALTS    : 0;
984
 
    /* if possible find long-range H/(-) taut. on =C-OH, >C=O    */
985
 
    ip->bTautFlags |= bAcidTautomerism?         TG_FLAG_TEST_TAUT__SALTS    : 0;
986
 
    /* allow long-range movement of N(+), P(+) charges           */
987
 
    ip->bTautFlags |= bMovePositiveCharges?     TG_FLAG_MOVE_POS_CHARGES    : 0;
988
 
    /* multi-attachement long-range H/(-) taut. on =C-OH, >C=O   */
989
 
    ip->bTautFlags |= (bAcidTautomerism > 1)?   TG_FLAG_TEST_TAUT2_SALTS    : 0;
990
 
    /* (debug) allow to find long-range H-only tautomerism on =C-OH, >C=O */
991
 
    ip->bTautFlags |= (bUnchargedAcidTaut==1)?  TG_FLAG_ALLOW_NO_NEGTV_O    : 0;
992
 
    /* merge =C-OH and >C=O containing t-groups and other =C-OH groups */
993
 
    ip->bTautFlags |= bMergeSaltTGroups?        TG_FLAG_MERGE_TAUT_SALTS    : 0;
994
 
    ip->bTautFlags |= bDisconnectCoord?         TG_FLAG_DISCONNECT_COORD    : 0;
995
 
    ip->bTautFlags |=(bDisconnectCoord &&
996
 
                      bReconnectCoord)?         TG_FLAG_RECONNECT_COORD     : 0;
997
 
    ip->bTautFlags |= bDisconnectCoordChkVal?   TG_FLAG_CHECK_VALENCE_COORD : 0;
998
 
    ip->bTautFlags |= bTgFlagVariableProtons?   TG_FLAG_VARIABLE_PROTONS     : 0;
999
 
    ip->bTautFlags |= bTgFlagHardAddRenProtons? TG_FLAG_HARD_ADD_REM_PROTONS : 0;
1000
 
#ifdef STEREO_WEDGE_ONLY
1001
 
    ip->bTautFlags  |= bPointedEdgeStereo?      TG_FLAG_POINTED_EDGE_STEREO  : 0;
1002
 
#endif
1003
 
#if( FIX_ADJ_RAD == 1 )
1004
 
    ip->bTautFlags  |= bFixAdjacentRad?         TG_FLAG_FIX_ADJ_RADICALS : 0;
1005
 
#endif
1006
 
#if( ADD_PHOSPHINE_STEREO == 1 )
1007
 
    ip->bTautFlags  |= bAddPhosphineStereo?     TG_FLAG_PHOSPHINE_STEREO : 0;
1008
 
#endif
1009
 
#if( ADD_ARSINE_STEREO == 1 )
1010
 
    ip->bTautFlags  |= bAddArsineStereo?        TG_FLAG_ARSINE_STEREO : 0;
1011
 
#endif
1012
 
    ip->bTautFlags  |= bFixSp3bug?              TG_FLAG_FIX_SP3_BUG   : 0;
1013
 
 
1014
 
    if ( !ip->nInputType ) {
1015
 
        ip->nInputType = INPUT_MOLFILE;
1016
 
    }
1017
 
    return 0;
1018
 
}
1019
 
/*******************************************************************/
1020
 
int PrintInputParms( INCHI_FILE *log_file, INPUT_PARMS *ip )
1021
 
{
1022
 
    INCHI_MODE nMode = ip->nMode;
1023
 
    int i, k;
1024
 
    /*  output options: line 1 */
1025
 
    my_fprintf( log_file, "Options: " );
1026
 
    i = 0;
1027
 
 
1028
 
    /* SDfile output */
1029
 
    if ( ip->bINChIOutputOptions & INCHI_OUT_SDFILE_ONLY ) {
1030
 
        my_fprintf( log_file, "Output SDfile only%s\n",
1031
 
            (ip->bINChIOutputOptions & INCHI_OUT_SDFILE_ATOMS_DT)? " (write H isotopes as D, T)":"" );
1032
 
        return 0;
1033
 
    }
1034
 
    /* tautomerism */
1035
 
    if( (nMode & (REQ_MODE_BASIC | REQ_MODE_TAUT )) == (REQ_MODE_BASIC | REQ_MODE_TAUT) ) {
1036
 
        my_fprintf( log_file, "Mobile H Perception OFF" );
1037
 
    } else
1038
 
    if( (nMode & (REQ_MODE_BASIC | REQ_MODE_TAUT )) == (REQ_MODE_TAUT) ) {
1039
 
        my_fprintf( log_file, "Mobile H Perception ON" );
1040
 
    } else
1041
 
    if( (nMode & (REQ_MODE_BASIC | REQ_MODE_TAUT )) == (REQ_MODE_BASIC) ) {
1042
 
        my_fprintf( log_file, "Mobile H ignored" );
1043
 
    } else {
1044
 
        my_fprintf( log_file, "Undefined Mobile H mode" );
1045
 
    }
1046
 
    if ( (ip->bTautFlags & TG_FLAG_VARIABLE_PROTONS) ) { 
1047
 
         if ( !(ip->bTautFlags & TG_FLAG_HARD_ADD_REM_PROTONS) ) {
1048
 
            my_fprintf( log_file, ", Disabled Aggressive (De)protonation" );
1049
 
         }
1050
 
    }
1051
 
    my_fprintf( log_file, "\n");
1052
 
#if( FIX_ADJ_RAD == 1 )
1053
 
    if ( ip->bTautFlags & TG_FLAG_FIX_ADJ_RADICALS ) {
1054
 
        my_fprintf( log_file, "Fix Adjacent Radicals\n" );
1055
 
    }
1056
 
#endif
1057
 
    i = 0;
1058
 
    /* isotopic */
1059
 
    if ( nMode & REQ_MODE_ISO ) {
1060
 
        my_fprintf( log_file, "Isotopic ON");
1061
 
    } else
1062
 
    if ( nMode & REQ_MODE_NON_ISO ) {
1063
 
        my_fprintf( log_file, "Isotopic OFF");
1064
 
    }
1065
 
    i ++;
1066
 
    /*  stereo */
1067
 
    if ( nMode & REQ_MODE_STEREO ) {
1068
 
        my_fprintf( log_file,  ", %s%s%s%sStereo ON",
1069
 
                     ( nMode & REQ_MODE_NOEQ_STEREO )?     "Slow ":"",
1070
 
                     ( nMode & REQ_MODE_REDNDNT_STEREO )?  "Redund. ":"",
1071
 
                     ( nMode & REQ_MODE_NO_ALT_SBONDS)?    "No AltBond ":"",
1072
 
 
1073
 
                     ( nMode & REQ_MODE_RACEMIC_STEREO)?   "Racemic " :
1074
 
                     ( nMode &  REQ_MODE_RELATIVE_STEREO)? "Relative " :
1075
 
                     ( nMode &  REQ_MODE_CHIR_FLG_STEREO)? "Chiral Flag " : "Absolute " );
1076
 
        if ( 0 == (nMode & (REQ_MODE_SB_IGN_ALL_UU | REQ_MODE_SC_IGN_ALL_UU)) ) {
1077
 
            my_fprintf( log_file, "\nInclude undefined/unknown stereogenic centers and bonds");
1078
 
        } else
1079
 
        if ( REQ_MODE_SC_IGN_ALL_UU == (nMode & (REQ_MODE_SB_IGN_ALL_UU | REQ_MODE_SC_IGN_ALL_UU)) ) {
1080
 
            my_fprintf( log_file, "\nOmit undefined/unknown stereogenic centers");
1081
 
        } else
1082
 
        if ( REQ_MODE_SB_IGN_ALL_UU == (nMode & (REQ_MODE_SB_IGN_ALL_UU | REQ_MODE_SC_IGN_ALL_UU)) ) {
1083
 
            my_fprintf( log_file, "\nOmit undefined/unknown stereogenic bonds");
1084
 
        } else {
1085
 
        /*case REQ_MODE_SB_IGN_ALL_UU | REQ_MODE_SC_IGN_ALL_UU*/
1086
 
            my_fprintf( log_file, "\nOmit undefined/unknown stereogenic centers and bonds");
1087
 
        }
1088
 
#if( defined(MIN_SB_RING_SIZE) && MIN_SB_RING_SIZE > 0 )
1089
 
        k = (ip->nMode & REQ_MODE_MIN_SB_RING_MASK) >> REQ_MODE_MIN_SB_RING_SHFT;
1090
 
        if ( bRELEASE_VERSION != 1 || k != MIN_SB_RING_SIZE ) {
1091
 
            if ( k >= 3 ) {
1092
 
                my_fprintf( log_file, "\nMin. stereobond ring size: %d\n", k );
1093
 
            } else {
1094
 
                my_fprintf( log_file, "\nMin. stereobond ring size: NONE\n" );
1095
 
            }
1096
 
            i = 0;
1097
 
        }
1098
 
        if ( TG_FLAG_POINTED_EDGE_STEREO & ip->bTautFlags ) {
1099
 
            my_fprintf( log_file, "%sOnly narrow end of wedge points to stereocenter\n", i? "\n":"" );
1100
 
            i = 0;
1101
 
        }
1102
 
#if( ADD_PHOSPHINE_STEREO == 1 )
1103
 
        if ( TG_FLAG_PHOSPHINE_STEREO & ip->bTautFlags ) {
1104
 
            my_fprintf( log_file, "%sInclude phoshine stereochemistry\n", i? "\n":"" );
1105
 
            i = 0;
1106
 
        }
1107
 
#endif
1108
 
#if( ADD_ARSINE_STEREO == 1 )
1109
 
        if ( TG_FLAG_ARSINE_STEREO & ip->bTautFlags ) {
1110
 
            my_fprintf( log_file, "%sInclude arsine stereochemistry\n", i? "\n":"" );
1111
 
            i = 0;
1112
 
        }
1113
 
#endif
1114
 
#endif
1115
 
    } else {
1116
 
        my_fprintf( log_file, ", Stereo OFF");
1117
 
    }
1118
 
    if ( i ) {
1119
 
        my_fprintf( log_file, "\n");
1120
 
        i = 0;
1121
 
    }
1122
 
 
1123
 
    /* metals disconnection */
1124
 
    if ( ip->bTautFlags & TG_FLAG_DISCONNECT_COORD ) {
1125
 
        if ( ip->bTautFlags & TG_FLAG_RECONNECT_COORD ) {
1126
 
            my_fprintf( log_file, "Include bonds to metals\n");
1127
 
        }
1128
 
    } else {
1129
 
        my_fprintf( log_file, "Do not disconnect metals\n");
1130
 
    }
1131
 
    /*  other options: line 2 */
1132
 
#if( bRELEASE_VERSION == 1 )
1133
 
    if ( ip->bCtPredecessors || ip->bAbcNumbers ) {
1134
 
        if ( ip->bCtPredecessors && ip->bAbcNumbers ) {
1135
 
            my_fprintf( log_file, "Representation: Compressed");
1136
 
            i ++;
1137
 
        } else {
1138
 
            my_fprintf( log_file, "Connection table: %s, %s\n",
1139
 
                ip->bCtPredecessors? "Predecessor_numbers(closures)":"Canon_numbers(branching, ring closures)",
1140
 
                ip->bAbcNumbers?     "Shorter alternative":"Numerical");
1141
 
            i = 0;
1142
 
        }
1143
 
    }
1144
 
#else
1145
 
    if ( (bRELEASE_VERSION != 1) || ip->bCtPredecessors || ip->bAbcNumbers ) {
1146
 
        my_fprintf( log_file, "Connection table: %s, %s\n",
1147
 
            ip->bCtPredecessors? "Predecessor_numbers(closures)":"Canon_numbers(branching, ring closures)",
1148
 
            ip->bAbcNumbers?     "Shorter alternative":"Numerical");
1149
 
        i = 0;
1150
 
    } else {
1151
 
        my_fprintf( log_file, "Representation: Numerical");
1152
 
        i ++;
1153
 
    }
1154
 
#endif
1155
 
    if( ip->bINChIOutputOptions & INCHI_OUT_NO_AUX_INFO ) {
1156
 
        my_fprintf( log_file, "%sAux. info suppressed", i?"; ":"");
1157
 
        i ++;
1158
 
    } else
1159
 
    if ( ip->bINChIOutputOptions & INCHI_OUT_SHORT_AUX_INFO ) {
1160
 
        my_fprintf( log_file, "%sMinimal Aux. info", i?"; ":"");
1161
 
        i ++;
1162
 
    } else {
1163
 
        my_fprintf( log_file, "%sFull Aux. info", i?"; ":"");
1164
 
        i ++;
1165
 
    }
1166
 
    if ( ip->bDoNotAddH ) {
1167
 
        my_fprintf( log_file, "%sDo not add H", i?"; ":"");
1168
 
    }
1169
 
    if ( i ) {
1170
 
        my_fprintf( log_file, "\n");
1171
 
        i = 0;
1172
 
    }
1173
 
    if ( ip->bAllowEmptyStructure ) {
1174
 
        my_fprintf( log_file, "Issue warning on empty structure\n" );
1175
 
    }
1176
 
 
1177
 
    if ( ip->szSdfDataHeader[0] && ip->nInputType != INPUT_SDFILE ) {
1178
 
        my_fprintf( log_file, "SDfile data header: \"%s\"\n", ip->szSdfDataHeader);
1179
 
    }
1180
 
    /* input format */
1181
 
    if ( ip->nInputType ) {
1182
 
        my_fprintf( log_file, "Input format: %s",
1183
 
            ip->nInputType == INPUT_MOLFILE?     "MOLfile"       :
1184
 
            ip->nInputType == INPUT_SDFILE?      "SDfile"        :
1185
 
            ip->nInputType == INPUT_CMLFILE?     "CMLfile"       :
1186
 
#if( READ_INCHI_STRING == 1 )
1187
 
            ip->nInputType == INPUT_INCHI?       "InChI (plain identifier)" :
1188
 
#endif
1189
 
#if( SPECIAL_BUILD == 1 )
1190
 
            ip->nInputType == INPUT_INCHI_XML?   "MoChI (xml)"   :
1191
 
            ip->nInputType == INPUT_INCHI_PLAIN? "MoChI (plain)" : "Unknown" );
1192
 
#else
1193
 
            ip->nInputType == INPUT_INCHI_XML?   "InChI (xml)"   :
1194
 
            ip->nInputType == INPUT_INCHI_PLAIN? "InChI (plain)" : "Unknown" );
1195
 
#endif
1196
 
        if ( (ip->nInputType == INPUT_MOLFILE || ip->nInputType == INPUT_SDFILE) &&
1197
 
             ip->bGetMolfileNumber ) {
1198
 
            my_fprintf( log_file, "  (attempting to read Molfile number)" );
1199
 
        }
1200
 
        my_fprintf( log_file, "\n");
1201
 
    }
1202
 
    /*  output format */
1203
 
    my_fprintf( log_file, "Output format: %s%s\n", 
1204
 
        (ip->bINChIOutputOptions & INCHI_OUT_PLAIN_TEXT)?  "Plain text" :
1205
 
        (ip->bINChIOutputOptions & INCHI_OUT_XML)?         "XML":
1206
 
        (ip->bINChIOutputOptions & INCHI_OUT_SDFILE_ONLY)? "SDfile only" : "Unknown",
1207
 
 
1208
 
        ((ip->bINChIOutputOptions & INCHI_OUT_PLAIN_TEXT) &&
1209
 
        (ip->bINChIOutputOptions & INCHI_OUT_TABBED_OUTPUT))? ", tabbed":"");
1210
 
    i = 0;
1211
 
    /*  other options: line 4 */
1212
 
    if ( ip->msec_MaxTime ) {
1213
 
        unsigned long seconds = ip->msec_MaxTime/1000;
1214
 
        unsigned long milliseconds = (ip->msec_MaxTime%1000);
1215
 
        my_fprintf( log_file, "Timeout per structure: %lu.%03lu sec", seconds, milliseconds);
1216
 
        i ++;
1217
 
    } else {
1218
 
        my_fprintf( log_file, "No timeout");
1219
 
        i ++;
1220
 
    }
1221
 
    my_fprintf( log_file, "%sUp to %d atoms per structure\n", i?"; ":"", MAX_ATOMS);
1222
 
    i = 0;
1223
 
    if ( ip->first_struct_number > 1 ) {
1224
 
        my_fprintf( log_file, "Skipping %ld structure%s\n", ip->first_struct_number-1, ip->first_struct_number==2? "":"s" );
1225
 
    }
1226
 
    if ( ip->last_struct_number > 0 ) {
1227
 
        my_fprintf( log_file, "Terminate after structure #%ld\n", ip->last_struct_number );
1228
 
    }
1229
 
    if ( ip->bSaveWarningStructsAsProblem && ip->path[3] && ip->path[3][0] ) {
1230
 
        my_fprintf( log_file, "Saving warning structures into the problem file\n");
1231
 
    }
1232
 
    if ( ip->bSaveAllGoodStructsAsProblem && ip->path[3] && ip->path[3][0] ) {
1233
 
        my_fprintf( log_file, "Saving only all good structures into the problem file\n");
1234
 
    }
1235
 
    /*  Report debug modes */
1236
 
    i = 0;
1237
 
#if( bRELEASE_VERSION != 1 )
1238
 
    my_fprintf( log_file, "Release version = NO");
1239
 
    i ++;
1240
 
#endif
1241
 
 
1242
 
#if( FIND_RING_SYSTEMS != 1 )
1243
 
    my_fprintf( log_file, "%s5-, 6-, 7-memb. ring taut. ignored", i?"; ":"");
1244
 
    i ++;
1245
 
#endif
1246
 
 
1247
 
#if( TRACE_MEMORY_LEAKS == 1 && defined(_DEBUG) )
1248
 
    my_fprintf( log_file, "%sTracing memory leaks (SLOW)", i?"; ":"");
1249
 
    i ++;
1250
 
#endif
1251
 
 
1252
 
    if ( i ) {
1253
 
        my_fprintf( log_file, "\n" );
1254
 
    }
1255
 
 
1256
 
#if( bRELEASE_VERSION != 1 )
1257
 
 
1258
 
#if( FIND_RING_SYSTEMS == 1 )
1259
 
    my_fprintf( log_file, "Find ring systems=Y\nTautomers:" );
1260
 
    my_fprintf( log_file, " 4-pyridinol=%s", TAUT_4PYRIDINOL_RINGS==1? "Y":"N");
1261
 
    my_fprintf( log_file, " pyrazole=%s", TAUT_PYRAZOLE_RINGS==1? "Y":"N");
1262
 
    my_fprintf( log_file, " tropolone=%s", TAUT_TROPOLONE_7==1? "Y":"N");
1263
 
    my_fprintf( log_file, " tropolone-5=%s", TAUT_TROPOLONE_5==1? "Y":"N");
1264
 
    my_fprintf( log_file, "\n" );
1265
 
    my_fprintf( log_file, "Only chain attachments to tautomeric rings=%s\n", TAUT_RINGS_ATTACH_CHAIN==1? "Y":"N");
1266
 
#endif
1267
 
    if ( ip->bGetSdfileId ) {
1268
 
        my_fprintf( log_file, "Extracting SDfile IDs\n");
1269
 
    }
1270
 
    my_fprintf( log_file, "\nDbg: MOVE_CHARGES=%d\n",
1271
 
                           0!=(ip->bTautFlags&TG_FLAG_MOVE_POS_CHARGES));
1272
 
    my_fprintf( log_file, "     REPLACE_ALT_WITH_TAUT=%d; NEUTRALIZE_ENDPOINTS=%d; BNS_PROTECT_FROM_TAUT=%d\n",
1273
 
                                  REPLACE_ALT_WITH_TAUT,    NEUTRALIZE_ENDPOINTS, BNS_PROTECT_FROM_TAUT);
1274
 
    my_fprintf( log_file, "     DISCONNECT_SALTS=%d;   TEST_TAUT_SALTS=%d;    TEST_TAUT2_SALTS=%d\n",
1275
 
                                  0!=(ip->bTautFlags&TG_FLAG_DISCONNECT_SALTS),
1276
 
                                  0!=(ip->bTautFlags&TG_FLAG_TEST_TAUT__SALTS),
1277
 
                                  0!=(ip->bTautFlags&TG_FLAG_TEST_TAUT2_SALTS));
1278
 
 
1279
 
    my_fprintf( log_file, "     CHARGED_ACID_TAUT_ONLY=%d MERGE_TAUT_SALTS=%d\n",
1280
 
                                  0==(ip->bTautFlags&TG_FLAG_ALLOW_NO_NEGTV_O),
1281
 
                                  0!=(ip->bTautFlags&TG_FLAG_MERGE_TAUT_SALTS));
1282
 
    my_fprintf( log_file, "     DISCONNECT_COORD=%d\n", 0!=(ip->bTautFlags&TG_FLAG_DISCONNECT_COORD) );
1283
 
#if( TEST_RENUMB_ATOMS == 1 )
1284
 
    my_fprintf( log_file, "\nDbg: TEST_RENUMB_ATOMS=%d; TEST_RENUMB_NEIGH=%d; TEST_RENUMB_SWITCH=%d\n",
1285
 
                                  TEST_RENUMB_ATOMS,    TEST_RENUMB_NEIGH,    TEST_RENUMB_SWITCH );
1286
 
    my_fprintf( log_file, "     TEST_RENUMB_ATOMS_SAVE_LONGEST=%d\n",
1287
 
                                  TEST_RENUMB_ATOMS_SAVE_LONGEST);
1288
 
#endif
1289
 
 
1290
 
#endif
1291
 
 
1292
 
    return 0;
1293
 
}
1294
 
/************************************************************************************/
1295
 
void HelpCommandLineParms( INCHI_FILE *f )
1296
 
{
1297
 
    if ( !f )
1298
 
        return;
1299
 
 
1300
 
#if ( bRELEASE_VERSION == 1 )
1301
 
 
1302
 
    inchi_print_nodisplay( f, "%s ver %s%s.\n\nUsage:\nc%s-%s inputFile [outputFile [logFile [problemFile]]] [%coption[ %coption...]]\n", INCHI_NAME, INCHI_VERSION, SPECIAL_BUILD_STRING, INCHI_NAME, INCHI_VERSION, INCHI_OPTION_PREFX, INCHI_OPTION_PREFX);
1303
 
    inchi_print_nodisplay( f, "\nOptions:\n");
1304
 
    inchi_print_nodisplay( f, "  SNon        Exclude stereo (Default: Include Absolute stereo)\n");
1305
 
    inchi_print_nodisplay( f, "  SRel        Relative stereo\n");
1306
 
    inchi_print_nodisplay( f, "  SRac        Racemic stereo\n");
1307
 
    inchi_print_nodisplay( f, "  SUCF        Use Chiral Flag: On means Absolute stereo, Off - Relative\n"); 
1308
 
    inchi_print_nodisplay( f, "  SUU         Include omitted unknown/undefined stereo\n");
1309
 
    inchi_print_nodisplay( f, "  NEWPS       Narrow end of wedge points to stereocenter (default: both)\n");
1310
 
#if( ADD_PHOSPHINE_STEREO == 1 )
1311
 
    inchi_print_nodisplay( f, "  SPXYZ       Include Phosphines Stereochemistry\n");
1312
 
#endif
1313
 
#if( ADD_ARSINE_STEREO == 1 )
1314
 
    inchi_print_nodisplay( f, "  SAsXYZ      Include Arsines Stereochemistry\n");
1315
 
#endif
1316
 
    inchi_print_nodisplay( f, "  RecMet      Include reconnected metals results\n");
1317
 
    inchi_print_nodisplay( f, "  FixedH      Mobile H Perception Off (Default: On)\n");
1318
 
    inchi_print_nodisplay( f, "  AuxNone     Omit auxiliary information (default: Include)\n");
1319
 
    /*inchi_print_nodisplay( f, "  AuxMin      Output minimal auxiliary information\n");*/
1320
 
    inchi_print_nodisplay( f, "  NoADP       Disable Aggressive Deprotonation (for testing only)\n");
1321
 
    /*inchi_print_nodisplay( f, "    PLAIN       Plain text output (Default: XML format)\n");*/
1322
 
    inchi_print_nodisplay( f, "  Compress    Compressed output\n");
1323
 
    /*inchi_print_nodisplay( f, "    FULL        Standard set of options for Full Verbose Output\n");*/
1324
 
    /*inchi_print_nodisplay( f, "    MIN         Standard set of options for Minimal Concise Output\n");*/
1325
 
    inchi_print_nodisplay( f, "  DoNotAddH   Don't add H according to usual valences: all H are explicit\n");
1326
 
#if( defined(_WIN32) && defined(_MSC_VER) && !defined(INCHI_ANSI_ONLY) && !defined(INCHI_LIBRARY) )
1327
 
    inchi_print_nodisplay( f, "  D           Display the structures\n");
1328
 
    inchi_print_nodisplay( f, "  EQU         Display sets of identical components\n");
1329
 
    inchi_print_nodisplay( f, "  Fnumber     Set display Font size in number of points\n");
1330
 
#endif
1331
 
    inchi_print_nodisplay( f, "  Wnumber     Set time-out per structure in seconds; W0 means unlimited\n");
1332
 
    inchi_print_nodisplay( f, "  SDF:DataHeader Read from the input SDfile the ID under this DataHeader\n");
1333
 
#if( ADD_CMLPP == 1 )
1334
 
    inchi_print_nodisplay( f, "  CML         Input in CML format (default for input file .CML extension) \n");
1335
 
#endif
1336
 
    inchi_print_nodisplay( f, "  NoLabels    Omit structure number, DataHeader and ID from %s output\n", INCHI_NAME);
1337
 
    inchi_print_nodisplay( f, "  Tabbed      Separate structure number, %s, and AuxIndo with tabs\n", INCHI_NAME);
1338
 
    inchi_print_nodisplay( f, "  OutputSDF   Convert %s created with default aux. info to SDfile\n", INCHI_NAME);
1339
 
#ifdef INCHI_MAIN
1340
 
    inchi_print_nodisplay( f, "  InChI2Struct Test mode: Mol/SDfile->%s->Structure->%s and a structure in AuxInfo format\n", INCHI_NAME, INCHI_NAME);
1341
 
#else
1342
 
    /*
1343
 
    inchi_print_nodisplay( f, "  InChI2Struct Convert %s string into a structure in AuxInfo format and its %s\n", INCHI_NAME, INCHI_NAME);
1344
 
    */
1345
 
#endif
1346
 
    inchi_print_nodisplay( f, "  InChI2InChI  Convert %s string into %s string for validation purposes\n", INCHI_NAME, INCHI_NAME);
1347
 
#if ( SDF_OUTPUT_DT == 1 )
1348
 
    inchi_print_nodisplay( f, "  SdfAtomsDT  Output Hydrogen Isotopes to SDfile as Atoms D and T\n");
1349
 
#endif
1350
 
    inchi_print_nodisplay( f, "  STDIO       Use standard input/output streams\n");
1351
 
    inchi_print_nodisplay( f, "  WarnOnEmptyStructure Warn and produce empty %s for empty structure\n", INCHI_NAME);
1352
 
#if( FIX_ADJ_RAD == 1 )
1353
 
    inchi_print_nodisplay( f, "  FixRad      Fix Adjacent Radicals\n");
1354
 
#endif
1355
 
       
1356
 
#else
1357
 
 
1358
 
    inchi_print_nodisplay( f, "%s ver %s. Special testing version 12-12-2002.\n", INCHI_NAME, INCHI_VERSION);
1359
 
 
1360
 
    inchi_print_nodisplay( f, "\nUsage:\ncINChI09b inputFile [outputFile [logFile [problemFile]]] [%coption[ %coption...]]\n", INCHI_OPTION_PREFX, INCHI_OPTION_PREFX);
1361
 
 
1362
 
    inchi_print_nodisplay( f, "\nOptions:\n");
1363
 
    inchi_print_nodisplay( f, "\tB        Basic\n");
1364
 
    inchi_print_nodisplay( f, "\tT        basic Tautomeric\n");
1365
 
    inchi_print_nodisplay( f, "\tI        Isotopic\n");
1366
 
    inchi_print_nodisplay( f, "\tN        Non-isotopic\n");
1367
 
    inchi_print_nodisplay( f, "\tS        Stereo\n");
1368
 
    inchi_print_nodisplay( f, "\tE        Exclude Stereo\n");
1369
 
    inchi_print_nodisplay( f, "\tD        Display the structures\n");
1370
 
    inchi_print_nodisplay( f, "\tALT      produce shorter ALTernative representation (Abc)\n");
1371
 
    inchi_print_nodisplay( f, "\tSCT      produce shorter connection table representation\n");
1372
 
    inchi_print_nodisplay( f, "\tXML      output in xml format\n");
1373
 
    inchi_print_nodisplay( f, "\tPLAIN    output in plain format\n");
1374
 
    inchi_print_nodisplay( f, "\tMERGE    Merge all MOLfiles from the input file into one compound\n");
1375
 
    inchi_print_nodisplay( f, "\tWnumber  time-out per structure in seconds, W0 means unlimited\n");
1376
 
    inchi_print_nodisplay( f, "\tFnumber  set display Font size, points\n");
1377
 
    inchi_print_nodisplay( f, "\tSREL     Relative Stereo\n");
1378
 
    inchi_print_nodisplay( f, "\tSRAC     Racemic Stereo\n");
1379
 
    inchi_print_nodisplay( f, "\tNOUUSB   Omit stereobonds if all are unknown/undefined\n");
1380
 
    inchi_print_nodisplay( f, "\tNOUUSC   Omit stereocenters if all are unknown/undefined\n");
1381
 
    inchi_print_nodisplay( f, "\tSS       Slow Stereo: do not use stereo equivalence\n");
1382
 
    inchi_print_nodisplay( f, "\tRS       Do not test for Redundant Stereo elements\n");
1383
 
    inchi_print_nodisplay( f, "\tPW       Save warning structures in the problems file\n");
1384
 
    inchi_print_nodisplay( f, "\tPGO      Save only all good structures in the problems file\n");
1385
 
    inchi_print_nodisplay( f, "\tDSB      Double Stereo Bonds only (ignore alternating bonds stereo)\n");
1386
 
    inchi_print_nodisplay( f, "\tRSB:n    Min Ring Size for detecting for Stereo Bonds (n=1 => all)\n");
1387
 
    inchi_print_nodisplay( f, "\tAUXINFO:0          do not output auxiliary information (default:1)\n");
1388
 
    inchi_print_nodisplay( f, "\tDISCONSALT:0       do not disconnect salts (default:1)\n");
1389
 
    inchi_print_nodisplay( f, "\tDISCONMETAL:0      do not disconnect metals (default:1)\n");
1390
 
    inchi_print_nodisplay( f, "\tDISCONMETALCHKVAL:1 do not disconnect if typical valence (default:0)\n");
1391
 
    inchi_print_nodisplay( f, "\tRECONMETAL:0       do not reconnect metals (default:1)\n");
1392
 
    inchi_print_nodisplay( f, "\tMOVEPOS:0          do not check moveable positive charges (default:1)\n");
1393
 
    inchi_print_nodisplay( f, "\tACIDTAUT:n         n=1: one H/(-) tautomerism, 2: more (deflt), 0:none\n");
1394
 
    inchi_print_nodisplay( f, "\tMERGESALTTG:1      merge salt t-groups (default), 0: do not merge\n");
1395
 
    inchi_print_nodisplay( f, "\tUNCHARGEDACIDS:1   Apply salt (acid) tautomerism in neutral species\n");
1396
 
    inchi_print_nodisplay( f, "\tO:[suffix]         Open all 4 files adding suffix to the inputFile name\n");
1397
 
    inchi_print_nodisplay( f, "\tOP:outputpath      Set output path\n");
1398
 
    inchi_print_nodisplay( f, "\tMOL                input file is a MOLfile (default)\n");
1399
 
    inchi_print_nodisplay( f, "\tSDF[:DataHeader]   Include SDfile data for the header into the results\n");
1400
 
    inchi_print_nodisplay( f, "\tSDFID              extract CAS r.n. in addition to requested SDfile data\n");
1401
 
    inchi_print_nodisplay( f, "\tSTART:number       Start at the given structure ordering number\n");
1402
 
    inchi_print_nodisplay( f, "\tEND:number         Terminate after the given structure ordering number\n");
1403
 
#endif
1404
 
}
1405
 
 
1406
 
 
1407
 
#ifndef INCHI_LIBRARY
1408
 
/************************************************************************************/
1409
 
int OpenFiles( FILE **inp_file, FILE **output_file, FILE **log_file, FILE **prb_file, INPUT_PARMS *ip )
1410
 
{
1411
 
/*
1412
 
  -- Files --
1413
 
  ip->path[0] => Input
1414
 
  ip->path[1] => Output (INChI)
1415
 
  ip->path[2] => Log
1416
 
  ip->path[3] => Problem structures
1417
 
  ip->path[4] => Errors file (ACD Labs)
1418
 
 
1419
 
*/
1420
 
    /*  logfile -- open es early as possible */
1421
 
    if ( !ip->path[2] || !ip->path[2][0] ) {
1422
 
        my_fprintf( stderr, "%s version %s%s%s\n", INCHI_NAME, INCHI_VERSION, SPECIAL_BUILD_STRING, bRELEASE_VERSION? "":" (For pre-release testing)" );
1423
 
        my_fprintf( stderr, "Log file not specified. Using standard error output.\n");
1424
 
        *log_file = stderr;
1425
 
    } else
1426
 
    if ( !(*log_file = fopen( ip->path[2], "w" ) ) ) {
1427
 
        my_fprintf( stderr, "%s version %s%s%s\n", INCHI_NAME, INCHI_VERSION, SPECIAL_BUILD_STRING, bRELEASE_VERSION? "":" (For pre-release testing)" );
1428
 
        my_fprintf( stderr, "Cannot open log file '%s'. Using standard error output.\n", ip->path[2] );
1429
 
        *log_file = stderr;
1430
 
    } else {
1431
 
        my_fprintf( *log_file, "%s version %s%s%s\n", INCHI_NAME, INCHI_VERSION, SPECIAL_BUILD_STRING, bRELEASE_VERSION? "":" (For pre-release testing)" );
1432
 
        my_fprintf( *log_file, "Opened log file '%s'\n", ip->path[2] );
1433
 
    }
1434
 
    /* input file */
1435
 
    if ( (ip->nInputType == INPUT_MOLFILE || ip->nInputType == INPUT_SDFILE ||
1436
 
         ip->nInputType == INPUT_CMLFILE  || ip->nInputType == INPUT_INCHI) && ip->num_paths > 0 ) {
1437
 
        const char *fmode = NULL;
1438
 
#if( defined(_MSC_VER)&&defined(_WIN32) || defined(__BORLANDC__)&&defined(__WIN32__) || defined(__GNUC__)&&defined(__MINGW32__)&&defined(_WIN32) )
1439
 
        /* compilers that definitely allow fopen "rb" (binary read) mode */
1440
 
        fmode = "rb";
1441
 
        if ( !ip->path[0] || !ip->path[0][0] || !(*inp_file = fopen( ip->path[0], "rb" ) ) ) {
1442
 
            my_fprintf( *log_file, "Cannot open input file '%s'. Terminating.\n", ip->path[0]? ip->path[0] : "<No name>" );
1443
 
            goto exit_function;
1444
 
        } else
1445
 
        if ( ip->nInputType == INPUT_CMLFILE ) {
1446
 
            int c;
1447
 
#ifdef CML_DEBUG
1448
 
            printf ("cr %d lf %d ret %d\n", (int) '\r', (int) '\f', (int) '\n');
1449
 
#endif
1450
 
            /* read up to the end of the first line */
1451
 
            while( (c = fgetc( *inp_file )) && c != EOF && c != '\n' && c != '\r' )
1452
 
                ;
1453
 
            if ( c == '\r' || c == EOF ) {
1454
 
                /* text file contains CR; close and reopen as "text" */
1455
 
                fclose( *inp_file );
1456
 
                if ( !(*inp_file = fopen( ip->path[0], "r" ) ) ) {
1457
 
                    my_fprintf( *log_file, "Cannot open input file '%s' (2nd attempt). Terminating.\n", ip->path[0] );
1458
 
                    goto exit_function;
1459
 
                }
1460
 
                my_fprintf( *log_file, "Opened input file '%s'\n", ip->path[0] );
1461
 
                fmode = "r";
1462
 
            } else {
1463
 
                fclose( *inp_file );
1464
 
                if ( !(*inp_file = fopen( ip->path[0], "rb" ) ) ) {
1465
 
                    my_fprintf( *log_file, "Cannot open input file '%s' (2nd attempt). Terminating.\n", ip->path[0] );
1466
 
                    goto exit_function;
1467
 
                }
1468
 
                my_fprintf( *log_file, "Opened input file '%s': no CR.\n", ip->path[0] );
1469
 
                fmode = "rb";
1470
 
            }
1471
 
        }
1472
 
#else
1473
 
        if ( !ip->path[0] || !ip->path[0][0] || !(*inp_file = fopen( ip->path[0], "r" ) ) ) {
1474
 
            my_fprintf( *log_file, "Cannot open input file '%s'. Terminating.\n", ip->path[0]? ip->path[0] : "<No Name>" );
1475
 
            goto exit_function;
1476
 
        } else {
1477
 
            my_fprintf( *log_file, "Opened input file '%s'\n", ip->path[0] );
1478
 
        }
1479
 
        fmode = "r";
1480
 
#endif
1481
 
        DetectInputINChIFileType( inp_file, ip, fmode );
1482
 
    } else
1483
 
    if ( (ip->nInputType != INPUT_MOLFILE && ip->nInputType != INPUT_SDFILE && ip->nInputType != INPUT_CMLFILE && ip->nInputType != INPUT_INCHI) ) {
1484
 
        my_fprintf( *log_file, "Input file type not specified. Terminating.\n");
1485
 
        goto exit_function;
1486
 
    } else {
1487
 
        my_fprintf( *log_file, "Input file not specified. Using standard input.\n");
1488
 
        *inp_file = stdin;
1489
 
    }
1490
 
    /*  output file */
1491
 
    if ( !ip->path[1] || !ip->path[1][0] ) {
1492
 
        my_fprintf( *log_file, "Output file not specified. Using standard output.\n");
1493
 
        *output_file = stdout;
1494
 
    } else {
1495
 
        if ( !(*output_file = fopen( ip->path[1], "w" ) ) ) {
1496
 
            my_fprintf( *log_file, "Cannot open output file '%s'. Terminating.\n", ip->path[1] );
1497
 
            goto exit_function;
1498
 
        } else {
1499
 
             my_fprintf( *log_file, "Opened output file '%s'\n", ip->path[1] );
1500
 
             if ( (ip->bINChIOutputOptions & (INCHI_OUT_PLAIN_TEXT)) &&
1501
 
                  *inp_file != stdin &&
1502
 
                  !(ip->bINChIOutputOptions & INCHI_OUT_SDFILE_ONLY) &&
1503
 
                  !ip->bNoStructLabels &&
1504
 
                  !(ip->bINChIOutputOptions & INCHI_OUT_TABBED_OUTPUT)) {
1505
 
                 PrintFileName( "* Input_File: \"%s\"\n", *output_file, ip->path[0] );
1506
 
             }
1507
 
        }
1508
 
    }
1509
 
    /*  problem file */
1510
 
    if ( ip->path[3] && ip->path[3][0] ) {
1511
 
        const char *fmode = "w";
1512
 
#if( defined(_MSC_VER)&&defined(_WIN32) || defined(__BORLANDC__)&&defined(__WIN32__) || defined(__GNUC__)&&defined(__MINGW32__)&&defined(_WIN32) )
1513
 
        if ( ip->nInputType != INPUT_CMLFILE ) {
1514
 
            fmode = "wb";
1515
 
        }
1516
 
#endif
1517
 
        if (  !(*prb_file = fopen( ip->path[3], fmode ) ) ) {
1518
 
            my_fprintf( *log_file, "Cannot open problem file '%s'. Terminating.\n", ip->path[3] );
1519
 
            goto exit_function;
1520
 
        } else {
1521
 
             my_fprintf( *log_file, "Opened problem file '%s'\n", ip->path[3] );
1522
 
        }
1523
 
    }
1524
 
    return 1;  /*  success */
1525
 
 
1526
 
exit_function:
1527
 
    return 0; /*  failed */
1528
 
 
1529
 
}
1530
 
#define NUM_VERSIONS 6
1531
 
#define LEN_VERSIONS 64
1532
 
/*******************************************************************/
1533
 
static int bMatchOnePrefix( int len, char *str, int lenPrefix[],
1534
 
                            char strPrefix[][LEN_VERSIONS], int numPrefix);
1535
 
/*******************************************************************/
1536
 
static int bMatchOnePrefix( int len, char *str, int lenPrefix[],
1537
 
                            char strPrefix[][LEN_VERSIONS], int numPrefix)
1538
 
{
1539
 
    int i;
1540
 
    for ( i = 0; i < numPrefix; i ++ ) {
1541
 
        if ( len >= lenPrefix[i] &&
1542
 
             !memcmp( str, strPrefix[i], lenPrefix[i] ) ) { 
1543
 
            return 1;
1544
 
        }
1545
 
    }
1546
 
    return 0;
1547
 
}
1548
 
/*******************************************************************/
1549
 
int DetectInputINChIFileType( FILE **inp_file, INPUT_PARMS *ip, const char *fmode )
1550
 
{
1551
 
    char szLine[256], ret = 0;
1552
 
    static char szPlnVersion[NUM_VERSIONS][LEN_VERSIONS]; /* = "INChI:1.1Beta/";*/
1553
 
    static int  lenPlnVersion[NUM_VERSIONS];
1554
 
    static char szPlnAuxVer[NUM_VERSIONS][LEN_VERSIONS]; /* = "AuxInfo:1.1Beta/";*/
1555
 
    static int  lenPlnAuxVer[NUM_VERSIONS];
1556
 
    static char szXmlVersion[NUM_VERSIONS][LEN_VERSIONS]; /* = "<INChI version=\"1.1Beta\">";*/
1557
 
    static int  lenXmlVersion[NUM_VERSIONS];
1558
 
    static char szXmlStruct[LEN_VERSIONS]  = "<structure";
1559
 
    static int  lenXmlStruct;
1560
 
    static char szXmlIdentVer[NUM_VERSIONS][LEN_VERSIONS]; /*= "<identifier version=\"1.1Beta\"";*/
1561
 
    static int  lenXmlIdentVer[NUM_VERSIONS];
1562
 
    static char szXmlMsgError[LEN_VERSIONS];
1563
 
    static int  lenXmlMsgError = 0;
1564
 
    static char szXmlMsgFatal[LEN_VERSIONS]= "<message type=\"fatal (aborted)\"";
1565
 
    static int  lenXmlMsgFatal;
1566
 
    static int  bInitilized = 0;
1567
 
    int  bINChI_plain = 0, bINChI_xml = 0, len, i;
1568
 
    if ( ip->nInputType == INPUT_INCHI_XML || ip->nInputType == INPUT_INCHI_PLAIN || ip->nInputType == INPUT_INCHI ) {
1569
 
        return 1;
1570
 
    }
1571
 
    if ( !bInitilized ) {
1572
 
        lenPlnVersion[0]  = sprintf( szPlnVersion[0],  "%s=%s/", INCHI_NAME, INCHI_VERSION );
1573
 
        lenPlnVersion[1]  = sprintf( szPlnVersion[1],  "INChI=1.12Beta/" );
1574
 
        lenPlnVersion[2]  = sprintf( szPlnVersion[2],  "INChI=1.0RC/" );
1575
 
        lenPlnVersion[3]  = sprintf( szPlnVersion[3],  "InChI=1.0RC/" );
1576
 
        lenPlnVersion[4]  = sprintf( szPlnVersion[4],  "InChI=1/" );
1577
 
        lenPlnVersion[5]  = sprintf( szPlnVersion[5],  "MoChI=1a/" );
1578
 
        lenPlnAuxVer[0]   = sprintf( szPlnAuxVer[0],   "AuxInfo=%s/", INCHI_VERSION );
1579
 
        lenPlnAuxVer[1]   = sprintf( szPlnAuxVer[1],   "AuxInfo=1.12Beta/" );
1580
 
        lenPlnAuxVer[2]   = sprintf( szPlnAuxVer[2],   "AuxInfo=1.0RC/" );
1581
 
        lenPlnAuxVer[3]   = sprintf( szPlnAuxVer[3],   "AuxInfo=1.0RC/" );
1582
 
        lenPlnAuxVer[4]   = sprintf( szPlnAuxVer[4],   "AuxInfo=1/" );
1583
 
        lenPlnAuxVer[5]   = sprintf( szPlnAuxVer[5],   "AuxInfo=1a/" );
1584
 
        lenXmlVersion[0]  = sprintf( szXmlVersion[0],  "<%s version=\"%s\">", INCHI_NAME, INCHI_VERSION );
1585
 
        lenXmlVersion[1]  = sprintf( szXmlVersion[1],  "<INChI version=\"1.12Beta\">" );
1586
 
        lenXmlVersion[2]  = sprintf( szXmlVersion[2],  "<INChI version=\"1.0RC\">" );
1587
 
        lenXmlVersion[3]  = sprintf( szXmlVersion[3],  "<InChI version=\"1.0RC\">" );
1588
 
        lenXmlVersion[4]  = sprintf( szXmlVersion[4],  "<InChI version=\"1\">" );
1589
 
        lenXmlVersion[5]  = sprintf( szXmlVersion[5],  "<MoChI version=\"1a\">" );
1590
 
        lenXmlIdentVer[0] = sprintf( szXmlIdentVer[0], "<identifier version=\"%s\"", INCHI_VERSION );
1591
 
        lenXmlIdentVer[1] = sprintf( szXmlIdentVer[1], "<identifier version=\"1.12Beta\"" );
1592
 
        lenXmlIdentVer[2] = sprintf( szXmlIdentVer[2], "<identifier version=\"1.0RC\"" );
1593
 
        lenXmlIdentVer[3] = sprintf( szXmlIdentVer[3], "<identifier version=\"1.0RC\"" );
1594
 
        lenXmlIdentVer[4] = sprintf( szXmlIdentVer[4], "<identifier version=\"1\"" );
1595
 
        lenXmlIdentVer[5] = sprintf( szXmlIdentVer[5], "<identifier version=\"1a\"" );
1596
 
        lenXmlMsgError    = sprintf( szXmlMsgError,    "<message type=\"error (no %s)\"", INCHI_NAME );
1597
 
        lenXmlStruct      = strlen(szXmlStruct);
1598
 
        lenXmlMsgFatal    = strlen(szXmlMsgFatal);
1599
 
    }
1600
 
    for ( i = 0; i < 4; i ++ ) {
1601
 
        len = my_fgetsUpToLfOrTab( szLine, sizeof(szLine)-1, *inp_file );
1602
 
        if ( len < 0 )
1603
 
            break;
1604
 
        if ( bMatchOnePrefix( len, szLine, lenPlnVersion, szPlnVersion, NUM_VERSIONS ) ||
1605
 
             bMatchOnePrefix( len, szLine, lenPlnAuxVer, szPlnAuxVer, NUM_VERSIONS ) ) {
1606
 
            bINChI_plain ++;
1607
 
        } else
1608
 
        if ( bMatchOnePrefix( len, szLine, lenXmlVersion, szXmlVersion, NUM_VERSIONS ) ||
1609
 
             bMatchOnePrefix( len, szLine, &lenXmlStruct, &szXmlStruct, 1 ) ||
1610
 
             bMatchOnePrefix( len, szLine, lenXmlIdentVer, szXmlIdentVer, NUM_VERSIONS ) ||
1611
 
             bMatchOnePrefix( len, szLine, &lenXmlMsgError, &szXmlMsgError, 1 ) ||
1612
 
             bMatchOnePrefix( len, szLine, &lenXmlMsgFatal, &szXmlMsgFatal, 1 ) ) {
1613
 
            bINChI_xml ++;
1614
 
        }
1615
 
    }
1616
 
    if ( bINChI_plain >= 2 && !bINChI_xml ) {
1617
 
        ip->nInputType = INPUT_INCHI_PLAIN;
1618
 
        ret = 1;
1619
 
    } else
1620
 
    if ( !bINChI_plain && bINChI_xml >= 3 ) {
1621
 
        ip->nInputType = INPUT_INCHI_XML;
1622
 
        ret = 1;
1623
 
    }
1624
 
/*exit_function:*/
1625
 
    fclose ( *inp_file );
1626
 
    *inp_file = fopen( ip->path[0], fmode );
1627
 
    return ret;
1628
 
}
1629
 
#undef NUM_VERSIONS
1630
 
#undef LEN_VERSIONS
1631
 
 
1632
 
#endif /* INCHI_LIBRARY */