diff --git a/INCHI-1-SRC/INCHI_BASE/src/ichiread.c b/INCHI-1-SRC/INCHI_BASE/src/ichiread.c index aea98a6..f64ba6c 100644 --- a/INCHI-1-SRC/INCHI_BASE/src/ichiread.c +++ b/INCHI-1-SRC/INCHI_BASE/src/ichiread.c @@ -96,7 +96,7 @@ typedef struct tagOneLinkedBond typedef struct tagLinkedBonds { - ONE_LINKED_BOND* pBond; + ONE_LINKED_BOND *pBond; int len; int len_alloc; }LINKED_BONDS; @@ -113,195 +113,195 @@ typedef enum tagModeProtonIsoExchgH /* Local prototypes */ -int InChILine2Data(INCHI_IOSTREAM* pInp, - SEGM_LINE* pLine, - char** pStr, - int* pState, - int* nErr, - INChI* pInpInChI[INCHI_NUM][TAUT_NUM], +int InChILine2Data(INCHI_IOSTREAM *pInp, + SEGM_LINE *pLine, + char **pStr, + int *pState, + int *nErr, + INChI *pInpInChI[INCHI_NUM][TAUT_NUM], int nNumComponents[INCHI_NUM][TAUT_NUM], REM_PROTONS nNumProtons[INCHI_NUM][TAUT_NUM], int s[INCHI_NUM][TAUT_NUM][2], int bReadCoord, int bInchi2Struct, INCHI_MODE nMode, - int* bStdFormat, - int* input_has_save_opt, - unsigned char* input_save_opt_bits, - OAD_Polymer** ppolymer, - OAD_V3000** pv3000); - -static int GetInChIFormulaNumH(INChI* pInChI, int* nNumH); -static int GetInChINumH(INChI* pInChI, int* nNumH); -static int GetInChIIsoH(INChI* pInChI, int nNumIsotopicH[NUM_H_ISOTOPES]); - -static int getInChIChar(INCHI_IOSTREAM* pInp); -static int AddInChIChar(INCHI_IOSTREAM* pInp, SEGM_LINE* Line, const char* pszToken); -static int AddLinkedBond(AT_NUMB at1, AT_NUMB at2, AT_NUMB num_at, LINKED_BONDS* pLB); -static int bInChIHasReconnectedMetal(INChI* pInChI); -static int SetProtonsAndXchgIsoH(int bInChI2Structure, - int bReqSplitOutputInChI, - int bReqProtonsForEachComponent, - int bReqNonTaut, int bReqStereo, - int num_components[INCHI_NUM], - MODE_PIXH nModeProtonIsoExchgH[INCHI_NUM], - InpInChI* OneInput); + int *bStdFormat, + int *input_has_save_opt, + unsigned char *input_save_opt_bits, + OAD_Polymer **ppolymer, + OAD_V3000 **pv3000); + +static int GetInChIFormulaNumH( INChI *pInChI, int *nNumH ); +static int GetInChINumH( INChI *pInChI, int *nNumH ); +static int GetInChIIsoH( INChI *pInChI, int nNumIsotopicH[NUM_H_ISOTOPES] ); + +static int getInChIChar( INCHI_IOSTREAM *pInp ); +static int AddInChIChar( INCHI_IOSTREAM *pInp, SEGM_LINE *Line, const char *pszToken ); +static int AddLinkedBond( AT_NUMB at1, AT_NUMB at2, AT_NUMB num_at, LINKED_BONDS *pLB ); +static int bInChIHasReconnectedMetal( INChI *pInChI ); +static int SetProtonsAndXchgIsoH( int bInChI2Structure, + int bReqSplitOutputInChI, + int bReqProtonsForEachComponent, + int bReqNonTaut, int bReqStereo, + int num_components[INCHI_NUM], + MODE_PIXH nModeProtonIsoExchgH[INCHI_NUM], + InpInChI *OneInput ); #if ( FIX_DALKE_BUGS == 1 ) -static int SetHillFormFromInChI(InpInChI* OneInput); +static int SetHillFormFromInChI( InpInChI *OneInput ); #endif -static int nGetInChISegment(INCHI_IOSTREAM* pInp, SEGM_LINE* Line, const char* pszToken); - -static int CopySegment(INChI* pInChITo, INChI* pInChIFrom, int StereoType, - int bIsotopicTo, int bIsotopicFrom); -static int nFillOutProtonMobileH(INChI* pInChI); -static int nProtonCopyIsotopicInfo(INChI* pInChI_to, INChI* pInChI_from); -static int CopyAtomNumbers(INChI* pInChI_To, int bIsoTo, INChI* pInChI_From, int bIsoFrom); - -static int ParseSegmentFormula(const char* str, int bMobileH, INChI* pInpInChI[], - int nNumComponents[], int* na_total); -static int ParseSegmentConnections(const char* str, int bMobileH, INChI** pInpInChI, - int* pnNumComponents, int* pbAbc, int* nb_total); -static int ParseSegmentMobileH(const char* str, int bMobileH, INChI* pInpInChI[], - int pnNumComponents[], int* pbAbc); -static int ParseSegmentCharge(const char* str, int bMobileH, INChI* pInpInChI[], - int nNumComponents[]); -static int ParseSegmentProtons(const char* str, int bMobileH, - REM_PROTONS nNumProtons[], int nNumComponents[]); -static int ParseSegmentPolymer(const char* str, int bMobileH, - REM_PROTONS nNumProtons[], int nNumComponents[], - int na_total, int nb_total, - int bInchi2Struct, - OAD_Polymer** ppPolymer, OAD_V3000** ppV3000); -static int ParseSegmentSp2(const char* str, int bMobileH, INChI* pInpInChI[], - int nNumComponents[], int state, int* pbAbc); -static int ParseSegmentSp3(const char* str, int bMobileH, INChI* pInpInChI[], - int ppnNumComponents[], int state, int* pbAbc); -static int SegmentSp3CreateEmpty(const char* str, int bMobileH, INChI* pInpInChI[], - int nNumComponents, int state, int* pbAbc); -static int SegmentSp3StoreStereoCenters(int* pbAbc, const char* pStart, const char* pEnd, - int pInChI_iComponent_nNumberOfAtoms, - INChI_Stereo* PStereo_0); -static int SegmentSp3ProcessAbbreviation(int* mpy_component, int iComponent, int nNumComponents, - int val, const char* q, int state, int* pbAbc, - int bMobileH, int nCpyType, - INChI* pInChI, INChI* pInpInChI_ALT_TAUT_bMobileH); -static int SegmentSp3CopyMultiplierCovered(int mpy_component, int iComponent, - INChI* pInpInChI, int bIso, int nCpyType); -static int ParseSegmentSp3m(const char* str, int bMobileH, INChI* pInpInChI[], - int nNumComponents[], int state); -static int bIsSp3LayerNotEmpty(INChI* pInpInChI[], int bMobileH, - int bIso, int nNumComponents); -static int ParseSegmentSp3s(const char* str, int bMobileH, INChI* pInpInChI[], - int s[TAUT_NUM][2], int ppnNumComponents[], int state); -static int ParseSegmentIsoAtoms(const char* str, int bMobileH, INChI* pInpInChI[], - int nNumComponents[], int state, int* pbAbc); -static int ParseSegmentIsoExchgH(const char* str, int bMobileH, - REM_PROTONS nNumProtons[], - int nNumComponents[], int state, int* pbAbc); -static int ParseSegmentPerm(const char* str, int bMobileH, INChI* pInpInChI[], - int ppnNumComponents[], int state, int* pbAbc); +static int nGetInChISegment( INCHI_IOSTREAM *pInp, SEGM_LINE *Line, const char *pszToken ); + +static int CopySegment( INChI *pInChITo, INChI *pInChIFrom, int StereoType, + int bIsotopicTo, int bIsotopicFrom ); +static int nFillOutProtonMobileH( INChI *pInChI ); +static int nProtonCopyIsotopicInfo( INChI *pInChI_to, INChI *pInChI_from ); +static int CopyAtomNumbers( INChI *pInChI_To, int bIsoTo, INChI *pInChI_From, int bIsoFrom ); + +static int ParseSegmentFormula( const char *str, int bMobileH, INChI *pInpInChI[], + int nNumComponents[], int *na_total ); +static int ParseSegmentConnections( const char *str, int bMobileH, INChI **pInpInChI, + int *pnNumComponents, int *pbAbc, int *nb_total ); +static int ParseSegmentMobileH( const char *str, int bMobileH, INChI *pInpInChI[], + int pnNumComponents[], int *pbAbc ); +static int ParseSegmentCharge( const char *str, int bMobileH, INChI *pInpInChI[], + int nNumComponents[] ); +static int ParseSegmentProtons( const char *str, int bMobileH, + REM_PROTONS nNumProtons[], int nNumComponents[] ); +static int ParseSegmentPolymer( const char *str, int bMobileH, + REM_PROTONS nNumProtons[], int nNumComponents[], + int na_total, int nb_total, + int bInchi2Struct, + OAD_Polymer **ppPolymer, OAD_V3000 **ppV3000 ); +static int ParseSegmentSp2( const char *str, int bMobileH, INChI *pInpInChI[], + int nNumComponents[], int state, int *pbAbc ); +static int ParseSegmentSp3( const char *str, int bMobileH, INChI *pInpInChI[], + int ppnNumComponents[], int state, int *pbAbc ); +static int SegmentSp3CreateEmpty( const char *str, int bMobileH, INChI *pInpInChI[], + int nNumComponents, int state, int *pbAbc ); +static int SegmentSp3StoreStereoCenters( int *pbAbc, const char *pStart, const char *pEnd, + int pInChI_iComponent_nNumberOfAtoms, + INChI_Stereo *PStereo_0 ); +static int SegmentSp3ProcessAbbreviation( int *mpy_component, int iComponent, int nNumComponents, + int val, const char *q, int state, int *pbAbc, + int bMobileH, int nCpyType, + INChI *pInChI, INChI *pInpInChI_ALT_TAUT_bMobileH ); +static int SegmentSp3CopyMultiplierCovered( int mpy_component, int iComponent, + INChI *pInpInChI, int bIso, int nCpyType ); +static int ParseSegmentSp3m( const char *str, int bMobileH, INChI *pInpInChI[], + int nNumComponents[], int state ); +static int bIsSp3LayerNotEmpty( INChI *pInpInChI[], int bMobileH, + int bIso, int nNumComponents ); +static int ParseSegmentSp3s( const char *str, int bMobileH, INChI *pInpInChI[], + int s[TAUT_NUM][2], int ppnNumComponents[], int state ); +static int ParseSegmentIsoAtoms( const char *str, int bMobileH, INChI *pInpInChI[], + int nNumComponents[], int state, int *pbAbc ); +static int ParseSegmentIsoExchgH( const char *str, int bMobileH, + REM_PROTONS nNumProtons[], + int nNumComponents[], int state, int *pbAbc ); +static int ParseSegmentPerm( const char *str, int bMobileH, INChI *pInpInChI[], + int ppnNumComponents[], int state, int *pbAbc ); #if ( FIX_ISO_FIXEDH_BUG_READ == 1 ) -static int bIsoMayBeArranged(int bInchi2Struct, int iso_diff[NUM_H_ISOTOPES], - REM_PROTONS nNumProtons[INCHI_NUM][TAUT_NUM], - INChI* pInpInChI[INCHI_NUM][TAUT_NUM], int nNumComponents[INCHI_NUM][TAUT_NUM], int iINChI); +static int bIsoMayBeArranged( int bInchi2Struct, int iso_diff[NUM_H_ISOTOPES], + REM_PROTONS nNumProtons[INCHI_NUM][TAUT_NUM], + INChI *pInpInChI[INCHI_NUM][TAUT_NUM], int nNumComponents[INCHI_NUM][TAUT_NUM], int iINChI ); #endif -static int ReadInChILine(INCHI_IOSTREAM* pInp, - SEGM_LINE* pLine, - char** pStr, - int* pState, - INChI* pInpInChI[INCHI_NUM][TAUT_NUM], - int nNumComponents[INCHI_NUM][TAUT_NUM], - REM_PROTONS nNumProtons[INCHI_NUM][TAUT_NUM], - int s[INCHI_NUM][TAUT_NUM][2], - int* input_is_stdinchi, - int* input_has_save_opt, - unsigned char* input_save_opt_bits, - int bInchi2Struct, - OAD_Polymer** ppolymer, - OAD_V3000** pv3000); - -int ReadInChICoord(INCHI_IOSTREAM* pInp, - SEGM_LINE* pLine, - int* pState, - INChI* pInpInChI[INCHI_NUM][TAUT_NUM], - int nNumComponents[INCHI_NUM][TAUT_NUM]); - -static int OutputInChIAsRequested(struct tagCANON_GLOBALS* pCG, - INCHI_IOSTREAM* pOut, - INCHI_IOSTREAM* pLog, - ICHICONST INPUT_PARMS* ip_inp, - STRUCT_DATA* sd_inp, - InpInChI* OneInput, - int num_components[INCHI_NUM], - MODE_PIXH nModeProtonIsoExchgH[INCHI_NUM], - long num_inp, - unsigned char save_opt_bits); - -static int ParseAuxSegmentVersion(const char* str, - int bMobileH, - INChI* pInpInChI[], - int ppnNumComponents[], - int state); - -static int ParseAuxSegmentNumbers(const char* str, - int bMobileH, - INChI* pInpInChI[], - int ppnNumComponents[], - int state, - int* pbAbc); - -static int ParseAuxSegmentAtomEqu(const char* str, - int bMobileH, - INChI* pInpInChI[], - int ppnNumComponents[], - int state); - -static int ParseAuxSegmentGroupEqu(const char* str, - int bMobileH, - INChI* pInpInChI[], - int ppnNumComponents[], - int state); - -static int ParseAuxSegmentSp3Inv(const char* str, - int bMobileH, - INChI* pInpInChI[], - int ppnNumComponents[], - int state); - -static int ParseAuxSegmentSp3InvNumbers(const char* str, - int bMobileH, - INChI* pInpInChI[], - int ppnNumComponents[], - int state); - -static int ParseAuxSegmentReverseCRV(const char* str, int state); - -static int ParseAuxSegmentReverseAtoms(const char* str, int state); - -static int ParseAuxSegmentReverseBonds(const char* str, int state); - -static int ParseAuxSegmentReverseXYZ(const char* str, - XYZ_COORD** ppXYZ, - int state); - -static int AddAuxSegmentCoord(int nRet, - XYZ_COORD* pXYZ, - int nLenXYZ, - INChI* pInpInChI[INCHI_NUM][TAUT_NUM], - int nNumComponents[INCHI_NUM][TAUT_NUM]); - - -static void getInchiStateReadErr(int stat, char* szMsg); - -static const char* getInchiErrName(int nErr); - -static int extract_from_inchi_string(char* sinchi, InpInChI* OneInput); - -const char* ParseSegmentReadDelimitedNumbers(const char* str, const char* pEnd, - INT_ARRAY* numlist, char c_delim, - char c_stop, int* ret); +static int ReadInChILine( INCHI_IOSTREAM *pInp, + SEGM_LINE *pLine, + char **pStr, + int *pState, + INChI *pInpInChI[INCHI_NUM][TAUT_NUM], + int nNumComponents[INCHI_NUM][TAUT_NUM], + REM_PROTONS nNumProtons[INCHI_NUM][TAUT_NUM], + int s[INCHI_NUM][TAUT_NUM][2], + int *input_is_stdinchi, + int *input_has_save_opt, + unsigned char *input_save_opt_bits, + int bInchi2Struct, + OAD_Polymer **ppolymer, + OAD_V3000 **pv3000 ); + +int ReadInChICoord( INCHI_IOSTREAM *pInp, + SEGM_LINE *pLine, + int *pState, + INChI *pInpInChI[INCHI_NUM][TAUT_NUM], + int nNumComponents[INCHI_NUM][TAUT_NUM] ); + +static int OutputInChIAsRequested( struct tagCANON_GLOBALS *pCG, + INCHI_IOSTREAM *pOut, + INCHI_IOSTREAM *pLog, + ICHICONST INPUT_PARMS *ip_inp, + STRUCT_DATA *sd_inp, + InpInChI *OneInput, + int num_components[INCHI_NUM], + MODE_PIXH nModeProtonIsoExchgH[INCHI_NUM], + long num_inp, + unsigned char save_opt_bits ); + +static int ParseAuxSegmentVersion( const char *str, + int bMobileH, + INChI *pInpInChI[], + int ppnNumComponents[], + int state ); + +static int ParseAuxSegmentNumbers( const char *str, + int bMobileH, + INChI *pInpInChI[], + int ppnNumComponents[], + int state, + int *pbAbc ); + +static int ParseAuxSegmentAtomEqu( const char *str, + int bMobileH, + INChI *pInpInChI[], + int ppnNumComponents[], + int state ); + +static int ParseAuxSegmentGroupEqu( const char *str, + int bMobileH, + INChI *pInpInChI[], + int ppnNumComponents[], + int state ); + +static int ParseAuxSegmentSp3Inv( const char *str, + int bMobileH, + INChI *pInpInChI[], + int ppnNumComponents[], + int state ); + +static int ParseAuxSegmentSp3InvNumbers( const char *str, + int bMobileH, + INChI *pInpInChI[], + int ppnNumComponents[], + int state ); + +static int ParseAuxSegmentReverseCRV( const char *str, int state ); + +static int ParseAuxSegmentReverseAtoms( const char *str, int state ); + +static int ParseAuxSegmentReverseBonds( const char *str, int state ); + +static int ParseAuxSegmentReverseXYZ( const char *str, + XYZ_COORD **ppXYZ, + int state ); + +static int AddAuxSegmentCoord( int nRet, + XYZ_COORD *pXYZ, + int nLenXYZ, + INChI *pInpInChI[INCHI_NUM][TAUT_NUM], + int nNumComponents[INCHI_NUM][TAUT_NUM] ); + + +static void getInchiStateReadErr( int stat, char *szMsg ); + +static const char *getInchiErrName( int nErr ); + +static int extract_from_inchi_string(char *sinchi, InpInChI *OneInput); + +const char * ParseSegmentReadDelimitedNumbers( const char *str, const char *pEnd, + INT_ARRAY *numlist, char c_delim, + char c_stop, int *ret ); #define SEG_END '/' /* the following 2 definitions are used to allow tab-delimited InChI input - 2008-11-17 DT */ @@ -322,53 +322,53 @@ typedef enum tagInChI_STATE IST_MOBILE_H_SP3_M, /* 7 */ IST_MOBILE_H_SP3_S, /* 8 */ - /* Fork */ - IST_MOBILE_H_ISO_LAYER_FORK, /* 9 */ - - /* MI */ - IST_MOBILE_H_ISO_ATOMS, /* 10 */ - IST_MOBILE_H_ISO_EXCH_H, /* 11 */ - IST_MOBILE_H_ISO_SP2, /* 12 */ - IST_MOBILE_H_ISO_SP3, /* 13 */ - IST_MOBILE_H_ISO_SP3_M, /* 14 */ - IST_MOBILE_H_ISO_SP3_S, /* 15 */ - - /* Fork */ - IST_FIXED_H_LAYER_FORK, /* 16 */ - - /* F */ - IST_FIXED_H_FORMULA, /* 17 */ - IST_FIXED_H, /* 18 */ - IST_FIXED_H_CHARGE, /* 19 */ - IST_FIXED_H_SP2, /* 20 */ - IST_FIXED_H_SP3, /* 21 */ - IST_FIXED_H_SP3_M, /* 22 */ - IST_FIXED_H_SP3_S, /* 23 */ - IST_FIXED_H_PERMUTATION, /* 24 */ - - /* Fork */ - IST_FIXED_H_ISO_LAYER_FORK, /* 25 */ - - /* FI */ - IST_FIXED_H_ISO_ATOMS, /* 26 */ - IST_FIXED_H_ISO_LAYER, /* 27 */ - IST_FIXED_H_ISO_SP2, /* 28 */ - IST_FIXED_H_ISO_SP3, /* 29 */ - IST_FIXED_H_ISO_SP3_M, /* 30 */ - IST_FIXED_H_ISO_SP3_S, /* 31 */ - IST_FIXED_H_ISO_PERMUTATION, /* 32 */ - - /* Reconnected */ - IST_RECONNECTED_LAYER_FORK, /* 33 */ - IST_RECONNECTED_FORMULA, /* 34 */ - - /* Other reading errors */ - IST_MATERIAL_BALANCE_ERROR, /* 35 */ - - /* */ - IST_MOBILE_H_POLYMER, /* 36 */ - - IST_END = -1 + /* Fork */ + IST_MOBILE_H_ISO_LAYER_FORK, /* 9 */ + + /* MI */ + IST_MOBILE_H_ISO_ATOMS, /* 10 */ + IST_MOBILE_H_ISO_EXCH_H, /* 11 */ + IST_MOBILE_H_ISO_SP2, /* 12 */ + IST_MOBILE_H_ISO_SP3, /* 13 */ + IST_MOBILE_H_ISO_SP3_M, /* 14 */ + IST_MOBILE_H_ISO_SP3_S, /* 15 */ + + /* Fork */ + IST_FIXED_H_LAYER_FORK, /* 16 */ + + /* F */ + IST_FIXED_H_FORMULA, /* 17 */ + IST_FIXED_H, /* 18 */ + IST_FIXED_H_CHARGE, /* 19 */ + IST_FIXED_H_SP2, /* 20 */ + IST_FIXED_H_SP3, /* 21 */ + IST_FIXED_H_SP3_M, /* 22 */ + IST_FIXED_H_SP3_S, /* 23 */ + IST_FIXED_H_PERMUTATION, /* 24 */ + + /* Fork */ + IST_FIXED_H_ISO_LAYER_FORK, /* 25 */ + + /* FI */ + IST_FIXED_H_ISO_ATOMS, /* 26 */ + IST_FIXED_H_ISO_LAYER, /* 27 */ + IST_FIXED_H_ISO_SP2, /* 28 */ + IST_FIXED_H_ISO_SP3, /* 29 */ + IST_FIXED_H_ISO_SP3_M, /* 30 */ + IST_FIXED_H_ISO_SP3_S, /* 31 */ + IST_FIXED_H_ISO_PERMUTATION, /* 32 */ + + /* Reconnected */ + IST_RECONNECTED_LAYER_FORK, /* 33 */ + IST_RECONNECTED_FORMULA, /* 34 */ + + /* Other reading errors */ + IST_MATERIAL_BALANCE_ERROR, /* 35 */ + + /* */ + IST_MOBILE_H_POLYMER, /* 36 */ + + IST_END = -1 }INCHI_STATE; @@ -378,7 +378,7 @@ typedef enum tagInChI_STATE typedef struct tagInchiReadErrMsg { int stat; - const char* msg; + const char *msg; } INCHI_READ_ERR_MSG; ICHICONST INCHI_READ_ERR_MSG irErrMsg[] = @@ -457,87 +457,87 @@ typedef enum tagCopySegmentType #define MAX_MSG_BUF_LEN 128 -void PrepareSaveOptBits(INPUT_PARMS* ip, - INCHI_IOSTREAM* pLog, - const long num_inp, - const char* szCurHdr, - int input_has_save_opt, - unsigned char input_save_opt_bits, - unsigned char* save_opt_bits); - -void TreatErrorsInReadInChIString(int nReadStatus, - int nErr, - int pState, - INPUT_PARMS* ip, - INCHI_IOSTREAM* pOut, - INCHI_IOSTREAM* pLog, - long* num_inp, - long* num_errors, - long* num_processed, - char** pstrHdr, - char** pszCurHdr, - InpInChI* pOneInput); - -int ConvertInChI2Struct(ICHICONST INPUT_PARMS* ip_inp, - INPUT_PARMS* ip, - InpInChI* pOneInput, - inp_ATOM** at, - int* num_at, - OAD_Polymer** polymer, - OAD_V3000** v3000, - INCHI_IOSTREAM* pOut, - INCHI_IOSTREAM* pLog, - STRUCT_DATA* sd, - int num_components[INCHI_NUM], - MODE_PIXH nModeProtonIsoExchgH[INCHI_NUM], - char** pszCurHdr, - char* szMsg, - int nMsgLen, - char szMessage[MAX_MSG_LEN], - int nInitLenMessage, - int nMessageLen, - int input_is_stdinchi, - int bHasSomeReconnected, - int bHasSomeFixedH, - int bHasMetal, - int nModeFlagsStereo, - int bTautFlags, - int bReqNonTaut, - unsigned long WarningFlags[2][2], - long num_inp, - long* num_errors, - unsigned char save_opt_bits, - inchiTime* pulTStart, - long* ulProcessingTime, - struct tagINCHI_CLOCK* ic, - struct tagCANON_GLOBALS* pCG); - -int ConvertInChI2InChI(INPUT_PARMS* ip, - InpInChI* pOneInput, - INCHI_IOSTREAM* pOut, - INCHI_IOSTREAM* pLog, - STRUCT_DATA* sd, - int num_components[INCHI_NUM], - MODE_PIXH nModeProtonIsoExchgH[INCHI_NUM], - char** pszCurHdr, - long num_inp, - long* num_errors, - unsigned char save_opt_bits, - inchiTime* pulTStart, - long* ulProcessingTime, - struct tagINCHI_CLOCK* ic, - struct tagCANON_GLOBALS* pCG); - -int DetectAndExposePolymerInternals(INCHI_IOSTREAM* is); - -int DetectHiddenPolymerStuff(char* tmpstr, int tmpstrlen, - int* ninsert, int* insert_pos, - int insert_lead_offset, int* nstars); +void PrepareSaveOptBits( INPUT_PARMS *ip, + INCHI_IOSTREAM *pLog, + const long num_inp, + const char *szCurHdr, + int input_has_save_opt, + unsigned char input_save_opt_bits, + unsigned char *save_opt_bits ); + +void TreatErrorsInReadInChIString( int nReadStatus, + int nErr, + int pState, + INPUT_PARMS *ip, + INCHI_IOSTREAM *pOut, + INCHI_IOSTREAM *pLog, + long *num_inp, + long *num_errors, + long *num_processed, + char **pstrHdr, + char **pszCurHdr, + InpInChI *pOneInput ); + +int ConvertInChI2Struct( ICHICONST INPUT_PARMS *ip_inp, + INPUT_PARMS *ip, + InpInChI *pOneInput, + inp_ATOM **at, + int *num_at, + OAD_Polymer **polymer, + OAD_V3000 **v3000, + INCHI_IOSTREAM *pOut, + INCHI_IOSTREAM *pLog, + STRUCT_DATA *sd, + int num_components[INCHI_NUM], + MODE_PIXH nModeProtonIsoExchgH[INCHI_NUM], + char **pszCurHdr, + char *szMsg, + int nMsgLen, + char szMessage[MAX_MSG_LEN], + int nInitLenMessage, + int nMessageLen, + int input_is_stdinchi, + int bHasSomeReconnected, + int bHasSomeFixedH, + int bHasMetal, + int nModeFlagsStereo, + int bTautFlags, + int bReqNonTaut, + unsigned long WarningFlags[2][2], + long num_inp, + long *num_errors, + unsigned char save_opt_bits, + inchiTime *pulTStart, + long *ulProcessingTime, + struct tagINCHI_CLOCK *ic, + struct tagCANON_GLOBALS *pCG ); + +int ConvertInChI2InChI( INPUT_PARMS *ip, + InpInChI *pOneInput, + INCHI_IOSTREAM *pOut, + INCHI_IOSTREAM *pLog, + STRUCT_DATA *sd, + int num_components[INCHI_NUM], + MODE_PIXH nModeProtonIsoExchgH[INCHI_NUM], + char **pszCurHdr, + long num_inp, + long *num_errors, + unsigned char save_opt_bits, + inchiTime *pulTStart, + long *ulProcessingTime, + struct tagINCHI_CLOCK *ic, + struct tagCANON_GLOBALS *pCG ); + +int DetectAndExposePolymerInternals( INCHI_IOSTREAM *is ); + +int DetectHiddenPolymerStuff( char *tmpstr, int tmpstrlen, + int *ninsert, int *insert_pos, + int insert_lead_offset, int *nstars ); /****************************************************************************/ -void getInchiStateReadErr(int stat, char* szMsg) +void getInchiStateReadErr( int stat, char *szMsg ) /* const char *getInchiStateReadErr(int stat) */ { int i, bRecMet = 0; @@ -563,18 +563,18 @@ void getInchiStateReadErr(int stat, char* szMsg) /****************************************************************************/ -const char* getInchiErrName(int nErr) +const char *getInchiErrName( int nErr ) { switch (nErr) { - case RI_ERR_ALLOC: - return "Allocation failed"; - case RI_ERR_PROGR: - return "Program error"; - case RI_ERR_SYNTAX: - return "Syntax error"; - case RI_ERR_EOL: - return "End of line"; + case RI_ERR_ALLOC: + return "Allocation failed"; + case RI_ERR_PROGR: + return "Program error"; + case RI_ERR_SYNTAX: + return "Syntax error"; + case RI_ERR_EOL: + return "End of line"; } return "Unknown error"; } @@ -584,11 +584,11 @@ const char* getInchiErrName(int nErr) /****************************************************************************/ -int SetHillFormFromInChI(InpInChI* OneInput) +int SetHillFormFromInChI( InpInChI *OneInput ) { int iINChI, iTaut, iComp, num_diff; - INChI* pINChI; - char* szHillFormulaOld; + INChI *pINChI; + char *szHillFormulaOld; for (iINChI = 0, num_diff = 0; iINChI < INCHI_NUM; iINChI++) { for (iTaut = TAUT_NON; iTaut < TAUT_NUM; iTaut++) @@ -601,9 +601,9 @@ int SetHillFormFromInChI(InpInChI* OneInput) continue; } szHillFormulaOld = pINChI->szHillFormula; - pINChI->szHillFormula = AllocateAndFillHillFormula(pINChI); - num_diff += !pINChI->szHillFormula || !pINChI->szHillFormula[0] || strcmp(pINChI->szHillFormula, szHillFormulaOld); - inchi_free(szHillFormulaOld); + pINChI->szHillFormula = AllocateAndFillHillFormula( pINChI ); + num_diff += !pINChI->szHillFormula || !pINChI->szHillFormula[0] || strcmp( pINChI->szHillFormula, szHillFormulaOld ); + inchi_free( szHillFormulaOld ); } } } @@ -616,54 +616,54 @@ int SetHillFormFromInChI(InpInChI* OneInput) /**************************************************************************** Main entry point ****************************************************************************/ -int ReadWriteInChI(INCHI_CLOCK* ic, - struct tagCANON_GLOBALS* pCG, - INCHI_IOSTREAM* pInp, - INCHI_IOSTREAM* pOut, - INCHI_IOSTREAM* pLog, - INPUT_PARMS* ip_inp, - STRUCT_DATA* sd_inp, - /* the following are InChI library-specific parameters */ - inp_ATOM** at, - int* num_at, - int* num_bonds, - OAD_Polymer** polymer, - OAD_V3000** v3000, - /* end of InChI library-specific parameters */ - char* szMsg, - int nMsgLen, - unsigned long WarningFlags[2][2]) +int ReadWriteInChI( INCHI_CLOCK *ic, + struct tagCANON_GLOBALS *pCG, + INCHI_IOSTREAM *pInp, + INCHI_IOSTREAM *pOut, + INCHI_IOSTREAM *pLog, + INPUT_PARMS *ip_inp, + STRUCT_DATA *sd_inp, + /* the following are InChI library-specific parameters */ + inp_ATOM **at, + int *num_at, + int *num_bonds, + OAD_Polymer **polymer, + OAD_V3000 **v3000, + /* end of InChI library-specific parameters */ + char *szMsg, + int nMsgLen, + unsigned long WarningFlags[2][2] ) { InpInChI OneInput; - char* strHdr = NULL; - char* szCurHdr = NULL; + char *strHdr = NULL; + char *szCurHdr = NULL; int num_components[INCHI_NUM]; - int bReqNonTaut = (0 != ((ip_inp->nMode & REQ_MODE_BASIC) && - (ip_inp->nMode & REQ_MODE_TAUT))); + int bReqNonTaut = ( 0 != ( ( ip_inp->nMode & REQ_MODE_BASIC ) && + ( ip_inp->nMode & REQ_MODE_TAUT ) ) ); /* int bReqRecmet = (0 != ((ip->bTautFlags & TG_FLAG_RECONNECT_COORD) && (ip->bTautFlags & TG_FLAG_DISCONNECT_COORD))); */ - int bReqStereo = (0 != (ip_inp->nMode & REQ_MODE_STEREO)); + int bReqStereo = ( 0 != ( ip_inp->nMode & REQ_MODE_STEREO ) ); int bHasSomeReconnected = 0, bHasSomeFixedH = 0, bHasMetal = 0; int nModeFlagsStereo = 0, bTautFlags = 0; /* InChI creation flags modifications derived from current InChI */ MODE_PIXH nModeProtonIsoExchgH[INCHI_NUM]; NORM_CANON_FLAGS ncFlags; - NORM_CANON_FLAGS* pncFlags = &ncFlags; - INPUT_PARMS ip_cur, * ip; - STRUCT_DATA sd_cur, * sd; + NORM_CANON_FLAGS *pncFlags = &ncFlags; + INPUT_PARMS ip_cur, *ip; + STRUCT_DATA sd_cur, *sd; int pState; /* djb-rwth: removing redundant variables */ int bReqProtonsForEachComponent = 0; int bReqSplitOutputInChI = 0; SEGM_LINE Line; - SEGM_LINE* pLine = &Line; + SEGM_LINE *pLine = &Line; long ulProcessingTime = 0; inchiTime ulTStart; long num_processed = 0, num_errors = 0; int bPlainTabbedOutput; /* djb-rwth: ignoring LLVM warning: variable used */ - const char* pTAB; /* djb-rwth: ignoring LLVM warning: variable used */ + const char *pTAB; /* djb-rwth: ignoring LLVM warning: variable used */ long num_inp = 0; @@ -675,8 +675,8 @@ int ReadWriteInChI(INCHI_CLOCK* ic, unsigned char input_save_opt_bits = 0; unsigned char save_opt_bits = 0; - const int bInChI2Structure = 0 != (ip_inp->bReadInChIOptions & READ_INCHI_TO_STRUCTURE); - const int bInChI2InChI = 0 != (ip_inp->bReadInChIOptions & READ_INCHI_OUTPUT_INCHI); + const int bInChI2Structure = 0 != ( ip_inp->bReadInChIOptions & READ_INCHI_TO_STRUCTURE ); + const int bInChI2InChI = 0 != ( ip_inp->bReadInChIOptions & READ_INCHI_OUTPUT_INCHI ); const int bReadCoord = bInChI2Structure; int nMessageLen = MAX_MSG_LEN; @@ -691,24 +691,24 @@ int ReadWriteInChI(INCHI_CLOCK* ic, int ret = 0; int nReadStatus = RI_ERR_EOL; - INCHI_IOSTREAM* pRealOut = pOut; + INCHI_IOSTREAM *pRealOut = pOut; /* temporary output buffer pTmpOut may be used */ /* locally instead of legal pOut to capture */ /* InChI string which may then be recognised */ /* as erratic (whence should not be finally */ /* printed) */ INCHI_IOSTREAM tmpoutputstr; - INCHI_IOSTREAM* pTmpOut = &tmpoutputstr; + INCHI_IOSTREAM *pTmpOut = &tmpoutputstr; if (bInChI2Structure) { - inchi_ios_init(pTmpOut, INCHI_IOS_TYPE_STRING, NULL); + inchi_ios_init( pTmpOut, INCHI_IOS_TYPE_STRING, NULL ); if (pTmpOut->s.pStr) pRealOut = pTmpOut; } - memset(szMessage, 0, sizeof(szMessage)); /* djb-rwth: memset_s C11/Annex K variant? */ - memset(&OneInput, 0, sizeof(OneInput)); /* djb-rwth: memset_s C11/Annex K variant? */ - memset(pLine, 0, sizeof(pLine[0])); /* djb-rwth: memset_s C11/Annex K variant? */ + memset( szMessage, 0, sizeof( szMessage ) ); /* djb-rwth: memset_s C11/Annex K variant? */ + memset( &OneInput, 0, sizeof( OneInput ) ); /* djb-rwth: memset_s C11/Annex K variant? */ + memset( pLine, 0, sizeof( pLine[0] ) ); /* djb-rwth: memset_s C11/Annex K variant? */ if (szMsg) szMsg[0] = '\0'; @@ -725,14 +725,14 @@ int ReadWriteInChI(INCHI_CLOCK* ic, { if (OneInput.nNumProtons[iINChI][j].pNumProtons) { - inchi_free(OneInput.nNumProtons[iINChI][j].pNumProtons); + inchi_free( OneInput.nNumProtons[iINChI][j].pNumProtons ); OneInput.nNumProtons[iINChI][j].pNumProtons = NULL; } } } - memset(&OneInput, 0, sizeof(OneInput)); /* djb-rwth: memset_s C11/Annex K variant? */ - memset(pncFlags, 0, sizeof(*pncFlags)); /* djb-rwth: memset_s C11/Annex K variant? */ + memset( &OneInput, 0, sizeof( OneInput ) ); /* djb-rwth: memset_s C11/Annex K variant? */ + memset( pncFlags, 0, sizeof( *pncFlags ) ); /* djb-rwth: memset_s C11/Annex K variant? */ /* djb-rwth: removing redundant code */ ip_cur = *ip_inp; ip = &ip_cur; @@ -740,12 +740,12 @@ int ReadWriteInChI(INCHI_CLOCK* ic, sd = &sd_cur; bReqSplitOutputInChI = - 0 != (ip->bReadInChIOptions & READ_INCHI_SPLIT_OUTPUT); + 0 != ( ip->bReadInChIOptions & READ_INCHI_SPLIT_OUTPUT ); bReqProtonsForEachComponent = bReqSplitOutputInChI && - 0 != (READ_INCHI_KEEP_BALANCE_P & ip->bReadInChIOptions); + 0 != ( READ_INCHI_KEEP_BALANCE_P & ip->bReadInChIOptions ); bPlainTabbedOutput = - 0 != (ip->bINChIOutputOptions & INCHI_OUT_TABBED_OUTPUT); + 0 != ( ip->bINChIOutputOptions & INCHI_OUT_TABBED_OUTPUT ); pTAB = #if ( defined(TARGET_API_LIB) || defined(TARGET_LIB_FOR_WINCHI) ) @@ -760,8 +760,8 @@ int ReadWriteInChI(INCHI_CLOCK* ic, bReqStereo = 1; bReqSplitOutputInChI = 1; bReqProtonsForEachComponent = bReqNonTaut; - ip->bTautFlags |= (TG_FLAG_DISCONNECT_COORD | TG_FLAG_RECONNECT_COORD); - ip->nMode |= (REQ_MODE_BASIC | REQ_MODE_TAUT | REQ_MODE_STEREO | REQ_MODE_ISO_STEREO | REQ_MODE_ISO); + ip->bTautFlags |= ( TG_FLAG_DISCONNECT_COORD | TG_FLAG_RECONNECT_COORD ); + ip->nMode |= ( REQ_MODE_BASIC | REQ_MODE_TAUT | REQ_MODE_STEREO | REQ_MODE_ISO_STEREO | REQ_MODE_ISO ); /* bReqRecmet = 1; */ #if ( bRELEASE_VERSION == 1 ) bReqNonTaut = 1; /* bReqNonTaut=0 ignores Fixed-H layer in input InChI, for testing only */ @@ -775,23 +775,23 @@ int ReadWriteInChI(INCHI_CLOCK* ic, /* get here from inchi-1 main emulation mode */ num_inp = ip_inp->lMolfileNumber - 1; - res = DetectAndExposePolymerInternals(pInp); /* djb-rwth: ignoring LLVM warning: variable used to store function return value */ + res = DetectAndExposePolymerInternals( pInp ); /* djb-rwth: ignoring LLVM warning: variable used to store function return value */ /* proceed silently for now, errs mist be uncovered further on conversion */ } } - InchiTimeGet(&ulTStart); + InchiTimeGet( &ulTStart ); /* Read InChI string */ - nReadStatus = InChILine2Data(pInp, pLine, &strHdr, &pState, &nErr, - OneInput.pInpInChI, OneInput.nNumComponents, - OneInput.nNumProtons, OneInput.s, - bReadCoord, bInChI2Structure, ip_inp->nMode, - &input_is_stdinchi, &input_has_save_opt, - &input_save_opt_bits, - &OneInput.polymer, &OneInput.v3000); + nReadStatus = InChILine2Data( pInp, pLine, &strHdr, &pState, &nErr, + OneInput.pInpInChI, OneInput.nNumComponents, + OneInput.nNumProtons, OneInput.s, + bReadCoord, bInChI2Structure, ip_inp->nMode, + &input_is_stdinchi, &input_has_save_opt, + &input_save_opt_bits, + &OneInput.polymer, &OneInput.v3000 ); - ulProcessingTime += InchiTimeElapsed(ic, &ulTStart); + ulProcessingTime += InchiTimeElapsed( ic, &ulTStart ); #if 0 if (!bInChI2Structure && OneInput.polymer) @@ -818,14 +818,14 @@ int ReadWriteInChI(INCHI_CLOCK* ic, read_inchi_ok = end_of_data_reached && !nErr; /* then uncommented... commented out 2020-07-10 (potentially dangerous change, needs testing (TODO: i2s for InChI=1// )*/ - read_inchi_ok = read_inchi_ok && + read_inchi_ok = read_inchi_ok && (OneInput.nNumComponents[INCHI_BAS][TAUT_YES] + OneInput.nNumComponents[INCHI_BAS][TAUT_NON]); - + #if ALLOW_EMPTY_INCHI_AS_INPUT!=1 /* no empty InChI allowed */ read_inchi_ok = read_inchi_ok && - (OneInput.nNumComponents[INCHI_BAS][TAUT_YES] + - OneInput.nNumComponents[INCHI_BAS][TAUT_NON]); + ( OneInput.nNumComponents[INCHI_BAS][TAUT_YES] + + OneInput.nNumComponents[INCHI_BAS][TAUT_NON] ); #endif #ifdef TARGET_EXE_STANDALONE /* inchi-1: we currently disable conversion of polymeric InChI (inchi2struct) @@ -841,9 +841,9 @@ int ReadWriteInChI(INCHI_CLOCK* ic, if (!read_inchi_ok) { - TreatErrorsInReadInChIString(nReadStatus, nErr, pState, ip_inp, pRealOut, pLog, - &num_inp, &num_errors, &num_processed, - &strHdr, &szCurHdr, &OneInput); + TreatErrorsInReadInChIString( nReadStatus, nErr, pState, ip_inp, pRealOut, pLog, + &num_inp, &num_errors, &num_processed, + &strHdr, &szCurHdr, &OneInput ); if (nReadStatus == RI_ERR_SYNTAX || nReadStatus == RI_ERR_PROGR) { ret = nReadStatus; @@ -860,7 +860,7 @@ int ReadWriteInChI(INCHI_CLOCK* ic, if (pRealOut == pTmpOut) { - inchi_ios_reset(pRealOut); + inchi_ios_reset( pRealOut ); /*inchi_ios_close( pRealOut ); inchi_ios_init( pRealOut, INCHI_IOS_TYPE_STRING, NULL );*/ } @@ -888,10 +888,10 @@ int ReadWriteInChI(INCHI_CLOCK* ic, if (treat_save_opt) { - PrepareSaveOptBits(ip, pLog, num_inp, szCurHdr, - input_has_save_opt, - input_save_opt_bits, - &save_opt_bits); + PrepareSaveOptBits( ip, pLog, num_inp, szCurHdr, + input_has_save_opt, + input_save_opt_bits, + &save_opt_bits ); } #ifndef TARGET_API_LIB @@ -901,32 +901,32 @@ int ReadWriteInChI(INCHI_CLOCK* ic, */ if (!ip->bNoStructLabels && - !(bInChI2Structure && (ip->bINChIOutputOptions & INCHI_OUT_SDFILE_ONLY)) - ) + !( bInChI2Structure && ( ip->bINChIOutputOptions & INCHI_OUT_SDFILE_ONLY ) ) + ) { /* Added 2nd item: Do not output this extra line into the output SDfile. 2008-11-17 DCh */ - if (strHdr && strstr(strHdr, "Structure:")) + if (strHdr && strstr( strHdr, "Structure:" )) { - inchi_ios_print(pRealOut, "%s%s", strHdr, pTAB); /* output header */ + inchi_ios_print( pRealOut, "%s%s", strHdr, pTAB ); /* output header */ #if ( FIX_DALKE_BUGS == 1 ) #else - sprintf(szMessage, "%s (%ld)", strHdr ? strHdr : "", num_inp); + sprintf( szMessage, "%s (%ld)", strHdr ? strHdr : "", num_inp ); #endif } else { - if (bInChI2Structure) inchi_ios_print(pRealOut, "Structure: %ld. (%s)%s", - num_inp, strHdr ? strHdr : "No struct name", - pTAB); /* output header */ + if (bInChI2Structure) inchi_ios_print( pRealOut, "Structure: %ld. (%s)%s", + num_inp, strHdr ? strHdr : "No struct name", + pTAB ); /* output header */ #if ( FIX_DALKE_BUGS == 1 ) #else - sprintf(szMessage, "Structure: %ld. (%s)%s", num_inp, strHdr ? strHdr : "No struct name", pTAB); + sprintf( szMessage, "Structure: %ld. (%s)%s", num_inp, strHdr ? strHdr : "No struct name", pTAB ); #endif } if (strHdr && strHdr[0]) { strncpy(ip->szSdfDataHeader, strHdr, sizeof(ip->szSdfDataHeader)); - ip->szSdfDataHeader[sizeof(ip->szSdfDataHeader) - 1] = '\0'; + ip->szSdfDataHeader[sizeof( ip->szSdfDataHeader ) - 1] = '\0'; ip->pSdfLabel = NULL; ip->pSdfValue = ip->szSdfDataHeader; } @@ -944,7 +944,7 @@ int ReadWriteInChI(INCHI_CLOCK* ic, #endif #endif - nInitLenMessage = (int)strlen(szMessage); + nInitLenMessage = (int) strlen( szMessage ); if (strHdr) { szCurHdr = strHdr; @@ -954,12 +954,12 @@ int ReadWriteInChI(INCHI_CLOCK* ic, { /* Check whether the structure should be skipped */ static const char szStruct[] = "Structure:"; - char* pStrNum = strstr(szCurHdr, szStruct); + char *pStrNum = strstr( szCurHdr, szStruct ); long cur_struct_number; if (pStrNum) { - pStrNum += sizeof(szStruct) - 1; /* -1 takes care of the string terminal zero */ - cur_struct_number = inchi_strtol(pStrNum, NULL, 10); + pStrNum += sizeof( szStruct ) - 1; /* -1 takes care of the string terminal zero */ + cur_struct_number = inchi_strtol( pStrNum, NULL, 10 ); if (cur_struct_number) { OneInput.num_inp = cur_struct_number; @@ -969,12 +969,12 @@ int ReadWriteInChI(INCHI_CLOCK* ic, { #if ( !defined(TARGET_API_LIB) && !defined(TARGET_EXE_STANDALONE) ) - inchi_fprintf(stderr, "Skipping %s\r", szMessage); + inchi_fprintf( stderr, "Skipping %s\r", szMessage ); #endif - FreeInpInChI(&OneInput); + FreeInpInChI( &OneInput ); if (szCurHdr) { - inchi_free(szCurHdr); + inchi_free( szCurHdr ); szCurHdr = NULL; } INCHI_HEAPCHK @@ -991,13 +991,13 @@ int ReadWriteInChI(INCHI_CLOCK* ic, /* Note: if InChI is not to be splitted DO NOT create */ /* a separate component for /p, /i/h: it would be a bug*/ - InchiTimeGet(&ulTStart); + InchiTimeGet( &ulTStart ); INCHI_HEAPCHK - ret = SetProtonsAndXchgIsoH(bInChI2Structure, bReqSplitOutputInChI, - bReqProtonsForEachComponent, bReqNonTaut, bReqStereo, - num_components, nModeProtonIsoExchgH, &OneInput); + ret = SetProtonsAndXchgIsoH( bInChI2Structure, bReqSplitOutputInChI, + bReqProtonsForEachComponent, bReqNonTaut, bReqStereo, + num_components, nModeProtonIsoExchgH, &OneInput ); INCHI_HEAPCHK if (ret < 0) @@ -1010,11 +1010,11 @@ int ReadWriteInChI(INCHI_CLOCK* ic, sd->num_components[INCHI_REC] = num_components[INCHI_REC]; /* Do we have reconnected InChI ? */ - if ((OneInput.nNumComponents[INCHI_REC][TAUT_YES] || - OneInput.nNumComponents[INCHI_REC][TAUT_NON]) && - (ip->bTautFlags & TG_FLAG_RECONNECT_COORD) && - (ip->bTautFlags & TG_FLAG_DISCONNECT_COORD) - ) + if (( OneInput.nNumComponents[INCHI_REC][TAUT_YES] || + OneInput.nNumComponents[INCHI_REC][TAUT_NON] ) && + ( ip->bTautFlags & TG_FLAG_RECONNECT_COORD ) && + ( ip->bTautFlags & TG_FLAG_DISCONNECT_COORD ) + ) { /* needed for InChI string output to include reconnected InChI */ sd->bTautFlagsDone[0] |= TG_FLAG_DISCONNECT_COORD_DONE; @@ -1023,47 +1023,47 @@ int ReadWriteInChI(INCHI_CLOCK* ic, /* Do we have fixed H InChI ? */ if (bReqNonTaut && - /*OneInput.nNumComponents[bHasSomeReconnected?INCHI_REC:INCHI_BAS][TAUT_NON]*/ - (OneInput.nNumComponents[INCHI_REC][TAUT_NON] || - OneInput.nNumComponents[INCHI_BAS][TAUT_NON])) + /*OneInput.nNumComponents[bHasSomeReconnected?INCHI_REC:INCHI_BAS][TAUT_NON]*/ + ( OneInput.nNumComponents[INCHI_REC][TAUT_NON] || + OneInput.nNumComponents[INCHI_BAS][TAUT_NON] )) { bHasSomeFixedH = 1; } - ulProcessingTime += InchiTimeElapsed(ic, &ulTStart); + ulProcessingTime += InchiTimeElapsed( ic, &ulTStart ); - invalid_opt = (!bInChI2Structure && !bInChI2InChI) || - (bInChI2Structure && bInChI2InChI); + invalid_opt = ( !bInChI2Structure && !bInChI2InChI ) || + ( bInChI2Structure && bInChI2InChI ); if (invalid_opt) { - inchi_ios_eprint(pLog, "\nWrong command line options: expected Inch2Struct or Inchi2Inchi\n", num_inp); + inchi_ios_eprint( pLog, "\nWrong command line options: expected Inch2Struct or Inchi2Inchi\n", num_inp ); break; } /* InChI --> Structure */ else if (bInChI2Structure) { - char* result_string; + char *result_string; if (OneInput.polymer && OneInput.polymer->n) { OneInput.valid_polymer = 1; } - ret = ConvertInChI2Struct(ip_inp, ip, &OneInput, - at, num_at, - polymer, v3000, - pRealOut, pLog, - sd, num_components, nModeProtonIsoExchgH, - &szCurHdr, szMsg, nMsgLen, szMessage, - nInitLenMessage, nMessageLen, - input_is_stdinchi, bHasSomeReconnected, - bHasSomeFixedH, bHasMetal, - nModeFlagsStereo, bTautFlags, bReqNonTaut, - WarningFlags, num_inp, &num_errors, - save_opt_bits, &ulTStart, &ulProcessingTime, - ic, pCG); + ret = ConvertInChI2Struct( ip_inp, ip, &OneInput, + at, num_at, + polymer, v3000, + pRealOut, pLog, + sd, num_components, nModeProtonIsoExchgH, + &szCurHdr, szMsg, nMsgLen, szMessage, + nInitLenMessage, nMessageLen, + input_is_stdinchi, bHasSomeReconnected, + bHasSomeFixedH, bHasMetal, + nModeFlagsStereo, bTautFlags, bReqNonTaut, + WarningFlags, num_inp, &num_errors, + save_opt_bits, &ulTStart, &ulProcessingTime, + ic, pCG ); result_string = pRealOut->s.pStr; if (ret == 0) /* no problems */ @@ -1076,7 +1076,7 @@ int ReadWriteInChI(INCHI_CLOCK* ic, if (output_error_inchi) { /* emit error string */ - inchi_ios_eprint(pRealOut, "InChI creation Error!\n"); + inchi_ios_eprint( pRealOut, "InChI creation Error!\n" ); } } else if (ret < 0) @@ -1093,7 +1093,7 @@ int ReadWriteInChI(INCHI_CLOCK* ic, /* ignore mismatch, print InChI as usual */ if (result_string) { - inchi_ios_eprint(pRealOut, "%-s\n", result_string); + inchi_ios_eprint( pRealOut, "%-s\n", result_string ); } } else @@ -1109,27 +1109,27 @@ int ReadWriteInChI(INCHI_CLOCK* ic, if (result_string) { /* try to preserve header if any */ - char* pi = strstr(result_string, "InChI="); + char *pi = strstr( result_string, "InChI=" ); if (pi) { int np = pi - result_string; if (np) result_string[np - 1] = '\0'; - inchi_ios_eprint(pRealOut, "%-s\n", result_string); + inchi_ios_eprint( pRealOut, "%-s\n", result_string ); } } - inchi_ios_eprint(pRealOut, "InChICreationError!\n"); /* emit err string */ + inchi_ios_eprint( pRealOut, "InChICreationError!\n" ); /* emit err string */ } } - FreeInpInChI(&OneInput); + FreeInpInChI( &OneInput ); if (strHdr) { - inchi_free(strHdr); + inchi_free( strHdr ); strHdr = NULL; } if (szCurHdr) { - inchi_free(szCurHdr); + inchi_free( szCurHdr ); szCurHdr = NULL; } INCHI_HEAPCHK @@ -1142,11 +1142,11 @@ int ReadWriteInChI(INCHI_CLOCK* ic, /* InChI --> InChI */ else if (bInChI2InChI) { - ret = ConvertInChI2InChI(ip, &OneInput, pRealOut, pLog, sd, - num_components, nModeProtonIsoExchgH, - &szCurHdr, num_inp, &num_errors, - save_opt_bits, &ulTStart, - &ulProcessingTime, ic, pCG); + ret = ConvertInChI2InChI( ip, &OneInput, pRealOut, pLog, sd, + num_components, nModeProtonIsoExchgH, + &szCurHdr, num_inp, &num_errors, + save_opt_bits, &ulTStart, + &ulProcessingTime, ic, pCG ); } if (nReadStatus == RI_ERR_EOF) @@ -1164,8 +1164,8 @@ int ReadWriteInChI(INCHI_CLOCK* ic, #ifdef TARGET_EXE_STANDALONE #ifndef TARGET_API_LIB - inchi_ios_flush(pRealOut); - inchi_ios_flush2(pLog, stderr); + inchi_ios_flush( pRealOut ); + inchi_ios_flush2( pLog, stderr ); #endif #endif #ifdef TARGET_API_LIB @@ -1174,33 +1174,33 @@ int ReadWriteInChI(INCHI_CLOCK* ic, } /* while */ exit_error: - FreeInpInChI(&OneInput); + FreeInpInChI( &OneInput ); if (strHdr) { - inchi_free(strHdr); + inchi_free( strHdr ); strHdr = NULL; } if (pLine->str) { - inchi_free(pLine->str); + inchi_free( pLine->str ); } if (szCurHdr) { - inchi_free(szCurHdr); + inchi_free( szCurHdr ); szCurHdr = NULL; } INCHI_HEAPCHK - if (sd_inp) - { - sd_inp->ulStructTime = ulProcessingTime; - sd_inp->fPtrStart = num_processed; - sd_inp->fPtrEnd = num_errors; - } + if (sd_inp) + { + sd_inp->ulStructTime = ulProcessingTime; + sd_inp->fPtrStart = num_processed; + sd_inp->fPtrEnd = num_errors; + } if (pRealOut == pTmpOut) { - inchi_ios_close(pTmpOut); + inchi_ios_close( pTmpOut ); } return ret; @@ -1208,38 +1208,38 @@ int ReadWriteInChI(INCHI_CLOCK* ic, /****************************************************************************/ -int OutputInChIAsRequested(struct tagCANON_GLOBALS* pCG, - INCHI_IOSTREAM* pOut, - INCHI_IOSTREAM* pLog, - ICHICONST INPUT_PARMS* ip_inp, - STRUCT_DATA* sd_inp, - InpInChI* OneInput, - int num_components[INCHI_NUM], - MODE_PIXH nModeProtonIsoExchgH[INCHI_NUM], - long num_inp, - unsigned char save_opt_bits) +int OutputInChIAsRequested( struct tagCANON_GLOBALS *pCG, + INCHI_IOSTREAM *pOut, + INCHI_IOSTREAM *pLog, + ICHICONST INPUT_PARMS *ip_inp, + STRUCT_DATA *sd_inp, + InpInChI *OneInput, + int num_components[INCHI_NUM], + MODE_PIXH nModeProtonIsoExchgH[INCHI_NUM], + long num_inp, + unsigned char save_opt_bits ) { int j, k, k1, k2, ret2 = 0, iINChI, iINChI1; /* djb-rwth: removing redundant variables */ - PINChI2* pINChI[INCHI_NUM], * newPTR1; - PINChI_Aux2* pINChI_Aux[INCHI_NUM], * newPTR2; + PINChI2 *pINChI[INCHI_NUM], *newPTR1; + PINChI_Aux2 *pINChI_Aux[INCHI_NUM], *newPTR2; int bReqNonTaut; int bHasSomeReconnected; INPUT_PARMS ip_local; STRUCT_DATA sd_local; - INPUT_PARMS* ip = &ip_local; - STRUCT_DATA* sd = &sd_local; + INPUT_PARMS *ip = &ip_local; + STRUCT_DATA *sd = &sd_local; NORM_CANON_FLAGS ncFlags; - NORM_CANON_FLAGS* pncFlags = &ncFlags; + NORM_CANON_FLAGS *pncFlags = &ncFlags; int nRet1, bSortPrintINChIFlags; int bReqSplitOutputInChI; int nNumOutputComponents; INCHI_IOS_STRING temp_string_container; - INCHI_IOS_STRING* strbuf = &temp_string_container; - memset(strbuf, 0, sizeof(*strbuf)); /* djb-rwth: memset_s C11/Annex K variant? */ + INCHI_IOS_STRING *strbuf = &temp_string_container; + memset( strbuf, 0, sizeof( *strbuf ) ); /* djb-rwth: memset_s C11/Annex K variant? */ - if (0 >= inchi_strbuf_init(strbuf, INCHI_STRBUF_INITIAL_SIZE, INCHI_STRBUF_SIZE_INCREMENT)) + if (0 >= inchi_strbuf_init( strbuf, INCHI_STRBUF_INITIAL_SIZE, INCHI_STRBUF_SIZE_INCREMENT )) { ret2 = RI_ERR_ALLOC; goto exit_error; @@ -1247,60 +1247,60 @@ int OutputInChIAsRequested(struct tagCANON_GLOBALS* pCG, nRet1 = 0; k1 = k2 = 0; - memset(pncFlags, 0, sizeof(*pncFlags)); /* djb-rwth: memset_s C11/Annex K variant? */ - memset(pINChI, 0, sizeof(pINChI)); /* djb-rwth: memset_s C11/Annex K variant? */ - memset(pINChI_Aux, 0, sizeof(pINChI_Aux)); /* djb-rwth: memset_s C11/Annex K variant? */ + memset( pncFlags, 0, sizeof( *pncFlags ) ); /* djb-rwth: memset_s C11/Annex K variant? */ + memset( pINChI, 0, sizeof( pINChI ) ); /* djb-rwth: memset_s C11/Annex K variant? */ + memset( pINChI_Aux, 0, sizeof( pINChI_Aux ) ); /* djb-rwth: memset_s C11/Annex K variant? */ *ip = *ip_inp; *sd = *sd_inp; bHasSomeReconnected = 0; bSortPrintINChIFlags = 0; /* djb-rwth: removing redundant code */ - bReqNonTaut = (0 != (ip->nMode & REQ_MODE_BASIC)); - bReqSplitOutputInChI = (0 != (ip->bReadInChIOptions & READ_INCHI_SPLIT_OUTPUT)); + bReqNonTaut = ( 0 != ( ip->nMode & REQ_MODE_BASIC ) ); + bReqSplitOutputInChI = ( 0 != ( ip->bReadInChIOptions & READ_INCHI_SPLIT_OUTPUT ) ); INCHI_HEAPCHK - if (num_components[INCHI_BAS]) - { - /* djb-rwth: MYREALLOC2( PINChI2, PINChI_Aux2, pINChI[INCHI_BAS], pINChI_Aux[INCHI_BAS], num_components[INCHI_BAS], (long long)num_components[INCHI_BAS], k1 ); has been replaced and the whole block rewritten to address memory leaks and reading from freed memory locations */ - - do { - if ((num_components[INCHI_BAS]) <= ((long long)num_components[INCHI_BAS])) - { - newPTR1 = (PINChI2*)inchi_calloc(((long long)num_components[INCHI_BAS]) + 1, sizeof(PINChI2)); - newPTR2 = (PINChI_Aux2*)inchi_calloc(((long long)num_components[INCHI_BAS]) + 1, sizeof(PINChI_Aux2)); - if (newPTR1 && newPTR2) { - if ((pINChI[INCHI_BAS]) && (num_components[INCHI_BAS]) > 0) - memcpy(newPTR1, (pINChI[INCHI_BAS]), (num_components[INCHI_BAS]) * sizeof(PINChI2)); - if ((pINChI_Aux[INCHI_BAS]) && (num_components[INCHI_BAS]) > 0) - memcpy(newPTR2, (pINChI_Aux[INCHI_BAS]), (num_components[INCHI_BAS]) * sizeof(PINChI_Aux2)); - if (pINChI[INCHI_BAS]) - inchi_free(pINChI[INCHI_BAS]); - if (pINChI_Aux[INCHI_BAS]) - inchi_free(pINChI_Aux[INCHI_BAS]); - pINChI[INCHI_BAS] = newPTR1; - pINChI_Aux[INCHI_BAS] = newPTR2; - num_components[INCHI_BAS] = (long long)num_components[INCHI_BAS]; - k1 = 0; - } - else - { - inchi_free(newPTR1); - inchi_free(newPTR2); - k1 = 1; - } + if (num_components[INCHI_BAS]) + { + /* djb-rwth: MYREALLOC2( PINChI2, PINChI_Aux2, pINChI[INCHI_BAS], pINChI_Aux[INCHI_BAS], num_components[INCHI_BAS], (long long)num_components[INCHI_BAS], k1 ); has been replaced and the whole block rewritten to address memory leaks and reading from freed memory locations */ + + do { + if ((num_components[INCHI_BAS]) <= ((long long)num_components[INCHI_BAS])) + { + newPTR1 = (PINChI2*)inchi_calloc(((long long)num_components[INCHI_BAS]) + 1, sizeof(PINChI2)); + newPTR2 = (PINChI_Aux2*)inchi_calloc(((long long)num_components[INCHI_BAS]) + 1, sizeof(PINChI_Aux2)); + if (newPTR1 && newPTR2) { + if ((pINChI[INCHI_BAS]) && (num_components[INCHI_BAS]) > 0) + memcpy(newPTR1, (pINChI[INCHI_BAS]), (num_components[INCHI_BAS]) * sizeof(PINChI2)); + if ((pINChI_Aux[INCHI_BAS]) && (num_components[INCHI_BAS]) > 0) + memcpy(newPTR2, (pINChI_Aux[INCHI_BAS]), (num_components[INCHI_BAS]) * sizeof(PINChI_Aux2)); + if (pINChI[INCHI_BAS]) + inchi_free(pINChI[INCHI_BAS]); + if (pINChI_Aux[INCHI_BAS]) + inchi_free(pINChI_Aux[INCHI_BAS]); + pINChI[INCHI_BAS] = newPTR1; + pINChI_Aux[INCHI_BAS] = newPTR2; + num_components[INCHI_BAS] = (long long)num_components[INCHI_BAS]; + k1 = 0; + } + else + { + inchi_free(newPTR1); + inchi_free(newPTR2); + k1 = 1; } - else { k1 = 0; } - } while (0); - } + } + else { k1 = 0; } + } while (0); + } if (num_components[INCHI_REC]) { /* djb-rwth: MYREALLOC2( PINChI2, PINChI_Aux2, pINChI[INCHI_REC], pINChI_Aux[INCHI_REC], num_components[INCHI_REC], (long long)num_components[INCHI_REC], k2 ); has been replaced and the whole block rewritten to address memory leaks and reading from freed memory locations */ do { - if ((num_components[INCHI_REC]) <= ((long long)num_components[INCHI_REC])) + if ((num_components[INCHI_REC]) <= ((long long)num_components[INCHI_REC])) { newPTR1 = (PINChI2*)inchi_calloc(((long long)num_components[INCHI_REC]) + 1, sizeof(PINChI2)); newPTR2 = (PINChI_Aux2*)inchi_calloc(((long long)num_components[INCHI_REC]) + 1, sizeof(PINChI_Aux2)); @@ -1318,7 +1318,7 @@ int OutputInChIAsRequested(struct tagCANON_GLOBALS* pCG, num_components[INCHI_REC] = (long long)num_components[INCHI_REC]; k2 = 0; } - else + else { inchi_free(newPTR1); inchi_free(newPTR2); @@ -1344,8 +1344,8 @@ int OutputInChIAsRequested(struct tagCANON_GLOBALS* pCG, } if (num_components[INCHI_REC] && - (ip->bTautFlags & TG_FLAG_RECONNECT_COORD) && - (ip->bTautFlags & TG_FLAG_DISCONNECT_COORD)) + ( ip->bTautFlags & TG_FLAG_RECONNECT_COORD ) && + ( ip->bTautFlags & TG_FLAG_DISCONNECT_COORD )) { sd->bTautFlagsDone[0] |= TG_FLAG_DISCONNECT_COORD_DONE; bHasSomeReconnected = 1; @@ -1360,7 +1360,7 @@ int OutputInChIAsRequested(struct tagCANON_GLOBALS* pCG, for (k = 0; k < num_components[iINChI]; k++) { /* allocate InChI & AuxInfo */ - if (!(pINChI[iINChI][k][j] = (INChI*)inchi_calloc(1, sizeof(INChI)))) + if (!( pINChI[iINChI][k][j] = (INChI *) inchi_calloc( 1, sizeof( INChI ) ) )) { /* djb-rwth: avoiding memory leak */ free(pINChI[INCHI_BAS]); @@ -1370,7 +1370,7 @@ int OutputInChIAsRequested(struct tagCANON_GLOBALS* pCG, ret2 = RI_ERR_ALLOC; goto exit_error; } - if (!(pINChI_Aux[iINChI][k][j] = (INChI_Aux*)inchi_calloc(1, sizeof(INChI_Aux)))) + if (!( pINChI_Aux[iINChI][k][j] = (INChI_Aux *) inchi_calloc( 1, sizeof( INChI_Aux ) ) )) { /* djb-rwth: avoiding memory leak */ free(pINChI[INCHI_BAS]); @@ -1386,7 +1386,7 @@ int OutputInChIAsRequested(struct tagCANON_GLOBALS* pCG, /* copy InChI */ *pINChI[iINChI][k][j] = OneInput->pInpInChI[iINChI][j][k]; - memset(&OneInput->pInpInChI[iINChI][j][k], 0, sizeof(OneInput->pInpInChI[iINChI][j][k])); /* djb-rwth: memset_s C11/Annex K variant? */ + memset( &OneInput->pInpInChI[iINChI][j][k], 0, sizeof( OneInput->pInpInChI[iINChI][j][k] ) ); /* djb-rwth: memset_s C11/Annex K variant? */ INCHI_HEAPCHK /* take care of protons in AuxInfo */ @@ -1402,8 +1402,8 @@ int OutputInChIAsRequested(struct tagCANON_GLOBALS* pCG, INCHI_HEAPCHK } else if ((!k && nModeProtonIsoExchgH[iINChI] == MODE_PIXH_ADD_TO_FIRST) || - (k + 1 == OneInput->nNumComponents[iINChI][j] && - nModeProtonIsoExchgH[iINChI] == MODE_PIXH_ADD_A_PIXH_COMPONENT)) /* djb-rwth: addressing LLVM warnings */ + (k + 1 == OneInput->nNumComponents[iINChI][j] && + nModeProtonIsoExchgH[iINChI] == MODE_PIXH_ADD_A_PIXH_COMPONENT)) /* djb-rwth: addressing LLVM warnings */ { /* add protons and exchangeable isotopic H to the first component's AuxInfo */ pINChI_Aux[iINChI][k][j]->nNumRemovedProtons = OneInput->nNumProtons[iINChI][j].nNumRemovedProtons; @@ -1420,16 +1420,16 @@ int OutputInChIAsRequested(struct tagCANON_GLOBALS* pCG, } if (j == TAUT_YES && pINChI[iINChI][k][j] && pINChI[iINChI][k][j]->nNumberOfAtoms && - !pINChI[iINChI][k][j]->nNum_H_fixed) + !pINChI[iINChI][k][j]->nNum_H_fixed) { /* serializer crashes if it is not allocated */ - pINChI[iINChI][k][j]->nNum_H_fixed = (S_CHAR*)inchi_calloc((long long)pINChI[iINChI][k][j]->nNumberOfAtoms + 1, sizeof(pINChI[0][0][0]->nNum_H_fixed[0])); /* djb-rwth: cast operator added */ + pINChI[iINChI][k][j]->nNum_H_fixed = (S_CHAR *) inchi_calloc( (long long)pINChI[iINChI][k][j]->nNumberOfAtoms + 1, sizeof( pINChI[0][0][0]->nNum_H_fixed[0] ) ); /* djb-rwth: cast operator added */ } if (j == TAUT_YES && k < OneInput->nNumComponents[iINChI][TAUT_NON] && - pINChI[iINChI][k][j] && pINChI[iINChI][k][j]->nNumberOfAtoms && - pINChI[iINChI][k][TAUT_NON] && pINChI[iINChI][k][TAUT_NON]->nNumberOfAtoms && - !CompareReversedINChI(pINChI[iINChI][k][j], pINChI[iINChI][k][TAUT_NON], NULL, NULL)) + pINChI[iINChI][k][j] && pINChI[iINChI][k][j]->nNumberOfAtoms && + pINChI[iINChI][k][TAUT_NON] && pINChI[iINChI][k][TAUT_NON]->nNumberOfAtoms && + !CompareReversedINChI( pINChI[iINChI][k][j], pINChI[iINChI][k][TAUT_NON], NULL, NULL )) { pINChI[iINChI][k][TAUT_NON]->nNumberOfAtoms = 0; /* eliminate non-taut equal to taut */ } @@ -1447,7 +1447,7 @@ int OutputInChIAsRequested(struct tagCANON_GLOBALS* pCG, if (OneInput->pInpInChI[iINChI][j]) { INCHI_HEAPCHK - inchi_free(OneInput->pInpInChI[iINChI][j]); + inchi_free( OneInput->pInpInChI[iINChI][j] ); OneInput->pInpInChI[iINChI][j] = NULL; } } /* j */ @@ -1476,7 +1476,7 @@ int OutputInChIAsRequested(struct tagCANON_GLOBALS* pCG, nNumOutputComponents = 1; } - for (k1 = 0, k2 = (bReqSplitOutputInChI ? k1 + 1 : nNumOutputComponents); k1 < k2 && k1 < nNumOutputComponents; k1 = k2, k2++) + for (k1 = 0, k2 = ( bReqSplitOutputInChI ? k1 + 1 : nNumOutputComponents ); k1 < k2 && k1 < nNumOutputComponents; k1 = k2, k2++) { if (bReqSplitOutputInChI) @@ -1494,8 +1494,8 @@ int OutputInChIAsRequested(struct tagCANON_GLOBALS* pCG, for (k = k1; k < k2; k++) { /* find where the current processed structure is located */ - int cur_is_in_non_taut = (pINChI[iINChI][k][TAUT_NON] && pINChI[iINChI][k][TAUT_NON]->nNumberOfAtoms > 0); - int cur_is_in_taut = (pINChI[iINChI][k][TAUT_YES] && pINChI[iINChI][k][TAUT_YES]->nNumberOfAtoms > 0); + int cur_is_in_non_taut = ( pINChI[iINChI][k][TAUT_NON] && pINChI[iINChI][k][TAUT_NON]->nNumberOfAtoms > 0 ); + int cur_is_in_taut = ( pINChI[iINChI][k][TAUT_YES] && pINChI[iINChI][k][TAUT_YES]->nNumberOfAtoms > 0 ); int cur_is_non_taut = (cur_is_in_non_taut && 0 == pINChI[iINChI][k][TAUT_NON]->lenTautomer) || (cur_is_in_taut && 0 == pINChI[iINChI][k][TAUT_YES]->lenTautomer); /* djb-rwth: addressing LLVM warnings */ int cur_is_taut = cur_is_in_taut && 0 < pINChI[iINChI][k][TAUT_YES]->lenTautomer; @@ -1515,10 +1515,10 @@ int OutputInChIAsRequested(struct tagCANON_GLOBALS* pCG, } else { - sd->num_components[INCHI_BAS] = inchi_max(OneInput->nNumComponents[INCHI_BAS][TAUT_YES], - OneInput->nNumComponents[INCHI_BAS][TAUT_NON]); - sd->num_components[INCHI_REC] = inchi_max(OneInput->nNumComponents[INCHI_REC][TAUT_YES], - OneInput->nNumComponents[INCHI_REC][TAUT_NON]); + sd->num_components[INCHI_BAS] = inchi_max( OneInput->nNumComponents[INCHI_BAS][TAUT_YES], + OneInput->nNumComponents[INCHI_BAS][TAUT_NON] ); + sd->num_components[INCHI_REC] = inchi_max( OneInput->nNumComponents[INCHI_REC][TAUT_YES], + OneInput->nNumComponents[INCHI_REC][TAUT_NON] ); /* additional data needed for SortAndPrintINChI() */ for (iINChI = 0; iINChI < INCHI_NUM; iINChI++) { @@ -1529,8 +1529,8 @@ int OutputInChIAsRequested(struct tagCANON_GLOBALS* pCG, for (k = k1; k < k2; k++) { /* find where the current processed structure is located */ - int cur_is_in_non_taut = (pINChI[iINChI][k][TAUT_NON] && pINChI[iINChI][k][TAUT_NON]->nNumberOfAtoms > 0); - int cur_is_in_taut = (pINChI[iINChI][k][TAUT_YES] && pINChI[iINChI][k][TAUT_YES]->nNumberOfAtoms > 0); + int cur_is_in_non_taut = ( pINChI[iINChI][k][TAUT_NON] && pINChI[iINChI][k][TAUT_NON]->nNumberOfAtoms > 0 ); + int cur_is_in_taut = ( pINChI[iINChI][k][TAUT_YES] && pINChI[iINChI][k][TAUT_YES]->nNumberOfAtoms > 0 ); int cur_is_non_taut = (cur_is_in_non_taut && 0 == pINChI[iINChI][k][TAUT_NON]->lenTautomer) || (cur_is_in_taut && 0 == pINChI[iINChI][k][TAUT_YES]->lenTautomer); /* djb-rwth: addressing LLVM warnings */ int cur_is_taut = cur_is_in_taut && 0 < pINChI[iINChI][k][TAUT_YES]->lenTautomer; @@ -1552,12 +1552,12 @@ int OutputInChIAsRequested(struct tagCANON_GLOBALS* pCG, if (bReqSplitOutputInChI) { /* output components one by one (for splitting input InChI into components) */ - PINChI2* pInChI_2[INCHI_NUM]; - PINChI_Aux2* pInChI_Aux_2[INCHI_NUM]; - INChI* pInChI_1[1][2]; - INChI_Aux* pInChI_Aux_1[1][2]; - memset(pInChI_2, 0, sizeof(pInChI_2)); /* djb-rwth: memset_s C11/Annex K variant? */ - memset(pInChI_Aux_2, 0, sizeof(pInChI_Aux_2)); /* djb-rwth: memset_s C11/Annex K variant? */ + PINChI2 *pInChI_2[INCHI_NUM]; + PINChI_Aux2 *pInChI_Aux_2[INCHI_NUM]; + INChI *pInChI_1[1][2]; + INChI_Aux *pInChI_Aux_1[1][2]; + memset( pInChI_2, 0, sizeof( pInChI_2 ) ); /* djb-rwth: memset_s C11/Annex K variant? */ + memset( pInChI_Aux_2, 0, sizeof( pInChI_Aux_2 ) ); /* djb-rwth: memset_s C11/Annex K variant? */ for (j = 0; j < TAUT_NUM; j++) { pInChI_1[0][j] = pINChI[iINChI1][k1][j]; @@ -1567,8 +1567,8 @@ int OutputInChIAsRequested(struct tagCANON_GLOBALS* pCG, pInChI_Aux_2[INCHI_BAS] = pInChI_Aux_1; /* make sure purely reconnected InChI is marked as ReChI, not InChI */ if (bHasSomeReconnected && - (bInChIHasReconnectedMetal(pInChI_1[0][TAUT_YES]) || - bInChIHasReconnectedMetal(pInChI_1[0][TAUT_NON]))) + ( bInChIHasReconnectedMetal( pInChI_1[0][TAUT_YES] ) || + bInChIHasReconnectedMetal( pInChI_1[0][TAUT_NON] ) )) { bSortPrintINChIFlags = FLAG_SORT_PRINT_ReChI_PREFIX; } @@ -1577,16 +1577,16 @@ int OutputInChIAsRequested(struct tagCANON_GLOBALS* pCG, bSortPrintINChIFlags = 0; } INCHI_HEAPCHK - nRet1 = SortAndPrintINChI(pCG, pOut, strbuf, pLog, ip, - NULL /*orig_inp_data*/, - NULL /*prep_inp_data*/, - NULL /*composite_norm_data*/, - NULL /*pOrigStruct*/, - sd->num_components, sd->num_non_taut, - sd->num_taut, sd->bTautFlags, - sd->bTautFlagsDone, pncFlags, num_inp, - pInChI_2, pInChI_Aux_2, - &bSortPrintINChIFlags, save_opt_bits); + nRet1 = SortAndPrintINChI( pCG, pOut, strbuf, pLog, ip, + NULL /*orig_inp_data*/, + NULL /*prep_inp_data*/, + NULL /*composite_norm_data*/, + NULL /*pOrigStruct*/, + sd->num_components, sd->num_non_taut, + sd->num_taut, sd->bTautFlags, + sd->bTautFlagsDone, pncFlags, num_inp, + pInChI_2, pInChI_Aux_2, + &bSortPrintINChIFlags, save_opt_bits ); INCHI_HEAPCHK } else @@ -1594,13 +1594,13 @@ int OutputInChIAsRequested(struct tagCANON_GLOBALS* pCG, INCHI_HEAPCHK bSortPrintINChIFlags = 0; - nRet1 = SortAndPrintINChI(pCG, pOut, strbuf, pLog, ip, - NULL /*orig_inp_data*/, NULL /*prep_inp_data*/, - NULL /*composite_norm_data*/, NULL /*pOrigStruct*/, - sd->num_components, sd->num_non_taut, sd->num_taut, - sd->bTautFlags, sd->bTautFlagsDone, pncFlags, num_inp, - pINChI, pINChI_Aux, &bSortPrintINChIFlags, - save_opt_bits); + nRet1 = SortAndPrintINChI( pCG, pOut, strbuf, pLog, ip, + NULL /*orig_inp_data*/, NULL /*prep_inp_data*/, + NULL /*composite_norm_data*/, NULL /*pOrigStruct*/, + sd->num_components, sd->num_non_taut, sd->num_taut, + sd->bTautFlags, sd->bTautFlagsDone, pncFlags, num_inp, + pINChI, pINChI_Aux, &bSortPrintINChIFlags, + save_opt_bits ); INCHI_HEAPCHK } if (nRet1 == _IS_FATAL || nRet1 == _IS_ERROR) @@ -1610,7 +1610,7 @@ int OutputInChIAsRequested(struct tagCANON_GLOBALS* pCG, } INCHI_HEAPCHK - FreeAllINChIArrays(pINChI, pINChI_Aux, num_components); + FreeAllINChIArrays( pINChI, pINChI_Aux, num_components ); INCHI_HEAPCHK for (iINChI = 0; iINChI < INCHI_NUM; iINChI++) @@ -1619,7 +1619,7 @@ int OutputInChIAsRequested(struct tagCANON_GLOBALS* pCG, { if (OneInput->nNumProtons[iINChI][j].pNumProtons) { - inchi_free(OneInput->nNumProtons[iINChI][j].pNumProtons); + inchi_free( OneInput->nNumProtons[iINChI][j].pNumProtons ); OneInput->nNumProtons[iINChI][j].pNumProtons = NULL; } } @@ -1634,14 +1634,14 @@ int OutputInChIAsRequested(struct tagCANON_GLOBALS* pCG, exit_error: - inchi_strbuf_close(strbuf); + inchi_strbuf_close( strbuf ); return ret2; } /****************************************************************************/ -int GetNumNeighborsFromInchi(INChI* pInChI, AT_NUMB nAtNumber) +int GetNumNeighborsFromInchi( INChI *pInChI, AT_NUMB nAtNumber ) { int i, j, n_vertex, n_neigh, nNumNeigh, bTautAtom, nNumH, nTotNumNeigh, num_atoms; AT_NUMB taut_at_number; @@ -1650,7 +1650,7 @@ int GetNumNeighborsFromInchi(INChI* pInChI, AT_NUMB nAtNumber) bTautAtom = 0; /* 1 if atom belongs to a Mobile-H group */ nNumH = 0; /* number of terminal neighbors H */ num_atoms = 0; /* djb-rwth: initialisation with pInChI below */ - + if (pInChI) /* djb-rwth: fixing a NULL pointer dereference */ { num_atoms = pInChI->nNumberOfAtoms; @@ -1682,7 +1682,7 @@ int GetNumNeighborsFromInchi(INChI* pInChI, AT_NUMB nAtNumber) if (pInChI && pInChI->lenTautomer > 1 && pInChI->nTautomer && pInChI->nTautomer[0] > 0) { int itg, len_tg; - int tot_len_tg = pInChI->lenTautomer - T_GROUP_HDR_LEN * pInChI->nTautomer[0] - 1; /* number of endpoints */ + int tot_len_tg = pInChI->lenTautomer - T_GROUP_HDR_LEN*pInChI->nTautomer[0] - 1; /* number of endpoints */ j = 1; /* index in pInChI->nTautomer[] */ i = 0; /* index in ti->nEndpointAtomNumber[] */ for (itg = 0; itg < pInChI->nTautomer[0]; itg++) @@ -1693,7 +1693,7 @@ int GetNumNeighborsFromInchi(INChI* pInChI, AT_NUMB nAtNumber) for (; 0 < len_tg--; j++, i++) { taut_at_number = pInChI->nTautomer[j] - 1; /* Mobile-H group atom number */ - bTautAtom += (taut_at_number == nAtNumber); + bTautAtom += ( taut_at_number == nAtNumber ); } } if (i != tot_len_tg) @@ -1718,15 +1718,15 @@ int GetNumNeighborsFromInchi(INChI* pInChI, AT_NUMB nAtNumber) /****************************************************************************/ -int CountStereoTypes(INChI* pInChI, - int* num_known_SB, - int* num_known_SC, - int* num_unk_und_SB, - int* num_unk_und_SC, - int* num_SC_PIII, - int* num_SC_AsIII) +int CountStereoTypes( INChI *pInChI, + int *num_known_SB, + int *num_known_SC, + int *num_unk_und_SB, + int *num_unk_und_SC, + int *num_SC_PIII, + int *num_SC_AsIII ) { - INChI_Stereo* Stereo; + INChI_Stereo *Stereo; int i, ret; AT_NUMB nAtNumber; U_CHAR el_number; @@ -1735,12 +1735,12 @@ int CountStereoTypes(INChI* pInChI, { return 0; /* no InChI */ } - Stereo = (pInChI->StereoIsotopic && - (pInChI->StereoIsotopic->nNumberOfStereoBonds + - pInChI->StereoIsotopic->nNumberOfStereoCenters)) ? pInChI->StereoIsotopic : - (pInChI->Stereo && - (pInChI->Stereo->nNumberOfStereoBonds + - pInChI->Stereo->nNumberOfStereoCenters)) ? pInChI->Stereo : NULL; + Stereo = ( pInChI->StereoIsotopic && + ( pInChI->StereoIsotopic->nNumberOfStereoBonds + + pInChI->StereoIsotopic->nNumberOfStereoCenters ) ) ? pInChI->StereoIsotopic : + ( pInChI->Stereo && + ( pInChI->Stereo->nNumberOfStereoBonds + + pInChI->Stereo->nNumberOfStereoCenters ) ) ? pInChI->Stereo : NULL; if (!Stereo) { return 1; /* No Stereo */ @@ -1749,44 +1749,44 @@ int CountStereoTypes(INChI* pInChI, /* count SB and cumulenes */ for (i = 0; i < Stereo->nNumberOfStereoBonds; i++) { - if (ATOM_PARITY_WELL_DEF(Stereo->b_parity[i])) + if (ATOM_PARITY_WELL_DEF( Stereo->b_parity[i] )) { - (*num_known_SB)++; + ( *num_known_SB )++; } else { - (*num_unk_und_SB)++; + ( *num_unk_und_SB )++; } } /* count SC and allenes */ for (i = 0; i < Stereo->nNumberOfStereoCenters; i++) { - if (!(nAtNumber = Stereo->nNumber[i]) || nAtNumber > pInChI->nNumberOfAtoms) + if (!( nAtNumber = Stereo->nNumber[i] ) || nAtNumber > pInChI->nNumberOfAtoms) { return RI_ERR_PROGR; /* wrong data, should never happen */ } - if (ATOM_PARITY_WELL_DEF(Stereo->t_parity[i])) + if (ATOM_PARITY_WELL_DEF( Stereo->t_parity[i] )) { - (*num_known_SC)++; + ( *num_known_SC )++; } else { - (*num_unk_und_SC)++; + ( *num_unk_und_SC )++; } el_number = pInChI->nAtom[nAtNumber - 1]; if (el_number != EL_NUMBER_P && el_number != EL_NUMBER_AS) { continue; } - ret = GetNumNeighborsFromInchi(pInChI, nAtNumber); + ret = GetNumNeighborsFromInchi( pInChI, nAtNumber ); if (ret < 0) { return ret; } if (3 == ret) { - *num_SC_PIII += (EL_NUMBER_P == el_number); - *num_SC_AsIII += (EL_NUMBER_AS == el_number); + *num_SC_PIII += ( EL_NUMBER_P == el_number ); + *num_SC_AsIII += ( EL_NUMBER_AS == el_number ); } } @@ -1795,97 +1795,97 @@ int CountStereoTypes(INChI* pInChI, /****************************************************************************/ -int bInpInchiComponentExists(InpInChI* pOneInput, - int iInChI, - int bMobileH, - int k) +int bInpInchiComponentExists( InpInChI *pOneInput, + int iInChI, + int bMobileH, + int k ) { if ((INCHI_BAS != iInChI && iInChI != INCHI_REC) || - (TAUT_NON != bMobileH && TAUT_YES != bMobileH) || k < 0) /* djb-rwth: addressing LLVM warnings */ + (TAUT_NON != bMobileH && TAUT_YES != bMobileH) || k < 0) /* djb-rwth: addressing LLVM warnings */ { return 0; } - return (k < pOneInput->nNumComponents[iInChI][bMobileH] && - pOneInput->pInpInChI[iInChI][bMobileH] && - pOneInput->pInpInChI[iInChI][bMobileH][k].nNumberOfAtoms > 0 && - !pOneInput->pInpInChI[iInChI][bMobileH][k].bDeleted); + return ( k < pOneInput->nNumComponents[iInChI][bMobileH] && + pOneInput->pInpInChI[iInChI][bMobileH] && + pOneInput->pInpInChI[iInChI][bMobileH][k].nNumberOfAtoms > 0 && + !pOneInput->pInpInChI[iInChI][bMobileH][k].bDeleted ); } /****************************************************************************/ -int bInpInchiComponentDeleted(InpInChI* pOneInput, - int iInChI, - int bMobileH, - int k) +int bInpInchiComponentDeleted( InpInChI *pOneInput, + int iInChI, + int bMobileH, + int k ) { if ((INCHI_BAS != iInChI && iInChI != INCHI_REC) || - (TAUT_NON != bMobileH && TAUT_YES != bMobileH) || k < 0) /* djb-rwth: addressing LLVM warnings */ + (TAUT_NON != bMobileH && TAUT_YES != bMobileH) || k < 0) /* djb-rwth: addressing LLVM warnings */ { return 0; } - return (k < pOneInput->nNumComponents[iInChI][bMobileH] && - pOneInput->pInpInChI[iInChI][bMobileH] && - pOneInput->pInpInChI[iInChI][bMobileH][k].nNumberOfAtoms > 0 && - pOneInput->pInpInChI[iInChI][bMobileH][k].bDeleted); + return ( k < pOneInput->nNumComponents[iInChI][bMobileH] && + pOneInput->pInpInChI[iInChI][bMobileH] && + pOneInput->pInpInChI[iInChI][bMobileH][k].nNumberOfAtoms > 0 && + pOneInput->pInpInChI[iInChI][bMobileH][k].bDeleted ); } /****************************************************************************/ -int bRevInchiComponentExists(StrFromINChI* pStruct, - int iInChI, - int bMobileH, - int k) +int bRevInchiComponentExists( StrFromINChI *pStruct, + int iInChI, + int bMobileH, + int k ) { if (!pStruct || /*!pStruct->at2 ||*/ !pStruct->num_atoms || - (INCHI_BAS != iInChI && iInChI != INCHI_REC) || - (TAUT_NON != bMobileH && TAUT_YES != bMobileH) || k < 0) /* djb-rwth: addressing LLVM warnings */ + (INCHI_BAS != iInChI && iInChI != INCHI_REC) || + (TAUT_NON != bMobileH && TAUT_YES != bMobileH) || k < 0) /* djb-rwth: addressing LLVM warnings */ { return 0; } - return (k < pStruct->RevInChI.num_components[iInChI] && - pStruct->RevInChI.pINChI[iInChI] && - pStruct->RevInChI.pINChI[iInChI][k][bMobileH] && - pStruct->RevInChI.pINChI[iInChI][k][bMobileH]->nNumberOfAtoms > 0 && - !pStruct->RevInChI.pINChI[iInChI][k][bMobileH]->bDeleted); + return ( k < pStruct->RevInChI.num_components[iInChI] && + pStruct->RevInChI.pINChI[iInChI] && + pStruct->RevInChI.pINChI[iInChI][k][bMobileH] && + pStruct->RevInChI.pINChI[iInChI][k][bMobileH]->nNumberOfAtoms > 0 && + !pStruct->RevInChI.pINChI[iInChI][k][bMobileH]->bDeleted ); } /****************************************************************************/ -int bRevInchiComponentDeleted(StrFromINChI* pStruct, - int iInChI, - int bMobileH, - int k) +int bRevInchiComponentDeleted( StrFromINChI *pStruct, + int iInChI, + int bMobileH, + int k ) { if (!pStruct || /*!pStruct->at2 ||*/ !pStruct->num_atoms || - (INCHI_BAS != iInChI && iInChI != INCHI_REC) || - (TAUT_NON != bMobileH && TAUT_YES != bMobileH) || k < 0) /* djb-rwth: addressing LLVM warnings */ + (INCHI_BAS != iInChI && iInChI != INCHI_REC) || + (TAUT_NON != bMobileH && TAUT_YES != bMobileH) || k < 0) /* djb-rwth: addressing LLVM warnings */ { return 0; } - return (k < pStruct->RevInChI.num_components[iInChI] && - pStruct->RevInChI.pINChI[iInChI] && - pStruct->RevInChI.pINChI[iInChI][k][bMobileH] && - pStruct->RevInChI.pINChI[iInChI][k][bMobileH]->nNumberOfAtoms > 0 && - pStruct->RevInChI.pINChI[iInChI][k][bMobileH]->bDeleted); + return ( k < pStruct->RevInChI.num_components[iInChI] && + pStruct->RevInChI.pINChI[iInChI] && + pStruct->RevInChI.pINChI[iInChI][k][bMobileH] && + pStruct->RevInChI.pINChI[iInChI][k][bMobileH]->nNumberOfAtoms > 0 && + pStruct->RevInChI.pINChI[iInChI][k][bMobileH]->bDeleted ); } /****************************************************************************/ -int DetectInpInchiCreationOptions(InpInChI* pOneInput, - int* bHasReconnected, - int* bHasMetal, - int* bHasFixedH, - int* nModeFlagsStereo, - int* bTautFlagsStereo) +int DetectInpInchiCreationOptions( InpInChI *pOneInput, + int *bHasReconnected, + int *bHasMetal, + int *bHasFixedH, + int *nModeFlagsStereo, + int *bTautFlagsStereo ) { int ret = 0, bHasStereo; int nModeFlagsValue = 0, bTautFlagsValue; /* stereo flags */ int iInChI, iMobileH, bIso, k, max_components, num_components; - INChI* pInChI; + INChI *pInChI; int num_known_SB /*Stereo Bonds & Cumulenes >C==C==C==C< */; int num_known_SC /* Stereo Centers & Allenes >C=C=C< */; int num_unk_und_SB, num_unk_und_SC; @@ -1904,14 +1904,14 @@ int DetectInpInchiCreationOptions(InpInChI* pOneInput, { switch (pOneInput->s[iInChI][iMobileH][bIso]) { - case 1: /* SABS */ - nModeFlagsValue |= REQ_MODE_STEREO | REQ_MODE_ISO_STEREO; - break; - case 2: - nModeFlagsValue |= REQ_MODE_STEREO | REQ_MODE_ISO_STEREO | REQ_MODE_RELATIVE_STEREO; - break; - case 3: - nModeFlagsValue |= REQ_MODE_STEREO | REQ_MODE_ISO_STEREO | REQ_MODE_RACEMIC_STEREO; + case 1: /* SABS */ + nModeFlagsValue |= REQ_MODE_STEREO | REQ_MODE_ISO_STEREO; + break; + case 2: + nModeFlagsValue |= REQ_MODE_STEREO | REQ_MODE_ISO_STEREO | REQ_MODE_RELATIVE_STEREO; + break; + case 3: + nModeFlagsValue |= REQ_MODE_STEREO | REQ_MODE_ISO_STEREO | REQ_MODE_RACEMIC_STEREO; } } @@ -1921,28 +1921,28 @@ int DetectInpInchiCreationOptions(InpInChI* pOneInput, for (k = num_components = 0; k < max_components; k++) { pInChI = pOneInput->pInpInChI[iInChI][iMobileH] + k; - ret = CountStereoTypes(pInChI, - &num_known_SB, &num_known_SC, - &num_unk_und_SB, &num_unk_und_SC, - &num_SC_PIII, &num_SC_AsIII); + ret = CountStereoTypes( pInChI, + &num_known_SB, &num_known_SC, + &num_unk_und_SB, &num_unk_und_SC, + &num_SC_PIII, &num_SC_AsIII ); if (ret < 0) { return ret; /* error */ } - bHasStereo += (ret == 2); - if ((ret > 0)) + bHasStereo += ( ret == 2 ); + if (( ret > 0 )) { /* ret == 0 => Empty InChI, 1=> No Stereo, 2=> Has Stereo */ num_components++; - *bHasReconnected |= (iInChI == INCHI_REC); - *bHasFixedH |= (iMobileH == TAUT_NON); + *bHasReconnected |= ( iInChI == INCHI_REC ); + *bHasFixedH |= ( iMobileH == TAUT_NON ); } - *bHasMetal |= bInChIHasReconnectedMetal(pInChI); + *bHasMetal |= bInChIHasReconnectedMetal( pInChI ); } } } - if ((nModeFlagsValue & REQ_MODE_RELATIVE_STEREO) && (nModeFlagsValue & REQ_MODE_RACEMIC_STEREO)) + if (( nModeFlagsValue & REQ_MODE_RELATIVE_STEREO ) && ( nModeFlagsValue & REQ_MODE_RACEMIC_STEREO )) { return RI_ERR_SYNTAX; } @@ -1988,14 +1988,14 @@ int DetectInpInchiCreationOptions(InpInChI* pOneInput, /****************************************************************************/ -int bInChIHasReconnectedMetal(INChI* pInChI) +int bInChIHasReconnectedMetal( INChI *pInChI ) { int i; if (pInChI && !pInChI->bDeleted && pInChI->nNumberOfAtoms && pInChI->nAtom) { for (i = 0; i < pInChI->nNumberOfAtoms; i++) { - if (is_el_a_metal((int)pInChI->nAtom[i])) + if (is_el_a_metal( (int) pInChI->nAtom[i] )) { if (pInChI->nNumberOfAtoms > 1 || (pInChI->nNum_H && pInChI->nNum_H[0])) /* djb-rwth: addressing LLVM warning */ { @@ -2010,14 +2010,14 @@ int bInChIHasReconnectedMetal(INChI* pInChI) /****************************************************************************/ -int SetProtonsAndXchgIsoH(int bInChI2Structure, - int bReqSplitOutputInChI, - int bReqProtonsForEachComponent, - int bReqNonTaut, - int bReqStereo, - int num_components[INCHI_NUM], - MODE_PIXH nModeProtonIsoExchgH[INCHI_NUM], - InpInChI* OneInput) +int SetProtonsAndXchgIsoH( int bInChI2Structure, + int bReqSplitOutputInChI, + int bReqProtonsForEachComponent, + int bReqNonTaut, + int bReqStereo, + int num_components[INCHI_NUM], + MODE_PIXH nModeProtonIsoExchgH[INCHI_NUM], + InpInChI *OneInput ) { int j, k, k1, ret2 = 0, iINChI; int bAvailableProtonsForEachComponent, bAvailableProtonsTotal; @@ -2036,7 +2036,7 @@ int SetProtonsAndXchgIsoH(int bInChI2Structure, bAvailableProtonsTotal |= 0 != OneInput->nNumProtons[iINChI][TAUT_YES].nNumRemovedIsotopicH[k1]; } /* are /p and/or /i/h available for each component ? */ - bAvailableProtonsForEachComponent = (NULL != OneInput->nNumProtons[iINChI][TAUT_YES].pNumProtons); + bAvailableProtonsForEachComponent = ( NULL != OneInput->nNumProtons[iINChI][TAUT_YES].pNumProtons ); /* decision: add /p to each component, add total to the 1st, add total as one more component */ /* In case of bInChI2Structure just keep totals if not available for each component */ @@ -2082,9 +2082,9 @@ int SetProtonsAndXchgIsoH(int bInChI2Structure, /* remove unneeded data: protons for each component */ if (bAvailableProtonsForEachComponent && - nModeProtonIsoExchgH[iINChI] != MODE_PIXH_ADD_TO_EACH) + nModeProtonIsoExchgH[iINChI] != MODE_PIXH_ADD_TO_EACH) { - inchi_free(OneInput->nNumProtons[iINChI][TAUT_YES].pNumProtons); + inchi_free( OneInput->nNumProtons[iINChI][TAUT_YES].pNumProtons ); OneInput->nNumProtons[iINChI][TAUT_YES].pNumProtons = NULL; bAvailableProtonsForEachComponent = 0; } @@ -2104,9 +2104,9 @@ int SetProtonsAndXchgIsoH(int bInChI2Structure, j = TAUT_NON; for (k = 0; k < OneInput->nNumComponents[iINChI][j]; k++) { - Free_INChI_Members(&OneInput->pInpInChI[iINChI][j][k]); + Free_INChI_Members( &OneInput->pInpInChI[iINChI][j][k] ); } - inchi_free(OneInput->pInpInChI[iINChI][j]); + inchi_free( OneInput->pInpInChI[iINChI][j] ); OneInput->pInpInChI[iINChI][j] = NULL; OneInput->nNumComponents[iINChI][j] = 0; } @@ -2117,26 +2117,26 @@ int SetProtonsAndXchgIsoH(int bInChI2Structure, j = TAUT_YES; for (k = 0; k < OneInput->nNumComponents[iINChI][j]; k++) { - Free_INChI_Members(&OneInput->pInpInChI[iINChI][j][k]); + Free_INChI_Members( &OneInput->pInpInChI[iINChI][j][k] ); } - inchi_free(OneInput->pInpInChI[iINChI][j]); + inchi_free( OneInput->pInpInChI[iINChI][j] ); OneInput->pInpInChI[iINChI][j] = NULL; OneInput->nNumComponents[iINChI][j] = 0; nModeProtonIsoExchgH[iINChI] = MODE_PIXH_UNDEFINED; if (OneInput->nNumProtons[iINChI][TAUT_YES].pNumProtons) { - inchi_free(OneInput->nNumProtons[iINChI][TAUT_YES].pNumProtons); + inchi_free( OneInput->nNumProtons[iINChI][TAUT_YES].pNumProtons ); OneInput->nNumProtons[iINChI][TAUT_YES].pNumProtons = NULL; } } #endif /* add one more component containing only /p and /i/h */ if ((nModeProtonIsoExchgH[iINChI] == MODE_PIXH_ADD_A_PIXH_COMPONENT && - OneInput->nNumComponents[iINChI][TAUT_YES]) || - /* always add one deleted component if no non-taut InChI is available */ - (bInChI2Structure && !bAvailableProtonsForEachComponent && - !OneInput->nNumComponents[iINChI][TAUT_NON] && - OneInput->nNumComponents[iINChI][TAUT_YES])) /* djb-rwth: addressing LLVM warnings */ + OneInput->nNumComponents[iINChI][TAUT_YES]) || + /* always add one deleted component if no non-taut InChI is available */ + (bInChI2Structure && !bAvailableProtonsForEachComponent && + !OneInput->nNumComponents[iINChI][TAUT_NON] && + OneInput->nNumComponents[iINChI][TAUT_YES])) /* djb-rwth: addressing LLVM warnings */ { int nPrevLen, nLen = 0; j = TAUT_YES; @@ -2148,25 +2148,25 @@ int SetProtonsAndXchgIsoH(int bInChI2Structure, if (nLen == nPrevLen) { /* add one more component */ - INChI* pInChI = (INChI*)inchi_calloc((long long)nLen + 1, sizeof(*pInChI)); /* djb-rwth: cast operator added */ + INChI *pInChI = (INChI *) inchi_calloc( (long long)nLen + 1, sizeof( *pInChI ) ); /* djb-rwth: cast operator added */ if (!pInChI) { ret2 = RI_ERR_ALLOC; goto exit_error; } memcpy(pInChI, OneInput->pInpInChI[iINChI][j], nLen * sizeof(*pInChI)); - inchi_free(OneInput->pInpInChI[iINChI][j]); + inchi_free( OneInput->pInpInChI[iINChI][j] ); OneInput->pInpInChI[iINChI][j] = pInChI; } OneInput->nNumComponents[iINChI][j] = nLen + 1; for (k = nLen; k < nPrevLen; k++) { - Free_INChI_Members(&OneInput->pInpInChI[iINChI][j][k]); - memset(&OneInput->pInpInChI[iINChI][j][k], 0, sizeof(OneInput->pInpInChI[iINChI][j][k])); /* djb-rwth: memset_s C11/Annex K variant? */ + Free_INChI_Members( &OneInput->pInpInChI[iINChI][j][k] ); + memset( &OneInput->pInpInChI[iINChI][j][k], 0, sizeof( OneInput->pInpInChI[iINChI][j][k] ) ); /* djb-rwth: memset_s C11/Annex K variant? */ } /* mark the last component as a proton */ - if (0 > (ret2 = nFillOutProtonMobileH(OneInput->pInpInChI[iINChI][j] + nLen))) + if (0 >( ret2 = nFillOutProtonMobileH( OneInput->pInpInChI[iINChI][j] + nLen ) )) { goto exit_error; } @@ -2182,14 +2182,14 @@ int SetProtonsAndXchgIsoH(int bInChI2Structure, { if (OneInput->pInpInChI[iINChI][j][k].Stereo) { - Free_INChI_Stereo(OneInput->pInpInChI[iINChI][j][k].Stereo); - inchi_free(OneInput->pInpInChI[iINChI][j][k].Stereo); + Free_INChI_Stereo( OneInput->pInpInChI[iINChI][j][k].Stereo ); + inchi_free( OneInput->pInpInChI[iINChI][j][k].Stereo ); OneInput->pInpInChI[iINChI][j][k].Stereo = NULL; } if (OneInput->pInpInChI[iINChI][j][k].StereoIsotopic) { - Free_INChI_Stereo(OneInput->pInpInChI[iINChI][j][k].StereoIsotopic); - inchi_free(OneInput->pInpInChI[iINChI][j][k].StereoIsotopic); + Free_INChI_Stereo( OneInput->pInpInChI[iINChI][j][k].StereoIsotopic ); + inchi_free( OneInput->pInpInChI[iINChI][j][k].StereoIsotopic ); OneInput->pInpInChI[iINChI][j][k].StereoIsotopic = NULL; } INCHI_HEAPCHK @@ -2199,10 +2199,10 @@ int SetProtonsAndXchgIsoH(int bInChI2Structure, } - num_components[INCHI_BAS] = inchi_max(OneInput->nNumComponents[INCHI_BAS][TAUT_YES], - OneInput->nNumComponents[INCHI_BAS][TAUT_NON]); - num_components[INCHI_REC] = inchi_max(OneInput->nNumComponents[INCHI_REC][TAUT_YES], - OneInput->nNumComponents[INCHI_REC][TAUT_NON]); + num_components[INCHI_BAS] = inchi_max( OneInput->nNumComponents[INCHI_BAS][TAUT_YES], + OneInput->nNumComponents[INCHI_BAS][TAUT_NON] ); + num_components[INCHI_REC] = inchi_max( OneInput->nNumComponents[INCHI_REC][TAUT_YES], + OneInput->nNumComponents[INCHI_REC][TAUT_NON] ); exit_error: return ret2; @@ -2210,29 +2210,29 @@ int SetProtonsAndXchgIsoH(int bInChI2Structure, /****************************************************************************/ -int GetInChIFormulaNumH(INChI* pInChI, int* nNumH) +int GetInChIFormulaNumH( INChI *pInChI, int *nNumH ) { /* get number of H including bridging hydrogen atoms */ - const char* p, * q; + const char *p, *q; *nNumH = 0; if (pInChI->szHillFormula) { - for (p = strchr(pInChI->szHillFormula, 'H'); p; p = strchr(p, 'H')) + for (p = strchr( pInChI->szHillFormula, 'H' ); p; p = strchr( p, 'H' )) { p++; - if (!islower(UCINT * p)) + if (!islower( UCINT *p )) { /* found hydrogen in the formula */ - if (isdigit(UCINT * p)) + if (isdigit( UCINT *p )) { #if ( CHECK_STRTOL_ATNUMB==1 ) int delta = (int)inchi_strtol(p, &q, 10); - if (delta > MAX_ATOMS || delta < 0) + if (delta>MAX_ATOMS || delta<0) { return RI_ERR_SYNTAX; /* syntax error */ } *nNumH += delta; #else - * nNumH += (int)inchi_strtol(p, &q, 10); + *nNumH += (int)inchi_strtol(p, &q, 10); #endif p = q; } @@ -2249,13 +2249,13 @@ int GetInChIFormulaNumH(INChI* pInChI, int* nNumH) /****************************************************************************/ -int GetInChINumH(INChI* pInChI, int* nNumH) +int GetInChINumH( INChI *pInChI, int *nNumH ) { int i, j, nNumTautGroups, iTautGroup, nTautGroupLen, lenTautomer; *nNumH = 0; for (i = 0; i < pInChI->nNumberOfAtoms; i++) { - *nNumH += (pInChI->nAtom[i] == EL_NUMBER_H); /* bridging H */ + *nNumH += ( pInChI->nAtom[i] == EL_NUMBER_H ); /* bridging H */ *nNumH += pInChI->nNum_H[i]; } /* earlier nNum_H_fixed[] should have been added to pInChI->nNum_H[] */ @@ -2281,7 +2281,7 @@ int GetInChINumH(INChI* pInChI, int* nNumH) return RI_ERR_PROGR; } } - if (pInChI->nNum_H_fixed && (pInChI->lenTautomer || pInChI->nTautomer)) + if (pInChI->nNum_H_fixed && ( pInChI->lenTautomer || pInChI->nTautomer )) { return RI_ERR_PROGR; } @@ -2291,7 +2291,7 @@ int GetInChINumH(INChI* pInChI, int* nNumH) /****************************************************************************/ -int GetInChIIsoH(INChI* pInChI, int nNumIsotopicH[NUM_H_ISOTOPES]) +int GetInChIIsoH( INChI *pInChI, int nNumIsotopicH[NUM_H_ISOTOPES] ) { int i; for (i = 0; i < NUM_H_ISOTOPES; i++) @@ -2301,18 +2301,18 @@ int GetInChIIsoH(INChI* pInChI, int nNumIsotopicH[NUM_H_ISOTOPES]) for (i = 0; i < pInChI->nNumberOfIsotopicAtoms; i++) { if (pInChI->IsotopicAtom[i].nIsoDifference > 0 && - pInChI->IsotopicAtom[i].nIsoDifference <= NUM_H_ISOTOPES) + pInChI->IsotopicAtom[i].nIsoDifference <= NUM_H_ISOTOPES) { if (!pInChI->nAtom || - !pInChI->IsotopicAtom[i].nAtomNumber || - pInChI->IsotopicAtom[i].nAtomNumber > pInChI->nNumberOfAtoms) + !pInChI->IsotopicAtom[i].nAtomNumber || + pInChI->IsotopicAtom[i].nAtomNumber > pInChI->nNumberOfAtoms) { return RI_ERR_PROGR; } - if (pInChI->nAtom[pInChI->IsotopicAtom[i].nAtomNumber - 1] == (AT_NUMB)EL_NUMBER_H) + if (pInChI->nAtom[pInChI->IsotopicAtom[i].nAtomNumber - 1] == (AT_NUMB) EL_NUMBER_H) { /* isotopic H in connection table */ - nNumIsotopicH[pInChI->IsotopicAtom[i].nIsoDifference - 1]++; + nNumIsotopicH[pInChI->IsotopicAtom[i].nIsoDifference - 1] ++; } } nNumIsotopicH[0] += pInChI->IsotopicAtom[i].nNum_H; @@ -2337,29 +2337,29 @@ typedef struct tagNumElem /**************************************************************************** Read a single InChI input Line and convert to data ****************************************************************************/ -int InChILine2Data(INCHI_IOSTREAM* pInp, - SEGM_LINE* pLine, - char** pStr, - int* pState, - int* nErr, - INChI* pInpInChI[INCHI_NUM][TAUT_NUM], - int nNumComponents[INCHI_NUM][TAUT_NUM], - REM_PROTONS nNumProtons[INCHI_NUM][TAUT_NUM], - int s[INCHI_NUM][TAUT_NUM][2], - int bReadCoord, - int bInchi2Struct, - INCHI_MODE nMode, - int* bStdFormat, - int* input_has_save_opt, - unsigned char* input_save_opt_bits, - OAD_Polymer** ppolymer, - OAD_V3000** pv3000) +int InChILine2Data( INCHI_IOSTREAM *pInp, + SEGM_LINE *pLine, + char **pStr, + int *pState, + int *nErr, + INChI *pInpInChI[INCHI_NUM][TAUT_NUM], + int nNumComponents[INCHI_NUM][TAUT_NUM], + REM_PROTONS nNumProtons[INCHI_NUM][TAUT_NUM], + int s[INCHI_NUM][TAUT_NUM][2], + int bReadCoord, + int bInchi2Struct, + INCHI_MODE nMode, + int *bStdFormat, + int *input_has_save_opt, + unsigned char *input_save_opt_bits, + OAD_Polymer **ppolymer, + OAD_V3000 **pv3000 ) { int iINChI, i, j, k, m, len1, len2, ret2 = 0, retAux = 0, stateAux = 0; /* djb-rwth: ignoring LLVM warning: variable used to store function return value */ int ret, tot_charge[INCHI_NUM][TAUT_NUM]; int i1, i2, i3; int kc; - NUM_ELEM* num_elem[INCHI_NUM][TAUT_NUM]; + NUM_ELEM *num_elem[INCHI_NUM][TAUT_NUM]; #if ( FIX_I2I_STEREOCONVERSION_BUG == 1 ) @@ -2378,12 +2378,12 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, } #endif - memset(num_elem, 0, sizeof(num_elem)); /* djb-rwth: memset_s C11/Annex K variant? */ + memset( num_elem, 0, sizeof( num_elem ) ); /* djb-rwth: memset_s C11/Annex K variant? */ - ret = ReadInChILine(pInp, pLine, pStr, pState, pInpInChI, - nNumComponents, nNumProtons, s, bStdFormat, - input_has_save_opt, input_save_opt_bits, - bInchi2Struct, ppolymer, pv3000); + ret = ReadInChILine( pInp, pLine, pStr, pState, pInpInChI, + nNumComponents, nNumProtons, s, bStdFormat, + input_has_save_opt, input_save_opt_bits, + bInchi2Struct, ppolymer, pv3000 ); #if ( FIX_I2I_STEREOCONVERSION_BUG == 1 ) /* modify stereo type for layers as requested */ @@ -2409,18 +2409,18 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, } #endif - * nErr = 0; + *nErr = 0; - if ((ret == RI_ERR_EOL) && - nNumComponents[INCHI_BAS][TAUT_YES] - + nNumComponents[INCHI_BAS][TAUT_NON] && bReadCoord) + if (( ret == RI_ERR_EOL ) && + nNumComponents[INCHI_BAS][TAUT_YES] + + nNumComponents[INCHI_BAS][TAUT_NON] && bReadCoord) { - retAux = ReadInChICoord(pInp, pLine, &stateAux, pInpInChI, nNumComponents); /* djb-rwth: ignoring LLVM warning: variable used to store function return value */ + retAux = ReadInChICoord( pInp, pLine, &stateAux, pInpInChI, nNumComponents ); /* djb-rwth: ignoring LLVM warning: variable used to store function return value */ } - if ((ret == RI_ERR_EOL || ret == RI_ERR_EOF) && - nNumComponents[INCHI_BAS][TAUT_YES] - + nNumComponents[INCHI_BAS][TAUT_NON]) + if (( ret == RI_ERR_EOL || ret == RI_ERR_EOF ) && + nNumComponents[INCHI_BAS][TAUT_YES] + + nNumComponents[INCHI_BAS][TAUT_NON]) { /* post-processing: add omitted layers */ *pState = IST_MATERIAL_BALANCE_ERROR; @@ -2431,7 +2431,7 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, /* for Mobile/Fixed H (j) ... */ int bIsotopic, bStereoType, bStereoTypeAlt; int nMH2FH_AltInv = 0, nFH2iFH_AltInv = 0 /*, niMH2iFH_AltInv=0, nMH2iMH_AltInv=0*/; - int jAlt = ALT_TAUT(j); + int jAlt = ALT_TAUT( j ); INCHI_MODE nFlags = 0, nFlagsAlt = 0; /* get stereo type: ABS, REL, RAC, or nothing */ tot_charge[iINChI][j] = 0; @@ -2452,7 +2452,7 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, /* add missing nNum_H and nConnTable */ if (nNumComponents[iINChI][j]) { - num_elem[iINChI][j] = (NUM_ELEM*)inchi_calloc((long long)nElDataLen + 1, sizeof(num_elem[0][0][0])); /* djb-rwth: cast operator added */ + num_elem[iINChI][j] = (NUM_ELEM *) inchi_calloc( (long long)nElDataLen + 1, sizeof( num_elem[0][0][0] ) ); /* djb-rwth: cast operator added */ if (!num_elem[iINChI][j]) { ret2 = RI_ERR_ALLOC; @@ -2464,11 +2464,11 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, /* for each component k ... */ if (pInpInChI[iINChI][j]) { - INChI* pInChI = &pInpInChI[iINChI][j][k]; - INChI* pInChI_Alt = (k < nNumComponents[iINChI][jAlt] && - pInpInChI[iINChI][jAlt] && - /*pInpInChI[iINChI][jAlt]->nNumberOfAtoms)? pInpInChI[iINChI][jAlt]:NULL;*/ /* 2007-09-25 DT */ - pInpInChI[iINChI][jAlt][k].nNumberOfAtoms) ? &pInpInChI[iINChI][jAlt][k] : NULL; + INChI *pInChI = &pInpInChI[iINChI][j][k]; + INChI *pInChI_Alt = ( k < nNumComponents[iINChI][jAlt] && + pInpInChI[iINChI][jAlt] && + /*pInpInChI[iINChI][jAlt]->nNumberOfAtoms)? pInpInChI[iINChI][jAlt]:NULL;*/ /* 2007-09-25 DT */ + pInpInChI[iINChI][jAlt][k].nNumberOfAtoms ) ? &pInpInChI[iINChI][jAlt][k] : NULL; if (nFlags) { pInChI->nFlags |= nFlags; @@ -2482,7 +2482,7 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, } /**** add empty immobile H (nNum_H) if it is missing ****/ if (!pInChI->nNum_H && - !(pInChI->nNum_H = (S_CHAR*)inchi_calloc((long long)pInChI->nNumberOfAtoms + 1, sizeof(pInChI->nNum_H[0])))) /* djb-rwth: cast operator added */ + !( pInChI->nNum_H = (S_CHAR *) inchi_calloc( (long long)pInChI->nNumberOfAtoms + 1, sizeof( pInChI->nNum_H[0] ) ) )) /* djb-rwth: cast operator added */ { ret2 = RI_ERR_ALLOC; goto exit_function; @@ -2490,13 +2490,13 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, /**** add single atom nConnTable if it is missing ****/ if (!pInChI->nConnTable && pInpInChI[iINChI][TAUT_YES]) /* djb-rwth: fixing a NULL pointer dereference */ { - AT_NUMB* pCT; + AT_NUMB *pCT; int lenCT; if (j == TAUT_NON && k < nNumComponents[iINChI][TAUT_YES] && - (pCT = pInpInChI[iINChI][TAUT_YES][k].nConnTable) && - (lenCT = pInpInChI[iINChI][TAUT_YES][k].lenConnTable) > 0) + ( pCT = pInpInChI[iINChI][TAUT_YES][k].nConnTable ) && + ( lenCT = pInpInChI[iINChI][TAUT_YES][k].lenConnTable ) > 0) { - if (!(pInChI->nConnTable = (AT_NUMB*)inchi_calloc((long long)lenCT + 1, sizeof(pInChI->nConnTable[0])))) /* djb-rwth: cast operator added */ + if (!( pInChI->nConnTable = (AT_NUMB *) inchi_calloc( (long long)lenCT + 1, sizeof( pInChI->nConnTable[0] ) ) )) /* djb-rwth: cast operator added */ { ret2 = RI_ERR_ALLOC; goto exit_function; @@ -2508,11 +2508,11 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, { if (j == TAUT_YES && pInChI->nNumberOfAtoms > 1) { - *pState = IST_MOBILE_H_CONNECTIONS + (iINChI == INCHI_REC ? IST_HAPPENED_IN_RECMET : 0); + *pState = IST_MOBILE_H_CONNECTIONS + ( iINChI == INCHI_REC ? IST_HAPPENED_IN_RECMET : 0 ); ret2 = RI_ERR_SYNTAX; goto exit_function; } - if (!(pInChI->nConnTable = (AT_NUMB*)inchi_calloc((long long)pInChI->nNumberOfAtoms + 1, sizeof(pInChI->nConnTable[0])))) /* djb-rwth: cast operator added */ + if (!( pInChI->nConnTable = (AT_NUMB *) inchi_calloc( (long long)pInChI->nNumberOfAtoms + 1, sizeof( pInChI->nConnTable[0] ) ) )) /* djb-rwth: cast operator added */ { ret2 = RI_ERR_ALLOC; goto exit_function; @@ -2541,7 +2541,7 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, */ if (!pInChI->nTotalCharge && k < nNumComponents[iINChI][TAUT_YES] && pInpInChI[iINChI][TAUT_YES]) /* djb-rwth: fixing a NULL pointer dereference */ { - INChI* pAltInChI = &pInpInChI[iINChI][TAUT_YES][k]; /* Mobile H InChI */ + INChI *pAltInChI = &pInpInChI[iINChI][TAUT_YES][k]; /* Mobile H InChI */ if (pAltInChI->nTotalCharge && pAltInChI->nTotalCharge != NO_VALUE_INT) { pInChI->nTotalCharge = pAltInChI->nTotalCharge; @@ -2558,13 +2558,13 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, } /***** copy isotopic atoms: Mobile H --> Fixed H ******/ if (j == TAUT_YES && pInChI->nNumberOfIsotopicAtoms && - k < nNumComponents[iINChI][TAUT_NON]) + k < nNumComponents[iINChI][TAUT_NON]) { - INChI* pAltInChI = &pInpInChI[iINChI][TAUT_NON][k]; /* Fixed H InChI */ + INChI *pAltInChI = &pInpInChI[iINChI][TAUT_NON][k]; /* Fixed H InChI */ if (!pAltInChI->nNumberOfIsotopicAtoms) { - ret2 = CopySegment(pAltInChI, pInChI, CPY_ISO_AT, 0, 0); + ret2 = CopySegment( pAltInChI, pInChI, CPY_ISO_AT, 0, 0 ); if (ret2 < 0) { goto exit_function; @@ -2573,17 +2573,17 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, } /**** copy coordinates: Mobile H --> Fixed H ******/ if (j == TAUT_YES && pInChI->IsotopicTGroup && - k < nNumComponents[iINChI][TAUT_NON]) + k < nNumComponents[iINChI][TAUT_NON]) { - INChI* pAltInChI = &pInpInChI[iINChI][TAUT_NON][k]; /* Fixed H InChI */ + INChI *pAltInChI = &pInpInChI[iINChI][TAUT_NON][k]; /* Fixed H InChI */ if (!pAltInChI->IsotopicTGroup) { - XYZ_COORD* pxyz = (XYZ_COORD*)inchi_calloc(pInChI->nNumberOfAtoms, sizeof(pxyz[0])); + XYZ_COORD *pxyz = (XYZ_COORD *) inchi_calloc( pInChI->nNumberOfAtoms, sizeof( pxyz[0] ) ); if (pxyz) { memcpy(pxyz, pInChI->IsotopicTGroup, pInChI->nNumberOfAtoms * sizeof(pxyz[0])); - pAltInChI->IsotopicTGroup = (INChI_IsotopicTGroup*)pxyz; + pAltInChI->IsotopicTGroup = (INChI_IsotopicTGroup *) pxyz; } else { @@ -2610,24 +2610,24 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, if (j == TAUT_YES) { int bIso = pInChI->nNumberOfIsotopicAtoms || - (pInChI->StereoIsotopic && - pInChI->StereoIsotopic->nNumberOfStereoCenters - + pInChI->StereoIsotopic->nNumberOfStereoBonds) || + ( pInChI->StereoIsotopic && + pInChI->StereoIsotopic->nNumberOfStereoCenters + + pInChI->StereoIsotopic->nNumberOfStereoBonds ) || (pInChI_Alt && pInChI_Alt->nNumberOfIsotopicAtoms); /* djb-rwth: addressing LLVM warning */ /* non-isotopic Mobile H => isotopic Mobile H */ if (bIso) { if (pInChI->Stereo && pInChI->Stereo->nNumberOfStereoCenters && - (!pInChI->StereoIsotopic || !pInChI->StereoIsotopic->t_parity)) + ( !pInChI->StereoIsotopic || !pInChI->StereoIsotopic->t_parity )) { - if (0 > (ret2 = CopySegment(pInChI, pInChI, CPY_SP3, 1, 0)) || - ((!pInChI->StereoIsotopic->nCompInv2Abs || NO_VALUE_INT == pInChI->StereoIsotopic->nCompInv2Abs) && - 0 > (ret2 = CopySegment(pInChI, pInChI, CPY_SP3_M, 1, 0)))) /* djb-rwth: addressing LLVM warning */ + if (0 > ( ret2 = CopySegment( pInChI, pInChI, CPY_SP3, 1, 0 ) ) || + (( !pInChI->StereoIsotopic->nCompInv2Abs || NO_VALUE_INT == pInChI->StereoIsotopic->nCompInv2Abs ) && + 0 > ( ret2 = CopySegment( pInChI, pInChI, CPY_SP3_M, 1, 0 ) ))) /* djb-rwth: addressing LLVM warning */ { goto exit_function; } - if ((nFlags & (INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO))) + if (( nFlags & ( INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO ) )) { if (pInChI->Stereo->nCompInv2Abs == NO_VALUE_INT) { @@ -2643,12 +2643,12 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, { /* copy sp3 inversion info: non-isotopic Mobile H => isotopic Mobile H */ if (pInChI->Stereo && pInChI->Stereo->nNumberOfStereoCenters && - pInChI->StereoIsotopic && pInChI->StereoIsotopic->nNumberOfStereoCenters && - pInChI->Stereo->nCompInv2Abs) + pInChI->StereoIsotopic && pInChI->StereoIsotopic->nNumberOfStereoCenters && + pInChI->Stereo->nCompInv2Abs) { - if ((nFlags & (INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO)) && - pInChI->Stereo->nCompInv2Abs == NO_VALUE_INT && - pInChI->StereoIsotopic->nCompInv2Abs == NO_VALUE_INT) + if (( nFlags & ( INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO ) ) && + pInChI->Stereo->nCompInv2Abs == NO_VALUE_INT && + pInChI->StereoIsotopic->nCompInv2Abs == NO_VALUE_INT) { pInChI->Stereo->nCompInv2Abs = s[iINChI][j][0] > 0 ? 2 : 0; pInChI->StereoIsotopic->nCompInv2Abs = s[iINChI][j][1] > 0 ? 2 : 0; @@ -2664,10 +2664,10 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, } } if (bIso && - pInChI->Stereo && pInChI->Stereo->nNumberOfStereoBonds && - (!pInChI->StereoIsotopic || !pInChI->StereoIsotopic->b_parity)) + pInChI->Stereo && pInChI->Stereo->nNumberOfStereoBonds && + ( !pInChI->StereoIsotopic || !pInChI->StereoIsotopic->b_parity )) { - if (0 > (ret2 = CopySegment(pInChI, pInChI, CPY_SP2, 1, 0))) + if (0 > ( ret2 = CopySegment( pInChI, pInChI, CPY_SP2, 1, 0 ) )) { goto exit_function; } @@ -2677,25 +2677,25 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, if (j == TAUT_NON) { if (pInChI->Stereo && pInChI->Stereo->nNumberOfStereoCenters && - pInChI->Stereo->nCompInv2Abs == NO_VALUE_INT) + pInChI->Stereo->nCompInv2Abs == NO_VALUE_INT) { /* case of /sN and /t... in non-isotopic Mobile-H, no /s in non-isotopic Fixed-H */ if (!s[iINChI][j][0] && s[iINChI][jAlt][0] > 0 && /* /sN is not present in F and is present in M */ - pInChI_Alt && pInChI_Alt->Stereo && pInChI_Alt->Stereo->nNumberOfStereoCenters) + pInChI_Alt && pInChI_Alt->Stereo && pInChI_Alt->Stereo->nNumberOfStereoCenters) { /* inherit from Mobile-H */ /* /s1 in M and MI; /m1 or /m0 in MI; /m. in M; no /m in F. Inherit MI->FI. Added 10-15-2007 */ if (pInChI_Alt->Stereo->nCompInv2Abs == 0 && /* M: /m. ; means no /m for this component */ - pInChI->Stereo->nCompInv2Abs == NO_VALUE_INT && /* F: no /m segment for all components */ - pInChI_Alt->StereoIsotopic && /* MI: present */ - pInChI_Alt->StereoIsotopic->nCompInv2Abs != 0 && - pInChI_Alt->StereoIsotopic->nCompInv2Abs != NO_VALUE_INT && /* MI: /m0 or /m1 */ - !s[iINChI][j][0] && !s[iINChI][j][1] && /* F, FI: no /s */ - s[iINChI][jAlt][0] == 1 && s[iINChI][jAlt][1] == 1 /* M, MI: /s1 and /s1 */ - ) + pInChI->Stereo->nCompInv2Abs == NO_VALUE_INT && /* F: no /m segment for all components */ + pInChI_Alt->StereoIsotopic && /* MI: present */ + pInChI_Alt->StereoIsotopic->nCompInv2Abs != 0 && + pInChI_Alt->StereoIsotopic->nCompInv2Abs != NO_VALUE_INT && /* MI: /m0 or /m1 */ + !s[iINChI][j][0] && !s[iINChI][j][1] && /* F, FI: no /s */ + s[iINChI][jAlt][0] == 1 && s[iINChI][jAlt][1] == 1 /* M, MI: /s1 and /s1 */ + ) { /* copy /m from MI to FI */ - if (0 > (ret2 = CopySegment(pInChI, pInChI_Alt, CPY_SP3_M, 1, 1))) + if (0 > ( ret2 = CopySegment( pInChI, pInChI_Alt, CPY_SP3_M, 1, 1 ) )) { goto exit_function; } @@ -2711,20 +2711,20 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, { /* M and MI contain /sN and /sN, N=2,3. Added 10-15-2007 */ if (pInChI_Alt->Stereo->nCompInv2Abs == NO_VALUE_INT && - pInChI->Stereo->nCompInv2Abs == NO_VALUE_INT && - !s[iINChI][j][0] && !s[iINChI][j][1] && - (s[iINChI][jAlt][0] & (INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO)) && - (s[iINChI][jAlt][1] & (INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO))) + pInChI->Stereo->nCompInv2Abs == NO_VALUE_INT && + !s[iINChI][j][0] && !s[iINChI][j][1] && + ( s[iINChI][jAlt][0] & ( INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO ) ) && + ( s[iINChI][jAlt][1] & ( INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO ) )) { int bIso = pInChI->nNumberOfIsotopicAtoms || - (pInChI->StereoIsotopic && - pInChI->StereoIsotopic->nNumberOfStereoCenters - + pInChI->StereoIsotopic->nNumberOfStereoBonds) || + ( pInChI->StereoIsotopic && + pInChI->StereoIsotopic->nNumberOfStereoCenters + + pInChI->StereoIsotopic->nNumberOfStereoBonds ) || (pInChI_Alt && pInChI_Alt->nNumberOfIsotopicAtoms); /* djb-rwth: addressing LLVM warning */ if (bIso) { if (!pInChI_Alt->StereoIsotopic && /* create zero/NULL-initialized pInChI_Alt->StereoIsotopic */ - 0 > (ret2 = CopySegment(pInChI_Alt, pInChI_Alt, CPY_SP3_M, 1, -1))) + 0 > ( ret2 = CopySegment( pInChI_Alt, pInChI_Alt, CPY_SP3_M, 1, -1 ) )) { goto exit_function; } @@ -2750,10 +2750,10 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, { /* case of /sN in Isotopic Fixed-H only, /t... in Fixed-H, no /m (2007-08-27 DT) */ if (!s[iINChI][j][0] && !s[iINChI][jAlt][0] && /* /sN in Fixed-H isotopic only */ - (nFlags & (INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO)) && - !(pInChI->StereoIsotopic && pInChI->StereoIsotopic->nNumberOfStereoCenters) && - /*!(pInChI_Alt && pInChI_Alt->Stereo && pInChI_Alt->Stereo->nNumberOfStereoCenters) &&*/ - !(pInChI_Alt && pInChI_Alt->StereoIsotopic && pInChI_Alt->StereoIsotopic->nNumberOfStereoCenters)) + ( nFlags & ( INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO ) ) && + !( pInChI->StereoIsotopic && pInChI->StereoIsotopic->nNumberOfStereoCenters ) && + /*!(pInChI_Alt && pInChI_Alt->Stereo && pInChI_Alt->Stereo->nNumberOfStereoCenters) &&*/ + !( pInChI_Alt && pInChI_Alt->StereoIsotopic && pInChI_Alt->StereoIsotopic->nNumberOfStereoCenters )) { pInChI->Stereo->nCompInv2Abs = NO_VALUE_INT + 1; /* Stereo->CompInv2Abs=0, StereoIsotopic->CompInv2Abs=1 or -1 */ } @@ -2769,15 +2769,15 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, if (j == TAUT_NON) { int bIso = pInChI->nNumberOfIsotopicAtoms || - (pInChI->StereoIsotopic && - pInChI->StereoIsotopic->nNumberOfStereoCenters - + pInChI->StereoIsotopic->nNumberOfStereoBonds) || + ( pInChI->StereoIsotopic && + pInChI->StereoIsotopic->nNumberOfStereoCenters + + pInChI->StereoIsotopic->nNumberOfStereoBonds ) || (pInChI_Alt && pInChI_Alt->nNumberOfIsotopicAtoms); /* djb-rwth: addressing LLVM warning */ /* non-isotopic Fixed H => isotopic Fixed H */ if (bIso) { if (pInChI->Stereo && pInChI->Stereo->nNumberOfStereoCenters && - (!pInChI->StereoIsotopic || !pInChI->StereoIsotopic->t_parity)) + ( !pInChI->StereoIsotopic || !pInChI->StereoIsotopic->t_parity )) { /* -- replaced 2007-08-27 by (aaa), see below -- DT if ( 0 > (ret2 = CopySegment( pInChI, pInChI, CPY_SP3, 1, 0)) || @@ -2787,7 +2787,7 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, } */ /*----------- replacement (aaa) begin 2007-08-27 DT */ - if (0 > (ret2 = CopySegment(pInChI, pInChI, CPY_SP3, 1, 0))) + if (0 > ( ret2 = CopySegment( pInChI, pInChI, CPY_SP3, 1, 0 ) )) { goto exit_function; } @@ -2798,14 +2798,14 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, } else { - if (!(pInChI->StereoIsotopic->nCompInv2Abs || NO_VALUE_INT == pInChI->StereoIsotopic->nCompInv2Abs) && - 0 > (ret2 = CopySegment(pInChI, pInChI, CPY_SP3_M, 1, 0))) + if (!( pInChI->StereoIsotopic->nCompInv2Abs || NO_VALUE_INT == pInChI->StereoIsotopic->nCompInv2Abs ) && + 0 > ( ret2 = CopySegment( pInChI, pInChI, CPY_SP3_M, 1, 0 ) )) { goto exit_function; } } /*----------- replacement (aaa) end 2007-08-27 DT */ - if ((nFlags & (INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO))) + if (( nFlags & ( INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO ) )) { if (pInChI->Stereo->nCompInv2Abs == NO_VALUE_INT) { @@ -2817,13 +2817,13 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, } } #ifdef NEVER - if ((nFlags & (INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO)) && - !s[iINChI][j][0] && s[iINChI][j][0] > 0) + if (( nFlags & ( INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO ) ) && + !s[iINChI][j][0] && s[iINChI][j][0] > 0) { /* copied Rel/Rac stereo to Iso; /s is in Iso /s is not in non-Iso */ /* this means all difference in stereo is in inversion */ if (pInChI->Stereo->nCompInv2Abs == NO_VALUE_INT && - pInChI->StereoIsotopic->nCompInv2Abs == NO_VALUE_INT) + pInChI->StereoIsotopic->nCompInv2Abs == NO_VALUE_INT) { pInChI->Stereo->nCompInv2Abs = 0; /* missing */ pInChI->StereoIsotopic->nCompInv2Abs = 2; /* unusual value */ @@ -2835,12 +2835,12 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, { /* copy sp3 inversion info: non-isotopic Fixed H --> isotopic Fixed H */ if (pInChI->Stereo && pInChI->Stereo->nNumberOfStereoCenters && - pInChI->StereoIsotopic && pInChI->StereoIsotopic->nNumberOfStereoCenters && - pInChI->Stereo->nCompInv2Abs) + pInChI->StereoIsotopic && pInChI->StereoIsotopic->nNumberOfStereoCenters && + pInChI->Stereo->nCompInv2Abs) { - if ((nFlags & (INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO)) && - pInChI->Stereo->nCompInv2Abs == NO_VALUE_INT && - pInChI->StereoIsotopic->nCompInv2Abs == NO_VALUE_INT) + if (( nFlags & ( INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO ) ) && + pInChI->Stereo->nCompInv2Abs == NO_VALUE_INT && + pInChI->StereoIsotopic->nCompInv2Abs == NO_VALUE_INT) { pInChI->Stereo->nCompInv2Abs = s[iINChI][j][0] > 0 ? 2 : 0; pInChI->StereoIsotopic->nCompInv2Abs = s[iINChI][j][1] > 0 ? 2 : 0; @@ -2856,10 +2856,10 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, } } if (bIso && - pInChI->Stereo && pInChI->Stereo->nNumberOfStereoBonds && - (!pInChI->StereoIsotopic || !pInChI->StereoIsotopic->b_parity)) + pInChI->Stereo && pInChI->Stereo->nNumberOfStereoBonds && + ( !pInChI->StereoIsotopic || !pInChI->StereoIsotopic->b_parity )) { - if (0 > (ret2 = CopySegment(pInChI, pInChI, CPY_SP2, 1, 0))) + if (0 > ( ret2 = CopySegment( pInChI, pInChI, CPY_SP2, 1, 0 ) )) { goto exit_function; } @@ -2869,22 +2869,22 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, /***** copy stereo: Mobile H --> Fixed H ******/ if (j == TAUT_NON && k < nNumComponents[iINChI][TAUT_YES]) { - INChI* pAltInChI = &pInpInChI[iINChI][TAUT_YES][k]; /* Mobile H InChI */ + INChI *pAltInChI = &pInpInChI[iINChI][TAUT_YES][k]; /* Mobile H InChI */ int bIso = pInChI->nNumberOfIsotopicAtoms || - (pInChI->StereoIsotopic && - pInChI->StereoIsotopic->nNumberOfStereoCenters - + pInChI->StereoIsotopic->nNumberOfStereoBonds) || + ( pInChI->StereoIsotopic && + pInChI->StereoIsotopic->nNumberOfStereoCenters + + pInChI->StereoIsotopic->nNumberOfStereoBonds ) || (pAltInChI && ( pAltInChI->nNumberOfIsotopicAtoms || - (pAltInChI->StereoIsotopic && - pAltInChI->StereoIsotopic->nNumberOfStereoCenters - + pAltInChI->StereoIsotopic->nNumberOfStereoBonds))); /* djb-rwth: addressing LLVM warning */ - int bNo_InChI_t = (!pInChI->Stereo || !pInChI->Stereo->t_parity); - int bNo_InChI_m = (!pInChI->Stereo || NO_VALUE_INT == pInChI->Stereo->nCompInv2Abs); + ( pAltInChI->StereoIsotopic && + pAltInChI->StereoIsotopic->nNumberOfStereoCenters + + pAltInChI->StereoIsotopic->nNumberOfStereoBonds ) )); /* djb-rwth: addressing LLVM warning */ + int bNo_InChI_t = ( !pInChI->Stereo || !pInChI->Stereo->t_parity ); + int bNo_InChI_m = ( !pInChI->Stereo || NO_VALUE_INT == pInChI->Stereo->nCompInv2Abs ); /* (2) non-isotopic Mobile H => non-isotopic Fixed H */ if (pAltInChI->Stereo && pAltInChI->Stereo->nNumberOfStereoCenters && - (!pInChI->Stereo || !pInChI->Stereo->t_parity)) + ( !pInChI->Stereo || !pInChI->Stereo->t_parity )) { #if ( FIX_I2I_STEREOCONVERSION_BUG2 == 1 ) /* (2008-04-02) 1=> Fix bug of i2i conversion SAbs-->(SRel||Srac) */ @@ -2900,27 +2900,27 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, bHave_t_stereo = 1; /* copy stereo anyway ... */ #endif - if (0 > (ret2 = CopySegment(pInChI, pAltInChI, CPY_SP3, 0, 0)) || - ((!pInChI->Stereo->nCompInv2Abs || NO_VALUE_INT == pInChI->Stereo->nCompInv2Abs) && - 0 > (ret2 = CopySegment(pInChI, pAltInChI, CPY_SP3_M, 0, 0)))) /* djb-rwth: addressing LLVM warning */ + if (0 > ( ret2 = CopySegment( pInChI, pAltInChI, CPY_SP3, 0, 0 ) ) || + (( !pInChI->Stereo->nCompInv2Abs || NO_VALUE_INT == pInChI->Stereo->nCompInv2Abs ) && + 0 > ( ret2 = CopySegment( pInChI, pAltInChI, CPY_SP3_M, 0, 0 ) ))) /* djb-rwth: addressing LLVM warning */ { goto exit_function; } #if ( FIX_I2I_STEREOCONVERSION_BUG2 == 1 ) /* ... correct just copied stereo if applicable */ - if ((s[iINChI][j][0] < 1) && - (bHave_t_stereo < 1) && - (pAltInChI->Stereo->nNumberOfStereoCenters > 0) && - (s[iINChI][jAlt][0] < 1)) + if (( s[iINChI][j][0] < 1 ) && + ( bHave_t_stereo < 1 ) && + ( pAltInChI->Stereo->nNumberOfStereoCenters > 0 ) && + ( s[iINChI][jAlt][0] < 1 )) { /* (2010-02-28) if not all stereo centers are unknown/undefined */ /* at which condition stereo still should present .. */ int all_UU = 1; for (kc = 0; kc < pAltInChI->Stereo->nNumberOfStereoCenters; kc++) { - if ((pAltInChI->Stereo->t_parity[kc] != AB_PARITY_UNKN) && - (pAltInChI->Stereo->t_parity[kc] != AB_PARITY_UNDF)) + if (( pAltInChI->Stereo->t_parity[kc] != AB_PARITY_UNKN ) && + ( pAltInChI->Stereo->t_parity[kc] != AB_PARITY_UNDF )) { all_UU = 0; break; @@ -2932,13 +2932,13 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, #endif /* in case of missing nCompInv2Abs, 2005-05-10 */ - if ((pInChI->Stereo->nCompInv2Abs == NO_VALUE_INT) && - (nFlagsAlt & (INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO))) + if (( pInChI->Stereo->nCompInv2Abs == NO_VALUE_INT ) && + ( nFlagsAlt & ( INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO ) )) { if (s[iINChI][jAlt][0] > 0 && s[iINChI][j][0] > 0) { /* suppose once in a while only non-taut stereo changes if inverted */ - pAltInChI->Stereo->nCompInv2Abs = (++nMH2FH_AltInv) % 2 ? 2 : 0; + pAltInChI->Stereo->nCompInv2Abs = ( ++nMH2FH_AltInv ) % 2 ? 2 : 0; pInChI->Stereo->nCompInv2Abs = 2; } else @@ -2950,20 +2950,20 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, /* no pAltInChI->StereoIsotopic or pInChI->StereoIsotopic have been created yet. */ /* added 10-11-2007 to fix i2i bug for Rel/Rac stereo */ if (nNumComponents[iINChI][j] > 1 && - bNo_InChI_t && bNo_InChI_m /* no /t... or /mN in Fixed-H */ && !nFlags && - !(pAltInChI->StereoIsotopic && pAltInChI->StereoIsotopic->t_parity) && - !(pInChI->StereoIsotopic && pInChI->StereoIsotopic->t_parity) && - s[iINChI][j][0] == 0 && s[iINChI][j][1] == 0 && - /* /sN, N=2 or 3 only in Mobile-H AND Mobile-H isotopic */ - (s[iINChI][jAlt][0] & ((INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO))) && - (s[iINChI][jAlt][1] & ((INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO)))) + bNo_InChI_t && bNo_InChI_m /* no /t... or /mN in Fixed-H */ && !nFlags && + !( pAltInChI->StereoIsotopic && pAltInChI->StereoIsotopic->t_parity ) && + !( pInChI->StereoIsotopic && pInChI->StereoIsotopic->t_parity ) && + s[iINChI][j][0] == 0 && s[iINChI][j][1] == 0 && + /* /sN, N=2 or 3 only in Mobile-H AND Mobile-H isotopic */ + ( s[iINChI][jAlt][0] & ( ( INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO ) ) ) && + ( s[iINChI][jAlt][1] & ( ( INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO ) ) )) { if (bIso) { /* create two zero/NULL-initialized isotopic stereo if they do not exist */ - if ((!pInChI->StereoIsotopic && 0 > (ret2 = CopySegment(pInChI, pAltInChI, CPY_SP3_M, 1, -1))) - /* -- the following will be created later, in TAUT_YES part of the code -- */ - || (!pAltInChI->StereoIsotopic && 0 > (ret2 = CopySegment(pAltInChI, pAltInChI, CPY_SP3_M, 1, -1)))) /* djb-rwth: addressing LLVM warnings */ + if ((!pInChI->StereoIsotopic && 0 > ( ret2 = CopySegment( pInChI, pAltInChI, CPY_SP3_M, 1, -1 ) )) + /* -- the following will be created later, in TAUT_YES part of the code -- */ + || (!pAltInChI->StereoIsotopic && 0 > ( ret2 = CopySegment( pAltInChI, pAltInChI, CPY_SP3_M, 1, -1 ) ))) /* djb-rwth: addressing LLVM warnings */ { goto exit_function; } @@ -2978,7 +2978,7 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, else { if (NO_VALUE_INT == pInChI->Stereo->nCompInv2Abs && - NO_VALUE_INT == pAltInChI->Stereo->nCompInv2Abs) + NO_VALUE_INT == pAltInChI->Stereo->nCompInv2Abs) { pInChI->Stereo->nCompInv2Abs = 2; pAltInChI->Stereo->nCompInv2Abs = 2; @@ -2987,7 +2987,7 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, } else { - if ((s[iINChI][jAlt][0] > 0 || s[iINChI][j][0] > 0) && s[iINChI][j][0] >= 0) + if (( s[iINChI][jAlt][0] > 0 || s[iINChI][j][0] > 0 ) && s[iINChI][j][0] >= 0) { pInChI->Stereo->nCompInv2Abs = 2; } @@ -2999,16 +2999,16 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, /* no pAltInChI->StereoIsotopic or pInChI->StereoIsotopic have been created yet. */ /* added 10-10-2007 to fix i2i bug for Rel/Rac stereo */ if (bIso && bNo_InChI_t && bNo_InChI_m /* no /t... or /mN in Fixed-H */ && !nFlags && - !(pAltInChI->StereoIsotopic && pAltInChI->StereoIsotopic->t_parity) && - !(pInChI->StereoIsotopic && pInChI->StereoIsotopic->t_parity) && - s[iINChI][jAlt][0] == 0 && s[iINChI][j][0] == 0 && s[iINChI][j][1] == 0 && - /* /sN, N=2 or 3 only in Mobile-H isotopic */ - (s[iINChI][jAlt][1] & ((INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO)))) + !( pAltInChI->StereoIsotopic && pAltInChI->StereoIsotopic->t_parity ) && + !( pInChI->StereoIsotopic && pInChI->StereoIsotopic->t_parity ) && + s[iINChI][jAlt][0] == 0 && s[iINChI][j][0] == 0 && s[iINChI][j][1] == 0 && + /* /sN, N=2 or 3 only in Mobile-H isotopic */ + ( s[iINChI][jAlt][1] & ( ( INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO ) ) )) { /* create two zero/NULL-initialized isotopic stereo if they do not exist */ - if (!pInChI->StereoIsotopic && 0 > (ret2 = CopySegment(pInChI, pAltInChI, CPY_SP3_M, 1, -1)) - /* -- the following will be created later, in TAUT_YES part of the code -- */ - /*|| !pAltInChI->StereoIsotopic && 0 > (ret2 = CopySegment( pAltInChI, pAltInChI, CPY_SP3_M, 1, -1))*/) + if (!pInChI->StereoIsotopic && 0 > ( ret2 = CopySegment( pInChI, pAltInChI, CPY_SP3_M, 1, -1 ) ) + /* -- the following will be created later, in TAUT_YES part of the code -- */ + /*|| !pAltInChI->StereoIsotopic && 0 > (ret2 = CopySegment( pAltInChI, pAltInChI, CPY_SP3_M, 1, -1))*/) { goto exit_function; } @@ -3028,9 +3028,9 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, } } } - if (!(pInChI->nFlags & (INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO))) + if (!( pInChI->nFlags & ( INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO ) )) { - pInChI->nFlags |= ((nFlagsAlt | nFlags) & (INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO)); + pInChI->nFlags |= ( ( nFlagsAlt | nFlags ) & ( INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO ) ); } } } @@ -3038,11 +3038,11 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, { /* copy sp3 inversion info: non-isotopic Mobile H => non-isotopic Fixed H */ if (pAltInChI->Stereo && pAltInChI->Stereo->nNumberOfStereoCenters && - pInChI->Stereo && pInChI->Stereo->nNumberOfStereoCenters && - pAltInChI->Stereo->nCompInv2Abs && - (!pInChI->Stereo->nCompInv2Abs || NO_VALUE_INT == pInChI->Stereo->nCompInv2Abs)) + pInChI->Stereo && pInChI->Stereo->nNumberOfStereoCenters && + pAltInChI->Stereo->nCompInv2Abs && + ( !pInChI->Stereo->nCompInv2Abs || NO_VALUE_INT == pInChI->Stereo->nCompInv2Abs )) { - if (!(nFlagsAlt && !nFlags) || NO_VALUE_INT == pInChI->Stereo->nCompInv2Abs) + if (!( nFlagsAlt && !nFlags ) || NO_VALUE_INT == pInChI->Stereo->nCompInv2Abs) { /* ??? */ pInChI->Stereo->nCompInv2Abs = pAltInChI->Stereo->nCompInv2Abs; @@ -3052,9 +3052,9 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, /* use same rule to copy stereobonds */ if (pAltInChI->Stereo && pAltInChI->Stereo->nNumberOfStereoBonds && - (!pInChI->Stereo || !pInChI->Stereo->b_parity)) + ( !pInChI->Stereo || !pInChI->Stereo->b_parity )) { - if (0 > (ret2 = CopySegment(pInChI, pAltInChI, CPY_SP2, 0, 0))) + if (0 > ( ret2 = CopySegment( pInChI, pAltInChI, CPY_SP2, 0, 0 ) )) { goto exit_function; } @@ -3063,55 +3063,55 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, /* if !FH_Stereo && !MH_Stereo && MH_IsoStereo!=NULL && FH_IsoStereo==NULL */ if (bIso) { - if (!(pInChI->Stereo && pInChI->Stereo->t_parity) && /* !FH_Stereo */ - !(pAltInChI->Stereo && pAltInChI->Stereo->t_parity) && /* !MH_Stereo */ - (pAltInChI->StereoIsotopic && pAltInChI->StereoIsotopic->nNumberOfStereoCenters) && /* MH_IsoStereo */ - (!pInChI->StereoIsotopic || !pInChI->StereoIsotopic->t_parity)) + if (!( pInChI->Stereo && pInChI->Stereo->t_parity ) && /* !FH_Stereo */ + !( pAltInChI->Stereo && pAltInChI->Stereo->t_parity ) && /* !MH_Stereo */ + ( pAltInChI->StereoIsotopic && pAltInChI->StereoIsotopic->nNumberOfStereoCenters ) && /* MH_IsoStereo */ + ( !pInChI->StereoIsotopic || !pInChI->StereoIsotopic->t_parity )) { /* !FH_IsoStereo */ /* copy sp3 iso stereo MI->FI (/t) and, if FH nCompInv2Abs (/m) is missing, copy it, too, MI->FI */ - if (0 > (ret2 = CopySegment(pInChI, pAltInChI, CPY_SP3, 1, 1)) || - ((!pInChI->StereoIsotopic->nCompInv2Abs || NO_VALUE_INT == pInChI->StereoIsotopic->nCompInv2Abs) && - 0 > (ret2 = CopySegment(pInChI, pAltInChI, CPY_SP3_M, 1, 1)))) /* djb-rwth: addressing LLVM warning */ + if (0 > ( ret2 = CopySegment( pInChI, pAltInChI, CPY_SP3, 1, 1 ) ) || + (( !pInChI->StereoIsotopic->nCompInv2Abs || NO_VALUE_INT == pInChI->StereoIsotopic->nCompInv2Abs ) && + 0 > ( ret2 = CopySegment( pInChI, pAltInChI, CPY_SP3_M, 1, 1 ) ))) /* djb-rwth: addressing LLVM warning */ { goto exit_function; } /* in case of missing nCompInv2Abs, Relative or Racemic stereo 2005-05-10 */ if (pInChI->StereoIsotopic->nCompInv2Abs == NO_VALUE_INT && - (nFlagsAlt & (INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO))) + ( nFlagsAlt & ( INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO ) )) { pInChI->StereoIsotopic->nCompInv2Abs = s[iINChI][jAlt][1] > 0 ? 2 : 0; - if (!(pInChI->nFlags & (INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO))) + if (!( pInChI->nFlags & ( INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO ) )) { - pInChI->nFlags |= (nFlagsAlt & (INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO)); + pInChI->nFlags |= ( nFlagsAlt & ( INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO ) ); } } } else { /* copy sp3 inversion info only: isotopic Mobile H -> isotopic Fixed H */ - if (!(pInChI->Stereo && pInChI->Stereo->t_parity) && /* !FH_Stereo /t */ - !(pAltInChI->Stereo && pAltInChI->Stereo->t_parity) && /* !MH_Stereo /t */ - (pAltInChI->StereoIsotopic && pAltInChI->StereoIsotopic->nNumberOfStereoCenters) && /* MH_IsoStereo /t */ - (pInChI->StereoIsotopic && pInChI->StereoIsotopic->nNumberOfStereoCenters) && /* FH_IsoStereo /t */ - pAltInChI->StereoIsotopic->nCompInv2Abs && /* MH_IsoStereo /m */ - (!pInChI->StereoIsotopic->nCompInv2Abs || NO_VALUE_INT == pInChI->StereoIsotopic->nCompInv2Abs)) + if (!( pInChI->Stereo && pInChI->Stereo->t_parity ) && /* !FH_Stereo /t */ + !( pAltInChI->Stereo && pAltInChI->Stereo->t_parity ) && /* !MH_Stereo /t */ + ( pAltInChI->StereoIsotopic && pAltInChI->StereoIsotopic->nNumberOfStereoCenters ) && /* MH_IsoStereo /t */ + ( pInChI->StereoIsotopic && pInChI->StereoIsotopic->nNumberOfStereoCenters ) && /* FH_IsoStereo /t */ + pAltInChI->StereoIsotopic->nCompInv2Abs && /* MH_IsoStereo /m */ + ( !pInChI->StereoIsotopic->nCompInv2Abs || NO_VALUE_INT == pInChI->StereoIsotopic->nCompInv2Abs )) { /* !FH_IsoStereo /m */ /* added 02-09-2006 */ - if (0 > (ret2 = CopySegment(pInChI, pAltInChI, CPY_SP3_M, 1, 1))) + if (0 > ( ret2 = CopySegment( pInChI, pAltInChI, CPY_SP3_M, 1, 1 ) )) { goto exit_function; } } } /* use same rule to copy stereobonds */ - if (!(pInChI->Stereo && pInChI->Stereo->b_parity) && - !(pAltInChI->Stereo && pAltInChI->Stereo->b_parity) && - (pAltInChI->StereoIsotopic && pAltInChI->StereoIsotopic->nNumberOfStereoBonds) && - (!pInChI->StereoIsotopic || !pInChI->StereoIsotopic->b_parity)) + if (!( pInChI->Stereo && pInChI->Stereo->b_parity ) && + !( pAltInChI->Stereo && pAltInChI->Stereo->b_parity ) && + ( pAltInChI->StereoIsotopic && pAltInChI->StereoIsotopic->nNumberOfStereoBonds ) && + ( !pInChI->StereoIsotopic || !pInChI->StereoIsotopic->b_parity )) { - if (0 > (ret2 = CopySegment(pInChI, pAltInChI, CPY_SP2, 1, 1))) + if (0 > ( ret2 = CopySegment( pInChI, pAltInChI, CPY_SP2, 1, 1 ) )) { goto exit_function; } @@ -3119,46 +3119,46 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, /* (4) Copy Fixed-H -> isotopic Fixed-H */ /* if FH_Stereo && !MH_IsoStereo && && !FH_IsoStereo */ - if ((pInChI->Stereo && pInChI->Stereo->nNumberOfStereoCenters) && /* FH_Stereo /t */ - !(pAltInChI->StereoIsotopic && pAltInChI->StereoIsotopic->t_parity) && /* !MH_IsoStereo /t */ - !(pInChI->StereoIsotopic && pInChI->StereoIsotopic->t_parity)) + if (( pInChI->Stereo && pInChI->Stereo->nNumberOfStereoCenters ) && /* FH_Stereo /t */ + !( pAltInChI->StereoIsotopic && pAltInChI->StereoIsotopic->t_parity ) && /* !MH_IsoStereo /t */ + !( pInChI->StereoIsotopic && pInChI->StereoIsotopic->t_parity )) { /* !FH_IsoStereo /t */ /* added 10-10-2007 DT: copy MH_Iso /m => FH_Iso /m to fix i2i bug for Abs stereo */ /* InChI string contains: MH(/t...), MH_Iso(/mN, no /t), FH(no /t /m), FH_Iso(no /t /m) */ if (pAltInChI->StereoIsotopic && pAltInChI->StereoIsotopic->nCompInv2Abs && /* MH_IsoStereo /m */ - bNo_InChI_t && - NO_VALUE_INT != pAltInChI->StereoIsotopic->nCompInv2Abs && /* undef FH_IsoStereo /m */ - !(pInChI->StereoIsotopic && NO_VALUE_INT != pInChI->StereoIsotopic->nCompInv2Abs)) + bNo_InChI_t && + NO_VALUE_INT != pAltInChI->StereoIsotopic->nCompInv2Abs && /* undef FH_IsoStereo /m */ + !( pInChI->StereoIsotopic && NO_VALUE_INT != pInChI->StereoIsotopic->nCompInv2Abs )) { - if (0 > (ret2 = CopySegment(pInChI, pAltInChI, CPY_SP3_M, 1, 1))) + if (0 > ( ret2 = CopySegment( pInChI, pAltInChI, CPY_SP3_M, 1, 1 ) )) { goto exit_function; } } /* added 05-09-2006: copy sp3 FH=>FH_Iso */ - if (0 > (ret2 = CopySegment(pInChI, pInChI, CPY_SP3, 1, 0)) || - ((!pInChI->StereoIsotopic->nCompInv2Abs || NO_VALUE_INT == pInChI->StereoIsotopic->nCompInv2Abs) && - 0 > (ret2 = CopySegment(pInChI, pInChI, CPY_SP3_M, 1, 0)))) /* djb-rwth: addressing LLVM warning */ + if (0 > ( ret2 = CopySegment( pInChI, pInChI, CPY_SP3, 1, 0 ) ) || + (( !pInChI->StereoIsotopic->nCompInv2Abs || NO_VALUE_INT == pInChI->StereoIsotopic->nCompInv2Abs ) && + 0 > ( ret2 = CopySegment( pInChI, pInChI, CPY_SP3_M, 1, 0 ) ))) /* djb-rwth: addressing LLVM warning */ { goto exit_function; } /* in case of missing nCompInv2Abs, Relative or Racemic stereo, /sN in Fixed-H, 2005-05-10 */ if (pInChI->StereoIsotopic->nCompInv2Abs == NO_VALUE_INT && - (nFlags & (INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO))) + ( nFlags & ( INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO ) )) { if (s[iINChI][j][0] > 0 && s[iINChI][j][1] > 0) { /* suppose once in a while only non-taut stereo changes if inverted */ pInChI->StereoIsotopic->nCompInv2Abs = 2; - pInChI->Stereo->nCompInv2Abs = (++nFH2iFH_AltInv) % 2 ? 2 : 0; + pInChI->Stereo->nCompInv2Abs = ( ++nFH2iFH_AltInv ) % 2 ? 2 : 0; } else { - if ((s[iINChI][j][0] > 0 || s[iINChI][j][1] > 0) && s[iINChI][j][1] >= 0) /* ??? != NO_VALUE_INT ??? */ + if (( s[iINChI][j][0] > 0 || s[iINChI][j][1] > 0 ) && s[iINChI][j][1] >= 0) /* ??? != NO_VALUE_INT ??? */ { pInChI->StereoIsotopic->nCompInv2Abs = 2; } @@ -3167,24 +3167,24 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, pInChI->StereoIsotopic->nCompInv2Abs = 0; } } - if (!(pInChI->nFlags & (INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO))) + if (!( pInChI->nFlags & ( INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO ) )) { - pInChI->nFlags |= (nFlags & (INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO)); + pInChI->nFlags |= ( nFlags & ( INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO ) ); } } } else { /* copy sp3 inversion info only: Fixed-H -> isotopic Fixed H */ - if ((pInChI->Stereo && pInChI->Stereo->t_parity) && - !(pAltInChI->StereoIsotopic && pAltInChI->StereoIsotopic->t_parity) && - (pAltInChI->StereoIsotopic && pAltInChI->StereoIsotopic->nNumberOfStereoCenters) && - (pInChI->StereoIsotopic && pInChI->StereoIsotopic->nNumberOfStereoCenters) && - pInChI->Stereo->nCompInv2Abs && - (!pInChI->StereoIsotopic->nCompInv2Abs || NO_VALUE_INT == pInChI->StereoIsotopic->nCompInv2Abs)) + if (( pInChI->Stereo && pInChI->Stereo->t_parity ) && + !( pAltInChI->StereoIsotopic && pAltInChI->StereoIsotopic->t_parity ) && + ( pAltInChI->StereoIsotopic && pAltInChI->StereoIsotopic->nNumberOfStereoCenters ) && + ( pInChI->StereoIsotopic && pInChI->StereoIsotopic->nNumberOfStereoCenters ) && + pInChI->Stereo->nCompInv2Abs && + ( !pInChI->StereoIsotopic->nCompInv2Abs || NO_VALUE_INT == pInChI->StereoIsotopic->nCompInv2Abs )) { /* added 05-09-2006 */ - if (0 > (ret2 = CopySegment(pInChI, pInChI, CPY_SP3_M, 1, 0))) + if (0 > ( ret2 = CopySegment( pInChI, pInChI, CPY_SP3_M, 1, 0 ) )) { goto exit_function; } @@ -3192,12 +3192,12 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, } } if (bIso && - !(pInChI->Stereo && pInChI->Stereo->nNumberOfStereoBonds) && - !(pAltInChI->Stereo && pAltInChI->Stereo->nNumberOfStereoBonds) && - (pAltInChI->StereoIsotopic && pAltInChI->StereoIsotopic->nNumberOfStereoBonds) && - (!pInChI->StereoIsotopic || !pInChI->StereoIsotopic->b_parity)) + !( pInChI->Stereo && pInChI->Stereo->nNumberOfStereoBonds ) && + !( pAltInChI->Stereo && pAltInChI->Stereo->nNumberOfStereoBonds ) && + ( pAltInChI->StereoIsotopic && pAltInChI->StereoIsotopic->nNumberOfStereoBonds ) && + ( !pInChI->StereoIsotopic || !pInChI->StereoIsotopic->b_parity )) { - if (0 > (ret2 = CopySegment(pInChI, pAltInChI, CPY_SP2, 1, 1))) + if (0 > ( ret2 = CopySegment( pInChI, pAltInChI, CPY_SP2, 1, 1 ) )) { goto exit_function; } @@ -3214,16 +3214,16 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, { if (pInpInChI[iINChI][j]) { - INChI* pInChI = &pInpInChI[iINChI][j][k]; + INChI *pInChI = &pInpInChI[iINChI][j][k]; if (pInChI->nTotalCharge == NO_VALUE_INT) { pInChI->nTotalCharge = 0; } if (pInChI->Stereo && pInChI->StereoIsotopic && - pInChI->StereoIsotopic->nCompInv2Abs == NO_VALUE_INT) + pInChI->StereoIsotopic->nCompInv2Abs == NO_VALUE_INT) { if (pInChI->Stereo->nNumberOfStereoCenters && - pInChI->Stereo->nCompInv2Abs != NO_VALUE_INT) + pInChI->Stereo->nCompInv2Abs != NO_VALUE_INT) { pInChI->StereoIsotopic->nCompInv2Abs = pInChI->Stereo->nCompInv2Abs; } @@ -3231,10 +3231,10 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, /* Add special nCompInv2Abs=2 to force /s2 or /s3 in InChI output */ if (pInChI->Stereo && pInChI->Stereo->nCompInv2Abs == NO_VALUE_INT) { - if (pInChI->nFlags & (INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO) && - pInChI->Stereo->nNumberOfStereoCenters) + if (pInChI->nFlags & ( INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO ) && + pInChI->Stereo->nNumberOfStereoCenters) { - pInChI->Stereo->nCompInv2Abs = (s[iINChI][j][0] > 0 /*|| s[iINChI][j][1]>0*/) ? 2 : 0; /* we do not know the real value */ + pInChI->Stereo->nCompInv2Abs = ( s[iINChI][j][0] > 0 /*|| s[iINChI][j][1]>0*/ ) ? 2 : 0; /* we do not know the real value */ } else { @@ -3243,8 +3243,8 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, } if (pInChI->StereoIsotopic && pInChI->StereoIsotopic->nCompInv2Abs == NO_VALUE_INT) { - if (pInChI->nFlags & (INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO) && - pInChI->StereoIsotopic->nNumberOfStereoCenters) + if (pInChI->nFlags & ( INCHI_FLAG_REL_STEREO | INCHI_FLAG_RAC_STEREO ) && + pInChI->StereoIsotopic->nNumberOfStereoCenters) { pInChI->StereoIsotopic->nCompInv2Abs = s[iINChI][j][1] > 0 ? 2 : 0; /* we do not know the real value */ } @@ -3255,7 +3255,7 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, } /* added 02-07-2006 */ if ((pInChI->Stereo && pInChI->Stereo->nCompInv2Abs == NO_VALUE_INT) || - (pInChI->StereoIsotopic && pInChI->StereoIsotopic->nCompInv2Abs == NO_VALUE_INT)) /* djb-rwth: addressing LLVM warnings */ + (pInChI->StereoIsotopic && pInChI->StereoIsotopic->nCompInv2Abs == NO_VALUE_INT)) /* djb-rwth: addressing LLVM warnings */ { ret2 = RI_ERR_PROGR; goto exit_function; @@ -3276,7 +3276,7 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, num_elem[iINChI][j][pInChI->nAtom[m]].num++; } } - if (0 > (ret2 = GetInChINumH(pInChI, &m))) + if (0 > ( ret2 = GetInChINumH( pInChI, &m ) )) { goto exit_function; } @@ -3292,7 +3292,7 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, { if (pInpInChI[iINChI][j]) { - INChI* pInChI = &pInpInChI[iINChI][j][k]; + INChI *pInChI = &pInpInChI[iINChI][j][k]; if (pInChI->Stereo && !pInChI->Stereo->nNumberOfStereoCenters) { pInChI->Stereo->nCompInv2Abs = 0; @@ -3312,7 +3312,7 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, { if (!s[iINChI][TAUT_YES][0] && !s[iINChI][TAUT_YES][1])/* if no /s in M, MI */ { - if ((s[iINChI][TAUT_NON][0] > 1) && (s[iINChI][TAUT_NON][1] > 1)) /* if /srel/srac in both F, FI */ + if (( s[iINChI][TAUT_NON][0] > 1 ) && ( s[iINChI][TAUT_NON][1] > 1 )) /* if /srel/srac in both F, FI */ { if (s[iINChI][TAUT_NON][0] == s[iINChI][TAUT_NON][1]) /* if same stereo in F and FI */ { @@ -3320,7 +3320,7 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, /* and place deliberately 0 to appropriate place */ for (k = 0; k < nNumComponents[iINChI][TAUT_NON]; k++) { - INChI* pInChI = &pInpInChI[iINChI][TAUT_NON][k]; + INChI *pInChI = &pInpInChI[iINChI][TAUT_NON][k]; if (pInChI->Stereo->nCompInv2Abs != 0) { pInChI->Stereo->nCompInv2Abs = 0; @@ -3348,10 +3348,10 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, int nFormulaH[TAUT_NUM], nNumH[TAUT_NUM], nCharge[TAUT_NUM], nNumIsotopicH[TAUT_NUM][NUM_H_ISOTOPES]; int nRemovedCharge, nRemovedH, nRemovedIsotopicH[NUM_H_ISOTOPES], nFoundRemovedIsoH; int nTotRemovedProtons, nTotRemovedIsotopicH[NUM_H_ISOTOPES], bExists[TAUT_NUM]; - INChI* pInChI[TAUT_NUM]; + INChI *pInChI[TAUT_NUM]; nTotRemovedProtons = 0; - memset(nTotRemovedIsotopicH, 0, sizeof(nTotRemovedIsotopicH)); /* djb-rwth: memset_s C11/Annex K variant? */ - len2 = inchi_max(nNumComponents[iINChI][TAUT_YES], nNumComponents[iINChI][TAUT_NON]); + memset( nTotRemovedIsotopicH, 0, sizeof( nTotRemovedIsotopicH ) ); /* djb-rwth: memset_s C11/Annex K variant? */ + len2 = inchi_max( nNumComponents[iINChI][TAUT_YES], nNumComponents[iINChI][TAUT_NON] ); for (k = 0; k < len2; k++) { @@ -3360,7 +3360,7 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, { /* j is 0=TAUT_NON or 1=TAUT_YES */ pInChI[j] = NULL; /* initialization 2006-03 */ - bExists[j] = (k < nNumComponents[iINChI][j]) && + bExists[j] = ( k < nNumComponents[iINChI][j] ) && pInpInChI[iINChI][j][k].nNumberOfAtoms && !pInpInChI[iINChI][j][k].bDeleted; } @@ -3393,9 +3393,9 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, { continue; } - if (0 > (ret2 = GetInChIFormulaNumH(pInChI[j], &nFormulaH[j])) || - 0 > (ret2 = GetInChINumH(pInChI[j], &nNumH[j])) || - 0 > (ret2 = GetInChIIsoH(pInChI[j], nNumIsotopicH[j]))) + if (0 >( ret2 = GetInChIFormulaNumH( pInChI[j], &nFormulaH[j] ) ) || + 0 > ( ret2 = GetInChINumH( pInChI[j], &nNumH[j] ) ) || + 0 > ( ret2 = GetInChIIsoH( pInChI[j], nNumIsotopicH[j] ) )) { goto exit_function; } @@ -3418,8 +3418,8 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, nRemovedH = nNumH[TAUT_NON] - nNumH[TAUT_YES]; for (m = 0; m < NUM_H_ISOTOPES; m++) { - nFoundRemovedIsoH += 0 != (nRemovedIsotopicH[m] = nNumIsotopicH[TAUT_NON][m] - - nNumIsotopicH[TAUT_YES][m]); + nFoundRemovedIsoH += 0 != ( nRemovedIsotopicH[m] = nNumIsotopicH[TAUT_NON][m] - + nNumIsotopicH[TAUT_YES][m] ); } if (nRemovedCharge != nRemovedH) { @@ -3428,13 +3428,13 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, } if (nRemovedCharge || nFoundRemovedIsoH) { - COMPONENT_REM_PROTONS* pNumProtons; + COMPONENT_REM_PROTONS *pNumProtons; if (!nNumProtons[iINChI][TAUT_YES].pNumProtons) { /* allocate only if needed */ nNumProtons[iINChI][TAUT_YES].pNumProtons = - (COMPONENT_REM_PROTONS*)inchi_calloc(len2, - sizeof(nNumProtons[0][0].pNumProtons[0])); + (COMPONENT_REM_PROTONS *) inchi_calloc( len2, + sizeof( nNumProtons[0][0].pNumProtons[0] ) ); if (!nNumProtons[iINChI][TAUT_YES].pNumProtons) { ret2 = RI_ERR_ALLOC; @@ -3458,7 +3458,7 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, } if (!pInChI[TAUT_YES]->nTautomer) { - pInChI[TAUT_YES]->nTautomer = (AT_NUMB*)inchi_calloc(pInChI[TAUT_YES]->lenTautomer, sizeof(pInChI[0]->nTautomer[0])); + pInChI[TAUT_YES]->nTautomer = (AT_NUMB *) inchi_calloc( pInChI[TAUT_YES]->lenTautomer, sizeof( pInChI[0]->nTautomer[0] ) ); } } } @@ -3492,7 +3492,7 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, } if (iso_diff_tot) { - if (0 > bIsoMayBeArranged(bInchi2Struct, iso_diff, nNumProtons, pInpInChI, nNumComponents, iINChI)) + if (0 > bIsoMayBeArranged( bInchi2Struct, iso_diff, nNumProtons, pInpInChI, nNumComponents, iINChI )) { ret2 = RI_ERR_SYNTAX; goto exit_function; @@ -3529,14 +3529,14 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, /* always len1 <= len2; if Mobile-H and Fixed-H have same number of components then len1=len2=0 */ if (len2 && len1) { - INChI* pInChI = (INChI*)inchi_calloc(len2, sizeof(pInChI[0])); + INChI *pInChI = (INChI *) inchi_calloc( len2, sizeof( pInChI[0] ) ); if (!pInChI) { ret2 = RI_ERR_ALLOC; goto exit_function; } memcpy(pInChI, pInpInChI[iINChI][j], len1 * sizeof(pInChI[0])); - inchi_free(pInpInChI[iINChI][j]); + inchi_free( pInpInChI[iINChI][j] ); pInpInChI[iINChI][j] = pInChI; nNumComponents[iINChI][j] = len2; for (; len1 < len2; len1++) @@ -3544,12 +3544,12 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, if (j == TAUT_YES) { /* mark added to Mobile H layer components as deleted protons */ - if (0 > (ret2 = nFillOutProtonMobileH(pInpInChI[iINChI][j] + len1))) + if (0 >( ret2 = nFillOutProtonMobileH( pInpInChI[iINChI][j] + len1 ) )) { goto exit_function; } - if (0 > (ret2 = nProtonCopyIsotopicInfo(pInpInChI[iINChI][j] + len1/* to */, - pInpInChI[iINChI][TAUT_NON] + len1/* from */))) + if (0 > ( ret2 = nProtonCopyIsotopicInfo( pInpInChI[iINChI][j] + len1/* to */, + pInpInChI[iINChI][TAUT_NON] + len1/* from */ ) )) { goto exit_function; } @@ -3573,7 +3573,7 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, { for (k = j; k < TAUT_NUM; k++) { - if ((iINChI != i || j != k) && num_elem[iINChI][j] && num_elem[i][k]) + if (( iINChI != i || j != k ) && num_elem[iINChI][j] && num_elem[i][k]) { if (tot_charge[iINChI][j] != tot_charge[i][k]) { @@ -3614,12 +3614,12 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, { if (num_elem[i][j]) { - inchi_free(num_elem[i][j]); + inchi_free( num_elem[i][j] ); num_elem[i][j] = NULL; } } } - *nErr = (ret2 < 0 && ret2 != RI_ERR_EOL) ? ret2 : 0; + *nErr = ( ret2 < 0 && ret2 != RI_ERR_EOL ) ? ret2 : 0; return ret; } @@ -3628,12 +3628,12 @@ int InChILine2Data(INCHI_IOSTREAM* pInp, /****************************************************************************/ #if ( FIX_ISO_FIXEDH_BUG_READ == 1 ) #undef TAUT_YES -int bIsoMayBeArranged(int bInchi2Struct, - int iso_diff[NUM_H_ISOTOPES], - REM_PROTONS nNumProtons[INCHI_NUM][TAUT_NUM], - INChI* pInpInChI[INCHI_NUM][TAUT_NUM], - int nNumComponents[INCHI_NUM][TAUT_NUM], - int iINChI) +int bIsoMayBeArranged( int bInchi2Struct, + int iso_diff[NUM_H_ISOTOPES], + REM_PROTONS nNumProtons[INCHI_NUM][TAUT_NUM], + INChI *pInpInChI[INCHI_NUM][TAUT_NUM], + int nNumComponents[INCHI_NUM][TAUT_NUM], + int iINChI ) { const int TAUT_YES = 1; int i, k, m, n_found = 0, n_found_at_in_component, n_found_H_in_component, i_iso_at, num_iso_H = 0, num_iso_H_orig, num_add_iso_H, orig_add_H; @@ -3644,18 +3644,18 @@ int bIsoMayBeArranged(int bInchi2Struct, num_iso_H_orig = num_iso_H; for (k = 0; k < nNumComponents[iINChI][TAUT_YES] && k < nNumComponents[iINChI][TAUT_NON]; k++) { - INChI* pInChI = &pInpInChI[iINChI][TAUT_NON][k]; - INChI* pInChITaut = &pInpInChI[iINChI][TAUT_YES][k]; + INChI *pInChI = &pInpInChI[iINChI][TAUT_NON][k]; + INChI *pInChITaut = &pInpInChI[iINChI][TAUT_YES][k]; if (pInChITaut->bDeleted || pInChI->bDeleted || - pInChITaut->nNumberOfIsotopicAtoms > 0 || - pInChITaut->lenTautomer > 1 && pInChITaut->nTautomer && pInChITaut->nTautomer[0] > 0 || - NULL == nNumProtons[iINChI][TAUT_YES].pNumProtons || - nNumProtons[iINChI][TAUT_YES].pNumProtons[k].nNumRemovedProtons <= 0 || - pInChI->nNumberOfIsotopicAtoms > 0 || - nNumProtons[iINChI][TAUT_YES].pNumProtons[k].nNumRemovedIsotopicH[0] || - nNumProtons[iINChI][TAUT_YES].pNumProtons[k].nNumRemovedIsotopicH[1] || - nNumProtons[iINChI][TAUT_YES].pNumProtons[k].nNumRemovedIsotopicH[2] - ) + pInChITaut->nNumberOfIsotopicAtoms > 0 || + pInChITaut->lenTautomer > 1 && pInChITaut->nTautomer && pInChITaut->nTautomer[0] > 0 || + NULL == nNumProtons[iINChI][TAUT_YES].pNumProtons || + nNumProtons[iINChI][TAUT_YES].pNumProtons[k].nNumRemovedProtons <= 0 || + pInChI->nNumberOfIsotopicAtoms > 0 || + nNumProtons[iINChI][TAUT_YES].pNumProtons[k].nNumRemovedIsotopicH[0] || + nNumProtons[iINChI][TAUT_YES].pNumProtons[k].nNumRemovedIsotopicH[1] || + nNumProtons[iINChI][TAUT_YES].pNumProtons[k].nNumRemovedIsotopicH[2] + ) { continue; } @@ -3665,7 +3665,7 @@ int bIsoMayBeArranged(int bInchi2Struct, n_found_H_in_component = 0; for (i = 0; i < pInChI->nNumberOfAtoms; i++) { - int nNumRemovedH = (int)pInChI->nNum_H[i] - (int)pInChITaut->nNum_H[i]; + int nNumRemovedH = (int) pInChI->nNum_H[i] - (int) pInChITaut->nNum_H[i]; if (nNumRemovedH > 0) { n_found_at_in_component++; @@ -3674,11 +3674,11 @@ int bIsoMayBeArranged(int bInchi2Struct, } if (n_found_at_in_component > 0 && num_iso_H > 0 && bInchi2Struct) { - pInChI->IsotopicAtom = (INChI_IsotopicAtom*)inchi_calloc(inchi_min(n_found_at_in_component, num_iso_H), sizeof(pInChI->IsotopicAtom[0])); + pInChI->IsotopicAtom = (INChI_IsotopicAtom *) inchi_calloc( inchi_min( n_found_at_in_component, num_iso_H ), sizeof( pInChI->IsotopicAtom[0] ) ); } for (i = 0, i_iso_at = 0; i < pInChI->nNumberOfAtoms; i++) { - int nNumRemovedH = (int)pInChI->nNum_H[i] - (int)pInChITaut->nNum_H[i]; + int nNumRemovedH = (int) pInChI->nNum_H[i] - (int) pInChITaut->nNum_H[i]; n_found += nNumRemovedH; /* found H removed in mobile-H layer */ if (nNumRemovedH > 0 && num_iso_H > 0 && orig_add_H) { @@ -3686,7 +3686,7 @@ int bIsoMayBeArranged(int bInchi2Struct, { if (iso_diff[m] > 0) { - num_add_iso_H = inchi_min(iso_diff[m], nNumRemovedH); /* atom limit */ + num_add_iso_H = inchi_min( iso_diff[m], nNumRemovedH ); /* atom limit */ if (num_add_iso_H > orig_add_H) /* component limit */ num_add_iso_H = orig_add_H; iso_diff[m] -= num_add_iso_H; /* update tot removed single isotope H limit */ @@ -3699,15 +3699,15 @@ int bIsoMayBeArranged(int bInchi2Struct, pInChI->IsotopicAtom[i_iso_at].nAtomNumber = i + 1; switch (m) { - case 0: - pInChI->IsotopicAtom[i_iso_at].nNum_H += num_add_iso_H; - break; - case 1: - pInChI->IsotopicAtom[i_iso_at].nNum_D += num_add_iso_H; - break; - case 2: - pInChI->IsotopicAtom[i_iso_at].nNum_T += num_add_iso_H; - break; + case 0: + pInChI->IsotopicAtom[i_iso_at].nNum_H += num_add_iso_H; + break; + case 1: + pInChI->IsotopicAtom[i_iso_at].nNum_D += num_add_iso_H; + break; + case 2: + pInChI->IsotopicAtom[i_iso_at].nNum_T += num_add_iso_H; + break; } } } @@ -3778,14 +3778,14 @@ typedef enum tagAuxInfoState { /****************************************************************************/ -int ParseAuxSegmentVersion(const char* str, - int bMobileH, - INChI* pInpInChI[], - int ppnNumComponents[], - int state) +int ParseAuxSegmentVersion( const char *str, + int bMobileH, + INChI *pInpInChI[], + int ppnNumComponents[], + int state ) { - const char* q; - if (isdigit(UCINT * str) && (inchi_strtol(str, &q, 10), !*q)) + const char *q; + if (isdigit( UCINT *str ) && ( inchi_strtol( str, &q, 10 ), !*q )) { return 1; } @@ -3801,30 +3801,30 @@ elements of INChI::nPossibleLocationsOfIsotopicH; save non-isotopic numbering into the second half of nNumberOfAtoms elements of INChI::nPossibleLocationsOfIsotopicH ****************************************************************************/ -int CopyAtomNumbers(INChI* pInChI_To, - int bIsoTo, - INChI* pInChI_From, - int bIsoFrom) +int CopyAtomNumbers( INChI *pInChI_To, + int bIsoTo, + INChI *pInChI_From, + int bIsoFrom ) { - AT_NUMB* pTo, * pFrom; + AT_NUMB *pTo, *pFrom; if (!pInChI_To || !pInChI_From || pInChI_To->bDeleted || pInChI_From->bDeleted || - !pInChI_To->nNumberOfAtoms || !pInChI_From->nNumberOfAtoms || - pInChI_To->nNumberOfAtoms != pInChI_From->nNumberOfAtoms || - !pInChI_From->nPossibleLocationsOfIsotopicH) + !pInChI_To->nNumberOfAtoms || !pInChI_From->nNumberOfAtoms || + pInChI_To->nNumberOfAtoms != pInChI_From->nNumberOfAtoms || + !pInChI_From->nPossibleLocationsOfIsotopicH) { return RI_ERR_PROGR; } if (!pInChI_To->nPossibleLocationsOfIsotopicH) { - pInChI_To->nPossibleLocationsOfIsotopicH = (AT_NUMB*)inchi_calloc(2 * (long long)pInChI_To->nNumberOfAtoms, - sizeof(pInChI_To->nPossibleLocationsOfIsotopicH[0])); /* djb-rwth: cast operator added */ + pInChI_To->nPossibleLocationsOfIsotopicH = (AT_NUMB *) inchi_calloc( 2 * (long long)pInChI_To->nNumberOfAtoms, + sizeof( pInChI_To->nPossibleLocationsOfIsotopicH[0] ) ); /* djb-rwth: cast operator added */ if (!pInChI_To->nPossibleLocationsOfIsotopicH) { return RI_ERR_ALLOC; } } - pTo = pInChI_To->nPossibleLocationsOfIsotopicH + (bIsoTo ? 0 : pInChI_To->nNumberOfAtoms); - pFrom = pInChI_From->nPossibleLocationsOfIsotopicH + (bIsoFrom ? 0 : pInChI_To->nNumberOfAtoms); + pTo = pInChI_To->nPossibleLocationsOfIsotopicH + ( bIsoTo ? 0 : pInChI_To->nNumberOfAtoms ); + pFrom = pInChI_From->nPossibleLocationsOfIsotopicH + ( bIsoFrom ? 0 : pInChI_To->nNumberOfAtoms ); if (pTo == pFrom) { return RI_ERR_PROGR; @@ -3842,71 +3842,71 @@ elements of INChI::nPossibleLocationsOfIsotopicH; save non-isotopic numbering into the second half of nNumberOfAtoms elements of INChI::nPossibleLocationsOfIsotopicH ****************************************************************************/ -int ParseAuxSegmentNumbers(const char* str, /* AuxInfo string */ - int bMobileH, /* treat mobile or fixedH domain nums */ - INChI* pInpInChI[], - int ppnNumComponents[], - int state, /* start position==state of reading */ - int* pbAbc /* ==1 if treating compresssed InChI */ +int ParseAuxSegmentNumbers( const char *str, /* AuxInfo string */ + int bMobileH, /* treat mobile or fixedH domain nums */ + INChI *pInpInChI[], + int ppnNumComponents[], + int state, /* start position==state of reading */ + int *pbAbc /* ==1 if treating compresssed InChI */ ) { int bIso = 0, iComponent = 0, nNumComponents, bIso_From = 0, bAltInChIExists; - INChI* pInChI = NULL, * pAltInChI = NULL, * pInChI_From = NULL; - const char* p, * q, * pStart, * pEnd, * t; + INChI *pInChI = NULL, *pAltInChI = NULL, *pInChI_From = NULL; + const char *p, *q, *pStart, *pEnd, *t; static const char mult_type[] = "mnM"; int val, ret, k, mpy_component, num; - AT_NUMB* pNumb; + AT_NUMB *pNumb; int base = 10; switch (state) { - case AST_MOBILE_H_NUMBERS: - if (bMobileH != TAUT_YES) - { - return RI_ERR_PROGR; - } - if (memcmp(str, "N:", 2)) - { - return 0; - } - break; - case AST_FIXED_H_NUMBERS: - if (bMobileH != TAUT_NON) - { - return RI_ERR_PROGR; - } - if (memcmp(str, "F:", 2)) - { - return 0; - } - break; - case AST_MOBILE_H_ISO_NUMBERS: - if (bMobileH != TAUT_YES) - { - return RI_ERR_PROGR; - } - if (memcmp(str, "I:", 2)) - { - return 0; - } - bIso = 1; - break; - case AST_FIXED_H_ISO_NUMBERS: - if (bMobileH != TAUT_NON) - { + case AST_MOBILE_H_NUMBERS: + if (bMobileH != TAUT_YES) + { + return RI_ERR_PROGR; + } + if (memcmp( str, "N:", 2 )) + { + return 0; + } + break; + case AST_FIXED_H_NUMBERS: + if (bMobileH != TAUT_NON) + { + return RI_ERR_PROGR; + } + if (memcmp( str, "F:", 2 )) + { + return 0; + } + break; + case AST_MOBILE_H_ISO_NUMBERS: + if (bMobileH != TAUT_YES) + { + return RI_ERR_PROGR; + } + if (memcmp( str, "I:", 2 )) + { + return 0; + } + bIso = 1; + break; + case AST_FIXED_H_ISO_NUMBERS: + if (bMobileH != TAUT_NON) + { + return RI_ERR_PROGR; + } + if (memcmp( str, "I:", 2 )) + { + return 0; + } + bIso = 1; + break; + default: return RI_ERR_PROGR; - } - if (memcmp(str, "I:", 2)) - { - return 0; - } - bIso = 1; - break; - default: - return RI_ERR_PROGR; } - pStart = (char*)str + 2; + pStart = (char *) str + 2; if (!*pStart) { return 1; @@ -3914,13 +3914,13 @@ int ParseAuxSegmentNumbers(const char* str, /* AuxInfo string iComponent = 0; nNumComponents = ppnNumComponents[bMobileH]; - bAltInChIExists = (NULL != pInpInChI[ALT_TAUT(bMobileH)]); + bAltInChIExists = ( NULL != pInpInChI[ALT_TAUT( bMobileH )] ); while (1) { /* Cycle over components */ - if (!(pEnd = strchr(pStart, ';'))) + if (!( pEnd = strchr( pStart, ';' ) )) { - pEnd = pStart + strlen(pStart); + pEnd = pStart + strlen( pStart ); } /* check */ if (!pInpInChI[bMobileH]) @@ -3928,7 +3928,7 @@ int ParseAuxSegmentNumbers(const char* str, /* AuxInfo string return 1; /* invalid aux info */ } pInChI = pInpInChI[bMobileH] + iComponent; - pAltInChI = pInpInChI[ALT_TAUT(bMobileH)] + iComponent; + pAltInChI = pInpInChI[ALT_TAUT( bMobileH )] + iComponent; /* djb-rwth: condition for if block had to be rewritten */ if ((int)inchi_strtol(pStart, &q, 10) > 0) @@ -3944,88 +3944,88 @@ int ParseAuxSegmentNumbers(const char* str, /* AuxInfo string if_cnd = true; } - if (if_cnd && (t = strchr((char*)mult_type, *q)) && q + 1 == pEnd) /* djb-rwth: bool if_cnd applied; ignoring LLVM warning: variable used to store function return value */ + if (if_cnd && ( t = strchr((char *)mult_type, *q)) && q + 1 == pEnd) /* djb-rwth: bool if_cnd applied; ignoring LLVM warning: variable used to store function return value */ { /* Process the abbreviation */ pInChI_From = NULL; switch (bMobileH) { - case TAUT_YES: - switch (bIso) - { - case 0: - ret = RI_ERR_SYNTAX; /* syntax error */ - goto exit_function; - case 1: - if (*q != 'm') - { - ret = RI_ERR_SYNTAX; /* syntax error */ - goto exit_function; - } - /* isotopic Mobile-H <-- non-isotopic Mobile H */ - pInChI_From = pInChI; - bIso_From = 0; - break; - default: - ret = RI_ERR_PROGR; - goto exit_function; - } - break; - - case TAUT_NON: - switch (*q) - { - case 'm': /* same as mobile H */ - switch (bIso) - { - case 0: /* from Mobile-H not isotopic */ - pInChI_From = bAltInChIExists ? pAltInChI : NULL; - bIso_From = 0; - break; - - case 1: - pInChI_From = bAltInChIExists ? pAltInChI : NULL;; - bIso_From = 1; - break; - default: - ret = RI_ERR_PROGR; - goto exit_function; - } - break; - case 'n': /* same as non-isotopic Fixed-H */ + case TAUT_YES: switch (bIso) { - case 0: - ret = 1; /*RI_ERR_SYNTAX;*/ - goto exit_function; - case 1: - pInChI_From = pInChI; /* djb-rwth: ignoring LLVM warning: value used */ - bIso_From = 0; /* djb-rwth: ignoring LLVM warning: value used */ - default: - ret = RI_ERR_PROGR; - goto exit_function; + case 0: + ret = RI_ERR_SYNTAX; /* syntax error */ + goto exit_function; + case 1: + if (*q != 'm') + { + ret = RI_ERR_SYNTAX; /* syntax error */ + goto exit_function; + } + /* isotopic Mobile-H <-- non-isotopic Mobile H */ + pInChI_From = pInChI; + bIso_From = 0; + break; + default: + ret = RI_ERR_PROGR; + goto exit_function; } break; - case 'M': /* same as isotopic Mobile-H */ - switch (bIso) + + case TAUT_NON: + switch (*q) { - case 0: - ret = RI_ERR_SYNTAX; - goto exit_function; - case 1: - pInChI_From = bAltInChIExists ? pAltInChI : NULL;; - bIso_From = 1; - break; - default: - ret = RI_ERR_PROGR; - goto exit_function; + case 'm': /* same as mobile H */ + switch (bIso) + { + case 0: /* from Mobile-H not isotopic */ + pInChI_From = bAltInChIExists ? pAltInChI : NULL; + bIso_From = 0; + break; + + case 1: + pInChI_From = bAltInChIExists ? pAltInChI : NULL;; + bIso_From = 1; + break; + default: + ret = RI_ERR_PROGR; + goto exit_function; + } + break; + case 'n': /* same as non-isotopic Fixed-H */ + switch (bIso) + { + case 0: + ret = 1; /*RI_ERR_SYNTAX;*/ + goto exit_function; + case 1: + pInChI_From = pInChI; /* djb-rwth: ignoring LLVM warning: value used */ + bIso_From = 0; /* djb-rwth: ignoring LLVM warning: value used */ + default: + ret = RI_ERR_PROGR; + goto exit_function; + } + break; + case 'M': /* same as isotopic Mobile-H */ + switch (bIso) + { + case 0: + ret = RI_ERR_SYNTAX; + goto exit_function; + case 1: + pInChI_From = bAltInChIExists ? pAltInChI : NULL;; + bIso_From = 1; + break; + default: + ret = RI_ERR_PROGR; + goto exit_function; + } + break; + default: + ret = 1; /*RI_ERR_SYNTAX;*/ + goto exit_function; } break; - default: - ret = 1; /*RI_ERR_SYNTAX;*/ - goto exit_function; - } - break; } /* Save numbers */ @@ -4033,7 +4033,7 @@ int ParseAuxSegmentNumbers(const char* str, /* AuxInfo string { for (k = 0; k < val; k++) { - CopyAtomNumbers(pInChI + k, bIso, pInChI_From + k, bIso_From); + CopyAtomNumbers( pInChI + k, bIso, pInChI_From + k, bIso_From ); } } mpy_component = val; @@ -4045,7 +4045,7 @@ int ParseAuxSegmentNumbers(const char* str, /* AuxInfo string pNumb = pInChI->nPossibleLocationsOfIsotopicH; if (!pNumb) { - pNumb = (AT_NUMB*)inchi_calloc(2 * (long long)pInChI->nNumberOfAtoms, sizeof(pNumb[0])); /* djb-rwth: cast operator added */ + pNumb = (AT_NUMB *) inchi_calloc( 2 * (long long)pInChI->nNumberOfAtoms, sizeof( pNumb[0] ) ); /* djb-rwth: cast operator added */ if (!pNumb) { ret = RI_ERR_ALLOC; @@ -4057,17 +4057,17 @@ int ParseAuxSegmentNumbers(const char* str, /* AuxInfo string if (pStart < pEnd && *pbAbc == -1) { /* Check if compressed InChI */ - *pbAbc = isupper(UCINT * pStart) ? 1 : 0; + *pbAbc = isupper( UCINT *pStart ) ? 1 : 0; } - base = (*pbAbc == 1) ? ALPHA_BASE : 10; + base = ( *pbAbc == 1 ) ? ALPHA_BASE : 10; if (*pbAbc == 1) { for (k = 0, p = pStart; k < pInChI->nNumberOfAtoms && p < pEnd; k++, p++) { - num = (AT_NUMB)inchi_strtol(p, &q, base); + num = (AT_NUMB) inchi_strtol( p, &q, base ); #if ( CHECK_STRTOL_ATNUMB==1 ) - if (num > MAX_ATOMS || num < 0) + if (num>MAX_ATOMS || num<0) { ret = RI_ERR_SYNTAX; goto exit_function; @@ -4078,7 +4078,7 @@ int ParseAuxSegmentNumbers(const char* str, /* AuxInfo string ret = RI_ERR_SYNTAX; goto exit_function; } - pNumb[k] = (AT_NUMB)num; + pNumb[k] = (AT_NUMB) num; p = q; if (p == pEnd) { @@ -4090,9 +4090,9 @@ int ParseAuxSegmentNumbers(const char* str, /* AuxInfo string { for (k = 0, p = pStart; k < pInChI->nNumberOfAtoms && p < pEnd; k++, p++) { - pNumb[k] = (AT_NUMB)inchi_strtol(p, &q, 10); + pNumb[k] = (AT_NUMB) inchi_strtol( p, &q, 10 ); #if ( CHECK_STRTOL_ATNUMB==1 ) - if (pNumb[k] > MAX_ATOMS || pNumb[k] < 0) + if (pNumb[k]>MAX_ATOMS || pNumb[k]<0) { ret = RI_ERR_SYNTAX; goto exit_function; @@ -4148,56 +4148,56 @@ int ParseAuxSegmentNumbers(const char* str, /* AuxInfo string /**************************************************************************** Read and skip AuxInfo segment atom equivalence classes, "/E:" segments ****************************************************************************/ -int ParseAuxSegmentAtomEqu(const char* str, - int bMobileH, - INChI* pInpInChI[], - int ppnNumComponents[], - int state) +int ParseAuxSegmentAtomEqu( const char *str, + int bMobileH, + INChI *pInpInChI[], + int ppnNumComponents[], + int state ) { switch (state) { - case AST_MOBILE_H_ATOM_EQ: - if (bMobileH != TAUT_YES) - { - return RI_ERR_PROGR; - } - if (memcmp(str, "E:", 2)) - { - return 0; - } - break; - case AST_MOBILE_H_ISO_ATOM_EQ: - if (bMobileH != TAUT_YES) - { - return RI_ERR_PROGR; - } - if (memcmp(str, "E:", 2)) - { - return 0; - } - break; - case AST_FIXED_H_ATOM_EQ: - if (bMobileH != TAUT_NON) - { - return RI_ERR_PROGR; - } - if (memcmp(str, "E:", 2)) - { - return 0; - } - break; - case AST_FIXED_H_ISO_ATOM_EQ: - if (bMobileH != TAUT_NON) - { + case AST_MOBILE_H_ATOM_EQ: + if (bMobileH != TAUT_YES) + { + return RI_ERR_PROGR; + } + if (memcmp( str, "E:", 2 )) + { + return 0; + } + break; + case AST_MOBILE_H_ISO_ATOM_EQ: + if (bMobileH != TAUT_YES) + { + return RI_ERR_PROGR; + } + if (memcmp( str, "E:", 2 )) + { + return 0; + } + break; + case AST_FIXED_H_ATOM_EQ: + if (bMobileH != TAUT_NON) + { + return RI_ERR_PROGR; + } + if (memcmp( str, "E:", 2 )) + { + return 0; + } + break; + case AST_FIXED_H_ISO_ATOM_EQ: + if (bMobileH != TAUT_NON) + { + return RI_ERR_PROGR; + } + if (memcmp( str, "E:", 2 )) + { + return 0; + } + break; + default: return RI_ERR_PROGR; - } - if (memcmp(str, "E:", 2)) - { - return 0; - } - break; - default: - return RI_ERR_PROGR; } return 1; @@ -4207,36 +4207,36 @@ int ParseAuxSegmentAtomEqu(const char* str, /**************************************************************************** Read and skip AuxInfo segment group equivalence classes, "/gE:" segments ****************************************************************************/ -int ParseAuxSegmentGroupEqu(const char* str, - int bMobileH, - INChI* pInpInChI[], - int ppnNumComponents[], - int state) +int ParseAuxSegmentGroupEqu( const char *str, + int bMobileH, + INChI *pInpInChI[], + int ppnNumComponents[], + int state ) { switch (state) { - case AST_MOBILE_H_GROUP_EQ: - if (bMobileH != TAUT_YES) - { - return RI_ERR_PROGR; - } - if (memcmp(str, "gE:", 3)) - { - return 0; - } - break; - case AST_MOBILE_H_ISO_GROUP_EQ: - if (bMobileH != TAUT_YES) - { - return RI_ERR_PROGR; - } - if (memcmp(str, "gE:", 3)) - { - return 0; - } - break; - default: - return RI_ERR_PROGR; + case AST_MOBILE_H_GROUP_EQ: + if (bMobileH != TAUT_YES) + { + return RI_ERR_PROGR; + } + if (memcmp( str, "gE:", 3 )) + { + return 0; + } + break; + case AST_MOBILE_H_ISO_GROUP_EQ: + if (bMobileH != TAUT_YES) + { + return RI_ERR_PROGR; + } + if (memcmp( str, "gE:", 3 )) + { + return 0; + } + break; + default: + return RI_ERR_PROGR; } return 1; @@ -4246,56 +4246,56 @@ int ParseAuxSegmentGroupEqu(const char* str, /**************************************************************************** Read and skip AuxInfo segment sp3 inv info, , "/it:" segment ****************************************************************************/ -int ParseAuxSegmentSp3Inv(const char* str, - int bMobileH, - INChI* pInpInChI[], - int ppnNumComponents[], - int state) +int ParseAuxSegmentSp3Inv( const char *str, + int bMobileH, + INChI *pInpInChI[], + int ppnNumComponents[], + int state ) { switch (state) { - case AST_MOBILE_H_SP3_INV: - if (bMobileH != TAUT_YES) - { - return RI_ERR_PROGR; - } - if (memcmp(str, "it:", 3)) - { - return 0; - } - break; - case AST_MOBILE_H_ISO_SP3_INV: - if (bMobileH != TAUT_YES) - { - return RI_ERR_PROGR; - } - if (memcmp(str, "it:", 3)) - { - return 0; - } - break; - case AST_FIXED_H_SP3_INV: - if (bMobileH != TAUT_NON) - { - return RI_ERR_PROGR; - } - if (memcmp(str, "it:", 3)) - { - return 0; - } - break; - case AST_FIXED_H_ISO_SP3_INV: - if (bMobileH != TAUT_NON) - { + case AST_MOBILE_H_SP3_INV: + if (bMobileH != TAUT_YES) + { + return RI_ERR_PROGR; + } + if (memcmp( str, "it:", 3 )) + { + return 0; + } + break; + case AST_MOBILE_H_ISO_SP3_INV: + if (bMobileH != TAUT_YES) + { + return RI_ERR_PROGR; + } + if (memcmp( str, "it:", 3 )) + { + return 0; + } + break; + case AST_FIXED_H_SP3_INV: + if (bMobileH != TAUT_NON) + { + return RI_ERR_PROGR; + } + if (memcmp( str, "it:", 3 )) + { + return 0; + } + break; + case AST_FIXED_H_ISO_SP3_INV: + if (bMobileH != TAUT_NON) + { + return RI_ERR_PROGR; + } + if (memcmp( str, "it:", 3 )) + { + return 0; + } + break; + default: return RI_ERR_PROGR; - } - if (memcmp(str, "it:", 3)) - { - return 0; - } - break; - default: - return RI_ERR_PROGR; } return 1; @@ -4306,56 +4306,56 @@ int ParseAuxSegmentSp3Inv(const char* str, Read and skip AuxInfo atom numbers in "/iN:"segment, for sp3 inv sub-layer at specific reading state ****************************************************************************/ -int ParseAuxSegmentSp3InvNumbers(const char* str, - int bMobileH, - INChI* pInpInChI[], - int ppnNumComponents[], - int state) +int ParseAuxSegmentSp3InvNumbers( const char *str, + int bMobileH, + INChI *pInpInChI[], + int ppnNumComponents[], + int state ) { switch (state) { - case AST_MOBILE_H_SP3_INV_NUMBERS: - if (bMobileH != TAUT_YES) - { - return RI_ERR_PROGR; - } - if (memcmp(str, "iN:", 3)) - { - return 0; - } - break; - case AST_MOBILE_H_ISO_SP3_INV_NUMBERS: - if (bMobileH != TAUT_YES) - { - return RI_ERR_PROGR; - } - if (memcmp(str, "iN:", 3)) - { - return 0; - } - break; - case AST_FIXED_H_SP3_INV_NUMBERS: - if (bMobileH != TAUT_NON) - { - return RI_ERR_PROGR; - } - if (memcmp(str, "iN:", 3)) - { - return 0; - } - break; - case AST_FIXED_H_ISO_SP3_INV_NUMBERS: - if (bMobileH != TAUT_NON) - { + case AST_MOBILE_H_SP3_INV_NUMBERS: + if (bMobileH != TAUT_YES) + { + return RI_ERR_PROGR; + } + if (memcmp( str, "iN:", 3 )) + { + return 0; + } + break; + case AST_MOBILE_H_ISO_SP3_INV_NUMBERS: + if (bMobileH != TAUT_YES) + { + return RI_ERR_PROGR; + } + if (memcmp( str, "iN:", 3 )) + { + return 0; + } + break; + case AST_FIXED_H_SP3_INV_NUMBERS: + if (bMobileH != TAUT_NON) + { + return RI_ERR_PROGR; + } + if (memcmp( str, "iN:", 3 )) + { + return 0; + } + break; + case AST_FIXED_H_ISO_SP3_INV_NUMBERS: + if (bMobileH != TAUT_NON) + { + return RI_ERR_PROGR; + } + if (memcmp( str, "iN:", 3 )) + { + return 0; + } + break; + default: return RI_ERR_PROGR; - } - if (memcmp(str, "iN:", 3)) - { - return 0; - } - break; - default: - return RI_ERR_PROGR; } return 1; @@ -4365,18 +4365,18 @@ int ParseAuxSegmentSp3InvNumbers(const char* str, /**************************************************************************** Read and skip AuxInfo sp3 CRV (charge, radical, valence) segment ****************************************************************************/ -int ParseAuxSegmentReverseCRV(const char* str, int state) +int ParseAuxSegmentReverseCRV( const char *str, int state ) { switch (state) { - case AST_REVERSE_INFO_CRV: - if (memcmp(str, "CRV:", 4)) - { - return 0; - } - break; - default: - return RI_ERR_PROGR; + case AST_REVERSE_INFO_CRV: + if (memcmp( str, "CRV:", 4 )) + { + return 0; + } + break; + default: + return RI_ERR_PROGR; } return 1; @@ -4386,18 +4386,18 @@ int ParseAuxSegmentReverseCRV(const char* str, int state) /**************************************************************************** Read and skip AuxInfo segment ReverseAtoms ****************************************************************************/ -int ParseAuxSegmentReverseAtoms(const char* str, int state) +int ParseAuxSegmentReverseAtoms( const char *str, int state ) { switch (state) { - case AST_REVERSE_INFO_ATOMS: - if (memcmp(str, "rA:", 3)) - { - return 0; - } - break; - default: - return RI_ERR_PROGR; + case AST_REVERSE_INFO_ATOMS: + if (memcmp( str, "rA:", 3 )) + { + return 0; + } + break; + default: + return RI_ERR_PROGR; } return 1; @@ -4407,18 +4407,18 @@ int ParseAuxSegmentReverseAtoms(const char* str, int state) /**************************************************************************** Read and skip AuxInfo segment ReverseBonds ****************************************************************************/ -int ParseAuxSegmentReverseBonds(const char* str, int state) +int ParseAuxSegmentReverseBonds( const char *str, int state ) { switch (state) { - case AST_REVERSE_INFO_BONDS: - if (memcmp(str, "rB:", 3)) - { - return 0; - } - break; - default: - return RI_ERR_PROGR; + case AST_REVERSE_INFO_BONDS: + if (memcmp( str, "rB:", 3 )) + { + return 0; + } + break; + default: + return RI_ERR_PROGR; } return 1; @@ -4426,36 +4426,36 @@ int ParseAuxSegmentReverseBonds(const char* str, int state) /* Parse and save AuxInfo segment ReverseXYZ */ -int ParseAuxSegmentReverseXYZ(const char* str, - XYZ_COORD** ppXYZ, - int state) +int ParseAuxSegmentReverseXYZ( const char *str, + XYZ_COORD **ppXYZ, + int state ) { - const char* pStart, * p, * q; - XYZ_COORD* pXYZ = NULL; + const char *pStart, *p, *q; + XYZ_COORD *pXYZ = NULL; int nLenXYZ = 0, i, j; switch (state) { - case AST_REVERSE_INFO_XYZ: - if (memcmp(str, "rC:", 3)) - { - return 0; - } - break; - default: - return RI_ERR_PROGR; + case AST_REVERSE_INFO_XYZ: + if (memcmp( str, "rC:", 3 )) + { + return 0; + } + break; + default: + return RI_ERR_PROGR; } - pStart = (char*)str + 3; + pStart = (char *) str + 3; /* Count coordinates */ for (p = pStart, nLenXYZ = 0; *p; p++) { - nLenXYZ += (*p == ';'); + nLenXYZ += ( *p == ';' ); } if (!nLenXYZ) { return RI_ERR_SYNTAX; } - if (NULL == (pXYZ = (XYZ_COORD*)inchi_calloc(nLenXYZ, sizeof(pXYZ[0])))) + if (NULL == ( pXYZ = (XYZ_COORD *) inchi_calloc( nLenXYZ, sizeof( pXYZ[0] ) ) )) { return RI_ERR_ALLOC; } @@ -4463,8 +4463,8 @@ int ParseAuxSegmentReverseXYZ(const char* str, { for (j = 0; j < 3; j++) { - pXYZ[i].xyz[j] = inchi_strtod(p, &q); - p = q + (*q == ','); + pXYZ[i].xyz[j] = inchi_strtod( p, &q ); + p = q + ( *q == ',' ); } if (*p != ';') { @@ -4485,16 +4485,16 @@ int ParseAuxSegmentReverseXYZ(const char* str, /**************************************************************************** Parse and save atom coordinates from AuxInfo ****************************************************************************/ -int AddAuxSegmentCoord(int nRet, - XYZ_COORD* pXYZ, - int nLenXYZ, - INChI* pInpInChI[INCHI_NUM][TAUT_NUM], - int nNumComponents[INCHI_NUM][TAUT_NUM]) +int AddAuxSegmentCoord( int nRet, + XYZ_COORD *pXYZ, + int nLenXYZ, + INChI *pInpInChI[INCHI_NUM][TAUT_NUM], + int nNumComponents[INCHI_NUM][TAUT_NUM] ) { int iINChI, j, k, n, m, numAt[TAUT_NUM], num_at, ret = 0; /* djb-rwth: removing redundant variables */ - INChI* pInChI = NULL; - INChI* pAltInChI = NULL; - XYZ_COORD* pxyz; + INChI *pInChI = NULL; + INChI *pAltInChI = NULL; + XYZ_COORD *pxyz; /* Propagate numberings (original:canonical atom mapping) */ /* NB: we already saved isotopic numbering, if any, into the first nNumberOfAtoms elements of INChI::nPossibleLocationsOfIsotopicH, */ @@ -4677,11 +4677,11 @@ int AddAuxSegmentCoord(int nRet, /**************************************************************************** ReadInChICoord (from AuxInfo if present) ****************************************************************************/ -int ReadInChICoord(INCHI_IOSTREAM* pInp, - SEGM_LINE* pLine, - int* pState, - INChI* pInpInChI[INCHI_NUM][TAUT_NUM], - int nNumComponents[INCHI_NUM][TAUT_NUM]) +int ReadInChICoord( INCHI_IOSTREAM *pInp, + SEGM_LINE *pLine, + int *pState, + INChI *pInpInChI[INCHI_NUM][TAUT_NUM], + int nNumComponents[INCHI_NUM][TAUT_NUM] ) { int c; /* djb-rwth: removing redundant variables */ @@ -4695,7 +4695,7 @@ int ReadInChICoord(INCHI_IOSTREAM* pInp, const char szToken[] = INCHI_TOKEN; XYZ_COORD - * pXYZ = NULL; + *pXYZ = NULL; *pState = 0; INCHI_HEAPCHK @@ -4707,7 +4707,7 @@ int ReadInChICoord(INCHI_IOSTREAM* pInp, } else { - c = nGetInChISegment(pInp, pLine, szToken); + c = nGetInChISegment( pInp, pLine, szToken ); } if (c == RI_ERR_EOF && !pLine->len && !pLine->str[0]) { @@ -4715,14 +4715,14 @@ int ReadInChICoord(INCHI_IOSTREAM* pInp, pLine->len = 0; goto exit_error; } - if (pLine->len == 0 || (c != SEG_END && c != RI_ERR_EOF && !INCHI_INP_EOL(c))) /* djb-rwth: addressing LLVM warning */ + if (pLine->len == 0 || (c != SEG_END && c != RI_ERR_EOF && !INCHI_INP_EOL( c ))) /* djb-rwth: addressing LLVM warning */ { *pState = -1; pLine->len = 0; ret = RI_ERR_PROGR; goto exit_error; } - if (memcmp(pLine->str, "AuxInfo=", 8)) + if (memcmp( pLine->str, "AuxInfo=", 8 )) { *pState = -1; return c; @@ -4739,19 +4739,19 @@ int ReadInChICoord(INCHI_IOSTREAM* pInp, *pState = prev_state; break; } - prev_state = state + (bReconn ? IST_HAPPENED_IN_RECMET : 0); + prev_state = state + ( bReconn ? IST_HAPPENED_IN_RECMET : 0 ); if (0 < ret) { /* read next segment */ if (c != RI_ERR_EOF && c != SEG_END) { /* abnormal reading result; should not happen */ - while (c != RI_ERR_EOF && !INCHI_INP_EOL(c)) + while (c != RI_ERR_EOF && !INCHI_INP_EOL( c )) { /* bypass to the end of line or file */ - c = getInChIChar(pInp); + c = getInChIChar( pInp ); } - ret = (c == RI_ERR_EOF) ? RI_ERR_EOF : RI_ERR_EOL; /* end of line */ + ret = ( c == RI_ERR_EOF ) ? RI_ERR_EOF : RI_ERR_EOL; /* end of line */ pLine->len = 0; pLine->c = ret; break; @@ -4763,7 +4763,7 @@ int ReadInChICoord(INCHI_IOSTREAM* pInp, } if (c == SEG_END) { - c = nGetInChISegment(pInp, pLine, szToken); + c = nGetInChISegment( pInp, pLine, szToken ); } if (c < 0) { @@ -4780,53 +4780,102 @@ int ReadInChICoord(INCHI_IOSTREAM* pInp, /* Process the seqment */ switch (state) { - case AST_VERSION: - /* Mobile H */ - bMobileH = TAUT_YES; - ret = ParseAuxSegmentVersion(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state); - state = AST_MOBILE_H_NUMBERS; - break; - case AST_MOBILE_H_NUMBERS: - ret = ParseAuxSegmentNumbers(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc); - state = AST_MOBILE_H_ATOM_EQ; - break; - case AST_MOBILE_H_ATOM_EQ: - ret = ParseAuxSegmentAtomEqu(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state); - state = AST_MOBILE_H_GROUP_EQ; - break; - case AST_MOBILE_H_GROUP_EQ: - ret = ParseAuxSegmentGroupEqu(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state); - state = AST_MOBILE_H_SP3_INV; - break; - case AST_MOBILE_H_SP3_INV: - ret = ParseAuxSegmentSp3Inv(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state); - state = AST_MOBILE_H_SP3_INV_NUMBERS; - break; - case AST_MOBILE_H_SP3_INV_NUMBERS: - ret = ParseAuxSegmentSp3InvNumbers(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state); - state = AST_MOBILE_H_ISO_LAYER_FORK; - break; + case AST_VERSION: + /* Mobile H */ + bMobileH = TAUT_YES; + ret = ParseAuxSegmentVersion( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state ); + state = AST_MOBILE_H_NUMBERS; + break; + case AST_MOBILE_H_NUMBERS: + ret = ParseAuxSegmentNumbers( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc ); + state = AST_MOBILE_H_ATOM_EQ; + break; + case AST_MOBILE_H_ATOM_EQ: + ret = ParseAuxSegmentAtomEqu( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state ); + state = AST_MOBILE_H_GROUP_EQ; + break; + case AST_MOBILE_H_GROUP_EQ: + ret = ParseAuxSegmentGroupEqu( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state ); + state = AST_MOBILE_H_SP3_INV; + break; + case AST_MOBILE_H_SP3_INV: + ret = ParseAuxSegmentSp3Inv( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state ); + state = AST_MOBILE_H_SP3_INV_NUMBERS; + break; + case AST_MOBILE_H_SP3_INV_NUMBERS: + ret = ParseAuxSegmentSp3InvNumbers( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state ); + state = AST_MOBILE_H_ISO_LAYER_FORK; + break; - case AST_MOBILE_H_ISO_LAYER_FORK: - if (!memcmp(pLine->str, "I:", 2)) - { - state = AST_MOBILE_H_ISO_NUMBERS; - } - else if (!inchi_memicmp(pLine->str, "F:", 2)) - { - state = AST_FIXED_H_NUMBERS; - bMobileH = TAUT_NON; - } - else if ( /*bReconn == INCHI_BAS &&*/ !inchi_memicmp(pLine->str, "CRV:", 4)) - { - state = AST_REVERSE_INFO_CRV; - } - else - if (bReconn == INCHI_BAS && !inchi_memicmp(pLine->str, "rA:", 3)) + case AST_MOBILE_H_ISO_LAYER_FORK: + if (!memcmp( pLine->str, "I:", 2 )) + { + state = AST_MOBILE_H_ISO_NUMBERS; + } + else if (!inchi_memicmp( pLine->str, "F:", 2 )) + { + state = AST_FIXED_H_NUMBERS; + bMobileH = TAUT_NON; + } + else if ( /*bReconn == INCHI_BAS &&*/ !inchi_memicmp( pLine->str, "CRV:", 4 )) + { + state = AST_REVERSE_INFO_CRV; + } + else + if (bReconn == INCHI_BAS && !inchi_memicmp( pLine->str, "rA:", 3 )) + { + state = AST_REVERSE_INFO_ATOMS; + } + else if (bReconn == INCHI_BAS && !inchi_memicmp( pLine->str, "R:", 3 )) + { + ret = 1; /* read the next segment */ + state = AST_VERSION; + bMobileH = TAUT_YES; + bReconn = INCHI_REC; + } + else + { + ret = RI_ERR_SYNTAX; + } + break; + + /* Mobile H, isotopic */ + case AST_MOBILE_H_ISO_NUMBERS: + ret = ParseAuxSegmentNumbers( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc ); + state = AST_MOBILE_H_ISO_ATOM_EQ; + break; + case AST_MOBILE_H_ISO_ATOM_EQ: + ret = ParseAuxSegmentAtomEqu( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state ); + state = AST_MOBILE_H_ISO_GROUP_EQ; + break; + case AST_MOBILE_H_ISO_GROUP_EQ: + ret = ParseAuxSegmentGroupEqu( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state ); + state = AST_MOBILE_H_ISO_SP3_INV; + break; + case AST_MOBILE_H_ISO_SP3_INV: + ret = ParseAuxSegmentSp3Inv( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state ); + state = AST_MOBILE_H_ISO_SP3_INV_NUMBERS; + break; + case AST_MOBILE_H_ISO_SP3_INV_NUMBERS: + ret = ParseAuxSegmentSp3InvNumbers( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state ); + state = AST_FIXED_H_LAYER_FORK; + break; + + case AST_FIXED_H_LAYER_FORK: + if (!inchi_memicmp( pLine->str, "F:", 2 )) + { + state = AST_FIXED_H_NUMBERS; + bMobileH = TAUT_NON; + } + else if ( /*bReconn == INCHI_BAS &&*/ !inchi_memicmp( pLine->str, "CRV:", 4 )) + { + state = AST_REVERSE_INFO_CRV; + } + else if (bReconn == INCHI_BAS && !inchi_memicmp( pLine->str, "rA:", 3 )) { state = AST_REVERSE_INFO_ATOMS; } - else if (bReconn == INCHI_BAS && !inchi_memicmp(pLine->str, "R:", 3)) + else if (bReconn == INCHI_BAS && !inchi_memicmp( pLine->str, "R:", 3 )) { ret = 1; /* read the next segment */ state = AST_VERSION; @@ -4837,159 +4886,110 @@ int ReadInChICoord(INCHI_IOSTREAM* pInp, { ret = RI_ERR_SYNTAX; } - break; - - /* Mobile H, isotopic */ - case AST_MOBILE_H_ISO_NUMBERS: - ret = ParseAuxSegmentNumbers(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc); - state = AST_MOBILE_H_ISO_ATOM_EQ; - break; - case AST_MOBILE_H_ISO_ATOM_EQ: - ret = ParseAuxSegmentAtomEqu(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state); - state = AST_MOBILE_H_ISO_GROUP_EQ; - break; - case AST_MOBILE_H_ISO_GROUP_EQ: - ret = ParseAuxSegmentGroupEqu(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state); - state = AST_MOBILE_H_ISO_SP3_INV; - break; - case AST_MOBILE_H_ISO_SP3_INV: - ret = ParseAuxSegmentSp3Inv(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state); - state = AST_MOBILE_H_ISO_SP3_INV_NUMBERS; - break; - case AST_MOBILE_H_ISO_SP3_INV_NUMBERS: - ret = ParseAuxSegmentSp3InvNumbers(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state); - state = AST_FIXED_H_LAYER_FORK; - break; + break; - case AST_FIXED_H_LAYER_FORK: - if (!inchi_memicmp(pLine->str, "F:", 2)) - { - state = AST_FIXED_H_NUMBERS; - bMobileH = TAUT_NON; - } - else if ( /*bReconn == INCHI_BAS &&*/ !inchi_memicmp(pLine->str, "CRV:", 4)) - { - state = AST_REVERSE_INFO_CRV; - } - else if (bReconn == INCHI_BAS && !inchi_memicmp(pLine->str, "rA:", 3)) - { - state = AST_REVERSE_INFO_ATOMS; - } - else if (bReconn == INCHI_BAS && !inchi_memicmp(pLine->str, "R:", 3)) - { - ret = 1; /* read the next segment */ - state = AST_VERSION; - bMobileH = TAUT_YES; - bReconn = INCHI_REC; - } - else - { - ret = RI_ERR_SYNTAX; - } - break; + case AST_FIXED_H_NUMBERS: + ret = ParseAuxSegmentNumbers( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc ); + state = AST_FIXED_H_ATOM_EQ; + break; + case AST_FIXED_H_ATOM_EQ: + ret = ParseAuxSegmentAtomEqu( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state ); + state = AST_FIXED_H_SP3_INV; + break; + case AST_FIXED_H_SP3_INV: + ret = ParseAuxSegmentSp3Inv( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state ); + state = AST_FIXED_H_SP3_INV_NUMBERS; + break; + case AST_FIXED_H_SP3_INV_NUMBERS: + ret = ParseAuxSegmentSp3InvNumbers( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state ); + state = AST_FIXED_H_ISO_LAYER_FORK; + break; - case AST_FIXED_H_NUMBERS: - ret = ParseAuxSegmentNumbers(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc); - state = AST_FIXED_H_ATOM_EQ; - break; - case AST_FIXED_H_ATOM_EQ: - ret = ParseAuxSegmentAtomEqu(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state); - state = AST_FIXED_H_SP3_INV; - break; - case AST_FIXED_H_SP3_INV: - ret = ParseAuxSegmentSp3Inv(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state); - state = AST_FIXED_H_SP3_INV_NUMBERS; - break; - case AST_FIXED_H_SP3_INV_NUMBERS: - ret = ParseAuxSegmentSp3InvNumbers(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state); - state = AST_FIXED_H_ISO_LAYER_FORK; - break; + case AST_FIXED_H_ISO_LAYER_FORK: + if (!memcmp( pLine->str, "I:", 2 )) + { + state = AST_FIXED_H_ISO_NUMBERS; + } + else if ( /*bReconn == INCHI_BAS &&*/ !inchi_memicmp( pLine->str, "CRV:", 4 )) + { + state = AST_REVERSE_INFO_CRV; + } + else if (bReconn == INCHI_BAS && !inchi_memicmp( pLine->str, "rA:", 3 )) + { + state = AST_REVERSE_INFO_ATOMS; + } + else if (bReconn == INCHI_BAS && !inchi_memicmp( pLine->str, "R:", 3 )) + { + ret = 1; /* read the next segment */ + state = AST_VERSION; + bMobileH = TAUT_YES; + bReconn = INCHI_REC; + } + else + { + ret = RI_ERR_SYNTAX; + } + break; - case AST_FIXED_H_ISO_LAYER_FORK: - if (!memcmp(pLine->str, "I:", 2)) - { - state = AST_FIXED_H_ISO_NUMBERS; - } - else if ( /*bReconn == INCHI_BAS &&*/ !inchi_memicmp(pLine->str, "CRV:", 4)) - { + case AST_FIXED_H_ISO_NUMBERS: + ret = ParseAuxSegmentNumbers( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc ); + state = AST_FIXED_H_ISO_ATOM_EQ; + break; + case AST_FIXED_H_ISO_ATOM_EQ: + ret = ParseAuxSegmentAtomEqu( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state ); + state = AST_FIXED_H_SP3_INV; + break; + case AST_FIXED_H_ISO_SP3_INV: + ret = ParseAuxSegmentSp3Inv( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state ); + state = AST_FIXED_H_ISO_SP3_INV_NUMBERS; + break; + case AST_FIXED_H_ISO_SP3_INV_NUMBERS: + ret = ParseAuxSegmentSp3InvNumbers( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state ); state = AST_REVERSE_INFO_CRV; - } - else if (bReconn == INCHI_BAS && !inchi_memicmp(pLine->str, "rA:", 3)) - { + break; + case AST_REVERSE_INFO_CRV: + ret = ParseAuxSegmentReverseCRV( pLine->str, state ); + /* state = (bReconn == INCHI_BAS)? AST_REVERSE_INFO_ATOMS : AST_RECONNECTED_LAYER_FORK;*/ state = AST_REVERSE_INFO_ATOMS; - } - else if (bReconn == INCHI_BAS && !inchi_memicmp(pLine->str, "R:", 3)) - { - ret = 1; /* read the next segment */ - state = AST_VERSION; - bMobileH = TAUT_YES; - bReconn = INCHI_REC; - } - else - { - ret = RI_ERR_SYNTAX; - } - break; - - case AST_FIXED_H_ISO_NUMBERS: - ret = ParseAuxSegmentNumbers(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc); - state = AST_FIXED_H_ISO_ATOM_EQ; - break; - case AST_FIXED_H_ISO_ATOM_EQ: - ret = ParseAuxSegmentAtomEqu(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state); - state = AST_FIXED_H_SP3_INV; - break; - case AST_FIXED_H_ISO_SP3_INV: - ret = ParseAuxSegmentSp3Inv(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state); - state = AST_FIXED_H_ISO_SP3_INV_NUMBERS; - break; - case AST_FIXED_H_ISO_SP3_INV_NUMBERS: - ret = ParseAuxSegmentSp3InvNumbers(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state); - state = AST_REVERSE_INFO_CRV; - break; - case AST_REVERSE_INFO_CRV: - ret = ParseAuxSegmentReverseCRV(pLine->str, state); - /* state = (bReconn == INCHI_BAS)? AST_REVERSE_INFO_ATOMS : AST_RECONNECTED_LAYER_FORK;*/ - state = AST_REVERSE_INFO_ATOMS; - break; - case AST_REVERSE_INFO_ATOMS: - ret = ParseAuxSegmentReverseAtoms(pLine->str, state); - state = AST_REVERSE_INFO_BONDS; - break; - case AST_REVERSE_INFO_BONDS: - ret = ParseAuxSegmentReverseBonds(pLine->str, state); - state = AST_REVERSE_INFO_XYZ; - break; - case AST_REVERSE_INFO_XYZ: - ret = ParseAuxSegmentReverseXYZ(pLine->str, &pXYZ, state); - state = AST_RECONNECTED_LAYER_FORK; - if (ret > 0) - { - nLenXYZ = ret - 1; - } - break; - case AST_RECONNECTED_LAYER_FORK: - if (bReconn == INCHI_BAS && !inchi_memicmp(pLine->str, "R:", 3)) - { - ret = 1; /* read the next segment */ - state = AST_VERSION; - bMobileH = TAUT_YES; - bReconn = INCHI_REC; - } - else - { - ret = RI_ERR_SYNTAX; - } - break; + break; + case AST_REVERSE_INFO_ATOMS: + ret = ParseAuxSegmentReverseAtoms( pLine->str, state ); + state = AST_REVERSE_INFO_BONDS; + break; + case AST_REVERSE_INFO_BONDS: + ret = ParseAuxSegmentReverseBonds( pLine->str, state ); + state = AST_REVERSE_INFO_XYZ; + break; + case AST_REVERSE_INFO_XYZ: + ret = ParseAuxSegmentReverseXYZ( pLine->str, &pXYZ, state ); + state = AST_RECONNECTED_LAYER_FORK; + if (ret > 0) + { + nLenXYZ = ret - 1; + } + break; + case AST_RECONNECTED_LAYER_FORK: + if (bReconn == INCHI_BAS && !inchi_memicmp( pLine->str, "R:", 3 )) + { + ret = 1; /* read the next segment */ + state = AST_VERSION; + bMobileH = TAUT_YES; + bReconn = INCHI_REC; + } + else + { + ret = RI_ERR_SYNTAX; + } + break; } } while (c >= 0); - ret = AddAuxSegmentCoord(ret, pXYZ, nLenXYZ, pInpInChI, nNumComponents); + ret = AddAuxSegmentCoord( ret, pXYZ, nLenXYZ, pInpInChI, nNumComponents ); exit_error: if (pXYZ) { - inchi_free(pXYZ); + inchi_free( pXYZ ); } if (ret >= 0 || c == RI_ERR_EOF || c == RI_ERR_EOL) { @@ -5003,25 +5003,25 @@ int ReadInChICoord(INCHI_IOSTREAM* pInp, /**************************************************************************** Read a single InChI input line ****************************************************************************/ -int ReadInChILine(INCHI_IOSTREAM* pInp, - SEGM_LINE* pLine, - char** pStr, - int* pState, - INChI* pInpInChI[INCHI_NUM][TAUT_NUM], - int nNumComponents[INCHI_NUM][TAUT_NUM], - REM_PROTONS nNumProtons[INCHI_NUM][TAUT_NUM], - int s[INCHI_NUM][TAUT_NUM][2], - int* bStdFormat, - int* input_has_save_opt, - unsigned char* input_save_opt_bits, - int bInchi2Struct, - OAD_Polymer** ppPolymer, - OAD_V3000** ppV3000) +int ReadInChILine( INCHI_IOSTREAM *pInp, + SEGM_LINE *pLine, + char **pStr, + int *pState, + INChI *pInpInChI[INCHI_NUM][TAUT_NUM], + int nNumComponents[INCHI_NUM][TAUT_NUM], + REM_PROTONS nNumProtons[INCHI_NUM][TAUT_NUM], + int s[INCHI_NUM][TAUT_NUM][2], + int *bStdFormat, + int *input_has_save_opt, + unsigned char *input_save_opt_bits, + int bInchi2Struct, + OAD_Polymer **ppPolymer, + OAD_V3000 **ppV3000 ) { int c, ret = RI_ERR_ALLOC, len; /* djb-rwth: removing redundant variables */ int bMobileH = TAUT_YES, bReconn = INCHI_BAS; const char szToken[] = INCHI_TOKEN; - char* p; + char *p; int state = -1, prev_state = -1; int bAbc = -1; /* -1=> undefined, 0=> decimal, 1=> abc (compressed) */ @@ -5038,59 +5038,59 @@ int ReadInChILine(INCHI_IOSTREAM* pInp, /* Parsing compressed InChI easily fails on fake/fuzzing inputs */ #endif /* memset( pLine, 0, sizeof( pLine[0] ) ); */ - * pState = 0; + *pState = 0; next_line: INCHI_HEAPCHK - /* Got "InChI=1/" */ - if (pLine->len) - { - c = pLine->c; - } - else - { - INCHI_HEAPCHK - c = nGetInChISegment(pInp, pLine, szToken); - INCHI_HEAPCHK - } - if (pLine->str && (c == RI_ERR_EOF && !pLine->len && !pLine->str[0])) /* djb-rwth: fixing a NULL pointer dereference */ + /* Got "InChI=1/" */ + if (pLine->len) { - ret = c; - goto exit_function; + c = pLine->c; + } + else + { + INCHI_HEAPCHK + c = nGetInChISegment( pInp, pLine, szToken ); + INCHI_HEAPCHK } + if (pLine->str && (c == RI_ERR_EOF && !pLine->len && !pLine->str[0])) /* djb-rwth: fixing a NULL pointer dereference */ + { + ret = c; + goto exit_function; + } INCHI_HEAPCHK - if (pLine->str && (pLine->len == 0 || (c != SEG_END && c != RI_ERR_EOF) || !(p = strstr(pLine->str, "InChI=1")))) /* djb-rwth: fixing a NULL pointer dereference; addressing LLVM warning; ignoring LLVM warning: value used */ + if (pLine->str && (pLine->len == 0 || (c != SEG_END && c != RI_ERR_EOF) || !( p = strstr( pLine->str, "InChI=1" ) ))) /* djb-rwth: fixing a NULL pointer dereference; addressing LLVM warning; ignoring LLVM warning: value used */ { - if (pLine->str && pLine->str == strstr(pLine->str, "Structure")) + if (pLine->str && pLine->str == strstr( pLine->str, "Structure" )) { if (*pStr) { INCHI_HEAPCHK - inchi_free(*pStr); + inchi_free( *pStr ); } *pStr = pLine->str; /* bypass to the end of the 'Structure nnn' line */ - memset(pLine, 0, sizeof(pLine[0])); /* djb-rwth: memset_s C11/Annex K variant? */ - while (c && !INCHI_INP_EOL(c)) + memset( pLine, 0, sizeof( pLine[0] ) ); /* djb-rwth: memset_s C11/Annex K variant? */ + while (c && !INCHI_INP_EOL( c )) { - c = getInChIChar(pInp); + c = getInChIChar( pInp ); } goto next_line; } /* bypass to the end of unrecognized line */ - while (c != RI_ERR_EOF && !INCHI_INP_EOL(c)) + while (c != RI_ERR_EOF && !INCHI_INP_EOL( c )) { - c = getInChIChar(pInp); + c = getInChIChar( pInp ); } pLine->len = 0; INCHI_HEAPCHK - goto next_line; + goto next_line; } /* Check if got a standard InChI */ - if (pLine->str && (pLine->len == len_std_prefix) && (pLine->str[len_std_prefix - 1] == 'S')) /* djb-rwth: fixing a NULL pointer dereference */ + if (pLine->str && ( pLine->len == len_std_prefix ) && ( pLine->str[len_std_prefix - 1] == 'S' )) /* djb-rwth: fixing a NULL pointer dereference */ { *bStdFormat = 1; } @@ -5110,7 +5110,7 @@ int ReadInChILine(INCHI_IOSTREAM* pInp, *pState = prev_state; break; } - prev_state = state + (bReconn ? IST_HAPPENED_IN_RECMET : 0); + prev_state = state + ( bReconn ? IST_HAPPENED_IN_RECMET : 0 ); if (0 < ret) { /* read next segment */ @@ -5124,10 +5124,10 @@ int ReadInChILine(INCHI_IOSTREAM* pInp, *input_has_save_opt = 1; } k = 0; - while (c != RI_ERR_EOF && !INCHI_INP_EOL(c)) + while (c != RI_ERR_EOF && !INCHI_INP_EOL( c )) { /* bypass to the end of line or file */ - c = getInChIChar(pInp); + c = getInChIChar( pInp ); k++; if (k == 1) { @@ -5150,7 +5150,7 @@ int ReadInChILine(INCHI_IOSTREAM* pInp, else { /* may be SaveOpt - analyze the content */ - if ((let2 >= 'A') && (let2 <= 'D')) /* letter-2 OK */ + if (( let2 >= 'A' ) && ( let2 <= 'D' )) /* letter-2 OK */ { *input_has_save_opt = 0; *input_save_opt_bits = 0; @@ -5158,7 +5158,7 @@ int ReadInChILine(INCHI_IOSTREAM* pInp, { if (a2p[k] == let1) /* letter-1 OK */ { - *input_save_opt_bits = (unsigned char)k; + *input_save_opt_bits = (unsigned char) k; *input_has_save_opt = 1; break; } @@ -5177,7 +5177,7 @@ int ReadInChILine(INCHI_IOSTREAM* pInp, } } - ret = (c == RI_ERR_EOF) ? RI_ERR_EOF : RI_ERR_EOL; /* end of line */ + ret = ( c == RI_ERR_EOF ) ? RI_ERR_EOF : RI_ERR_EOL; /* end of line */ pLine->len = 0; pLine->c = ret; break; /* exit */ @@ -5189,7 +5189,7 @@ int ReadInChILine(INCHI_IOSTREAM* pInp, } if (c == SEG_END) { - c = nGetInChISegment(pInp, pLine, szToken); + c = nGetInChISegment( pInp, pLine, szToken ); } if (c < 0) { @@ -5213,301 +5213,301 @@ int ReadInChILine(INCHI_IOSTREAM* pInp, switch (state) { /* Mobile H, M */ /* / */ - case IST_MOBILE_H_FORMULA: - bMobileH = TAUT_YES; + case IST_MOBILE_H_FORMULA: + bMobileH = TAUT_YES; #if ( FIX_GAF_2019_2==1 ) - /* hack: pass state in na_total (will be updated in ParseSegmentFormula anyway) */ - na_total = state; + /* hack: pass state in na_total (will be updated in ParseSegmentFormula anyway) */ + na_total = state; #endif - ret = ParseSegmentFormula(pLine->str, bMobileH, pInpInChI[bReconn], - nNumComponents[bReconn], &na_total); - state = IST_MOBILE_H_CONNECTIONS; - break; - case IST_MOBILE_H_CONNECTIONS: /* /c */ - ret = ParseSegmentConnections(pLine->str, bMobileH, &pInpInChI[bReconn][bMobileH], - &nNumComponents[bReconn][bMobileH], &bAbc, &nb_total); - state = IST_MOBILE_H; - break; - case IST_MOBILE_H: /* /h */ - ret = ParseSegmentMobileH(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], &bAbc); - state = IST_MOBILE_H_CHARGE; - break; - case IST_MOBILE_H_CHARGE: /* /q */ - ret = ParseSegmentCharge(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn]); - state = IST_MOBILE_H_PROTONS; - break; - case IST_MOBILE_H_PROTONS: /* /p */ - ret = ParseSegmentProtons(pLine->str, bMobileH, nNumProtons[bReconn], nNumComponents[bReconn]); - state = IST_MOBILE_H_POLYMER; - break; - case IST_MOBILE_H_POLYMER: /* /z */ - ret = ParseSegmentPolymer(pLine->str, bMobileH, - nNumProtons[bReconn], nNumComponents[bReconn], - na_total, nb_total, bInchi2Struct, ppPolymer, ppV3000); - if (*ppPolymer) - (*ppPolymer)->is_in_reconn = bReconn; - state = IST_MOBILE_H_SP2; - break; - case IST_MOBILE_H_SP2: /* /b */ - ret = ParseSegmentSp2(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc); - state = IST_MOBILE_H_SP3; - break; - case IST_MOBILE_H_SP3: /* t */ - ret = ParseSegmentSp3(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc); - state = IST_MOBILE_H_SP3_M; - break; - case IST_MOBILE_H_SP3_M: /* /m */ - ret = ParseSegmentSp3m(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state); - state = IST_MOBILE_H_SP3_S; - break; - case IST_MOBILE_H_SP3_S: /* /s */ - ret = ParseSegmentSp3s(pLine->str, bMobileH, pInpInChI[bReconn], s[bReconn], nNumComponents[bReconn], state); - state = IST_MOBILE_H_ISO_LAYER_FORK; - break; - case IST_MOBILE_H_ISO_LAYER_FORK: - /* find layer type after M */ - ret = 0; - switch (pLine->str[0]) - { - case 'i': - state = IST_MOBILE_H_ISO_ATOMS; /* MI */ + ret = ParseSegmentFormula( pLine->str, bMobileH, pInpInChI[bReconn], + nNumComponents[bReconn], &na_total ); + state = IST_MOBILE_H_CONNECTIONS; break; - case 'f': - state = IST_FIXED_H_FORMULA; /* F */ + case IST_MOBILE_H_CONNECTIONS: /* /c */ + ret = ParseSegmentConnections( pLine->str, bMobileH, &pInpInChI[bReconn][bMobileH], + &nNumComponents[bReconn][bMobileH], &bAbc, &nb_total ); + state = IST_MOBILE_H; break; - case 'r': - state = IST_RECONNECTED_FORMULA; /* reconnected */ + case IST_MOBILE_H: /* /h */ + ret = ParseSegmentMobileH( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], &bAbc ); + state = IST_MOBILE_H_CHARGE; break; - default: - ret = RI_ERR_SYNTAX; - } - if (INCHI_INP_EOL(c) && ret == 0 && !pLine->str[1]) - { - prev_state = state + (bReconn ? IST_HAPPENED_IN_RECMET : 0); - ret = RI_ERR_SYNTAX; /* empty layer /i or /f or /r at the end of InChI line */ - } - else - { - if (!ret && state != IST_MOBILE_H_ISO_ATOMS) + case IST_MOBILE_H_CHARGE: /* /q */ + ret = ParseSegmentCharge( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn] ); + state = IST_MOBILE_H_PROTONS; + break; + case IST_MOBILE_H_PROTONS: /* /p */ + ret = ParseSegmentProtons( pLine->str, bMobileH, nNumProtons[bReconn], nNumComponents[bReconn] ); + state = IST_MOBILE_H_POLYMER; + break; + case IST_MOBILE_H_POLYMER: /* /z */ + ret = ParseSegmentPolymer( pLine->str, bMobileH, + nNumProtons[bReconn], nNumComponents[bReconn], + na_total, nb_total, bInchi2Struct, ppPolymer, ppV3000 ); + if (*ppPolymer) + ( *ppPolymer )->is_in_reconn = bReconn; + state = IST_MOBILE_H_SP2; + break; + case IST_MOBILE_H_SP2: /* /b */ + ret = ParseSegmentSp2( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc ); + state = IST_MOBILE_H_SP3; + break; + case IST_MOBILE_H_SP3: /* t */ + ret = ParseSegmentSp3( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc ); + state = IST_MOBILE_H_SP3_M; + break; + case IST_MOBILE_H_SP3_M: /* /m */ + ret = ParseSegmentSp3m( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state ); + state = IST_MOBILE_H_SP3_S; + break; + case IST_MOBILE_H_SP3_S: /* /s */ + ret = ParseSegmentSp3s( pLine->str, bMobileH, pInpInChI[bReconn], s[bReconn], nNumComponents[bReconn], state ); + state = IST_MOBILE_H_ISO_LAYER_FORK; + break; + case IST_MOBILE_H_ISO_LAYER_FORK: + /* find layer type after M */ + ret = 0; + switch (pLine->str[0]) { - len = (int)strlen(pLine->str); - if (len > 1) - { - memmove(pLine->str, pLine->str + 1, len); - } - else + case 'i': + state = IST_MOBILE_H_ISO_ATOMS; /* MI */ + break; + case 'f': + state = IST_FIXED_H_FORMULA; /* F */ + break; + case 'r': + state = IST_RECONNECTED_FORMULA; /* reconnected */ + break; + default: + ret = RI_ERR_SYNTAX; + } + if (INCHI_INP_EOL( c ) && ret == 0 && !pLine->str[1]) + { + prev_state = state + ( bReconn ? IST_HAPPENED_IN_RECMET : 0 ); + ret = RI_ERR_SYNTAX; /* empty layer /i or /f or /r at the end of InChI line */ + } + else + { + if (!ret && state != IST_MOBILE_H_ISO_ATOMS) { - ret = 1; /* read the next segment */ + len = (int) strlen( pLine->str ); + if (len > 1) + { + memmove(pLine->str, pLine->str + 1, len); + } + else + { + ret = 1; /* read the next segment */ + } } } - } - break; - /* Mobile H, isotopic, MI */ - case IST_MOBILE_H_ISO_ATOMS: /* i */ - ret = ParseSegmentIsoAtoms(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc); - state = IST_MOBILE_H_ISO_EXCH_H; - break; - case IST_MOBILE_H_ISO_EXCH_H: /* /i/h */ - ret = ParseSegmentIsoExchgH(pLine->str, bMobileH, nNumProtons[bReconn], nNumComponents[bReconn], state, &bAbc); - state = IST_MOBILE_H_ISO_SP2; - break; - case IST_MOBILE_H_ISO_SP2: /* /i/b */ - ret = ParseSegmentSp2(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc); - state = IST_MOBILE_H_ISO_SP3; - break; - case IST_MOBILE_H_ISO_SP3: /* /i/t */ - ret = ParseSegmentSp3(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc); - state = IST_MOBILE_H_ISO_SP3_M; - break; - case IST_MOBILE_H_ISO_SP3_M: /* /i/m */ - ret = ParseSegmentSp3m(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state); - state = IST_MOBILE_H_ISO_SP3_S; - break; - case IST_MOBILE_H_ISO_SP3_S: /* /i/s */ - ret = ParseSegmentSp3s(pLine->str, bMobileH, pInpInChI[bReconn], s[bReconn], nNumComponents[bReconn], state); - state = IST_FIXED_H_LAYER_FORK; - break; - case IST_FIXED_H_LAYER_FORK: - /* find layer type after MI */ - ret = 0; - switch (pLine->str[0]) - { - case 'f': - state = IST_FIXED_H_FORMULA; /* F */ break; - case 'r': - state = IST_RECONNECTED_FORMULA; /* reconnected */ + /* Mobile H, isotopic, MI */ + case IST_MOBILE_H_ISO_ATOMS: /* i */ + ret = ParseSegmentIsoAtoms( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc ); + state = IST_MOBILE_H_ISO_EXCH_H; break; - default: - ret = RI_ERR_SYNTAX; - } - if (INCHI_INP_EOL(c) && ret == 0 && !pLine->str[1]) - { - prev_state = state + (bReconn ? IST_HAPPENED_IN_RECMET : 0); - ret = RI_ERR_SYNTAX; /* empty layer /f or /r at the end of InChI line */ - } - else - { - if (!ret) + case IST_MOBILE_H_ISO_EXCH_H: /* /i/h */ + ret = ParseSegmentIsoExchgH( pLine->str, bMobileH, nNumProtons[bReconn], nNumComponents[bReconn], state, &bAbc ); + state = IST_MOBILE_H_ISO_SP2; + break; + case IST_MOBILE_H_ISO_SP2: /* /i/b */ + ret = ParseSegmentSp2( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc ); + state = IST_MOBILE_H_ISO_SP3; + break; + case IST_MOBILE_H_ISO_SP3: /* /i/t */ + ret = ParseSegmentSp3( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc ); + state = IST_MOBILE_H_ISO_SP3_M; + break; + case IST_MOBILE_H_ISO_SP3_M: /* /i/m */ + ret = ParseSegmentSp3m( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state ); + state = IST_MOBILE_H_ISO_SP3_S; + break; + case IST_MOBILE_H_ISO_SP3_S: /* /i/s */ + ret = ParseSegmentSp3s( pLine->str, bMobileH, pInpInChI[bReconn], s[bReconn], nNumComponents[bReconn], state ); + state = IST_FIXED_H_LAYER_FORK; + break; + case IST_FIXED_H_LAYER_FORK: + /* find layer type after MI */ + ret = 0; + switch (pLine->str[0]) { - len = (int)strlen(pLine->str); - if (len > 1) - { - memmove(pLine->str, pLine->str + 1, len); - } - else + case 'f': + state = IST_FIXED_H_FORMULA; /* F */ + break; + case 'r': + state = IST_RECONNECTED_FORMULA; /* reconnected */ + break; + default: + ret = RI_ERR_SYNTAX; + } + if (INCHI_INP_EOL( c ) && ret == 0 && !pLine->str[1]) + { + prev_state = state + ( bReconn ? IST_HAPPENED_IN_RECMET : 0 ); + ret = RI_ERR_SYNTAX; /* empty layer /f or /r at the end of InChI line */ + } + else + { + if (!ret) { - ret = 1; /* read the next segment */ + len = (int) strlen( pLine->str ); + if (len > 1) + { + memmove(pLine->str, pLine->str + 1, len); + } + else + { + ret = 1; /* read the next segment */ + } } } - } - break; + break; /* Fixed H, F */ - case IST_FIXED_H_FORMULA: - bMobileH = TAUT_NON; + case IST_FIXED_H_FORMULA: + bMobileH = TAUT_NON; #if ( FIX_GAF_2019_2==1 ) - /* hack: pass state in na_total (will be updated in ParseSegmentFormula anyway) */ - na_total = state; + /* hack: pass state in na_total (will be updated in ParseSegmentFormula anyway) */ + na_total = state; #endif - ret = ParseSegmentFormula(pLine->str, bMobileH, pInpInChI[bReconn], - nNumComponents[bReconn], &na_total); - state = IST_FIXED_H; - break; - case IST_FIXED_H: /* /f/h */ - ret = ParseSegmentMobileH(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], &bAbc); - state = IST_FIXED_H_CHARGE; - break; - case IST_FIXED_H_CHARGE: /* /f/q */ - ret = ParseSegmentCharge(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn]); - state = IST_FIXED_H_SP2; - break; - case IST_FIXED_H_SP2: /* /f/b */ - ret = ParseSegmentSp2(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc); - state = IST_FIXED_H_SP3; - break; - case IST_FIXED_H_SP3: /* /f/t */ - ret = ParseSegmentSp3(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc); - state = IST_FIXED_H_SP3_M; - break; - case IST_FIXED_H_SP3_M: /* /f/m */ - ret = ParseSegmentSp3m(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state); - state = IST_FIXED_H_SP3_S; - break; - case IST_FIXED_H_SP3_S: /* /f/s */ - ret = ParseSegmentSp3s(pLine->str, bMobileH, pInpInChI[bReconn], s[bReconn], nNumComponents[bReconn], state); - state = IST_FIXED_H_PERMUTATION; - break; - case IST_FIXED_H_PERMUTATION: /* /f/o */ - ret = ParseSegmentPerm(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc); - state = IST_FIXED_H_ISO_LAYER_FORK; - break; - case IST_FIXED_H_ISO_LAYER_FORK: - /* find layer type after M */ - ret = 0; - switch (pLine->str[0]) - { - case 'i': - state = IST_FIXED_H_ISO_ATOMS; /* FI */ + ret = ParseSegmentFormula( pLine->str, bMobileH, pInpInChI[bReconn], + nNumComponents[bReconn], &na_total ); + state = IST_FIXED_H; break; - case 'r': - state = IST_RECONNECTED_FORMULA; /* reconnected */ + case IST_FIXED_H: /* /f/h */ + ret = ParseSegmentMobileH( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], &bAbc ); + state = IST_FIXED_H_CHARGE; break; - default: - ret = RI_ERR_SYNTAX; - } - if (INCHI_INP_EOL(c) && ret == 0 && !pLine->str[1]) - { - prev_state = state + (bReconn ? IST_HAPPENED_IN_RECMET : 0); - ret = RI_ERR_SYNTAX; /* empty layer /i or /r at the end of InChI line */ - } - else - { - if (!ret && state != IST_FIXED_H_ISO_ATOMS) + case IST_FIXED_H_CHARGE: /* /f/q */ + ret = ParseSegmentCharge( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn] ); + state = IST_FIXED_H_SP2; + break; + case IST_FIXED_H_SP2: /* /f/b */ + ret = ParseSegmentSp2( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc ); + state = IST_FIXED_H_SP3; + break; + case IST_FIXED_H_SP3: /* /f/t */ + ret = ParseSegmentSp3( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc ); + state = IST_FIXED_H_SP3_M; + break; + case IST_FIXED_H_SP3_M: /* /f/m */ + ret = ParseSegmentSp3m( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state ); + state = IST_FIXED_H_SP3_S; + break; + case IST_FIXED_H_SP3_S: /* /f/s */ + ret = ParseSegmentSp3s( pLine->str, bMobileH, pInpInChI[bReconn], s[bReconn], nNumComponents[bReconn], state ); + state = IST_FIXED_H_PERMUTATION; + break; + case IST_FIXED_H_PERMUTATION: /* /f/o */ + ret = ParseSegmentPerm( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc ); + state = IST_FIXED_H_ISO_LAYER_FORK; + break; + case IST_FIXED_H_ISO_LAYER_FORK: + /* find layer type after M */ + ret = 0; + switch (pLine->str[0]) { - len = (int)strlen(pLine->str); - if (len > 1) - { - memmove(pLine->str, pLine->str + 1, len); - } - else + case 'i': + state = IST_FIXED_H_ISO_ATOMS; /* FI */ + break; + case 'r': + state = IST_RECONNECTED_FORMULA; /* reconnected */ + break; + default: + ret = RI_ERR_SYNTAX; + } + if (INCHI_INP_EOL( c ) && ret == 0 && !pLine->str[1]) + { + prev_state = state + ( bReconn ? IST_HAPPENED_IN_RECMET : 0 ); + ret = RI_ERR_SYNTAX; /* empty layer /i or /r at the end of InChI line */ + } + else + { + if (!ret && state != IST_FIXED_H_ISO_ATOMS) { - ret = 1; /* read the next segment */ + len = (int) strlen( pLine->str ); + if (len > 1) + { + memmove(pLine->str, pLine->str + 1, len); + } + else + { + ret = 1; /* read the next segment */ + } } } - } - break; + break; /* Fixed H, isotopic, FI */ - case IST_FIXED_H_ISO_ATOMS: /* /f/i */ - ret = ParseSegmentIsoAtoms(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc); - state = IST_FIXED_H_ISO_SP2; - break; - case IST_FIXED_H_ISO_SP2: /* /f/i/b */ - ret = ParseSegmentSp2(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc); - state = IST_FIXED_H_ISO_SP3; - break; - case IST_FIXED_H_ISO_SP3: /* /f/i/t */ - ret = ParseSegmentSp3(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc); - state = IST_FIXED_H_ISO_SP3_M; - break; - case IST_FIXED_H_ISO_SP3_M: /* /f/i/m */ - ret = ParseSegmentSp3m(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state); - state = IST_FIXED_H_ISO_SP3_S; - break; - case IST_FIXED_H_ISO_SP3_S: /* /f/i/s */ - ret = ParseSegmentSp3s(pLine->str, bMobileH, pInpInChI[bReconn], s[bReconn], nNumComponents[bReconn], state); - state = IST_FIXED_H_ISO_PERMUTATION; - break; - case IST_FIXED_H_ISO_PERMUTATION: /* /f/i/o */ - ret = ParseSegmentPerm(pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc); - state = IST_RECONNECTED_LAYER_FORK; - break; - case IST_RECONNECTED_LAYER_FORK: - /* find layer type after FI */ - ret = 0; - switch (pLine->str[0]) - { - case 'r': - state = IST_RECONNECTED_FORMULA; /* reconnected */ + case IST_FIXED_H_ISO_ATOMS: /* /f/i */ + ret = ParseSegmentIsoAtoms( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc ); + state = IST_FIXED_H_ISO_SP2; break; - default: - ret = RI_ERR_SYNTAX; - } - if (INCHI_INP_EOL(c) && ret == 0 && !pLine->str[1]) - { - prev_state = state + (bReconn ? IST_HAPPENED_IN_RECMET : 0); - ret = RI_ERR_SYNTAX; /* empty layer /r at the end of InChI line */ - } - else - { - if (!ret) + case IST_FIXED_H_ISO_SP2: /* /f/i/b */ + ret = ParseSegmentSp2( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc ); + state = IST_FIXED_H_ISO_SP3; + break; + case IST_FIXED_H_ISO_SP3: /* /f/i/t */ + ret = ParseSegmentSp3( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc ); + state = IST_FIXED_H_ISO_SP3_M; + break; + case IST_FIXED_H_ISO_SP3_M: /* /f/i/m */ + ret = ParseSegmentSp3m( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state ); + state = IST_FIXED_H_ISO_SP3_S; + break; + case IST_FIXED_H_ISO_SP3_S: /* /f/i/s */ + ret = ParseSegmentSp3s( pLine->str, bMobileH, pInpInChI[bReconn], s[bReconn], nNumComponents[bReconn], state ); + state = IST_FIXED_H_ISO_PERMUTATION; + break; + case IST_FIXED_H_ISO_PERMUTATION: /* /f/i/o */ + ret = ParseSegmentPerm( pLine->str, bMobileH, pInpInChI[bReconn], nNumComponents[bReconn], state, &bAbc ); + state = IST_RECONNECTED_LAYER_FORK; + break; + case IST_RECONNECTED_LAYER_FORK: + /* find layer type after FI */ + ret = 0; + switch (pLine->str[0]) { - len = (int)strlen(pLine->str); - if (len > 1) - { - memmove(pLine->str, pLine->str + 1, len); - } - else + case 'r': + state = IST_RECONNECTED_FORMULA; /* reconnected */ + break; + default: + ret = RI_ERR_SYNTAX; + } + if (INCHI_INP_EOL( c ) && ret == 0 && !pLine->str[1]) + { + prev_state = state + ( bReconn ? IST_HAPPENED_IN_RECMET : 0 ); + ret = RI_ERR_SYNTAX; /* empty layer /r at the end of InChI line */ + } + else + { + if (!ret) { - ret = 1; /* read the next segment */ + len = (int) strlen( pLine->str ); + if (len > 1) + { + memmove(pLine->str, pLine->str + 1, len); + } + else + { + ret = 1; /* read the next segment */ + } } } - } - break; - case IST_RECONNECTED_FORMULA: -#if ( FIX_GAF_2019_1==1 ) - if (bReconn == INCHI_REC) - { - /* reconnected layer may appear only once */ - ret = RI_ERR_SYNTAX; break; - } + case IST_RECONNECTED_FORMULA: +#if ( FIX_GAF_2019_1==1 ) + if (bReconn == INCHI_REC) + { + /* reconnected layer may appear only once */ + ret = RI_ERR_SYNTAX; + break; + } #endif - bReconn = INCHI_REC; - bMobileH = TAUT_YES; - state = IST_MOBILE_H_FORMULA; - break; + bReconn = INCHI_REC; + bMobileH = TAUT_YES; + state = IST_MOBILE_H_FORMULA; + break; } } while (c >= 0); @@ -5528,15 +5528,15 @@ exit_error:; /**************************************************************************** Parse InChI layer "/i/h" ****************************************************************************/ -int ParseSegmentIsoExchgH(const char* str, - int bMobileH, - REM_PROTONS nNumProtons[], - int pnNumComponents[], - int state, - int* pbAbc) +int ParseSegmentIsoExchgH( const char *str, + int bMobileH, + REM_PROTONS nNumProtons[], + int pnNumComponents[], + int state, + int *pbAbc ) { /* Pass 1: count bonds and find actual numbers of atom */ - const char* p, * q, * pStart, * pEnd; + const char *p, *q, *pStart, *pEnd; int ret = 0, num, i, i_prev; static const char abc_h[] = "hdt"; @@ -5545,16 +5545,16 @@ int ParseSegmentIsoExchgH(const char* str, return 0; } - pStart = (char*)str + 1; + pStart = (char *) str + 1; - if (!(bMobileH == TAUT_YES && state == IST_MOBILE_H_ISO_EXCH_H)) + if (!( bMobileH == TAUT_YES && state == IST_MOBILE_H_ISO_EXCH_H )) { return RI_ERR_PROGR; /* program error */ } - if (!(strchr(pStart, ';'))) /* djb-rwth: removing redundant code */ + if (!(strchr( pStart, ';' ) )) /* djb-rwth: removing redundant code */ { - pEnd = pStart + strlen(pStart); + pEnd = pStart + strlen( pStart ); } else { @@ -5568,17 +5568,17 @@ int ParseSegmentIsoExchgH(const char* str, /* check if compressed InChI */ /* compressed: /hNtNdNh where N is a decimal number */ /* uncompressed: /hT[n]D[n]H[n] where n > 1 is a decimal number */ - *pbAbc = isdigit(UCINT * p) ? 1 : 0; + *pbAbc = isdigit( UCINT *p ) ? 1 : 0; } if (*pbAbc == 1) { - i_prev = (int)sizeof(abc_h); + i_prev = ( int )sizeof( abc_h ); while (p < pEnd) { - num = (int)inchi_strtol(p, &q, 10); + num = (int) inchi_strtol( p, &q, 10 ); #if ( CHECK_STRTOL_ATNUMB==1 ) - if (num > MAX_ATOMS || num < 0) + if (num>MAX_ATOMS || num<0) { ret = RI_ERR_SYNTAX; goto exit_function; @@ -5589,10 +5589,10 @@ int ParseSegmentIsoExchgH(const char* str, ret = RI_ERR_SYNTAX; goto exit_function; } - p = strchr((char*)abc_h, *q); - if (p && (i = (int)(p - abc_h)) < i_prev && (i < NUM_H_ISOTOPES)) /* djb-rwth: additional condition for buffer overrun prevention */ + p = strchr((char *)abc_h, *q); + if (p && ( i = (int) ( p - abc_h ) ) < i_prev && (i < NUM_H_ISOTOPES)) /* djb-rwth: additional condition for buffer overrun prevention */ { - nNumProtons[bMobileH].nNumRemovedIsotopicH[i] = (NUM_H)num; + nNumProtons[bMobileH].nNumRemovedIsotopicH[i] = (NUM_H) num; p = q + 1; i_prev = i; } @@ -5609,9 +5609,9 @@ int ParseSegmentIsoExchgH(const char* str, { nNumProtons[bMobileH].nNumRemovedIsotopicH[2] = 1; p++; - if (isdigit(UCINT p[0])) + if (isdigit( UCINT p[0] )) { - nNumProtons[bMobileH].nNumRemovedIsotopicH[2] = (NUM_H)inchi_strtol(p, &q, 10); + nNumProtons[bMobileH].nNumRemovedIsotopicH[2] = (NUM_H) inchi_strtol( p, &q, 10 ); p = q; } } @@ -5619,9 +5619,9 @@ int ParseSegmentIsoExchgH(const char* str, { nNumProtons[bMobileH].nNumRemovedIsotopicH[1] = 1; p++; - if (isdigit(UCINT p[0])) + if (isdigit( UCINT p[0] )) { - nNumProtons[bMobileH].nNumRemovedIsotopicH[1] = (NUM_H)inchi_strtol(p, &q, 10); + nNumProtons[bMobileH].nNumRemovedIsotopicH[1] = (NUM_H) inchi_strtol( p, &q, 10 ); p = q; } } @@ -5629,9 +5629,9 @@ int ParseSegmentIsoExchgH(const char* str, { nNumProtons[bMobileH].nNumRemovedIsotopicH[0] = 1; p++; - if (isdigit(UCINT p[0])) + if (isdigit( UCINT p[0] )) { - nNumProtons[bMobileH].nNumRemovedIsotopicH[0] = (NUM_H)inchi_strtol(p, &q, 10); + nNumProtons[bMobileH].nNumRemovedIsotopicH[0] = (NUM_H) inchi_strtol( p, &q, 10 ); p = q; } } @@ -5650,17 +5650,17 @@ int ParseSegmentIsoExchgH(const char* str, /****************************************************************************/ -int ParseSegmentPerm(const char* str, - int bMobileH, - INChI* pInpInChI[], - int ppnNumComponents[], - int state, - int* pbAbc) +int ParseSegmentPerm( const char *str, + int bMobileH, + INChI *pInpInChI[], + int ppnNumComponents[], + int state, + int *pbAbc ) { int nNumComponents, iComponent1, iComponent2, numTrans; - const char* p, * q, * pStart, * pEnd, * pPermStart, * pPermEnd; + const char *p, *q, *pStart, *pEnd, *pPermStart, *pPermEnd; int ret = 0; - INChI* pInChI = pInpInChI[bMobileH]; /* bMobileH should be TAUT_NON = 0 */ + INChI *pInChI = pInpInChI[bMobileH]; /* bMobileH should be TAUT_NON = 0 */ INChI tmp; int base = 10; @@ -5675,17 +5675,17 @@ int ParseSegmentPerm(const char* str, return RI_ERR_ALLOC; } - pStart = (char*)str + 1; + pStart = (char *) str + 1; nNumComponents = ppnNumComponents[bMobileH]; - if (!(bMobileH == TAUT_NON && (state == IST_FIXED_H_PERMUTATION || state == IST_FIXED_H_ISO_PERMUTATION))) + if (!( bMobileH == TAUT_NON && ( state == IST_FIXED_H_PERMUTATION || state == IST_FIXED_H_ISO_PERMUTATION ) )) { return RI_ERR_PROGR; /* program error */ } - if (!(strchr(pStart, ';'))) /* djb-rwth: removing redundant code */ + if (!(strchr( pStart, ';' ) )) /* djb-rwth: removing redundant code */ { - pEnd = pStart + strlen(pStart); + pEnd = pStart + strlen( pStart ); } else { @@ -5701,8 +5701,8 @@ int ParseSegmentPerm(const char* str, goto exit_function; } pPermStart = pStart + 1; - memset(&tmp, 0, sizeof(tmp)); /* initialization 2006-03 */ /* djb-rwth: memset_s C11/Annex K variant? */ - if (!(pPermEnd = strchr(pPermStart, ')')) || pPermEnd == pPermStart) + memset( &tmp, 0, sizeof( tmp ) ); /* initialization 2006-03 */ /* djb-rwth: memset_s C11/Annex K variant? */ + if (!( pPermEnd = strchr( pPermStart, ')' ) ) || pPermEnd == pPermStart) { ret = RI_ERR_SYNTAX; goto exit_function; @@ -5711,9 +5711,9 @@ int ParseSegmentPerm(const char* str, if (pPermStart < pPermEnd && *pbAbc == -1) { /* check if compressed InChI */ - *pbAbc = isupper(UCINT * pPermStart) ? 1 : 0; + *pbAbc = isupper( UCINT *pPermStart ) ? 1 : 0; } - base = (*pbAbc == 1) ? ALPHA_BASE : 10; + base = ( *pbAbc == 1 ) ? ALPHA_BASE : 10; /* permutation cycle */ if (*pbAbc == 1) @@ -5721,13 +5721,13 @@ int ParseSegmentPerm(const char* str, for (p = pPermStart, iComponent2 = numTrans = 0; p < pPermEnd; iComponent2 = iComponent1, p = q) { /* get first atom number */ - if (0 >= (iComponent1 = (int)inchi_strtol(p, &q, base)) || iComponent1 > nNumComponents) + if (0 >= ( iComponent1 = (int) inchi_strtol( p, &q, base ) ) || iComponent1 > nNumComponents) { ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; } #if ( FIX_GAF_2019_2==1 ) - if ((iComponent1 - 1 > nNumComponents - 1) || (iComponent1 - 1 < 0)) + if ((iComponent1 - 1 > nNumComponents - 1) || (iComponent1 - 1<0)) { ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; @@ -5746,10 +5746,10 @@ int ParseSegmentPerm(const char* str, } else { - for (p = pPermStart, iComponent2 = numTrans = 0; p < pPermEnd; iComponent2 = iComponent1, p = q + (*q == ',')) + for (p = pPermStart, iComponent2 = numTrans = 0; p < pPermEnd; iComponent2 = iComponent1, p = q + ( *q == ',' )) { /* get first atom number */ - if (!isdigit(UCINT * p)) + if (!isdigit( UCINT *p )) { ret = RI_ERR_SYNTAX; goto exit_function; @@ -5793,21 +5793,21 @@ int ParseSegmentPerm(const char* str, /**************************************************************************** Parse InChI layer "/i" ****************************************************************************/ -int ParseSegmentIsoAtoms(const char* str, - int bMobileH, - INChI* pInpInChI[], - int ppnNumComponents[], - int state, - int* pbAbc) +int ParseSegmentIsoAtoms( const char *str, + int bMobileH, + INChI *pInpInChI[], + int ppnNumComponents[], + int state, + int *pbAbc ) { int i, mpy_component, val; int nNumComponents, iComponent, len = 0, iAtom; AT_NUMB nAtom1; - const char* p, * q, * t, * pStart, * pEnd, * r; + const char *p, *q, *t, *pStart, *pEnd, *r; int ret = 0; - INChI* pInChI = pInpInChI[bMobileH]; - INChI* pInChIFrom = NULL; - INChI_IsotopicAtom** pIsotopicAtom = NULL; + INChI *pInChI = pInpInChI[bMobileH]; + INChI *pInChIFrom = NULL; + INChI_IsotopicAtom **pIsotopicAtom = NULL; INChI_IsotopicAtom isoAtom; const char mult_type[] = "mnMNe"; @@ -5820,12 +5820,12 @@ int ParseSegmentIsoAtoms(const char* str, return 0; } - pStart = (char*)str + 1; + pStart = (char *) str + 1; iComponent = 0; nNumComponents = ppnNumComponents[bMobileH]; - if (!((bMobileH == TAUT_YES && state == IST_MOBILE_H_ISO_ATOMS) || - (bMobileH == TAUT_NON && state == IST_FIXED_H_ISO_ATOMS))) /* djb-rwth: addressing LLVM warnings */ + if (!( (bMobileH == TAUT_YES && state == IST_MOBILE_H_ISO_ATOMS) || + (bMobileH == TAUT_NON && state == IST_FIXED_H_ISO_ATOMS) )) /* djb-rwth: addressing LLVM warnings */ { return RI_ERR_PROGR; /* program error */ } @@ -5837,13 +5837,13 @@ int ParseSegmentIsoAtoms(const char* str, while (1) { /* cycle over components */ - if (!(pEnd = strchr(pStart, ';'))) + if (!( pEnd = strchr( pStart, ';' ) )) { - pEnd = pStart + strlen(pStart); + pEnd = pStart + strlen( pStart ); } - if ((p = strchr(pStart, '*')) && p < pEnd) + if (( p = strchr( pStart, '*' ) ) && p < pEnd) { - mpy_component = (int)inchi_strtol(pStart, &q, 10); + mpy_component = (int) inchi_strtol( pStart, &q, 10 ); if (p != q) { ret = RI_ERR_SYNTAX; /* syntax error */ @@ -5874,7 +5874,7 @@ int ParseSegmentIsoAtoms(const char* str, if_cnd = true; } - if (if_cnd && (t = strchr((char*)mult_type, *q)) && q + 1 == pEnd) /* djb-rwth: bool if_cnd applied; ignoring LLVM warning: variable used to store function return value */ + if ( if_cnd && ( t = strchr((char *)mult_type, *q)) && q + 1 == pEnd) /* djb-rwth: bool if_cnd applied; ignoring LLVM warning: variable used to store function return value */ { /* process the abbreviation */ ret = 0; @@ -5888,32 +5888,32 @@ int ParseSegmentIsoAtoms(const char* str, bIsoFrom = 0; switch (bMobileH) { - case TAUT_YES: - ret = RI_ERR_SYNTAX; - break; - case TAUT_NON: - if (*q == 'm') - { - /* copy from mobile H to fixed H */ - pInChIFrom = pInpInChI[ALT_TAUT(bMobileH)]; - } - else - { - if (*q == 'e') + case TAUT_YES: + ret = RI_ERR_SYNTAX; + break; + case TAUT_NON: + if (*q == 'm') { - /* copy from mobile H to isotopic mobile H */ - pInChIFrom = pInChI; - bIsoFrom = -1; /* empty */ + /* copy from mobile H to fixed H */ + pInChIFrom = pInpInChI[ALT_TAUT( bMobileH )]; } else { - ret = RI_ERR_SYNTAX; /* syntax error */ - } - } - break; - default: - ret = RI_ERR_SYNTAX; - break; + if (*q == 'e') + { + /* copy from mobile H to isotopic mobile H */ + pInChIFrom = pInChI; + bIsoFrom = -1; /* empty */ + } + else + { + ret = RI_ERR_SYNTAX; /* syntax error */ + } + } + break; + default: + ret = RI_ERR_SYNTAX; + break; } if (ret < 0) { @@ -5924,22 +5924,22 @@ int ParseSegmentIsoAtoms(const char* str, { #if ( FIX_GAF_2019_2==1 ) { - if ((iComponent + i > nNumComponents) || (iComponent + i < 0)) + if ((iComponent + i>nNumComponents) || (iComponent + i<0)) { ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; } } #endif - ret = CopySegment(pInChI + iComponent + i, pInChIFrom + iComponent + i, nCpyType, 0, bIsoFrom); - if (!ret) - { - ret = RI_ERR_SYNTAX; - } - if (ret < 0) - { - goto exit_function; - } + ret = CopySegment( pInChI + iComponent + i, pInChIFrom + iComponent + i, nCpyType, 0, bIsoFrom ); + if (!ret) + { + ret = RI_ERR_SYNTAX; + } + if (ret < 0) + { + goto exit_function; + } } iComponent += val; /* continue to the next component(s) */ @@ -5961,7 +5961,7 @@ int ParseSegmentIsoAtoms(const char* str, } #if ( FIX_GAF_2019_2==1 ) - if ((iComponent > nNumComponents - 1) || (iComponent < 0)) + if ((iComponent > nNumComponents - 1) || (iComponent<0)) { ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; @@ -5983,34 +5983,34 @@ int ParseSegmentIsoAtoms(const char* str, if (p < pEnd && *pbAbc == -1) { /* check if compressed InChI */ - *pbAbc = isupper(UCINT * p) ? 1 : 0; + *pbAbc = isupper( UCINT *p ) ? 1 : 0; } - base = (*pbAbc == 1) ? ALPHA_BASE : 10; + base = ( *pbAbc == 1 ) ? ALPHA_BASE : 10; - one_more_time: +one_more_time: if (*pbAbc == 1) { /* process the componnt: At[+/-Charge]TDH,... */ /* pass 1: find number of stereoatoms */ for (p = pStart, iAtom = 0; p < pEnd; iAtom++) { - nAtom1 = (AT_NUMB)inchi_strtol(p, &p, base); + nAtom1 = (AT_NUMB) inchi_strtol( p, &p, base ); #if ( CHECK_STRTOL_ATNUMB==1 ) - if (nAtom1 > MAX_ATOMS || nAtom1 < 0) + if (nAtom1>MAX_ATOMS || nAtom1<0) { ret = RI_ERR_SYNTAX; goto exit_function; } #endif if (!nAtom1 || - nAtom1 > pInChI[iComponent].nNumberOfAtoms) + nAtom1 > pInChI[iComponent].nNumberOfAtoms) { ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; } - memset(&isoAtom, 0, sizeof(isoAtom)); /* djb-rwth: memset_s C11/Annex K variant? */ + memset( &isoAtom, 0, sizeof( isoAtom ) ); /* djb-rwth: memset_s C11/Annex K variant? */ isoAtom.nAtomNumber = nAtom1; - isoAtom.nIsoDifference = (NUM_H)inchi_strtol(p, &q, 10); /* alway in abc */ + isoAtom.nIsoDifference = (NUM_H) inchi_strtol( p, &q, 10 ); /* alway in abc */ if (p == q) { ret = RI_ERR_SYNTAX; /* syntax error */ @@ -6021,9 +6021,9 @@ int ParseSegmentIsoAtoms(const char* str, { isoAtom.nNum_T = 1; p++; - if (isdigit(UCINT * p)) + if (isdigit( UCINT *p )) { - isoAtom.nNum_T = (NUM_H)inchi_strtol(p, &q, 10); + isoAtom.nNum_T = (NUM_H) inchi_strtol( p, &q, 10 ); p = q; } } @@ -6031,9 +6031,9 @@ int ParseSegmentIsoAtoms(const char* str, { isoAtom.nNum_D = 1; p++; - if (isdigit(UCINT * p)) + if (isdigit( UCINT *p )) { - isoAtom.nNum_D = (NUM_H)inchi_strtol(p, &q, 10); + isoAtom.nNum_D = (NUM_H) inchi_strtol( p, &q, 10 ); p = q; } } @@ -6041,9 +6041,9 @@ int ParseSegmentIsoAtoms(const char* str, { isoAtom.nNum_H = 1; p++; - if (isdigit(UCINT * p)) + if (isdigit( UCINT *p )) { - isoAtom.nNum_H = (NUM_H)inchi_strtol(p, &q, 10); + isoAtom.nNum_H = (NUM_H) inchi_strtol( p, &q, 10 ); p = q; } } @@ -6064,9 +6064,9 @@ int ParseSegmentIsoAtoms(const char* str, /* pass 1: find number of stereoatoms */ for (p = pStart, iAtom = 0; p < pEnd; iAtom++) { - nAtom1 = (AT_NUMB)inchi_strtol(p, &q, 10); + nAtom1 = (AT_NUMB) inchi_strtol( p, &q, 10 ); #if ( CHECK_STRTOL_ATNUMB==1 ) - if (nAtom1 > MAX_ATOMS || nAtom1 < 0) + if (nAtom1>MAX_ATOMS || nAtom1<0) { ret = RI_ERR_SYNTAX; goto exit_function; @@ -6075,23 +6075,23 @@ int ParseSegmentIsoAtoms(const char* str, p = q; if (!nAtom1 || nAtom1 > pInChI[iComponent].nNumberOfAtoms || - !(r = strchr((char*)parity_type, *p))) /* djb-rwth: ignoring LLVM warning: variable used to store function return value */ + !(r = strchr( (char*)parity_type, *p ))) /* djb-rwth: ignoring LLVM warning: variable used to store function return value */ { ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; } - memset(&isoAtom, 0, sizeof(isoAtom)); /* djb-rwth: memset_s C11/Annex K variant? */ + memset( &isoAtom, 0, sizeof( isoAtom ) ); /* djb-rwth: memset_s C11/Annex K variant? */ isoAtom.nAtomNumber = nAtom1; - if (p[0] == '+' && isdigit(UCINT p[1])) + if (p[0] == '+' && isdigit( UCINT p[1] )) { - isoAtom.nIsoDifference = (NUM_H)inchi_strtol(p + 1, &q, 10); + isoAtom.nIsoDifference = (NUM_H) inchi_strtol( p + 1, &q, 10 ); if (isoAtom.nIsoDifference >= 0) isoAtom.nIsoDifference++; p = q; } else - if (p[0] == '-' && isdigit(UCINT p[1])) + if (p[0] == '-' && isdigit( UCINT p[1] )) { - isoAtom.nIsoDifference = -(NUM_H)inchi_strtol(p + 1, &q, 10); + isoAtom.nIsoDifference = -(NUM_H) inchi_strtol( p + 1, &q, 10 ); if (isoAtom.nIsoDifference == 0) isoAtom.nIsoDifference++; p = q; } @@ -6099,9 +6099,9 @@ int ParseSegmentIsoAtoms(const char* str, { isoAtom.nNum_T = 1; p++; - if (isdigit(UCINT * p)) + if (isdigit( UCINT *p )) { - isoAtom.nNum_T = (NUM_H)inchi_strtol(p, &q, 10); + isoAtom.nNum_T = (NUM_H) inchi_strtol( p, &q, 10 ); p = q; } } @@ -6109,9 +6109,9 @@ int ParseSegmentIsoAtoms(const char* str, { isoAtom.nNum_D = 1; p++; - if (isdigit(UCINT * p)) + if (isdigit( UCINT *p )) { - isoAtom.nNum_D = (NUM_H)inchi_strtol(p, &q, 10); + isoAtom.nNum_D = (NUM_H) inchi_strtol( p, &q, 10 ); p = q; } } @@ -6119,9 +6119,9 @@ int ParseSegmentIsoAtoms(const char* str, { isoAtom.nNum_H = 1; p++; - if (isdigit(UCINT * p)) + if (isdigit( UCINT *p )) { - isoAtom.nNum_H = (NUM_H)inchi_strtol(p, &q, 10); + isoAtom.nNum_H = (NUM_H) inchi_strtol( p, &q, 10 ); p = q; } } @@ -6159,7 +6159,7 @@ int ParseSegmentIsoAtoms(const char* str, /* end of the 1st pass */ len = iAtom; /* memory allocation */ - if (!(*pIsotopicAtom = (INChI_IsotopicAtom*)inchi_calloc((long long)len + 1, sizeof(**pIsotopicAtom)))) /* djb-rwth: cast operator added */ + if (!( *pIsotopicAtom = (INChI_IsotopicAtom *) inchi_calloc( (long long)len + 1, sizeof( **pIsotopicAtom ) ) )) /* djb-rwth: cast operator added */ { ret = RI_ERR_ALLOC; /* memory allocation failed */ goto exit_function; @@ -6180,7 +6180,7 @@ int ParseSegmentIsoAtoms(const char* str, /* multiplier */ for (i = 1; i < mpy_component; i++) { - ret = CopySegment(pInChI + iComponent + i, pInChI + iComponent, nCpyType, 0, 0); + ret = CopySegment( pInChI + iComponent + i, pInChI + iComponent, nCpyType, 0, 0 ); if (!ret) { ret = RI_ERR_SYNTAX; /* syntax error */ @@ -6221,21 +6221,21 @@ int ParseSegmentIsoAtoms(const char* str, /**************************************************************************** Parse "/i/s" InChI layer ****************************************************************************/ -int ParseSegmentSp3s(const char* str, - int bMobileH, - INChI* pInpInChI[], - int s[TAUT_NUM][2], - int ppnNumComponents[], - int state) +int ParseSegmentSp3s( const char *str, + int bMobileH, + INChI *pInpInChI[], + int s[TAUT_NUM][2], + int ppnNumComponents[], + int state ) { /* Pass 1: count bonds and find actual numbers of atom */ int nNumComponents, iComponent, val; - const char* p, * q, * pStart, * pEnd; + const char *p, *q, *pStart, *pEnd; int ret = 0; - INChI* pInChI = pInpInChI[bMobileH]; - INChI_Stereo** pStereo = NULL; + INChI *pInChI = pInpInChI[bMobileH]; + INChI_Stereo **pStereo = NULL; - int bIso = (state == IST_MOBILE_H_ISO_SP3_S || state == IST_FIXED_H_ISO_SP3_S); + int bIso = ( state == IST_MOBILE_H_ISO_SP3_S || state == IST_FIXED_H_ISO_SP3_S ); if (!bIso && state != IST_MOBILE_H_SP3_S && state != IST_FIXED_H_SP3_S) { @@ -6247,14 +6247,14 @@ int ParseSegmentSp3s(const char* str, return 0; } - pStart = (char*)str + 1; + pStart = (char *) str + 1; /* djb-rwth: removing redundant code */ nNumComponents = ppnNumComponents[bMobileH]; /*if ( !(pEnd = strchr( pStart, ';' )) )*/ /* 2007-09-25 DT */ - if (!(strchr(pStart, '/'))) /* djb-rwth: removing redundant variables/code */ + if (!(strchr( pStart, '/' ) )) /* djb-rwth: removing redundant variables/code */ { - pEnd = pStart + strlen(pStart); + pEnd = pStart + strlen( pStart ); } else { @@ -6267,13 +6267,13 @@ int ParseSegmentSp3s(const char* str, /* create empty sp3 segment */ int len = 0; s[bMobileH][bIso] = NO_VALUE_INT; /* empty */ - /* create empty sp3 segment */ + /* create empty sp3 segment */ for (iComponent = 0; iComponent < nNumComponents; iComponent++) { pStereo = bIso ? &pInChI[iComponent].StereoIsotopic : &pInChI[iComponent].Stereo; if (!*pStereo) { - if (!(*pStereo = (INChI_Stereo*)inchi_calloc(1, sizeof(**pStereo)))) + if (!( *pStereo = (INChI_Stereo *) inchi_calloc( 1, sizeof( **pStereo ) ) )) { ret = RI_ERR_ALLOC; /* memory allocation failed */ goto exit_function; @@ -6288,21 +6288,21 @@ int ParseSegmentSp3s(const char* str, } /* allocate empty sp3 stereo */ if ((!pStereo[0]->t_parity && - !(pStereo[0]->t_parity = (S_CHAR*)inchi_calloc((long long)len + 1, sizeof(pStereo[0]->b_parity[0])))) || - (!pStereo[0]->nNumber && - !(pStereo[0]->nNumber = (AT_NUMB*)inchi_calloc((long long)len + 1, sizeof(pStereo[0]->nNumber[0]))))) /* djb-rwth: cast operators added; addressing LLVM warnings */ + !( pStereo[0]->t_parity = (S_CHAR *) inchi_calloc( (long long)len + 1, sizeof( pStereo[0]->b_parity[0] ) ) )) || + (!pStereo[0]->nNumber && + !( pStereo[0]->nNumber = (AT_NUMB *) inchi_calloc( (long long)len + 1, sizeof( pStereo[0]->nNumber[0] ) ) ))) /* djb-rwth: cast operators added; addressing LLVM warnings */ { /* cleanup */ if (pStereo[0]->t_parity) { INCHI_HEAPCHK - inchi_free(pStereo[0]->t_parity); + inchi_free( pStereo[0]->t_parity ); pStereo[0]->t_parity = NULL; } if (pStereo[0]->nNumber) { INCHI_HEAPCHK - inchi_free(pStereo[0]->nNumber); + inchi_free( pStereo[0]->nNumber ); pStereo[0]->nNumber = NULL; } ret = RI_ERR_ALLOC; /* memory allocation failed */ @@ -6313,7 +6313,7 @@ int ParseSegmentSp3s(const char* str, } else { - val = (int)inchi_strtol(p, &q, 10); + val = (int) inchi_strtol( p, &q, 10 ); if (q == pEnd && 1 <= val && val <= 3) { s[bMobileH][bIso] = val; @@ -6332,13 +6332,13 @@ int ParseSegmentSp3s(const char* str, /****************************************************************************/ -int bIsSp3LayerNotEmpty(INChI* pInpInChI[], - int bMobileH, - int bIso, - int nNumComponents) +int bIsSp3LayerNotEmpty( INChI *pInpInChI[], + int bMobileH, + int bIso, + int nNumComponents ) { - INChI* pInChI; - INChI_Stereo* pStereo; + INChI *pInChI; + INChI_Stereo *pStereo; int iComponent, num_not_empty = 0; if (pInpInChI[bMobileH]) @@ -6364,20 +6364,20 @@ int bIsSp3LayerNotEmpty(INChI* pInpInChI[], /**************************************************************************** Parse "/i/m" InChI layer ****************************************************************************/ -int ParseSegmentSp3m(const char* str, - int bMobileH, - INChI* pInpInChI[], - int ppnNumComponents[], - int state) +int ParseSegmentSp3m( const char *str, + int bMobileH, + INChI *pInpInChI[], + int ppnNumComponents[], + int state ) { /* Pass 1: count bonds and find actual numbers of atom */ int nNumComponents, iComponent; - const char* p, * pStart, * pEnd; + const char *p, *pStart, *pEnd; int ret = 0; - INChI* pInChI = pInpInChI[bMobileH]; - INChI_Stereo** pStereo = NULL; + INChI *pInChI = pInpInChI[bMobileH]; + INChI_Stereo **pStereo = NULL; - int bIso = (state == IST_MOBILE_H_ISO_SP3_M || state == IST_FIXED_H_ISO_SP3_M); + int bIso = ( state == IST_MOBILE_H_ISO_SP3_M || state == IST_FIXED_H_ISO_SP3_M ); if (!bIso && state != IST_MOBILE_H_SP3_M && state != IST_FIXED_H_SP3_M) { @@ -6388,8 +6388,8 @@ int ParseSegmentSp3m(const char* str, if (str[0] != 'm') { /* /m is missing: check whether we have to inherit /m from a preceding stereo layer */ - INChI_Stereo* pStereoFrom, * pStereoTo; - INChI* pInChIFrom; + INChI_Stereo *pStereoFrom, *pStereoTo; + INChI *pInChIFrom; int bMobileHFrom = -1, bIsoFrom = -1; /* djb-rwth: removing redundant variables */ if (bMobileH && !bIso) { @@ -6419,8 +6419,8 @@ int ParseSegmentSp3m(const char* str, bMobileHFrom = TAUT_NON; bIsoFrom = 0; /* if Sp3 is empty in F as well as in M, then inherit from MI */ - if (!bIsSp3LayerNotEmpty(pInpInChI, TAUT_NON, 0, ppnNumComponents[TAUT_NON /*bMobileH*/]) /* F */ && - !bIsSp3LayerNotEmpty(pInpInChI, TAUT_YES, 0, ppnNumComponents[TAUT_YES /*bMobileH*/]) /* M */) + if (!bIsSp3LayerNotEmpty( pInpInChI, TAUT_NON, 0, ppnNumComponents[TAUT_NON /*bMobileH*/] ) /* F */ && + !bIsSp3LayerNotEmpty( pInpInChI, TAUT_YES, 0, ppnNumComponents[TAUT_YES /*bMobileH*/] ) /* M */) { bMobileHFrom = TAUT_YES; bIsoFrom = 1; @@ -6433,7 +6433,7 @@ int ParseSegmentSp3m(const char* str, { return RI_ERR_PROGR; } - if (!bIsSp3LayerNotEmpty(pInpInChI, bMobileHFrom, bIsoFrom, ppnNumComponents[/*bMobileH*/ bMobileHFrom])) + if (!bIsSp3LayerNotEmpty( pInpInChI, bMobileHFrom, bIsoFrom, ppnNumComponents[/*bMobileH*/ bMobileHFrom] )) { /* nothing to copy; check whether it should have inherited from a preceding layer */ if ((!bMobileHFrom && bIsoFrom) || (bMobileHFrom && !bIsoFrom)) /* djb-rwth: addressing LLVM warnings */ @@ -6441,7 +6441,7 @@ int ParseSegmentSp3m(const char* str, /* MI or F inherit stereo from M */ bMobileHFrom = TAUT_YES; bIsoFrom = 0; - if (!bIsSp3LayerNotEmpty(pInpInChI, bMobileHFrom, bIsoFrom, ppnNumComponents[bMobileHFrom /*bMobileH*/])) + if (!bIsSp3LayerNotEmpty( pInpInChI, bMobileHFrom, bIsoFrom, ppnNumComponents[bMobileHFrom /*bMobileH*/] )) { return 0; } @@ -6451,13 +6451,13 @@ int ParseSegmentSp3m(const char* str, return 0; } } - nNumComponents = inchi_min(ppnNumComponents[bMobileH], ppnNumComponents[bMobileHFrom]); + nNumComponents = inchi_min( ppnNumComponents[bMobileH], ppnNumComponents[bMobileHFrom] ); for (iComponent = 0; iComponent < nNumComponents; iComponent++) { pInChIFrom = pInpInChI[bMobileHFrom] + iComponent; pInChI = pInpInChI[bMobileH] + iComponent; if (pInChIFrom->nNumberOfAtoms > 0 && !pInChIFrom->bDeleted && - pInChI->nNumberOfAtoms > 0 && !pInChI->bDeleted) + pInChI->nNumberOfAtoms > 0 && !pInChI->bDeleted) { pStereoFrom = bIsoFrom ? pInChIFrom->StereoIsotopic : pInChIFrom->Stereo; pStereoTo = bIso ? pInChI->StereoIsotopic : pInChI->Stereo; @@ -6475,9 +6475,9 @@ int ParseSegmentSp3m(const char* str, iComponent = 0; /*if ( !(pEnd = strchr( pStart, ';' )) )*/ /* 2007-09-25 DT */ - if (!(strchr(pStart, '/'))) /* djb-rwth: removing redundant code */ + if (!( strchr( pStart, '/' ) )) /* djb-rwth: removing redundant code */ { - pEnd = pStart + strlen(pStart); + pEnd = pStart + strlen( pStart ); } else { @@ -6491,11 +6491,11 @@ int ParseSegmentSp3m(const char* str, int len = 0; for (iComponent = 0; iComponent < nNumComponents; iComponent++) { - INChI* pIsoInChI = &pInChI[iComponent]; + INChI *pIsoInChI = &pInChI[iComponent]; pStereo = bIso ? &pIsoInChI->StereoIsotopic : &pIsoInChI->Stereo; if (!*pStereo) { - if (!(*pStereo = (INChI_Stereo*)inchi_calloc(1, sizeof(**pStereo)))) + if (!( *pStereo = (INChI_Stereo *) inchi_calloc( 1, sizeof( **pStereo ) ) )) { ret = RI_ERR_ALLOC; /* memory allocation failed */ goto exit_function; @@ -6511,21 +6511,21 @@ int ParseSegmentSp3m(const char* str, #endif /* allocate empty sp3 stereo */ if ((!pStereo[0]->t_parity && - !(pStereo[0]->t_parity = (S_CHAR*)inchi_calloc((long long)len + 1, sizeof(pStereo[0]->b_parity[0])))) || - (!pStereo[0]->nNumber && - !(pStereo[0]->nNumber = (AT_NUMB*)inchi_calloc((long long)len + 1, sizeof(pStereo[0]->nNumber[0]))))) /* djb-rwth: cast operators added; addressing LLVM warnings */ + !( pStereo[0]->t_parity = (S_CHAR *) inchi_calloc( (long long)len + 1, sizeof( pStereo[0]->b_parity[0] ) ) )) || + (!pStereo[0]->nNumber && + !( pStereo[0]->nNumber = (AT_NUMB *) inchi_calloc( (long long)len + 1, sizeof( pStereo[0]->nNumber[0] ) ) ))) /* djb-rwth: cast operators added; addressing LLVM warnings */ { /* cleanup */ if (pStereo[0]->t_parity) { INCHI_HEAPCHK - inchi_free(pStereo[0]->t_parity); + inchi_free( pStereo[0]->t_parity ); pStereo[0]->t_parity = NULL; } if (pStereo[0]->nNumber) { INCHI_HEAPCHK - inchi_free(pStereo[0]->nNumber); + inchi_free( pStereo[0]->nNumber ); pStereo[0]->nNumber = NULL; } ret = RI_ERR_ALLOC; /* memory allocation failed */ @@ -6542,7 +6542,7 @@ int ParseSegmentSp3m(const char* str, pStereo = bIso ? &pInChI[iComponent].StereoIsotopic : &pInChI[iComponent].Stereo; if (*p != '.' && !*pStereo) { - if (!(*pStereo = (INChI_Stereo*)inchi_calloc(1, sizeof(**pStereo)))) + if (!( *pStereo = (INChI_Stereo *) inchi_calloc( 1, sizeof( **pStereo ) ) )) { ret = RI_ERR_ALLOC; /* memory allocation failed */ goto exit_function; @@ -6550,21 +6550,21 @@ int ParseSegmentSp3m(const char* str, } switch (*p) { - case '1': - pStereo[0]->nCompInv2Abs = -1; - break; - case '0': - pStereo[0]->nCompInv2Abs = 1; - break; - case '.': - if (*pStereo) - { - pStereo[0]->nCompInv2Abs = 0; - } - break; - default: - ret = RI_ERR_SYNTAX; /* syntax error */ - goto exit_function; + case '1': + pStereo[0]->nCompInv2Abs = -1; + break; + case '0': + pStereo[0]->nCompInv2Abs = 1; + break; + case '.': + if (*pStereo) + { + pStereo[0]->nCompInv2Abs = 0; + } + break; + default: + ret = RI_ERR_SYNTAX; /* syntax error */ + goto exit_function; } iComponent++; p++; @@ -6580,23 +6580,23 @@ int ParseSegmentSp3m(const char* str, exit_function: return ret; - } +} /**************************************************************************** Parse "/t" InChI layer ****************************************************************************/ -int ParseSegmentSp3(const char* str, /* input; string of segment starting with "/t" */ - int bMobileH, /* input; bMobileH indicates what we have, fixed or tauto */ - INChI* pInpInChI[], /* output; to be allocated and filled */ - int ppnNumComponents[], /* input; ppnNumComponents[bMobileH] is number of components*/ - int state, /* input; gen parser state code */ - int* pbAbc) /* input; inicator of compresssed InChI or not */ +int ParseSegmentSp3( const char *str, /* input; string of segment starting with "/t" */ + int bMobileH, /* input; bMobileH indicates what we have, fixed or tauto */ + INChI *pInpInChI[], /* output; to be allocated and filled */ + int ppnNumComponents[], /* input; ppnNumComponents[bMobileH] is number of components*/ + int state, /* input; gen parser state code */ + int *pbAbc ) /* input; inicator of compresssed InChI or not */ { /* Pass 1: count bonds and find actual numbers of atom */ const char mult_type[] = "mnMNe"; const char parity_type[] = "-+u?"; - const char* p, * q, * t, * pStart, * pEnd, * r; + const char *p, *q, *t, *pStart, *pEnd, *r; AT_NUMB nAtom1; int mpy_component = 0, val; int nNumComponents, iComponent, len, iAtom; @@ -6604,9 +6604,9 @@ int ParseSegmentSp3(const char* str, /* input; string of segment starting with int ret = 0, retf = 0; int base = 10; int nCpyType = CPY_SP3; - int bIso = (state == IST_MOBILE_H_ISO_SP3 || state == IST_FIXED_H_ISO_SP3); - INChI* pInChI = pInpInChI[bMobileH]; - INChI_Stereo** pStereo = NULL; + int bIso = ( state == IST_MOBILE_H_ISO_SP3 || state == IST_FIXED_H_ISO_SP3 ); + INChI *pInChI = pInpInChI[bMobileH]; + INChI_Stereo **pStereo = NULL; if (!bIso && state != IST_MOBILE_H_SP3 && state != IST_FIXED_H_SP3) { @@ -6617,23 +6617,23 @@ int ParseSegmentSp3(const char* str, /* input; string of segment starting with return 0; /* RI_ERR_EOF - ? */ } - pStart = (char*)str + 1; + pStart = (char *) str + 1; iComponent = 0; nNumComponents = ppnNumComponents[bMobileH]; /* Pass 1: create empty segment and exit */ if (!*pStart) { - ret = SegmentSp3CreateEmpty(str, bMobileH, pInpInChI, nNumComponents, state, pbAbc); + ret = SegmentSp3CreateEmpty( str, bMobileH, pInpInChI, nNumComponents, state, pbAbc ); goto exit_function; } /* Cycle over components */ while (1) { - if (!(pEnd = strchr(pStart, ';'))) + if (!( pEnd = strchr( pStart, ';' ) )) { - pEnd = pStart + strlen(pStart); + pEnd = pStart + strlen( pStart ); } /* djb-rwth: condition for if block had to be rewritten */ @@ -6651,12 +6651,12 @@ int ParseSegmentSp3(const char* str, /* input; string of segment starting with } /* Abbreviation? */ - if (if_cnd && (t = strchr((char*)mult_type, *q)) && q + 1 == pEnd) /* djb-rwth: if_cnd applied; ignoring LLVM warning: variable used */ + if (if_cnd && ( t = strchr((char *)mult_type, *q)) && q + 1 == pEnd) /* djb-rwth: if_cnd applied; ignoring LLVM warning: variable used */ { /* Process abbrebiation */ - retf = SegmentSp3ProcessAbbreviation(&mpy_component, iComponent, nNumComponents, - val, q, state, pbAbc, bMobileH, nCpyType, - pInChI, pInpInChI[ALT_TAUT(bMobileH)]); + retf = SegmentSp3ProcessAbbreviation( &mpy_component, iComponent, nNumComponents, + val, q, state, pbAbc, bMobileH, nCpyType, + pInChI, pInpInChI[ALT_TAUT( bMobileH )] ); if (retf == RI_ERR_SYNTAX) { ret = RI_ERR_SYNTAX; @@ -6665,10 +6665,10 @@ int ParseSegmentSp3(const char* str, /* input; string of segment starting with goto end_main_cycle; } /* Multiplier? */ - else if ((p = strchr(pStart, '*')) && p < pEnd) + else if (( p = strchr( pStart, '*' ) ) && p < pEnd) { /* Process regular multiplier */ - mpy_component = (int)inchi_strtol(pStart, &q, 10); + mpy_component = (int) inchi_strtol( pStart, &q, 10 ); if (p != q) { ret = RI_ERR_SYNTAX; @@ -6685,7 +6685,7 @@ int ParseSegmentSp3(const char* str, /* input; string of segment starting with #if (FIX_DALKE_BUGS == 1) if (iComponent + mpy_component > nNumComponents) { - ret = RI_ERR_SYNTAX; + ret = RI_ERR_SYNTAX; goto exit_function; } #endif @@ -6694,60 +6694,60 @@ int ParseSegmentSp3(const char* str, /* input; string of segment starting with if (p < pEnd && *pbAbc == -1) { /* check if compressed InChI */ - *pbAbc = isupper(UCINT * p) ? 1 : 0; + *pbAbc = isupper( UCINT *p ) ? 1 : 0; } - base = (*pbAbc == 1) ? ALPHA_BASE : 10; - + base = ( *pbAbc == 1 ) ? ALPHA_BASE : 10; + /* Process the component: at1p,at1p,... */ - + /* Pass 1: find number of stereoatoms len */ if (*pbAbc == 1) { for (p = pStart, iAtom = 0; p < pEnd; iAtom++) { - if ((nAtom1 = (AT_NUMB)inchi_strtol(p, &p, base)) && - (atomParity = (int)inchi_strtol(p, &p, 10), - AB_MIN_KNOWN_PARITY <= atomParity && atomParity <= AB_MAX_KNOWN_PARITY)) + if (( nAtom1 = (AT_NUMB) inchi_strtol( p, &p, base ) ) && + ( atomParity = (int) inchi_strtol( p, &p, 10 ), + AB_MIN_KNOWN_PARITY <= atomParity && atomParity <= AB_MAX_KNOWN_PARITY )) { ; /* okay */ } else { - ret = RI_ERR_SYNTAX; + ret = RI_ERR_SYNTAX; goto exit_function; } if (nAtom1 > pInChI[iComponent].nNumberOfAtoms) { - ret = RI_ERR_SYNTAX; + ret = RI_ERR_SYNTAX; goto exit_function; } } } else { - for (p = pStart, iAtom = 0; p < pEnd; iAtom++, p += (*p == ',')) + for (p = pStart, iAtom = 0; p < pEnd; iAtom++, p += ( *p == ',' )) { - nAtom1 = (AT_NUMB)inchi_strtol(p, &q, 10); + nAtom1 = (AT_NUMB) inchi_strtol( p, &q, 10 ); p = q + 1; - if (!nAtom1 || - nAtom1 > pInChI[iComponent].nNumberOfAtoms || - !(r = strchr((char*)parity_type, *q))) /* djb-rwth: ignoring LLVM warning: variable used to store function return value */ + if ( !nAtom1 || + nAtom1 > pInChI[iComponent].nNumberOfAtoms || + !(r = strchr((char *)parity_type, *q))) /* djb-rwth: ignoring LLVM warning: variable used to store function return value */ { - ret = RI_ERR_SYNTAX; + ret = RI_ERR_SYNTAX; goto exit_function; } } } if (p != pEnd) { - ret = RI_ERR_SYNTAX; + ret = RI_ERR_SYNTAX; goto exit_function; } - len = iAtom; + len = iAtom; /* Found len, the number of stereo centers in /t segment for component iComponent */ #if ( ( FIX_GAF_2019_1==1 ) || ( FIX_GAF_2019_2==1 ) ) - if ((iComponent > nNumComponents - 1) || (iComponent < 0)) + if ((iComponent > nNumComponents - 1) || (iComponent<0)) { ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; @@ -6763,33 +6763,33 @@ int ParseSegmentSp3(const char* str, /* input; string of segment starting with pStereo = bIso ? &pInChI[iComponent].StereoIsotopic : &pInChI[iComponent].Stereo; if (!*pStereo) { - if (!(*pStereo = (INChI_Stereo*)inchi_calloc(1, sizeof(**pStereo)))) + if (!( *pStereo = (INChI_Stereo *) inchi_calloc( 1, sizeof( **pStereo ) ) )) { - ret = RI_ERR_ALLOC; + ret = RI_ERR_ALLOC; goto exit_function; } } if (pStereo[0]->t_parity || pStereo[0]->nNumberOfStereoCenters || - pStereo[0]->nNumber) + pStereo[0]->nNumber) { ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; } /* Allocate sp3 stereo */ - if (!(pStereo[0]->t_parity = (S_CHAR*)inchi_calloc((long long)len + 1, sizeof(pStereo[0]->b_parity[0]))) || - !(pStereo[0]->nNumber = (AT_NUMB*)inchi_calloc((long long)len + 1, sizeof(pStereo[0]->nNumber[0])))) /* djb-rwth: cast operators added */ + if (!( pStereo[0]->t_parity = (S_CHAR *) inchi_calloc( (long long)len + 1, sizeof( pStereo[0]->b_parity[0] ) ) ) || + !( pStereo[0]->nNumber = (AT_NUMB *) inchi_calloc( (long long)len + 1, sizeof( pStereo[0]->nNumber[0] ) ) )) /* djb-rwth: cast operators added */ { /* cleanup */ if (pStereo[0]->t_parity) { INCHI_HEAPCHK - inchi_free(pStereo[0]->t_parity); + inchi_free( pStereo[0]->t_parity ); pStereo[0]->t_parity = NULL; } if (pStereo[0]->nNumber) { INCHI_HEAPCHK - inchi_free(pStereo[0]->nNumber); + inchi_free( pStereo[0]->nNumber ); pStereo[0]->nNumber = NULL; } ret = RI_ERR_ALLOC; /* memory allocation failed */ @@ -6798,7 +6798,7 @@ int ParseSegmentSp3(const char* str, /* input; string of segment starting with /* Store stereocenters (pass 2) */ - retf = SegmentSp3StoreStereoCenters(pbAbc, pStart, pEnd, pInChI[iComponent].nNumberOfAtoms, pStereo[0]); + retf = SegmentSp3StoreStereoCenters( pbAbc, pStart, pEnd, pInChI[iComponent].nNumberOfAtoms, pStereo[0] ); if (retf == RI_ERR_SYNTAX) { ret = RI_ERR_SYNTAX; @@ -6806,7 +6806,7 @@ int ParseSegmentSp3(const char* str, /* input; string of segment starting with } /* Treat multiplier-covered components */ - retf = SegmentSp3CopyMultiplierCovered(mpy_component, iComponent, pInChI, bIso, nCpyType); + retf = SegmentSp3CopyMultiplierCovered( mpy_component, iComponent, pInChI, bIso, nCpyType ); if (retf == RI_ERR_SYNTAX) { ret = RI_ERR_SYNTAX; @@ -6836,9 +6836,9 @@ int ParseSegmentSp3(const char* str, /* input; string of segment starting with /* At this moment, INChI_Stereo pInChI[k].Stereo provides stereocenter parity info for k-th component pInChI[k].Stereo. nNumber[nNumberOfStereoCenters] cano numbers - t_parity[nNumberOfStereoCenters] tetrahedral atom parities + t_parity[nNumberOfStereoCenters] tetrahedral atom parities */ - + ret = iComponent + 1; @@ -6851,32 +6851,32 @@ int ParseSegmentSp3(const char* str, /* input; string of segment starting with /**************************************************************************** Parse "/b" InChI layer ****************************************************************************/ -int ParseSegmentSp2(const char* str, - int bMobileH, - INChI* pInpInChI[], - int ppnNumComponents[], - int state, - int* pbAbc) +int ParseSegmentSp2( const char *str, + int bMobileH, + INChI *pInpInChI[], + int ppnNumComponents[], + int state, + int *pbAbc ) { /* Pass 1: count bonds and find actual numbers of atom */ int i, mpy_component, val; int nNumComponents, iComponent, len, iBond; AT_NUMB nAtom1, nAtom2; int bondParity; - const char* p, * q, * t, * pStart, * pEnd, * r; + const char *p, *q, *t, *pStart, *pEnd, *r; int ret = 0; - INChI* pInChI = pInpInChI[bMobileH]; - INChI* pInChIFrom = NULL; + INChI *pInChI = pInpInChI[bMobileH]; + INChI *pInChIFrom = NULL; /* INChI_Stereo *Stereo = NULL; INChI_Stereo *StereoOther = NULL; */ - INChI_Stereo** pStereo = NULL; + INChI_Stereo **pStereo = NULL; const char mult_type[] = "mnMNe"; const char parity_type[] = "-+u?"; int bIsoTo, bIsoFrom, nCpyType = CPY_SP2; - int bIso = (state == IST_MOBILE_H_ISO_SP2 || state == IST_FIXED_H_ISO_SP2); + int bIso = ( state == IST_MOBILE_H_ISO_SP2 || state == IST_FIXED_H_ISO_SP2 ); int base = 10; if (!bIso && state != IST_MOBILE_H_SP2 && state != IST_FIXED_H_SP2) @@ -6889,7 +6889,7 @@ int ParseSegmentSp2(const char* str, return 0; } - pStart = (char*)str + 1; + pStart = (char *) str + 1; iComponent = 0; nNumComponents = ppnNumComponents[bMobileH]; @@ -6898,16 +6898,16 @@ int ParseSegmentSp2(const char* str, /* create empty sp2 segment which means no sp2 */ for (iComponent = 0; iComponent < nNumComponents; iComponent++) { - INChI* pIsoInChI = &pInChI[iComponent]; + INChI *pIsoInChI = &pInChI[iComponent]; pStereo = bIso ? &pIsoInChI->StereoIsotopic : &pIsoInChI->Stereo; - if (*pStereo && (pStereo[0]->b_parity || pStereo[0]->nNumberOfStereoBonds || - pStereo[0]->nBondAtom1 || pStereo[0]->nBondAtom2)) + if (*pStereo && ( pStereo[0]->b_parity || pStereo[0]->nNumberOfStereoBonds || + pStereo[0]->nBondAtom1 || pStereo[0]->nBondAtom2 )) { ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; } /* allocate empty sp2 stereo */ - ret = CopySegment(pIsoInChI, NULL, CPY_SP2, bIso, -1); + ret = CopySegment( pIsoInChI, NULL, CPY_SP2, bIso, -1 ); if (ret < 0) { goto exit_function; @@ -6920,16 +6920,16 @@ int ParseSegmentSp2(const char* str, while (1) { /* Cycle over components */ - if (!(pEnd = strchr(pStart, ';'))) + if (!( pEnd = strchr( pStart, ';' ) )) { - pEnd = pStart + strlen(pStart); + pEnd = pStart + strlen( pStart ); } /* djb-rwth: condition for if block had to be rewritten -- GH issue #09, thanks to Istvan Ori */ if ((int)inchi_strtol(pStart, &q, 10) > 0) { val = (int)inchi_strtol(pStart, &q, 10); - if_cnd = isdigit(*pStart); + if_cnd = isdigit( *pStart ); } else @@ -6953,80 +6953,13 @@ int ParseSegmentSp2(const char* str, #endif switch (bMobileH) { - case TAUT_YES: - switch (state) - { - case IST_MOBILE_H_ISO_SP2: - if (*q == 'm') - { - /* copy from mobile H to isotopic mobile H */ - pInChIFrom = pInChI; - bIsoTo = 1; - bIsoFrom = 0; - } - else - { - if (*q == 'e') - { - /* copy from mobile H to isotopic mobile H */ - pInChIFrom = pInChI; - bIsoTo = 1; - bIsoFrom = -1; /* empty */ - } - else - { - ret = RI_ERR_SYNTAX; /* syntax error */ - } - } - break; - default: - ret = RI_ERR_SYNTAX; - break; - } - break; - case TAUT_NON: - switch (state) - { - case IST_FIXED_H_SP2: - if (*q == 'm') - { - /* copy from mobile H to fixed H */ -#if ( FIX_GAF_2019_2==1 ) - int inum = ALT_TAUT(bMobileH); - pInChIFrom = pInpInChI[inum]; -#else - pInChIFrom = pInpInChI[ALT_TAUT(bMobileH)]; -#endif - bIsoTo = 0; - bIsoFrom = 0; - } - else - { - ret = RI_ERR_SYNTAX; /* syntax error */ - } - break; - case IST_FIXED_H_ISO_SP2: - if (*q == 'm') - { - /* copy from mobile H to fixed isotopic H */ - pInChIFrom = pInpInChI[ALT_TAUT(bMobileH)]; - bIsoTo = 1; - bIsoFrom = 0; - } - else + case TAUT_YES: + switch (state) { - if (*q == 'M') - { - /* copy from isotopic mobile H to fixed isotopic H */ - pInChIFrom = pInpInChI[ALT_TAUT(bMobileH)]; - bIsoTo = 1; - bIsoFrom = 1; - } - else - { - if (*q == 'n') + case IST_MOBILE_H_ISO_SP2: + if (*q == 'm') { - /* copy from fixed H to fixed isotopic H */ + /* copy from mobile H to isotopic mobile H */ pInChIFrom = pInChI; bIsoTo = 1; bIsoFrom = 0; @@ -7045,18 +6978,85 @@ int ParseSegmentSp2(const char* str, ret = RI_ERR_SYNTAX; /* syntax error */ } } - } + break; + default: + ret = RI_ERR_SYNTAX; + break; + } + break; + case TAUT_NON: + switch (state) + { + case IST_FIXED_H_SP2: + if (*q == 'm') + { + /* copy from mobile H to fixed H */ +#if ( FIX_GAF_2019_2==1 ) + int inum = ALT_TAUT(bMobileH); + pInChIFrom = pInpInChI[inum]; +#else + pInChIFrom = pInpInChI[ALT_TAUT(bMobileH)]; +#endif + bIsoTo = 0; + bIsoFrom = 0; + } + else + { + ret = RI_ERR_SYNTAX; /* syntax error */ + } + break; + case IST_FIXED_H_ISO_SP2: + if (*q == 'm') + { + /* copy from mobile H to fixed isotopic H */ + pInChIFrom = pInpInChI[ALT_TAUT( bMobileH )]; + bIsoTo = 1; + bIsoFrom = 0; + } + else + { + if (*q == 'M') + { + /* copy from isotopic mobile H to fixed isotopic H */ + pInChIFrom = pInpInChI[ALT_TAUT( bMobileH )]; + bIsoTo = 1; + bIsoFrom = 1; + } + else + { + if (*q == 'n') + { + /* copy from fixed H to fixed isotopic H */ + pInChIFrom = pInChI; + bIsoTo = 1; + bIsoFrom = 0; + } + else + { + if (*q == 'e') + { + /* copy from mobile H to isotopic mobile H */ + pInChIFrom = pInChI; + bIsoTo = 1; + bIsoFrom = -1; /* empty */ + } + else + { + ret = RI_ERR_SYNTAX; /* syntax error */ + } + } + } + } + break; + default: + ret = RI_ERR_SYNTAX; + break; } break; + default: ret = RI_ERR_SYNTAX; break; - } - break; - - default: - ret = RI_ERR_SYNTAX; - break; } if (ret < 0) { @@ -7066,7 +7066,7 @@ int ParseSegmentSp2(const char* str, for (i = 0; i < val; i++) { #if ( FIX_GAF_2019_2==1 ) - if ((iComponent + i > nNumComponents - 1) || (iComponent + i < 0)) + if ((iComponent + i> nNumComponents - 1) || (iComponent + i<0)) { ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; @@ -7077,7 +7077,7 @@ int ParseSegmentSp2(const char* str, goto exit_function; } - if ((pInChIFrom[iComponent + i].nNumberOfAtoms <= 0) || (pInChIFrom[iComponent + i].nNumberOfAtoms > MAX_ATOMS)) + if ((pInChIFrom[iComponent + i].nNumberOfAtoms <= 0) || (pInChIFrom[iComponent + i].nNumberOfAtoms>MAX_ATOMS)) { ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; @@ -7098,11 +7098,11 @@ int ParseSegmentSp2(const char* str, } else /* regular multiplier */ - if ((p = strchr(pStart, '*')) && p < pEnd) + if (( p = strchr( pStart, '*' ) ) && p < pEnd) { - mpy_component = (int)inchi_strtol(pStart, &q, 10); + mpy_component = (int) inchi_strtol( pStart, &q, 10 ); #if ( CHECK_STRTOL_ATNUMB==1 ) - if (mpy_component > MAX_ATOMS || mpy_component < 0) + if (mpy_component>MAX_ATOMS || mpy_component<0) { ret = RI_ERR_SYNTAX; goto exit_function; @@ -7132,9 +7132,9 @@ int ParseSegmentSp2(const char* str, if (p < pEnd && *pbAbc == -1) { /* check if compressed InChI */ - *pbAbc = isupper(UCINT * p) ? 1 : 0; + *pbAbc = isupper( UCINT *p ) ? 1 : 0; } - base = (*pbAbc == 1) ? ALPHA_BASE : 10; + base = ( *pbAbc == 1 ) ? ALPHA_BASE : 10; if (*pbAbc == 1) { /* process the componnt: at1-at2p,at1-at2p,... */ @@ -7142,10 +7142,10 @@ int ParseSegmentSp2(const char* str, for (p = pStart, iBond = 0; p < pEnd; iBond++) { /* atoms 1, 2, and parity */ - if ((nAtom1 = (AT_NUMB)inchi_strtol(p, &p, base)) && - (nAtom2 = (AT_NUMB)inchi_strtol(p, &p, base)) && - (bondParity = (int)inchi_strtol(p, &p, 10), - AB_MIN_KNOWN_PARITY <= bondParity && bondParity <= AB_MAX_KNOWN_PARITY)) + if (( nAtom1 = (AT_NUMB) inchi_strtol( p, &p, base ) ) && + ( nAtom2 = (AT_NUMB) inchi_strtol( p, &p, base ) ) && + ( bondParity = (int) inchi_strtol( p, &p, 10 ), + AB_MIN_KNOWN_PARITY <= bondParity && bondParity <= AB_MAX_KNOWN_PARITY )) { ; /* okay */ } @@ -7155,7 +7155,7 @@ int ParseSegmentSp2(const char* str, goto exit_function; } if (nAtom1 <= nAtom2 || - nAtom1 > pInChI[iComponent].nNumberOfAtoms) + nAtom1 > pInChI[iComponent].nNumberOfAtoms) { ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; @@ -7166,11 +7166,11 @@ int ParseSegmentSp2(const char* str, { /* process the componnt: at1-at2p,at1-at2p,... */ /* pass 1: find number of stereobonds */ - for (p = pStart, iBond = 0; p < pEnd; iBond++, p += (*p == ',')) + for (p = pStart, iBond = 0; p < pEnd; iBond++, p += ( *p == ',' )) { - nAtom1 = (AT_NUMB)inchi_strtol(p, &q, 10); + nAtom1 = (AT_NUMB) inchi_strtol( p, &q, 10 ); #if ( CHECK_STRTOL_ATNUMB==1 ) - if (nAtom1 > MAX_ATOMS || nAtom1 < 0) + if (nAtom1>MAX_ATOMS || nAtom1<0) { ret = RI_ERR_SYNTAX; goto exit_function; @@ -7182,18 +7182,18 @@ int ParseSegmentSp2(const char* str, goto exit_function; } p = q + 1; - nAtom2 = (AT_NUMB)inchi_strtol(p, &q, 10); + nAtom2 = (AT_NUMB) inchi_strtol( p, &q, 10 ); #if ( CHECK_STRTOL_ATNUMB==1 ) - if (nAtom2 > MAX_ATOMS || nAtom2 < 0) + if (nAtom2>MAX_ATOMS || nAtom2<0) { ret = RI_ERR_SYNTAX; goto exit_function; } #endif if (!nAtom1 || !nAtom2 || - nAtom1 <= nAtom2 || - nAtom1 > pInChI[iComponent].nNumberOfAtoms || - !(r = strchr((char*)parity_type, *q))) /* djb-rwth: ignoring LLVM warning: variable used to store function return value */ + nAtom1 <= nAtom2 || + nAtom1 > pInChI[iComponent].nNumberOfAtoms || + !(r = strchr((char *)parity_type, *q))) /* djb-rwth: ignoring LLVM warning: variable used to store function return value */ { ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; @@ -7210,7 +7210,7 @@ int ParseSegmentSp2(const char* str, len = iBond; #if ( FIX_GAF_2019_2==1 ) - if ((iComponent > nNumComponents - 1) || (iComponent < 0)) + if ((iComponent > nNumComponents - 1) || (iComponent<0)) { ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; @@ -7226,40 +7226,40 @@ int ParseSegmentSp2(const char* str, pStereo = bIso ? &pInChI[iComponent].StereoIsotopic : &pInChI[iComponent].Stereo; if (!*pStereo) { - if (!(*pStereo = (INChI_Stereo*)inchi_calloc(1, sizeof(**pStereo)))) + if (!( *pStereo = (INChI_Stereo *) inchi_calloc( 1, sizeof( **pStereo ) ) )) { ret = RI_ERR_ALLOC; /* memory allocation failed */ goto exit_function; } } if (pStereo[0]->b_parity || pStereo[0]->nNumberOfStereoBonds || - pStereo[0]->nBondAtom1 || pStereo[0]->nBondAtom2) + pStereo[0]->nBondAtom1 || pStereo[0]->nBondAtom2) { ret = RI_ERR_SYNTAX; /* syntax error: bonds have already been allocated */ goto exit_function; } /* allocate sp2 stereo */ - if (!(pStereo[0]->b_parity = (S_CHAR*)inchi_calloc((long long)len + 1, sizeof(pStereo[0]->b_parity[0]))) || - !(pStereo[0]->nBondAtom1 = (AT_NUMB*)inchi_calloc((long long)len + 1, sizeof(pStereo[0]->nBondAtom1[0]))) || - !(pStereo[0]->nBondAtom2 = (AT_NUMB*)inchi_calloc((long long)len + 1, sizeof(pStereo[0]->nBondAtom2[0])))) /* djb-rwth: cast operators added */ + if (!( pStereo[0]->b_parity = (S_CHAR *) inchi_calloc( (long long)len + 1, sizeof( pStereo[0]->b_parity[0] ) ) ) || + !( pStereo[0]->nBondAtom1 = (AT_NUMB *) inchi_calloc( (long long)len + 1, sizeof( pStereo[0]->nBondAtom1[0] ) ) ) || + !( pStereo[0]->nBondAtom2 = (AT_NUMB *) inchi_calloc( (long long)len + 1, sizeof( pStereo[0]->nBondAtom2[0] ) ) )) /* djb-rwth: cast operators added */ { /* cleanup */ if (pStereo[0]->b_parity) { INCHI_HEAPCHK - inchi_free(pStereo[0]->b_parity); + inchi_free( pStereo[0]->b_parity ); pStereo[0]->b_parity = NULL; } if (pStereo[0]->nBondAtom1) { INCHI_HEAPCHK - inchi_free(pStereo[0]->nBondAtom1); + inchi_free( pStereo[0]->nBondAtom1 ); pStereo[0]->nBondAtom1 = NULL; } if (pStereo[0]->nBondAtom2) { INCHI_HEAPCHK - inchi_free(pStereo[0]->nBondAtom2); + inchi_free( pStereo[0]->nBondAtom2 ); pStereo[0]->nBondAtom2 = NULL; } INCHI_HEAPCHK @@ -7272,10 +7272,10 @@ int ParseSegmentSp2(const char* str, { for (p = pStart, iBond = 0; p < pEnd; iBond++) { - if ((nAtom1 = (AT_NUMB)inchi_strtol(p, &p, base)) && - (nAtom2 = (AT_NUMB)inchi_strtol(p, &p, base)) && - (bondParity = (int)inchi_strtol(p, &p, 10), - AB_MIN_KNOWN_PARITY <= bondParity && bondParity <= AB_MAX_KNOWN_PARITY)) + if (( nAtom1 = (AT_NUMB) inchi_strtol( p, &p, base ) ) && + ( nAtom2 = (AT_NUMB) inchi_strtol( p, &p, base ) ) && + ( bondParity = (int) inchi_strtol( p, &p, 10 ), + AB_MIN_KNOWN_PARITY <= bondParity && bondParity <= AB_MAX_KNOWN_PARITY )) { ; /* okay */ } @@ -7289,9 +7289,9 @@ int ParseSegmentSp2(const char* str, pStereo[0]->nBondAtom2[iBond] = nAtom2; if (iBond && - !(pStereo[0]->nBondAtom1[iBond - 1] < nAtom1 || + !( pStereo[0]->nBondAtom1[iBond - 1] < nAtom1 || (pStereo[0]->nBondAtom1[iBond - 1] == nAtom1 && - pStereo[0]->nBondAtom2[iBond - 1] < nAtom2))) /* djb-rwth: addressing LLVM warning */ + pStereo[0]->nBondAtom2[iBond - 1] < nAtom2 ))) /* djb-rwth: addressing LLVM warning */ { ret = RI_ERR_SYNTAX; /* syntax error: wrong bond order */ goto exit_function; @@ -7300,11 +7300,11 @@ int ParseSegmentSp2(const char* str, } else { - for (p = pStart, iBond = 0; p < pEnd; iBond++, p += (*p == ',')) + for (p = pStart, iBond = 0; p < pEnd; iBond++, p += ( *p == ',' )) { - nAtom1 = (AT_NUMB)inchi_strtol(p, &q, 10); + nAtom1 = (AT_NUMB) inchi_strtol( p, &q, 10 ); #if ( CHECK_STRTOL_ATNUMB==1 ) - if (nAtom1 > MAX_ATOMS || nAtom1 < 0) + if (nAtom1>MAX_ATOMS || nAtom1<0) { ret = RI_ERR_SYNTAX; goto exit_function; @@ -7316,30 +7316,30 @@ int ParseSegmentSp2(const char* str, goto exit_function; } p = q + 1; - nAtom2 = (AT_NUMB)inchi_strtol(p, &q, 10); + nAtom2 = (AT_NUMB) inchi_strtol( p, &q, 10 ); #if ( CHECK_STRTOL_ATNUMB==1 ) - if (nAtom2 > MAX_ATOMS || nAtom2 < 0) + if (nAtom2>MAX_ATOMS || nAtom2<0) { ret = RI_ERR_SYNTAX; goto exit_function; } #endif - if (!(r = strchr((char*)parity_type, *q))) + if (!(r = strchr((char *)parity_type, *q))) { ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; } p = q + 1; - bondParity = (int)(r - parity_type) + 1; + bondParity = (int) ( r - parity_type ) + 1; /* djb-rwth: ui_rr? */ pStereo[0]->b_parity[iBond] = bondParity; pStereo[0]->nBondAtom1[iBond] = nAtom1; pStereo[0]->nBondAtom2[iBond] = nAtom2; if (iBond && - !(pStereo[0]->nBondAtom1[iBond - 1] < nAtom1 || + !( pStereo[0]->nBondAtom1[iBond - 1] < nAtom1 || (pStereo[0]->nBondAtom1[iBond - 1] == nAtom1 && - pStereo[0]->nBondAtom2[iBond - 1] < nAtom2))) /* djb-rwth: addressing LLVM warning */ + pStereo[0]->nBondAtom2[iBond - 1] < nAtom2 ))) /* djb-rwth: addressing LLVM warning */ { ret = RI_ERR_SYNTAX; /* syntax error: wrong bond order */ goto exit_function; @@ -7357,7 +7357,7 @@ int ParseSegmentSp2(const char* str, /* multiplier */ for (i = 1; i < mpy_component; i++) { - ret = CopySegment(pInChI + iComponent + i, pInChI + iComponent, nCpyType, bIso, bIso); + ret = CopySegment( pInChI + iComponent + i, pInChI + iComponent, nCpyType, bIso, bIso ); if (ret < 0) { goto exit_function; @@ -7375,7 +7375,7 @@ int ParseSegmentSp2(const char* str, { break; } - } + } if (nNumComponents != iComponent) { ret = RI_ERR_SYNTAX; /* syntax error */ @@ -7386,20 +7386,20 @@ int ParseSegmentSp2(const char* str, exit_function: return ret; - } +} /**************************************************************************** Parse "/p" InChI layer ****************************************************************************/ -int ParseSegmentProtons(const char* str, - int bMobileH, - REM_PROTONS nNumProtons[], - int ppnNumComponents[]) +int ParseSegmentProtons( const char *str, + int bMobileH, + REM_PROTONS nNumProtons[], + int ppnNumComponents[] ) { /* Pass 1: count bonds and find actual numbers of atom */ int val; - const char* q, * pStart, * pEnd; + const char *q, *pStart, *pEnd; int ret; if (str[0] != 'p') @@ -7407,25 +7407,25 @@ int ParseSegmentProtons(const char* str, return 0; } - pStart = (char*)str + 1; + pStart = (char *) str + 1; while (1) { /* cycle over components */ - if (!(pEnd = strchr(pStart, ';'))) + if (!( pEnd = strchr( pStart, ';' ) )) { - pEnd = pStart + strlen(pStart); + pEnd = pStart + strlen( pStart ); } - if (pStart[0] == '+' && isdigit(UCINT pStart[1])) + if (pStart[0] == '+' && isdigit( UCINT pStart[1] )) { - val = (int)inchi_strtol(pStart + 1, &q, 10); + val = (int) inchi_strtol( pStart + 1, &q, 10 ); } else { - if (pStart[0] == '-' && isdigit(UCINT pStart[1])) + if (pStart[0] == '-' && isdigit( UCINT pStart[1] )) { - val = -(int)inchi_strtol(pStart + 1, &q, 10); + val = -(int) inchi_strtol( pStart + 1, &q, 10 ); } else { @@ -7460,42 +7460,42 @@ int ParseSegmentProtons(const char* str, /**************************************************************************** Parse "/z" InChI layer ****************************************************************************/ -int ParseSegmentPolymer(const char* str, - int bMobileH, - REM_PROTONS nNumProtons[], - int ppnNumComponents[], - int na_total, - int nb_total, - int bInchi2Struct, - OAD_Polymer** ppPolymer, - OAD_V3000** ppV3000) +int ParseSegmentPolymer( const char *str, + int bMobileH, + REM_PROTONS nNumProtons[], + int ppnNumComponents[], + int na_total, + int nb_total, + int bInchi2Struct, + OAD_Polymer **ppPolymer, + OAD_V3000 **ppV3000 ) { - const char* p, * q, * pStart, * pEnd, * p0; + const char *p, *q, *pStart, *pEnd, *p0; char comma = ',', dot = '.', dash = '-', lt_par = '(', rt_par = ')'; int iunit, val, ret, prev, is_range; int curr_atom, type = -1, subtype = -1, conn = -1; AT_NUMB num_atom; INT_ARRAY alist; - OAD_Polymer* pd = NULL; + OAD_Polymer *pd = NULL; if (str[0] != 'z') { return 0; } - if (IntArray_Alloc(&alist, 4)) + if (IntArray_Alloc( &alist, 4 )) { return RI_ERR_ALLOC; } if (*ppPolymer) { - OAD_Polymer_Free(*ppPolymer); + OAD_Polymer_Free( *ppPolymer ); } - pd = *ppPolymer = (OAD_Polymer*) - inchi_calloc(1, sizeof(OAD_Polymer)); - (*ppPolymer)->pzz = NULL; + pd = *ppPolymer = (OAD_Polymer *) + inchi_calloc( 1, sizeof( OAD_Polymer ) ); + ( *ppPolymer )->pzz = NULL; if (!pd) { @@ -7510,24 +7510,24 @@ int ParseSegmentPolymer(const char* str, /* Count units */ pd->n = 1; - p = (char*)str + 1; - while ((p = strchr(p, ';'))) /* djb-rwth: addressing LLVM warning */ + p = (char *) str + 1; + while ((p = strchr( p, ';' ))) /* djb-rwth: addressing LLVM warning */ { p++; pd->n++; } pd->units = (OAD_PolymerUnit**) - inchi_calloc(pd->n, sizeof(OAD_PolymerUnit*)); + inchi_calloc( pd->n, sizeof( OAD_PolymerUnit * ) ); if (!pd->units) { ret = RI_ERR_ALLOC; goto exit_function; } - pStart = (char*)str; + pStart = (char *) str; pStart++; if (!pStart) { - ret = RI_ERR_PROGR; + ret = RI_ERR_PROGR; goto exit_function; } @@ -7535,33 +7535,33 @@ int ParseSegmentPolymer(const char* str, /* djb-rwth: fixing oss-fuzz issue #67678 */ while (pStart && (*pStart)) { - OAD_PolymerUnit* unit = NULL; + OAD_PolymerUnit *unit = NULL; if (*pStart == ';') { pStart++; } - if (!(pEnd = strchr(pStart, ';'))) + if (!( pEnd = strchr( pStart, ';' ) )) { - pEnd = pStart + strlen(pStart); + pEnd = pStart + strlen( pStart ); } - if (!isdigit(UCINT pStart[0])) + if (!isdigit( UCINT pStart[0] )) { ret = RI_ERR_SYNTAX; goto exit_function; } - val = (int)inchi_strtol(pStart + 0, &q, 10); + val = (int)inchi_strtol( pStart + 0, &q, 10 ); type = val / 100; subtype = (val - (type * 100)) / 10; - conn = (val - (type * 100 + subtype * 10)); + conn = (val - (type * 100 + subtype * 10)); if (*q != '-') { ret = RI_ERR_SYNTAX; goto exit_function; } #if ( FIX_OSS_FUZZ_30162_30343==1 ) - if (val < 100) /* type should always be non-zero followed by subtype and conn, like 101 or 200 */ + if (val<100) /* type should always be non-zero followed by subtype and conn, like 101 or 200 */ { ret = RI_ERR_SYNTAX; goto exit_function; @@ -7598,9 +7598,9 @@ int ParseSegmentPolymer(const char* str, is_range = 0; for (p = q, curr_atom = 0; p < pEnd && *p != '('; curr_atom++) { - num_atom = (AT_NUMB)inchi_strtol(p, &p, 10); + num_atom = (AT_NUMB) inchi_strtol( p, &p, 10 ); #if ( ( CHECK_STRTOL_ATNUMB==1 ) || ( FIX_GAF_2019_2==1 ) ) - if (num_atom > na_total || num_atom < 0) + if (num_atom>na_total || num_atom<0) { ret = RI_ERR_SYNTAX; goto exit_function; @@ -7615,7 +7615,7 @@ int ParseSegmentPolymer(const char* str, int a; for (a = prev + 1; a <= num_atom; a++) { - if (0 != IntArray_Append(&alist, a)) + if (0 != IntArray_Append( &alist, a )) { ret = RI_ERR_ALLOC; goto exit_function; } @@ -7625,7 +7625,7 @@ int ParseSegmentPolymer(const char* str, } else { - if (0 != IntArray_Append(&alist, num_atom)) + if (0 != IntArray_Append( &alist, num_atom )) { ret = RI_ERR_ALLOC; goto exit_function; } @@ -7644,20 +7644,20 @@ int ParseSegmentPolymer(const char* str, if (alist.used) { - unit = OAD_PolymerUnit_New(4, /* maxatoms */ - 0, /* maxbonds=0 for now */ - iunit + 1, /* id */ - iunit + 1, /* label */ - type, - subtype, - conn, - "", /* smt */ - alist.used, - &alist, - 0, /* blist.used */ - NULL, /* &blist */ - 0, /* nlinks */ - NULL /* **links */ + unit = OAD_PolymerUnit_New( 4, /* maxatoms */ + 0, /* maxbonds=0 for now */ + iunit + 1, /* id */ + iunit + 1, /* label */ + type, + subtype, + conn, + "", /* smt */ + alist.used, + &alist, + 0, /* blist.used */ + NULL, /* &blist */ + 0, /* nlinks */ + NULL /* **links */ ); if (!unit) @@ -7665,7 +7665,7 @@ int ParseSegmentPolymer(const char* str, ret = RI_ERR_ALLOC; goto exit_function; } pd->units[iunit] = unit; - IntArray_Reset(&alist); + IntArray_Reset( &alist ); iunit++; } @@ -7677,14 +7677,14 @@ int ParseSegmentPolymer(const char* str, int res, ib, err = 0; /* djb-rwth: ignoring LLVM warning: variable used to store function return value */ INT_ARRAY numlist; - if (IntArray_Alloc(&numlist, 4)) + if (IntArray_Alloc( &numlist, 4 )) { ret = RI_ERR_ALLOC; goto exit_function; } p0 = p; - while (*(++p)) + while (*( ++p )) { if (*p == '-') { @@ -7697,7 +7697,7 @@ int ParseSegmentPolymer(const char* str, } if (have == stars) { - while (*(++p)) + while (*( ++p )) { if (*p == ',') { @@ -7837,7 +7837,7 @@ int ParseSegmentPolymer(const char* str, } pStart = p + 1; - IntArray_Free(&numlist); + IntArray_Free( &numlist ); continue; } @@ -7860,7 +7860,7 @@ int ParseSegmentPolymer(const char* str, exit_function: - IntArray_Free(&alist); + IntArray_Free( &alist ); if (ret == RI_ERR_ALLOC || ret == RI_ERR_SYNTAX || ret == RI_ERR_PROGR) { /*FreeExtOrigAtData( pd, pv );*/ @@ -7891,7 +7891,7 @@ int ParseSegmentPolymer(const char* str, { break; } - if (astar1 > maxats || astar1 <= 0 || astar2 > maxats || astar2 <= 0) + if (astar1>maxats || astar1 <= 0 || astar2>maxats || astar2 <= 0) { ret = RI_ERR_SYNTAX; break; @@ -7901,7 +7901,7 @@ int ParseSegmentPolymer(const char* str, int a1psb, a2psb; a1psb = pd->units[iu]->bkbonds[ipsb][0]; a2psb = pd->units[iu]->bkbonds[ipsb][1]; - if (a1psb > maxats || a1psb <= 0 || a2psb > maxats || a2psb <= 0) + if (a1psb>maxats || a1psb <= 0 || a2psb>maxats || a2psb <= 0) { ret = RI_ERR_SYNTAX; break; @@ -7922,14 +7922,14 @@ Numbers are assumed to be delimited with commas. NB: on success, returns 1. ****************************************************************************/ -const char* ParseSegmentReadDelimitedNumbers(const char* str, - const char* pEnd, - INT_ARRAY* numlist, - char c_delim, - char c_stop, - int* ret) +const char* ParseSegmentReadDelimitedNumbers( const char *str, + const char *pEnd, + INT_ARRAY *numlist, + char c_delim, + char c_stop, + int *ret ) { - const char* p, * pStart; + const char *p, *pStart; int num, curr_atom = 0; *ret = 1; @@ -7940,22 +7940,22 @@ const char* ParseSegmentReadDelimitedNumbers(const char* str, return NULL; } - pStart = (char*)(str + 1); + pStart = (char *) ( str + 1 ); p = pStart; while (*pStart) { for (p = pStart, curr_atom = 0; p < pEnd && *p != c_stop; curr_atom++) { - num = (AT_NUMB)inchi_strtol(p, &p, 10); + num = (AT_NUMB) inchi_strtol( p, &p, 10 ); #if ( CHECK_STRTOL_ATNUMB==1 ) - if (num > MAX_ATOMS || num < 0) + if (num>MAX_ATOMS || num<0) { *ret = RI_ERR_SYNTAX; return p; } #endif { - if (0 != IntArray_Append(numlist, num)) + if (0 != IntArray_Append( numlist, num )) { *ret = RI_ERR_SYNTAX; return p; @@ -7984,21 +7984,20 @@ const char* ParseSegmentReadDelimitedNumbers(const char* str, } - /**************************************************************************** Parse "/q" InChI layer ****************************************************************************/ -int ParseSegmentCharge(const char* str, - int bMobileH, - INChI* pInpInChI[], - int ppnNumComponents[]) +int ParseSegmentCharge( const char *str, + int bMobileH, + INChI *pInpInChI[], + int ppnNumComponents[] ) { /* Pass 1: count bonds and find actual numbers of atom */ int i, mpy_component, val; int nNumComponents, iComponent; - const char* p, * q, * t, * pStart, * pEnd; + const char *p, *q, *t, *pStart, *pEnd; int ret; - INChI* pInChI = pInpInChI[bMobileH]; + INChI *pInChI = pInpInChI[bMobileH]; const char mult_type[] = "mnMNe"; if (str[0] != 'q') @@ -8006,7 +8005,7 @@ int ParseSegmentCharge(const char* str, return 0; } - pStart = (char*)str + 1; + pStart = (char *) str + 1; iComponent = 0; nNumComponents = ppnNumComponents[bMobileH]; @@ -8022,9 +8021,9 @@ int ParseSegmentCharge(const char* str, while (1) { /* cycle over components */ - if (!(pEnd = strchr(pStart, ';'))) + if (!( pEnd = strchr( pStart, ';' ) )) { - pEnd = pStart + strlen(pStart); + pEnd = pStart + strlen( pStart ); } /* djb-rwth: condition for if block had to be rewritten */ @@ -8048,39 +8047,39 @@ int ParseSegmentCharge(const char* str, switch (bMobileH) { - case TAUT_YES: - ret = RI_ERR_SYNTAX; /* syntax error */ - goto exit_function; - case TAUT_NON: - if (*q != 'm' || - iComponent + val > nNumComponents || - iComponent + val > ppnNumComponents[TAUT_YES]) - { + case TAUT_YES: + ret = RI_ERR_SYNTAX; /* syntax error */ + goto exit_function; + case TAUT_NON: + if (*q != 'm' || + iComponent + val > nNumComponents || + iComponent + val > ppnNumComponents[TAUT_YES]) + { + ret = RI_ERR_SYNTAX; /* syntax error */ + goto exit_function; + } + for (i = 0; i < val; i++) + { + /* avoid 0 which means "omitted" */ + pInChI[iComponent + i].nTotalCharge = pInpInChI[TAUT_YES][iComponent + i].nTotalCharge ? + pInpInChI[TAUT_YES][iComponent + i].nTotalCharge : + NO_VALUE_INT; + } + mpy_component = val; + goto end_main_cycle; + default: ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; - } - for (i = 0; i < val; i++) - { - /* avoid 0 which means "omitted" */ - pInChI[iComponent + i].nTotalCharge = pInpInChI[TAUT_YES][iComponent + i].nTotalCharge ? - pInpInChI[TAUT_YES][iComponent + i].nTotalCharge : - NO_VALUE_INT; - } - mpy_component = val; - goto end_main_cycle; - default: - ret = RI_ERR_SYNTAX; /* syntax error */ - goto exit_function; } } else { - if ((p = strchr(pStart, '*')) && p < pEnd) + if (( p = strchr( pStart, '*' ) ) && p < pEnd) { - mpy_component = (int)inchi_strtol(pStart, &q, 10); + mpy_component = (int) inchi_strtol( pStart, &q, 10 ); #if ( CHECK_STRTOL_ATNUMB==1 ) - if (mpy_component > MAX_ATOMS || mpy_component < 0) + if (mpy_component>MAX_ATOMS || mpy_component<0) { ret = RI_ERR_SYNTAX; goto exit_function; @@ -8109,16 +8108,16 @@ int ParseSegmentCharge(const char* str, pStart = p; if (pStart < pEnd) { - if (pStart[0] == '+' && isdigit(UCINT pStart[1])) + if (pStart[0] == '+' && isdigit( UCINT pStart[1] )) { - val = (int)inchi_strtol(pStart + 1, &q, 10); + val = (int) inchi_strtol( pStart + 1, &q, 10 ); pStart = q; } else { - if (pStart[0] == '-' && isdigit(UCINT pStart[1])) + if (pStart[0] == '-' && isdigit( UCINT pStart[1] )) { - val = -(int)inchi_strtol(pStart + 1, &q, 10); + val = -(int) inchi_strtol( pStart + 1, &q, 10 ); pStart = q; } else @@ -8198,9 +8197,9 @@ int ParseSegmentMobileH( const char *str, int i, mpy_component, num_H, num_Minus, val, num_Atoms, numCtAtoms, tg_alloc_len, len, len2, k = 0; int num_H_component, num_H_formula, num_taut_H_component, num_H_InChI, ret2; int nNumComponents, iComponent, lenTautomer, tg_pos_Tautomer, iTGroup; /* djb-rwth: removing redundant variables */ - const char* p, * q, * h, * t, * p1, * pTaut, * pStart, * pEnd; + const char *p, *q, *h, *t, *p1, *pTaut, *pStart, *pEnd; AT_NUMB curAtom, nxtAtom; - int state, ret, nAltMobileH = ALT_TAUT(bMobileH); /* djb-rwth: removing redundant variables */ + int state, ret, nAltMobileH = ALT_TAUT( bMobileH ); /* djb-rwth: removing redundant variables */ INChI *pInChI = pInpInChI[bMobileH]; INChI *pAltInChI = pInpInChI[nAltMobileH]; int base = 10; @@ -8213,7 +8212,9 @@ int ParseSegmentMobileH( const char *str, nNumComponents = pnNumComponents[bMobileH]; /* djb-rwth: fixing oss-fuzz issues #66985, #66718, #43512, #43456, #43420, #42774, #34772, #30156 */ - + /* S_CHAR** pi_nnh1 = (S_CHAR**)inchi_malloc(nNumComponents * sizeof(S_CHAR*)); + S_CHAR** pi_nnh2 = (S_CHAR**)inchi_malloc(nNumComponents * sizeof(S_CHAR*)); + bool pi_nnh2_init = false; */ for (i = 0; i < nNumComponents; i++) { len = pInChI[i].nNumberOfAtoms; @@ -8280,7 +8281,7 @@ int ParseSegmentMobileH( const char *str, ret = RI_ERR_ALLOC; goto exit_function; } - + } */ } @@ -8368,8 +8369,8 @@ int ParseSegmentMobileH( const char *str, pTaut = pEnd; t = NULL; /* found no tautomeric group for this component */ } - /* djb-rwth: fixing oss-fuzz issue #69489 -- ui_rr */ - for (i = 0; (i < mpy_component); i++) + /* djb-rwth: fixing oss-fuzz issue #69489 */ + for (i = 0; (i < mpy_component) && (iComponent + i < pi_nnc1); i++) { if (bMobileH == TAUT_NON) { @@ -8441,7 +8442,7 @@ int ParseSegmentMobileH( const char *str, ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; } - if ((curAtom = nxtAtom = (int)inchi_strtol(p, &q, base))) /* djb-rwth: addressing LLVM warning */ + if ((curAtom = nxtAtom = (int) inchi_strtol( p, &q, base ))) /* djb-rwth: addressing LLVM warning */ { p = q; if (isupper( UCINT *p )) @@ -8691,7 +8692,7 @@ int ParseSegmentMobileH( const char *str, tg_alloc_len = ( ( 3 + INCHI_T_NUM_MOVABLE )*pInChI[iComponent].nNumberOfAtoms ) / 2 + 1; for (i = 0; i < mpy_component; i++) { - pInChI[iComponent + i].nTautomer = (AT_NUMB*)inchi_calloc((long long)tg_alloc_len + 1, sizeof(pInChI->nTautomer[0])); /* djb-rwth: cast operator added */ + pInChI[iComponent + i].nTautomer = (AT_NUMB*) inchi_calloc( (long long)tg_alloc_len + 1, sizeof( pInChI->nTautomer[0] ) ); /* djb-rwth: cast operator added */ if (!pInChI[iComponent + i].nTautomer) { ret = RI_ERR_ALLOC; /* allocation error */ @@ -8729,7 +8730,7 @@ int ParseSegmentMobileH( const char *str, pInChI[iComponent].nTautomer[lenTautomer++] = val; p = q; } - if (!num_Atoms || (p < pEnd && !isdigit(UCINT * p))) /* djb-rwth: addressing LLVM warning */ + if (!num_Atoms || (p < pEnd && !isdigit( UCINT *p ))) /* djb-rwth: addressing LLVM warning */ { ret = RI_ERR_PROGR; /* wrong tautomer array length */ goto exit_function; @@ -8973,7 +8974,7 @@ int ParseSegmentMobileH( const char *str, } #endif /* djb-rwth: fixing oss-fuzz issue #69699 */ - if ((iComponent < 0) || (iComponent > pi_nnc2)) + if ((iComponent < 0) || (iComponent >= pi_nnc2)) { ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; @@ -9040,23 +9041,23 @@ int ParseSegmentMobileH( const char *str, /**************************************************************************** Parse "/c" InChI layer ****************************************************************************/ -int ParseSegmentConnections(const char* str, - int bMobileH, - INChI** pInpInChI, - int* pnNumComponents, - int* pbAbc, - int* nb_total) +int ParseSegmentConnections( const char *str, + int bMobileH, + INChI **pInpInChI, + int *pnNumComponents, + int *pbAbc, + int *nb_total ) { #define LAST_AT_LEN 256 /* Pass 1: count bonds and find actual numbers of atom */ int i, j, k, m, c, mpy_component; int nNumComponents, iComponent, nNumAtoms, nNumBonds, lenConnTable; /* djb-rwth: removing redundant variables */ - const char* p, * q, * pStart, * pEnd; + const char *p, *q, *pStart, *pEnd; AT_NUMB last_atom[LAST_AT_LEN], curAtom, maxAtom; int num_open, state, ret, base; - INChI* pInChI = *pInpInChI; + INChI *pInChI = *pInpInChI; LINKED_BONDS LB; - LINKED_BONDS* pLB = &LB; /* a list of linked lists of bonds, for each atom */ + LINKED_BONDS *pLB = &LB; /* a list of linked lists of bonds, for each atom */ AT_NUMB neighbor[MAXVAL]; int bPrevVersion = -1; @@ -9072,12 +9073,12 @@ int ParseSegmentConnections(const char* str, lenConnTable = 0; nNumComponents = 1; /* allocate InChI */ - if (!(pInChI = *pInpInChI = (INChI*)inchi_calloc(nNumComponents, sizeof(INChI)))) + if (!( pInChI = *pInpInChI = (INChI *) inchi_calloc( nNumComponents, sizeof( INChI ) ) )) { return RI_ERR_ALLOC; /* alloc failure */ } /* allocate empty formula */ - pInChI[iComponent].szHillFormula = (char*)inchi_calloc((long long)lenFormula + 1, sizeof(pInChI[0].szHillFormula[0])); /* djb-rwth: cast operator added */ + pInChI[iComponent].szHillFormula = (char *) inchi_calloc( (long long)lenFormula + 1, sizeof( pInChI[0].szHillFormula[0] ) ); /* djb-rwth: cast operator added */ if (!pInChI[iComponent].szHillFormula) { ret = RI_ERR_ALLOC; /* allocation failure */ @@ -9121,8 +9122,8 @@ int ParseSegmentConnections(const char* str, } /* Pass 1. Re-Count atoms, count bonds */ - - pStart = (char*)str + 1; + + pStart = (char *) str + 1; nNumComponents = *pnNumComponents; #if (FIX_DALKE_BUGS == 1) /* prevent crash on too many components */ @@ -9132,20 +9133,20 @@ int ParseSegmentConnections(const char* str, goto exit_function; } #endif - memset(pLB, 0, sizeof(pLB[0])); /* djb-rwth: memset_s C11/Annex K variant? */ + memset( pLB, 0, sizeof( pLB[0] ) ); /* djb-rwth: memset_s C11/Annex K variant? */ while (1) { /* cycle over components */ - if (!(pEnd = strchr(pStart, ';'))) + if (!( pEnd = strchr( pStart, ';' ) )) { - pEnd = pStart + strlen(pStart); + pEnd = pStart + strlen( pStart ); } - if ((p = strchr(pStart, '*')) && p < pEnd) + if (( p = strchr( pStart, '*' ) ) && p < pEnd) { - mpy_component = (int)inchi_strtol(pStart, &q, 10); + mpy_component = (int) inchi_strtol( pStart, &q, 10 ); #if ( CHECK_STRTOL_ATNUMB==1 ) - if (mpy_component > MAX_ATOMS || mpy_component < 0) + if (mpy_component>MAX_ATOMS || mpy_component<0) { ret = RI_ERR_SYNTAX; goto exit_function; @@ -9153,9 +9154,9 @@ int ParseSegmentConnections(const char* str, #endif if (p != q #if (FIX_DALKE_BUGS == 1) - || !isdigit(UCINT * pStart) + || !isdigit( UCINT *pStart ) #endif - ) + ) { ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; @@ -9177,7 +9178,7 @@ int ParseSegmentConnections(const char* str, pStart = p; /* Pass 1.1 parse a component */ num_open = 0; - memset(last_atom, 0, sizeof(last_atom)); /* djb-rwth: memset_s C11/Annex K variant? */ + memset( last_atom, 0, sizeof( last_atom ) ); /* djb-rwth: memset_s C11/Annex K variant? */ state = '\0'; /* initial state */ maxAtom = 0; nNumBonds = 0; @@ -9185,7 +9186,7 @@ int ParseSegmentConnections(const char* str, if (p < pEnd && *pbAbc == -1) { /* check if compressed InChI */ - *pbAbc = isupper(UCINT * p) ? 1 : 0; + *pbAbc = isupper( UCINT *p ) ? 1 : 0; } base = *pbAbc ? ALPHA_BASE : 10; @@ -9210,7 +9211,7 @@ int ParseSegmentConnections(const char* str, nNumAtoms--; p++; } - if (isdigit(UCINT * p)) + if (isdigit( UCINT *p )) { if (bPrevVersion == -1) { @@ -9223,9 +9224,9 @@ int ParseSegmentConnections(const char* str, ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; } - nNumAtoms -= inchi_strtol(p, &p, 10); /* bypass digits */ + nNumAtoms -= inchi_strtol( p, &p, 10 ); /* bypass digits */ } - if (*p != '-' && (curAtom = (AT_NUMB)inchi_strtol(p, &q, base))) + if (*p != '-' && ( curAtom = (AT_NUMB) inchi_strtol( p, &q, base ) )) { nNumAtoms++; nNumBonds++; @@ -9249,53 +9250,53 @@ int ParseSegmentConnections(const char* str, while (p < pEnd) { /* atom number */ - c = UCINT * p++; + c = UCINT *p++; switch (c) { - case '(': - case ')': - case ',': - case '-': - if (state != 'N') - { - ret = RI_ERR_SYNTAX; /* syntax error */ - goto exit_function; - } - state = c; - num_open += (c == '(') - (c == ')'); - if (num_open < 0) - { - ret = RI_ERR_SYNTAX; /* syntax error */ - goto exit_function; - } - break; - default: - if (isdigit(c) && (curAtom = (AT_NUMB)inchi_strtol(p - 1, &q, 10))) - { - p = q; - switch (state) + case '(': + case ')': + case ',': + case '-': + if (state != 'N') + { + ret = RI_ERR_SYNTAX; /* syntax error */ + goto exit_function; + } + state = c; + num_open += ( c == '(' ) - ( c == ')' ); + if (num_open < 0) + { + ret = RI_ERR_SYNTAX; /* syntax error */ + goto exit_function; + } + break; + default: + if (isdigit( c ) && ( curAtom = (AT_NUMB) inchi_strtol( p - 1, &q, 10 ) )) + { + p = q; + switch (state) + { + case '(': + case ')': + case ',': + case '-': + nNumBonds++; + case '\0': + if (maxAtom < curAtom) + maxAtom = curAtom; + state = 'N'; + break; + default: + ret = RI_ERR_SYNTAX; /* syntax error */ + goto exit_function; + } + } + else { - case '(': - case ')': - case ',': - case '-': - nNumBonds++; - case '\0': - if (maxAtom < curAtom) - maxAtom = curAtom; - state = 'N'; - break; - default: ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; } - } - else - { - ret = RI_ERR_SYNTAX; /* syntax error */ - goto exit_function; - } - break; + break; } } if (num_open) @@ -9305,10 +9306,10 @@ int ParseSegmentConnections(const char* str, /* syntax error: parentheses do not match */ } } - (*nb_total) += nNumBonds; + ( *nb_total ) += nNumBonds; /* Save the results and allocate memory */ - nNumAtoms = (int)maxAtom; /* 0 if empty connection table and no bonds present */ + nNumAtoms = (int) maxAtom; /* 0 if empty connection table and no bonds present */ lenConnTable = nNumAtoms + nNumBonds; /* connection table format: At1[,Neigh11,Neigh12,...],At2[,Neigh21,Neigh22,...],AtN[NeighN1,NeighN2,...] */ @@ -9316,7 +9317,7 @@ int ParseSegmentConnections(const char* str, for (i = 0; i < mpy_component; i++) { #if ( FIX_GAF_2019_2==1 ) - if ((iComponent + i > nNumComponents - 1) || (iComponent + i < 0)) + if ((iComponent + i > nNumComponents - 1) || (iComponent + i<0)) { ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; @@ -9328,16 +9329,16 @@ int ParseSegmentConnections(const char* str, } #endif /* check number of atoms: the difference may be due to bridging H */ - if ((j = pInChI[iComponent + i].nNumberOfAtoms) < nNumAtoms) + if (( j = pInChI[iComponent + i].nNumberOfAtoms ) < nNumAtoms) { /* reallocate */ - U_CHAR* nAtomTmp = (U_CHAR*)inchi_malloc((long long)nNumAtoms + 1); /* djb-rwth: cast operator added */ + U_CHAR *nAtomTmp = (U_CHAR *) inchi_malloc( (long long)nNumAtoms + 1 ); /* djb-rwth: cast operator added */ if (!nAtomTmp) { ret = RI_ERR_ALLOC; /* allocation failure */ goto exit_function; } - memcpy(nAtomTmp, pInChI[iComponent + i].nAtom, sizeof(nAtomTmp[0]) * j); + memcpy(nAtomTmp, pInChI[iComponent + i].nAtom, sizeof(nAtomTmp[0])* j); while (j < nNumAtoms) { nAtomTmp[j++] = EL_NUMBER_H; /* bridging H */ @@ -9346,14 +9347,14 @@ int ParseSegmentConnections(const char* str, INCHI_HEAPCHK if (pInChI[iComponent + i].nAtom) { - inchi_free(pInChI[iComponent + i].nAtom); + inchi_free( pInChI[iComponent + i].nAtom ); } pInChI[iComponent + i].nAtom = nAtomTmp; pInChI[iComponent + i].nNumberOfAtoms = nNumAtoms; } else { - if (j > nNumAtoms && (lenConnTable || j != 1)) + if (j > nNumAtoms && ( lenConnTable || j != 1 )) { ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; @@ -9362,13 +9363,13 @@ int ParseSegmentConnections(const char* str, /* allocate connection table */ if (pInChI[iComponent + i].nConnTable) { - inchi_free(pInChI[iComponent + i].nConnTable); + inchi_free( pInChI[iComponent + i].nConnTable ); } if (!nNumAtoms && !nNumBonds && !lenConnTable) { lenConnTable = 1; /* one atom, no bonds */ } - pInChI[iComponent + i].nConnTable = (AT_NUMB*)inchi_calloc((long long)lenConnTable + 1, sizeof(pInChI[0].nConnTable[0])); /* djb-rwth: cast operator added */ + pInChI[iComponent + i].nConnTable = (AT_NUMB *) inchi_calloc( (long long)lenConnTable + 1, sizeof( pInChI[0].nConnTable[0] ) ); /* djb-rwth: cast operator added */ if (!pInChI[iComponent + i].nConnTable) { ret = RI_ERR_ALLOC; /* allocation failure */ @@ -9379,7 +9380,7 @@ int ParseSegmentConnections(const char* str, /* Pass 1.2 parse a component and extract the bonds */ num_open = 0; - memset(last_atom, 0, sizeof(last_atom)); /* djb-rwth: memset_s C11/Annex K variant? */ + memset( last_atom, 0, sizeof( last_atom ) ); /* djb-rwth: memset_s C11/Annex K variant? */ state = '\0'; /* initial state */ /* djb-rwth: removing redundant code */ p = pStart; @@ -9398,10 +9399,10 @@ int ParseSegmentConnections(const char* str, ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; } - if (isupper(UCINT * p)) + if (isupper( UCINT *p )) { - curAtom = (AT_NUMB)inchi_strtol(p, &q, base); - if ((ret = AddLinkedBond(last_atom[num_open], curAtom, (AT_NUMB)nNumAtoms, pLB))) /* djb-rwth: addressing LLVM warning */ + curAtom = (AT_NUMB) inchi_strtol( p, &q, base ); + if ((ret = AddLinkedBond( last_atom[num_open], curAtom, (AT_NUMB) nNumAtoms, pLB ))) /* djb-rwth: addressing LLVM warning */ { goto exit_function; } @@ -9411,9 +9412,9 @@ int ParseSegmentConnections(const char* str, while (p < pEnd && *p == '-') { p++; - if ((curAtom = (AT_NUMB)inchi_strtol(p, &q, base))) /* djb-rwth: addressing LLVM warning */ + if ((curAtom = (AT_NUMB) inchi_strtol( p, &q, base ))) /* djb-rwth: addressing LLVM warning */ { - if ((ret = AddLinkedBond(last_atom[num_open], curAtom, (AT_NUMB)nNumAtoms, pLB))) /* djb-rwth: addressing LLVM warning */ + if ((ret = AddLinkedBond( last_atom[num_open], curAtom, (AT_NUMB) nNumAtoms, pLB ))) /* djb-rwth: addressing LLVM warning */ { goto exit_function; } @@ -9428,15 +9429,15 @@ int ParseSegmentConnections(const char* str, } else { - if (bPrevVersion == 0 && isdigit(*p)) + if (bPrevVersion == 0 && isdigit( *p )) { - num_neigh = (int)inchi_strtol(p, &q, 10); + num_neigh = (int) inchi_strtol( p, &q, 10 ); p = q; while (num_neigh-- && p < pEnd) { - if ((curAtom = (AT_NUMB)inchi_strtol(p, &q, base))) /* djb-rwth: addressing LLVM warning */ + if ((curAtom = (AT_NUMB) inchi_strtol( p, &q, base ))) /* djb-rwth: addressing LLVM warning */ { - if ((ret = AddLinkedBond(last_atom[num_open], curAtom, (AT_NUMB)nNumAtoms, pLB))) /* djb-rwth: addressing LLVM warning */ + if ((ret = AddLinkedBond( last_atom[num_open], curAtom, (AT_NUMB) nNumAtoms, pLB ))) /* djb-rwth: addressing LLVM warning */ { goto exit_function; } @@ -9450,7 +9451,7 @@ int ParseSegmentConnections(const char* str, } } } - last_atom[num_open]++; + last_atom[num_open] ++; } else { @@ -9464,93 +9465,93 @@ int ParseSegmentConnections(const char* str, while (p < pEnd) { /* each atom number except the first means a new bond */ - c = UCINT * p++; + c = UCINT *p++; switch (c) { - case '(': - case ')': - case ',': - case '-': - switch (state) - { - case 'N': - state = c; - break; - default: - ret = RI_ERR_SYNTAX; /* syntax error */ - goto exit_function; - } - break; - default: - if (isdigit(c) && (curAtom = (AT_NUMB)inchi_strtol(p - 1, &q, 10))) - { - p = q; + case '(': + case ')': + case ',': + case '-': switch (state) { - case '\0': - last_atom[num_open] = curAtom; - state = 'N'; - break; - case '(': - if ((ret = AddLinkedBond(last_atom[num_open], curAtom, (AT_NUMB)nNumAtoms, pLB))) /* djb-rwth: addressing LLVM warning */ - { - goto exit_function; - } - if (++num_open >= LAST_AT_LEN) - { - ret = RI_ERR_PROGR; /* program error: buffer overflow */ - goto exit_function; - } - last_atom[num_open] = curAtom; - state = 'N'; - break; - - case ')': - if (!num_open) - { + case 'N': + state = c; + break; + default: ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; - } - if ((ret = AddLinkedBond(last_atom[--num_open], curAtom, (AT_NUMB)nNumAtoms, pLB))) /* djb-rwth: addressing LLVM warning */ + } + break; + default: + if (isdigit( c ) && ( curAtom = (AT_NUMB) inchi_strtol( p - 1, &q, 10 ) )) + { + p = q; + switch (state) { - goto exit_function; - } - last_atom[num_open] = curAtom; - state = 'N'; - break; + case '\0': + last_atom[num_open] = curAtom; + state = 'N'; + break; + case '(': + if ((ret = AddLinkedBond( last_atom[num_open], curAtom, (AT_NUMB) nNumAtoms, pLB ))) /* djb-rwth: addressing LLVM warning */ + { + goto exit_function; + } + if (++num_open >= LAST_AT_LEN) + { + ret = RI_ERR_PROGR; /* program error: buffer overflow */ + goto exit_function; + } + last_atom[num_open] = curAtom; + state = 'N'; + break; - case ',': - if (!num_open) - { - ret = RI_ERR_SYNTAX; /* syntax error */ - goto exit_function; - } - if ((ret = AddLinkedBond(last_atom[num_open - 1], curAtom, (AT_NUMB)nNumAtoms, pLB))) /* djb-rwth: addressing LLVM warning */ - { - goto exit_function; - } - last_atom[num_open] = curAtom; - state = 'N'; - break; - case '-': - if ((ret = AddLinkedBond(last_atom[num_open], curAtom, (AT_NUMB)nNumAtoms, pLB))) /* djb-rwth: addressing LLVM warning */ - { - goto exit_function; + case ')': + if (!num_open) + { + ret = RI_ERR_SYNTAX; /* syntax error */ + goto exit_function; + } + if ((ret = AddLinkedBond( last_atom[--num_open], curAtom, (AT_NUMB) nNumAtoms, pLB ))) /* djb-rwth: addressing LLVM warning */ + { + goto exit_function; + } + last_atom[num_open] = curAtom; + state = 'N'; + break; + + case ',': + if (!num_open) + { + ret = RI_ERR_SYNTAX; /* syntax error */ + goto exit_function; + } + if ((ret = AddLinkedBond( last_atom[num_open - 1], curAtom, (AT_NUMB) nNumAtoms, pLB ))) /* djb-rwth: addressing LLVM warning */ + { + goto exit_function; + } + last_atom[num_open] = curAtom; + state = 'N'; + break; + case '-': + if ((ret = AddLinkedBond( last_atom[num_open], curAtom, (AT_NUMB) nNumAtoms, pLB ))) /* djb-rwth: addressing LLVM warning */ + { + goto exit_function; + } + last_atom[num_open] = curAtom; + state = 'N'; + break; + default: + ret = RI_ERR_SYNTAX; /* syntax error */ + goto exit_function; } - last_atom[num_open] = curAtom; - state = 'N'; - break; - default: + } + else + { ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; } - } - else - { - ret = RI_ERR_SYNTAX; /* syntax error */ - goto exit_function; - } - break; + break; } } } @@ -9586,16 +9587,16 @@ int ParseSegmentConnections(const char* str, /* sort the neighbors */ - insertions_sort_AT_NUMB(neighbor, k); + insertions_sort_AT_NUMB( neighbor, k ); if (m == pInChI[iComponent].lenConnTable) { ret = RI_ERR_SYNTAX; /* syntax error */ goto exit_function; } - + #if ( FIX_GAF_2020_25726==1 ) - for (j = 1; j < k; j++) + for (j = 1; j < k ; j++) { if (neighbor[j] == neighbor[j - 1]) { @@ -9605,7 +9606,7 @@ int ParseSegmentConnections(const char* str, } #endif pInChI[iComponent].nConnTable[m++] = i + 1; /* atom number */ - for (j = 0; j < k && (int)neighbor[j] <= i; j++) + for (j = 0; j < k && (int) neighbor[j] <= i; j++) { if (m == pInChI[iComponent].lenConnTable) { @@ -9665,7 +9666,7 @@ int ParseSegmentConnections(const char* str, if (pLB->pBond) { INCHI_HEAPCHK - inchi_free(pLB->pBond); + inchi_free( pLB->pBond ); } return ret; @@ -9674,13 +9675,13 @@ int ParseSegmentConnections(const char* str, /****************************************************************************/ -int nFillOutProtonMobileH(INChI* pInChI) +int nFillOutProtonMobileH( INChI *pInChI ) { int len = 1; pInChI->bDeleted = 1; /* formula */ if (!pInChI->szHillFormula && - !(pInChI->szHillFormula = (char*)inchi_calloc((long long)len + 1, sizeof(pInChI->szHillFormula[0])))) /* djb-rwth: cast operator added */ + !( pInChI->szHillFormula = (char *) inchi_calloc( (long long)len + 1, sizeof( pInChI->szHillFormula[0] ) ) )) /* djb-rwth: cast operator added */ { return RI_ERR_ALLOC; /* alloc failure */ } @@ -9689,7 +9690,7 @@ int nFillOutProtonMobileH(INChI* pInChI) /* atoms */ if (!pInChI->nAtom && - !(pInChI->nAtom = (U_CHAR*)inchi_calloc((long long)len + 1, sizeof(pInChI->nAtom[0])))) /* djb-rwth: cast operator added */ + !( pInChI->nAtom = (U_CHAR *) inchi_calloc( (long long)len + 1, sizeof( pInChI->nAtom[0] ) ) )) /* djb-rwth: cast operator added */ { return RI_ERR_ALLOC; /* alloc failure */ } @@ -9698,7 +9699,7 @@ int nFillOutProtonMobileH(INChI* pInChI) pInChI->nTotalCharge = 1; /* connection table */ if (!pInChI->nConnTable && - !(pInChI->nConnTable = (AT_NUMB*)inchi_calloc((long long)len + 1, sizeof(pInChI->nConnTable[0])))) /* djb-rwth: cast operator added */ + !( pInChI->nConnTable = (AT_NUMB *) inchi_calloc( (long long)len + 1, sizeof( pInChI->nConnTable[0] ) ) )) /* djb-rwth: cast operator added */ { return RI_ERR_ALLOC; /* alloc failure */ } @@ -9706,13 +9707,13 @@ int nFillOutProtonMobileH(INChI* pInChI) pInChI->lenConnTable = len; /* tautomer */ if (!pInChI->nTautomer && - !(pInChI->nTautomer = (AT_NUMB*)inchi_calloc((long long)len + 1, sizeof(pInChI->nTautomer[0])))) /* djb-rwth: cast operator added */ + !( pInChI->nTautomer = (AT_NUMB *) inchi_calloc( (long long)len + 1, sizeof( pInChI->nTautomer[0] ) ) )) /* djb-rwth: cast operator added */ { return RI_ERR_ALLOC; /* alloc failure */ } /* nNum_H */ if (!pInChI->nNum_H && - !(pInChI->nNum_H = (S_CHAR*)inchi_calloc((long long)len + 1, sizeof(pInChI->nNum_H[0])))) /* djb-rwth: cast operator added */ + !( pInChI->nNum_H = (S_CHAR *) inchi_calloc( (long long)len + 1, sizeof( pInChI->nNum_H[0] ) ) )) /* djb-rwth: cast operator added */ { return RI_ERR_ALLOC; /* alloc failure */ } @@ -9726,22 +9727,22 @@ int nFillOutProtonMobileH(INChI* pInChI) /****************************************************************************/ -int nProtonCopyIsotopicInfo(INChI* pInChI_to, INChI* pInChI_from) +int nProtonCopyIsotopicInfo( INChI *pInChI_to, INChI *pInChI_from ) { if (pInChI_from->nNumberOfIsotopicAtoms) { if (pInChI_to->nNumberOfIsotopicAtoms && - pInChI_from->nNumberOfIsotopicAtoms > pInChI_to->nNumberOfIsotopicAtoms) + pInChI_from->nNumberOfIsotopicAtoms > pInChI_to->nNumberOfIsotopicAtoms) { - inchi_free(pInChI_to->IsotopicAtom); + inchi_free( pInChI_to->IsotopicAtom ); pInChI_to->IsotopicAtom = NULL; pInChI_to->nNumberOfIsotopicAtoms = 0; } if (!pInChI_to->IsotopicAtom && - !(pInChI_to->IsotopicAtom = - (INChI_IsotopicAtom*)inchi_calloc(pInChI_from->nNumberOfIsotopicAtoms, - sizeof(pInChI_to->IsotopicAtom[0])))) + !( pInChI_to->IsotopicAtom = + (INChI_IsotopicAtom *) inchi_calloc( pInChI_from->nNumberOfIsotopicAtoms, + sizeof( pInChI_to->IsotopicAtom[0] ) ) )) { return RI_ERR_ALLOC; } @@ -9753,7 +9754,7 @@ int nProtonCopyIsotopicInfo(INChI* pInChI_to, INChI* pInChI_from) { if (pInChI_to->IsotopicAtom) { - inchi_free(pInChI_to->IsotopicAtom); + inchi_free( pInChI_to->IsotopicAtom ); } pInChI_to->IsotopicAtom = NULL; pInChI_to->nNumberOfIsotopicAtoms = 0; @@ -9766,16 +9767,16 @@ int nProtonCopyIsotopicInfo(INChI* pInChI_to, INChI* pInChI_from) /**************************************************************************** Parse InChI formula layer ****************************************************************************/ -int ParseSegmentFormula(const char* str, - int bMobileH, - INChI* pInpInChI[], - int pnNumComponents[], - int* na_total) +int ParseSegmentFormula( const char *str, + int bMobileH, + INChI *pInpInChI[], + int pnNumComponents[], + int *na_total ) { int i, j, mpy_component, mpy_atom, len, el_number; - int nNumComponents = 0, iComponent, nNumAtoms, nNumAtomsAndH, iAtom, nNumH, nAltMobileH = ALT_TAUT(bMobileH); - const char* p, * q, * e, * pStart, * pEnd; - INChI* pInChI; + int nNumComponents = 0, iComponent, nNumAtoms, nNumAtomsAndH, iAtom, nNumH, nAltMobileH = ALT_TAUT( bMobileH ); + const char *p, *q, *e, *pStart, *pEnd; + INChI *pInChI; char szEl[3]; #if ( FIX_GAF_2019_2==1 ) /* hack: state passed in *na_total (will be updated in ParseSegmentFormula anyway) */ @@ -9785,18 +9786,18 @@ int ParseSegmentFormula(const char* str, *na_total = 0; /* Pass 1. Count components */ - - pStart = (char*)str; + + pStart = (char *) str; while (1) { - if (!(pEnd = strchr(pStart, '.'))) + if (!( pEnd = strchr( pStart, '.' ) )) { - pEnd = pStart + strlen(pStart); + pEnd = pStart + strlen( pStart ); } p = pStart; - if (isdigit(*p)) + if (isdigit( *p )) { - mpy_component = (int)inchi_strtol(p, &q, 10); + mpy_component = (int) inchi_strtol( p, &q, 10 ); p = q; } else @@ -9807,7 +9808,7 @@ int ParseSegmentFormula(const char* str, { break; } - if (!isupper(UCINT * p)) + if (!isupper( UCINT *p )) { break; /* not a formula layer */ } @@ -9848,7 +9849,7 @@ int ParseSegmentFormula(const char* str, int low_case = 0; if (*pStart) { - low_case = islower(UCINT * pStart); + low_case = islower(UCINT *pStart); } if (!*pStart || low_case) { if (low_case) @@ -9870,11 +9871,11 @@ int ParseSegmentFormula(const char* str, }*/ } #else - if (!*pStart || islower(UCINT * pStart)) { + if (!*pStart || islower(UCINT *pStart)) { #endif INCHI_HEAPCHK - if (bMobileH == TAUT_NON && 0 < (nNumComponents = pnNumComponents[nAltMobileH])) + if (bMobileH == TAUT_NON && 0 < ( nNumComponents = pnNumComponents[nAltMobileH] )) { /* allocate InChI */ pInChI = (INChI*)inchi_calloc(nNumComponents, sizeof(INChI)); @@ -9893,10 +9894,10 @@ int ParseSegmentFormula(const char* str, /* copy number of atoms */ len = pInpInChI[bMobileH][i].nNumberOfAtoms = pInpInChI[nAltMobileH][i].nNumberOfAtoms; /* copy atoms */ - len = (len + 1) * sizeof(pInpInChI[0][0].nAtom[0]); + len = ( len + 1 ) * sizeof( pInpInChI[0][0].nAtom[0] ); if (pInpInChI[bMobileH][i].nAtom) { - inchi_free(pInpInChI[bMobileH][i].nAtom); + inchi_free( pInpInChI[bMobileH][i].nAtom ); } U_CHAR* piibmi_na = (U_CHAR*)inchi_malloc(((long long)len + 1) * sizeof(pInpInChI[0][0].nAtom[0])); if (piibmi_na) /* djb-rwth: cast operator added; addressing LLVM warning */ @@ -9910,10 +9911,10 @@ int ParseSegmentFormula(const char* str, return RI_ERR_ALLOC; /* alloc failure */ } /* copy Hill formula */ - len = (int)strlen(pInpInChI[nAltMobileH][i].szHillFormula) + 1; + len = (int) strlen( pInpInChI[nAltMobileH][i].szHillFormula ) + 1; if (pInpInChI[bMobileH][i].szHillFormula) { - inchi_free(pInpInChI[bMobileH][i].szHillFormula); + inchi_free( pInpInChI[bMobileH][i].szHillFormula ); } char* piibmi_shf = (char*)inchi_malloc((inchi_max(len, 2)) * sizeof(char)); if (piibmi_shf) /* djb-rwth: addressing LLVM warning */ @@ -9936,12 +9937,12 @@ int ParseSegmentFormula(const char* str, nNumComponents = 1; /* InChI */ pnNumComponents[bMobileH] = nNumComponents; - if (!(pInChI = (INChI*)inchi_calloc(nNumComponents, sizeof(INChI)))) + if (!( pInChI = (INChI *) inchi_calloc( nNumComponents, sizeof( INChI ) ) )) { return RI_ERR_ALLOC; /* alloc failure */ } pInpInChI[bMobileH] = pInChI; - ret = nFillOutProtonMobileH(pInChI); + ret = nFillOutProtonMobileH( pInChI ); if (ret < 0) { return ret; @@ -9951,7 +9952,7 @@ int ParseSegmentFormula(const char* str, return 0; } return RI_ERR_SYNTAX; /* syntax error */ - } + } if (*pEnd) { @@ -9959,7 +9960,7 @@ int ParseSegmentFormula(const char* str, } /* allocate InChI */ - if (!(pInpInChI[bMobileH] = (INChI*)inchi_calloc(nNumComponents, sizeof(INChI)))) + if (!( pInpInChI[bMobileH] = (INChI *) inchi_calloc( nNumComponents, sizeof( INChI ) ) )) { return RI_ERR_ALLOC; /* alloc failure */ } @@ -9967,20 +9968,20 @@ int ParseSegmentFormula(const char* str, nnumcomp_limit = nNumComponents; /* Pass 2. Count elements, save formulas and elements */ - pStart = (char*)str; + pStart = (char *) str; iComponent = 0; while (1) { - if (!(pEnd = strchr(pStart, '.'))) + if (!( pEnd = strchr( pStart, '.' ) )) { - pEnd = pStart + strlen(pStart); + pEnd = pStart + strlen( pStart ); } p = pStart; - if (isdigit(UCINT * p)) + if (isdigit( UCINT *p )) { - mpy_component = (int)inchi_strtol(p, &q, 10); + mpy_component = (int) inchi_strtol( p, &q, 10 ); #if ( CHECK_STRTOL_ATNUMB==1 ) - if (mpy_component > MAX_ATOMS || mpy_component < 0) + if (mpy_component>MAX_ATOMS || mpy_component<0) { return RI_ERR_SYNTAX; /* syntax error */ } @@ -10000,7 +10001,7 @@ int ParseSegmentFormula(const char* str, return RI_ERR_SYNTAX; /* syntax error */ } #endif - len = (int)(pEnd - p); + len = (int) ( pEnd - p ); for (i = 0; i < mpy_component; i++) { if (iComponent + i >= nNumComponents) @@ -10009,12 +10010,12 @@ int ParseSegmentFormula(const char* str, } if (pInChI[iComponent + i].szHillFormula) { - inchi_free(pInChI[iComponent + i].szHillFormula); + inchi_free( pInChI[iComponent + i].szHillFormula ); } - pInChI[iComponent + i].szHillFormula = (char*)inchi_malloc(inchi_max((long long)len, 1) + 1); /* djb-rwth: cast operator added */ + pInChI[iComponent + i].szHillFormula = (char*) inchi_malloc( inchi_max( (long long)len, 1 ) + 1 ); /* djb-rwth: cast operator added */ memcpy(pInChI[iComponent].szHillFormula, p, len); if (pInChI[iComponent + i].szHillFormula) /* djb-rwth: fixing a NULL pointer dereference */ - pInChI[iComponent + i].szHillFormula[len] = '\0'; + pInChI[iComponent + i].szHillFormula[len] = '\0'; if (!i) { /* Pass 2.1 Parse formula and count atoms except H */ @@ -10024,20 +10025,20 @@ int ParseSegmentFormula(const char* str, e = pInChI[iComponent].szHillFormula; while (e && *e) /* djb-rwth: fixing a NULL pointer dereference */ { - if (!isupper(UCINT * e)) + if (!isupper( UCINT *e )) { return RI_ERR_SYNTAX; } j = 0; szEl[j++] = *e++; - if (*e && islower(UCINT * e)) + if (*e && islower( UCINT *e )) szEl[j++] = *e++; szEl[j++] = '\0'; - if (*e && isdigit(UCINT * e)) + if (*e && isdigit( UCINT *e )) { - mpy_atom = (int)inchi_strtol(e, &q, 10); + mpy_atom = (int) inchi_strtol( e, &q, 10 ); #if ( CHECK_STRTOL_ATNUMB==1 ) - if (mpy_atom > MAX_ATOMS || mpy_atom < 0) + if (mpy_atom>MAX_ATOMS || mpy_atom<0) { return RI_ERR_SYNTAX; /* syntax error */ } @@ -10065,13 +10066,13 @@ int ParseSegmentFormula(const char* str, return RI_ERR_SYNTAX; /* syntax error */ } #endif - (*na_total) += mpy_component * nNumAtoms; + ( *na_total ) += mpy_component * nNumAtoms; - nNumAtomsAndH = nNumAtoms ? nNumAtoms : (nNumH > 0); + nNumAtomsAndH = nNumAtoms ? nNumAtoms : ( nNumH > 0 ); pInChI[iComponent + i].nNumberOfAtoms = nNumAtomsAndH; if (pInChI[iComponent + i].nAtom) { - inchi_free(pInChI[iComponent + i].nAtom); + inchi_free( pInChI[iComponent + i].nAtom ); } pInChI[iComponent + i].nAtom = (U_CHAR*)inchi_malloc(((long long)nNumAtomsAndH + 1) * sizeof(pInChI[0].nAtom[0])); /* djb-rwth: cast operator added */ if (!pInChI[iComponent + i].nAtom) @@ -10085,20 +10086,20 @@ int ParseSegmentFormula(const char* str, e = pInChI[iComponent + i].szHillFormula; while (*e) { - if (!isupper(UCINT * e)) + if (!isupper( UCINT *e )) { return RI_ERR_SYNTAX; } j = 0; szEl[j++] = *e++; - if (*e && islower(UCINT * e)) + if (*e && islower( UCINT *e )) szEl[j++] = *e++; szEl[j++] = '\0'; - if (*e && isdigit(UCINT * e)) + if (*e && isdigit( UCINT *e )) { - mpy_atom = (int)inchi_strtol(e, &q, 10); + mpy_atom = (int) inchi_strtol( e, &q, 10 ); #if ( CHECK_STRTOL_ATNUMB==1 ) - if (mpy_atom > MAX_ATOMS || mpy_atom < 0) + if (mpy_atom>MAX_ATOMS || mpy_atom<0) { return RI_ERR_SYNTAX; /* syntax error */ } @@ -10115,7 +10116,7 @@ int ParseSegmentFormula(const char* str, } if (szEl[0] == 'H' && !szEl[1]) continue; /* ignore H */ - el_number = get_periodic_table_number(szEl); + el_number = get_periodic_table_number( szEl ); if (el_number == ERR_ELEM) { return RI_ERR_SYNTAX; /* wrong element */ @@ -10126,7 +10127,7 @@ int ParseSegmentFormula(const char* str, { return RI_ERR_PROGR; /* program error */ } - pInChI[iComponent + i].nAtom[iAtom++] = (U_CHAR)el_number; + pInChI[iComponent + i].nAtom[iAtom++] = (U_CHAR) el_number; } } } @@ -10184,12 +10185,12 @@ int ParseSegmentFormula(const char* str, /* at this point the exact number of atoms including bridging H is known from TAUT_YES */ for (i = 0; i < nNumComponents && i < pnNumComponents[nAltMobileH]; i++) { - if (pInpInChI[bMobileH][i].nNumberOfAtoms < (len = pInpInChI[nAltMobileH][i].nNumberOfAtoms)) + if (pInpInChI[bMobileH][i].nNumberOfAtoms < ( len = pInpInChI[nAltMobileH][i].nNumberOfAtoms )) { /* there are bridging H in this component */ if (pInpInChI[nAltMobileH][i].nAtom) { - U_CHAR* nAtom = (U_CHAR*)inchi_malloc(((long long)len + 1) * sizeof(nAtom[0])); /* djb-rwth: cast operator added */ + U_CHAR *nAtom = (U_CHAR *) inchi_malloc( ( (long long)len + 1 ) * sizeof( nAtom[0] ) ); /* djb-rwth: cast operator added */ if (!nAtom) { return RI_ERR_ALLOC; @@ -10198,7 +10199,7 @@ int ParseSegmentFormula(const char* str, nAtom[len] = 0; if (pInpInChI[bMobileH][i].nAtom) { - inchi_free(pInpInChI[bMobileH][i].nAtom); + inchi_free( pInpInChI[bMobileH][i].nAtom ); } pInpInChI[bMobileH][i].nAtom = nAtom; } @@ -10208,26 +10209,26 @@ int ParseSegmentFormula(const char* str, } return nNumComponents + 1; - } +} /****************************************************************************/ -int CopySegment(INChI* pInChITo, - INChI* pInChIFrom, - int SegmentType, - int bIsotopicTo, - int bIsotopicFrom) +int CopySegment( INChI *pInChITo, + INChI *pInChIFrom, + int SegmentType, + int bIsotopicTo, + int bIsotopicFrom ) { int ret = RI_ERR_ALLOC; int len; if (SegmentType == CPY_SP2 || - SegmentType == CPY_SP3 || - SegmentType == CPY_SP3_M || - SegmentType == CPY_SP3_S) + SegmentType == CPY_SP3 || + SegmentType == CPY_SP3_M || + SegmentType == CPY_SP3_S) { - INChI_Stereo** pstereoTo = NULL; - INChI_Stereo* stereoFrom = bIsotopicFrom == 1 ? pInChIFrom->StereoIsotopic : + INChI_Stereo **pstereoTo = NULL; + INChI_Stereo *stereoFrom = bIsotopicFrom == 1 ? pInChIFrom->StereoIsotopic : bIsotopicFrom == 0 ? pInChIFrom->Stereo : NULL; if (stereoFrom || bIsotopicFrom < 0) { @@ -10242,12 +10243,12 @@ int CopySegment(INChI* pInChITo, } #endif if (bIsotopicFrom < 0 || - (stereoFrom->b_parity && - stereoFrom->nBondAtom1 && - stereoFrom->nBondAtom2)) /* djb-rwth: addressing LLVM warning */ + (stereoFrom->b_parity && + stereoFrom->nBondAtom1 && + stereoFrom->nBondAtom2)) /* djb-rwth: addressing LLVM warning */ { - len = (bIsotopicFrom < 0) ? 0 : stereoFrom->nNumberOfStereoBonds; + len = ( bIsotopicFrom < 0 ) ? 0 : stereoFrom->nNumberOfStereoBonds; pstereoTo = bIsotopicTo ? &pInChITo->StereoIsotopic : &pInChITo->Stereo; if (!pstereoTo[0]) { @@ -10280,19 +10281,19 @@ int CopySegment(INChI* pInChITo, if (pst0_bp) { INCHI_HEAPCHK - inchi_free(pst0_bp); + inchi_free( pst0_bp ); pst0_bp = NULL; } if (pst0_nba1) { INCHI_HEAPCHK - inchi_free(pst0_nba1); + inchi_free( pst0_nba1 ); pst0_nba1 = NULL; } if (pstereoTo[0]->nBondAtom2) { INCHI_HEAPCHK - inchi_free(pst0_nba2); + inchi_free( pst0_nba2 ); pst0_nba2 = NULL; } INCHI_HEAPCHK @@ -10326,39 +10327,39 @@ int CopySegment(INChI* pInChITo, if (SegmentType == CPY_SP3) { if (bIsotopicFrom < 0 || - (stereoFrom->t_parity && - stereoFrom->nNumber)) /* djb-rwth: addressing LLVM warning */ + (stereoFrom->t_parity && + stereoFrom->nNumber)) /* djb-rwth: addressing LLVM warning */ { - len = (bIsotopicFrom < 0) ? 0 : stereoFrom->nNumberOfStereoCenters; + len = ( bIsotopicFrom < 0 ) ? 0 : stereoFrom->nNumberOfStereoCenters; pstereoTo = bIsotopicTo ? &pInChITo->StereoIsotopic : &pInChITo->Stereo; if (!pstereoTo[0]) { - if (!(pstereoTo[0] = (INChI_Stereo*)inchi_calloc(1, sizeof(**pstereoTo)))) + if (!( pstereoTo[0] = (INChI_Stereo *) inchi_calloc( 1, sizeof( **pstereoTo ) ) )) { goto exit_function; } } if (pstereoTo[0]->nNumberOfStereoCenters > 0 || pstereoTo[0]->t_parity || - pstereoTo[0]->nNumber) + pstereoTo[0]->nNumber) { ret = RI_ERR_SYNTAX; /* stereo already exists */ goto exit_function; } /* allocate sp3 stereo */ - if (!(pstereoTo[0]->t_parity = (S_CHAR*)inchi_calloc((long long)len + 1, sizeof(pstereoTo[0]->b_parity[0]))) || - !(pstereoTo[0]->nNumber = (AT_NUMB*)inchi_calloc((long long)len + 1, sizeof(pstereoTo[0]->nBondAtom1[0])))) /* djb-rwth: cast operators added */ + if (!( pstereoTo[0]->t_parity = (S_CHAR *) inchi_calloc( (long long)len + 1, sizeof( pstereoTo[0]->b_parity[0] ) ) ) || + !( pstereoTo[0]->nNumber = (AT_NUMB *) inchi_calloc( (long long)len + 1, sizeof( pstereoTo[0]->nBondAtom1[0] ) ) )) /* djb-rwth: cast operators added */ { /* cleanup */ if (pstereoTo[0]->t_parity) { - inchi_free(pstereoTo[0]->t_parity); + inchi_free( pstereoTo[0]->t_parity ); pstereoTo[0]->t_parity = NULL; } if (pstereoTo[0]->nNumber) { - inchi_free(pstereoTo[0]->nNumber); + inchi_free( pstereoTo[0]->nNumber ); pstereoTo[0]->nNumber = NULL; } goto exit_function; @@ -10384,7 +10385,7 @@ int CopySegment(INChI* pInChITo, pstereoTo = bIsotopicTo ? &pInChITo->StereoIsotopic : &pInChITo->Stereo; if (!pstereoTo[0]) { - if (!(pstereoTo[0] = (INChI_Stereo*)inchi_calloc(1, sizeof(**pstereoTo)))) + if (!( pstereoTo[0] = (INChI_Stereo *) inchi_calloc( 1, sizeof( **pstereoTo ) ) )) { goto exit_function; } @@ -10412,7 +10413,7 @@ int CopySegment(INChI* pInChITo, pstereoTo = bIsotopicFrom ? &pInChITo->StereoIsotopic : &pInChITo->Stereo; if (!pstereoTo[0]) { - if (!(pstereoTo[0] = (INChI_Stereo*)inchi_calloc(1, sizeof(**pstereoTo)))) + if (!( pstereoTo[0] = (INChI_Stereo *) inchi_calloc( 1, sizeof( **pstereoTo ) ) )) { goto exit_function; } @@ -10445,13 +10446,13 @@ int CopySegment(INChI* pInChITo, else if (SegmentType == CPY_ISO_AT) { int nNumberOfIsotopicAtoms = pInChIFrom->nNumberOfIsotopicAtoms; - INChI_IsotopicAtom** pIsotopicAtomTo = NULL; - INChI_IsotopicAtom* IsotopicAtomFrom = pInChIFrom->IsotopicAtom; + INChI_IsotopicAtom **pIsotopicAtomTo = NULL; + INChI_IsotopicAtom *IsotopicAtomFrom = pInChIFrom->IsotopicAtom; if (bIsotopicFrom < 0 || IsotopicAtomFrom) { - len = (bIsotopicFrom < 0) ? 0 : nNumberOfIsotopicAtoms; + len = ( bIsotopicFrom < 0 ) ? 0 : nNumberOfIsotopicAtoms; #if ( FIX_GAF_2019_3==1 ) - if (pInChITo->nNumberOfIsotopicAtoms < 1) + if (pInChITo->nNumberOfIsotopicAtoms<1) { /* forcibly free iso-related memory and set to NULL */ qzfree(pInChITo->IsotopicAtom); @@ -10460,7 +10461,7 @@ int CopySegment(INChI* pInChITo, pIsotopicAtomTo = &pInChITo->IsotopicAtom; if (!*pIsotopicAtomTo) { - if (!(*pIsotopicAtomTo = (INChI_IsotopicAtom*)inchi_calloc((long long)len + 1, sizeof(**pIsotopicAtomTo)))) /* djb-rwth: cast operator added */ + if (!( *pIsotopicAtomTo = (INChI_IsotopicAtom *) inchi_calloc( (long long)len + 1, sizeof( **pIsotopicAtomTo ) ) )) /* djb-rwth: cast operator added */ { goto exit_function; } @@ -10492,13 +10493,13 @@ int CopySegment(INChI* pInChITo, /**************************************************************************** Sort neighbors in ascending order ****************************************************************************/ -int insertions_sort_AT_NUMB(AT_NUMB* base, int num) +int insertions_sort_AT_NUMB( AT_NUMB *base, int num ) { - AT_NUMB* i, * j, * pk, tmp; + AT_NUMB *i, *j, *pk, tmp; int k, num_trans = 0; for (k = 1, pk = base; k < num; k++, pk++) { - for (j = (i = pk) + 1, tmp = *j; j > base && *i > tmp; j = i, i--) + for (j = ( i = pk ) + 1, tmp = *j; j > base && *i > tmp; j = i, i--) { *j = *i; num_trans++; @@ -10511,14 +10512,14 @@ int insertions_sort_AT_NUMB(AT_NUMB* base, int num) /****************************************************************************/ -int getInChIChar(INCHI_IOSTREAM* pInp) +int getInChIChar( INCHI_IOSTREAM *pInp ) { if (pInp->type == INCHI_IOS_TYPE_STRING) { /* input from string */ if (pInp->s.nPtr < pInp->s.nUsedLength) { - return (int)pInp->s.pStr[pInp->s.nPtr++]; + return (int) pInp->s.pStr[pInp->s.nPtr++]; } return RI_ERR_EOF; } @@ -10529,7 +10530,7 @@ int getInChIChar(INCHI_IOSTREAM* pInp) #if ( defined(_MSC_VER)&&defined(_WIN32) || defined(__BORLANDC__)&&defined(__WIN32__) || defined(__GNUC__)&&defined(__MINGW32__)&&defined(_WIN32) ) do { - c = getc(pInp->f); + c = getc( pInp->f ); if (c == EOF) { c = RI_ERR_EOF; @@ -10537,7 +10538,7 @@ int getInChIChar(INCHI_IOSTREAM* pInp) } } while (c == '\r'); #else - c = getc(pInp->f); + c = getc( pInp->f ); if (c == EOF) { c = RI_ERR_EOF; @@ -10549,11 +10550,11 @@ int getInChIChar(INCHI_IOSTREAM* pInp) /****************************************************************************/ -int AddInChIChar(INCHI_IOSTREAM* pInp, - SEGM_LINE* Line, - const char* pszToken) +int AddInChIChar( INCHI_IOSTREAM *pInp, + SEGM_LINE *Line, + const char *pszToken ) { - int c = getInChIChar(pInp); + int c = getInChIChar( pInp ); /* while ( c == '\r' ) { c = getInChIChar( pInp ); @@ -10564,7 +10565,7 @@ int AddInChIChar(INCHI_IOSTREAM* pInp, if (Line->len + 2 >= Line->len_alloc) { - char* str = (char*)inchi_calloc((long long)Line->len_alloc + SEGM_LINE_ADD, sizeof(str[0])); /* djb-rwth: cast operator added */ + char *str = (char *) inchi_calloc( (long long)Line->len_alloc + SEGM_LINE_ADD, sizeof( str[0] ) ); /* djb-rwth: cast operator added */ INCHI_HEAPCHK if (str) { @@ -10572,7 +10573,7 @@ int AddInChIChar(INCHI_IOSTREAM* pInp, { memcpy(str, Line->str, sizeof(str[0]) * Line->len); Line->len_alloc += SEGM_LINE_ADD; - inchi_free(Line->str); + inchi_free( Line->str ); INCHI_HEAPCHK } else @@ -10596,11 +10597,11 @@ int AddInChIChar(INCHI_IOSTREAM* pInp, goto exit_function; } - if (c && strchr(pszToken, c)) /* /\ */ + if (c && strchr( pszToken, c )) /* /\ */ { Line->str[Line->len] = '\0'; INCHI_HEAPCHK - c = -(c + 2); + c = -( c + 2 ); goto exit_function; } else if (!c && !Line->len) @@ -10622,19 +10623,19 @@ int AddInChIChar(INCHI_IOSTREAM* pInp, } /****************************************************************************/ -int nGetInChISegment(INCHI_IOSTREAM* pInp, - SEGM_LINE* Line, - const char* pszToken) +int nGetInChISegment( INCHI_IOSTREAM *pInp, + SEGM_LINE *Line, + const char *pszToken ) { int c; Line->len = 0; - while (0 < (c = AddInChIChar(pInp, Line, pszToken))) + while (0 < ( c = AddInChIChar( pInp, Line, pszToken ) )) { ; } if (c < -2) { - c = -(c + 2); + c = -( c + 2 ); } Line->c = c; @@ -10645,16 +10646,16 @@ int nGetInChISegment(INCHI_IOSTREAM* pInp, /**************************************************************************** Add one more bond to the linked lists for both neighbors ****************************************************************************/ -int AddLinkedBond(AT_NUMB at1, - AT_NUMB at2, - AT_NUMB num_at, - LINKED_BONDS* pLB) +int AddLinkedBond( AT_NUMB at1, + AT_NUMB at2, + AT_NUMB num_at, + LINKED_BONDS *pLB ) { - int nReqLen = inchi_max(2 * num_at + 2, pLB->len + 2); + int nReqLen = inchi_max( 2 * num_at + 2, pLB->len + 2 ); AT_NUMB prev; #if ( FIX_GAF_2019_2==1 ) { - if (at2 > num_at || at1 > num_at || at1 < 0 || at2<0 || num_at>MAX_ATOMS) + if (at2>num_at || at1>num_at || at1<0 || at2<0 || num_at>MAX_ATOMS) { return RI_ERR_SYNTAX; } @@ -10663,8 +10664,8 @@ int AddLinkedBond(AT_NUMB at1, if (pLB->len_alloc <= nReqLen) { /*int nNewLen = nReqLen + (nReqLen + LINKED_BOND_ADD - 1)%LINKED_BOND_ADD + LINKED_BOND_ADD;*/ - int nNewLen = nReqLen - nReqLen % LINKED_BOND_ADD + 2 * LINKED_BOND_ADD; - ONE_LINKED_BOND* pBond = (ONE_LINKED_BOND*)inchi_calloc(nNewLen, sizeof(pBond[0])); + int nNewLen = nReqLen - nReqLen%LINKED_BOND_ADD + 2 * LINKED_BOND_ADD; + ONE_LINKED_BOND *pBond = (ONE_LINKED_BOND *) inchi_calloc( nNewLen, sizeof( pBond[0] ) ); if (!pBond) { return RI_ERR_ALLOC; /* allocation error */ @@ -10674,14 +10675,14 @@ int AddLinkedBond(AT_NUMB at1, memcpy(pBond, pLB->pBond, pLB->len * sizeof(pBond[0])); } if (pLB->pBond) - inchi_free(pLB->pBond); + inchi_free( pLB->pBond ); pLB->pBond = pBond; pLB->len_alloc = nNewLen; } if (!pLB->len) { pLB->len = num_at + 1; - memset(pLB->pBond, 0, ((long long)num_at + 1) * sizeof(pLB->pBond[0])); /* djb-rwth: cast operator added; memset_s C11/Annex K variant? */ + memset( pLB->pBond, 0, ( (long long)num_at + 1 ) * sizeof( pLB->pBond[0] ) ); /* djb-rwth: cast operator added; memset_s C11/Annex K variant? */ } prev = pLB->pBond[at1].prev; /* position of the last neighbor of at1 in the pLB->pBond */ @@ -10717,13 +10718,13 @@ int AddLinkedBond(AT_NUMB at1, /**************************************************************************** PrepareSaveOptBits ****************************************************************************/ -void PrepareSaveOptBits(INPUT_PARMS* ip, - INCHI_IOSTREAM* pLog, - const long num_inp, - const char* szCurHdr, - int input_has_save_opt, - unsigned char input_save_opt_bits, - unsigned char* save_opt_bits) +void PrepareSaveOptBits( INPUT_PARMS *ip, + INCHI_IOSTREAM *pLog, + const long num_inp, + const char *szCurHdr, + int input_has_save_opt, + unsigned char input_save_opt_bits, + unsigned char *save_opt_bits ) { if (!input_has_save_opt) @@ -10732,15 +10733,15 @@ void PrepareSaveOptBits(INPUT_PARMS* ip, ip->bINChIOutputOptions &= ~INCHI_OUT_SAVEOPT; if (szCurHdr && szCurHdr[0]) { - inchi_ios_eprint(pLog, - "Warning: ignore SaveOpt request for SaveOpt-less input, %s\n", - szCurHdr); + inchi_ios_eprint( pLog, + "Warning: ignore SaveOpt request for SaveOpt-less input, %s\n", + szCurHdr ); } else { - inchi_ios_eprint(pLog, - "Warning: ignore SaveOpt request for SaveOpt-less input, Structure %ld\n", - num_inp); + inchi_ios_eprint( pLog, + "Warning: ignore SaveOpt request for SaveOpt-less input, Structure %ld\n", + num_inp ); } } else @@ -10759,7 +10760,7 @@ void PrepareSaveOptBits(INPUT_PARMS* ip, int input_save_opt_has_pt_13_00 = input_save_opt_bits & SAVE_OPT_PT_13_00; int input_save_opt_has_pt_18_00 = input_save_opt_bits & SAVE_OPT_PT_18_00; - if (0 != (ip->bTautFlags & TG_FLAG_RECONNECT_COORD)) + if (0 != ( ip->bTautFlags & TG_FLAG_RECONNECT_COORD )) { /* RecMet requested */ if (input_save_opt_has_recmet) @@ -10771,16 +10772,16 @@ void PrepareSaveOptBits(INPUT_PARMS* ip, ip->bTautFlags &= ~TG_FLAG_RECONNECT_COORD; if (szCurHdr && szCurHdr[0]) { - inchi_ios_eprint(pLog, "Warning: input created w/o RecMet - ignoring RecMet request, %s\n", szCurHdr); + inchi_ios_eprint( pLog, "Warning: input created w/o RecMet - ignoring RecMet request, %s\n", szCurHdr ); } else { - inchi_ios_eprint(pLog, "Warning: input created w/o RecMet - ignoring RecMet request, Structure %ld\n", num_inp); + inchi_ios_eprint( pLog, "Warning: input created w/o RecMet - ignoring RecMet request, Structure %ld\n", num_inp ); } } } - if (0 != (ip->nMode & REQ_MODE_BASIC)) + if (0 != ( ip->nMode & REQ_MODE_BASIC )) { /* FixedH requested */ if (input_save_opt_has_fixedh) @@ -10792,11 +10793,11 @@ void PrepareSaveOptBits(INPUT_PARMS* ip, ip->nMode &= ~REQ_MODE_BASIC; if (szCurHdr && szCurHdr[0]) { - inchi_ios_eprint(pLog, "Warning: input created w/o FixedH - ignoring FixedH request, %s\n", szCurHdr); + inchi_ios_eprint( pLog, "Warning: input created w/o FixedH - ignoring FixedH request, %s\n", szCurHdr ); } else { - inchi_ios_eprint(pLog, "Warning: input created w/o FixedH - ignoring FixedH request, Structure %ld\n", num_inp); + inchi_ios_eprint( pLog, "Warning: input created w/o FixedH - ignoring FixedH request, Structure %ld\n", num_inp ); } } } @@ -10834,7 +10835,7 @@ void PrepareSaveOptBits(INPUT_PARMS* ip, *save_opt_bits |= SAVE_OPT_PT_18_00; /* Check if /SNon requested and turn OFF stereo bits if so */ - if (!(ip->nMode & REQ_MODE_STEREO)) + if (!( ip->nMode & REQ_MODE_STEREO )) { *save_opt_bits &= ~SAVE_OPT_SUU; *save_opt_bits &= ~SAVE_OPT_SLUUD; @@ -10846,20 +10847,20 @@ void PrepareSaveOptBits(INPUT_PARMS* ip, /****************************************************************************/ -void TreatErrorsInReadInChIString(int nReadStatus, - int nErr, - int pState, - INPUT_PARMS* ip, - INCHI_IOSTREAM* pOut, - INCHI_IOSTREAM* pLog, - long* num_inp, - long* num_errors, - long* num_processed, - char** pstrHdr, - char** pszCurHdr, - InpInChI* pOneInput) +void TreatErrorsInReadInChIString( int nReadStatus, + int nErr, + int pState, + INPUT_PARMS *ip, + INCHI_IOSTREAM *pOut, + INCHI_IOSTREAM *pLog, + long *num_inp, + long *num_errors, + long *num_processed, + char **pstrHdr, + char **pszCurHdr, + InpInChI *pOneInput ) { - int bInChI2Struct = (ip->bReadInChIOptions & READ_INCHI_TO_STRUCTURE) && ip->nInputType == INPUT_INCHI; + int bInChI2Struct = ( ip->bReadInChIOptions & READ_INCHI_TO_STRUCTURE ) && ip->nInputType == INPUT_INCHI; /* InChI could not be read */ if (nReadStatus == RI_ERR_EOF && nErr == 0 && pState == 0) /* && !(*pstrHdr) ) */ @@ -10872,35 +10873,35 @@ void TreatErrorsInReadInChIString(int nReadStatus, /* Output InChI parsing error message */ char szHdrSimulation[128]; char szMsg2[1024]; - (*num_inp)++; + ( *num_inp )++; sprintf(szHdrSimulation, "Structure: %ld", *num_inp); - getInchiStateReadErr(pState, szMsg2); + getInchiStateReadErr( pState, szMsg2 ); #ifdef TARGET_EXE_STANDALONE if (pOneInput->polymer && - bInChI2Struct && - !(ip->bINChIOutputOptions & INCHI_OUT_SDFILE_ONLY)) + bInChI2Struct && + !( ip->bINChIOutputOptions & INCHI_OUT_SDFILE_ONLY )) { - inchi_ios_eprint(pLog, "%s Skipping polymer InChI (only conversion to Molfile is available, use OutputSDF option)\n", - *pstrHdr ? *pstrHdr : szHdrSimulation); + inchi_ios_eprint( pLog, "%s Skipping polymer InChI (only conversion to Molfile is available, use OutputSDF option)\n", + *pstrHdr ? *pstrHdr : szHdrSimulation ); } else #endif { if (!bInChI2Struct && - (pState == IST_MOBILE_H_POLYMER && !ip->bPolymers)) + ( pState == IST_MOBILE_H_POLYMER && !ip->bPolymers )) { /* TO DO: implement InChI2InChI for polymers in a way similar to InChI2Struct thru an external (to ReadWriteInchi) loop */ - inchi_ios_eprint(pLog, "%s Skipping polymer InChI for conversion of InChI to InChI\n", - *pstrHdr ? *pstrHdr : szHdrSimulation); + inchi_ios_eprint( pLog, "%s Skipping polymer InChI for conversion of InChI to InChI\n", + *pstrHdr ? *pstrHdr : szHdrSimulation ); } else { - inchi_ios_eprint(pLog, "\n%s %s (%d) in %s (%d)\n", - *pstrHdr ? *pstrHdr : szHdrSimulation, - getInchiErrName(nErr), nErr, - szMsg2, pState); + inchi_ios_eprint( pLog, "\n%s %s (%d) in %s (%d)\n", + *pstrHdr ? *pstrHdr : szHdrSimulation, + getInchiErrName( nErr ), nErr, + szMsg2, pState ); } } @@ -10916,27 +10917,27 @@ void TreatErrorsInReadInChIString(int nReadStatus, else { inchi_ios_eprint(pOut, "InChI=1//\n"); - } + } } } - if (0 != (ip->bReadInChIOptions & READ_INCHI_TO_STRUCTURE)) + if ( 0 != (ip->bReadInChIOptions & READ_INCHI_TO_STRUCTURE) ) - (*num_errors)++; - (*num_processed)++; + ( *num_errors )++; + ( *num_processed )++; } if (*pstrHdr) { - inchi_free(*pstrHdr); + inchi_free( *pstrHdr ); *pstrHdr = NULL; } if (*pszCurHdr) { - inchi_free(*pszCurHdr); + inchi_free( *pszCurHdr ); *pszCurHdr = NULL; } - FreeInpInChI(pOneInput); + FreeInpInChI( pOneInput ); return; } @@ -10948,25 +10949,25 @@ InChi --> InChI string(s) /****************************************************************************/ -int ConvertInChI2InChI(INPUT_PARMS* ip, - InpInChI* pOneInput, - INCHI_IOSTREAM* pOut, - INCHI_IOSTREAM* pLog, - STRUCT_DATA* sd, - int num_components[INCHI_NUM], - MODE_PIXH nModeProtonIsoExchgH[INCHI_NUM], - char** pszCurHdr, - long num_inp, - long* num_errors, - unsigned char save_opt_bits, - inchiTime* pulTStart, - long* ulProcessingTime, - struct tagINCHI_CLOCK* ic, - struct tagCANON_GLOBALS* pCG) +int ConvertInChI2InChI( INPUT_PARMS *ip, + InpInChI *pOneInput, + INCHI_IOSTREAM *pOut, + INCHI_IOSTREAM *pLog, + STRUCT_DATA *sd, + int num_components[INCHI_NUM], + MODE_PIXH nModeProtonIsoExchgH[INCHI_NUM], + char **pszCurHdr, + long num_inp, + long *num_errors, + unsigned char save_opt_bits, + inchiTime *pulTStart, + long *ulProcessingTime, + struct tagINCHI_CLOCK *ic, + struct tagCANON_GLOBALS *pCG ) { int ret, tmp; - InchiTimeGet(pulTStart); + InchiTimeGet( pulTStart ); tmp = ip->bNoStructLabels; ip->bNoStructLabels = 1; @@ -10975,13 +10976,13 @@ int ConvertInChI2InChI(INPUT_PARMS* ip, ip->pSdfLabel = NULL; #if ( FIX_DALKE_BUGS == 1 ) - SetHillFormFromInChI(pOneInput); + SetHillFormFromInChI( pOneInput ); #endif - ret = OutputInChIAsRequested(pCG, pOut, pLog, ip, sd, - pOneInput, num_components, - nModeProtonIsoExchgH, - num_inp, save_opt_bits); + ret = OutputInChIAsRequested( pCG, pOut, pLog, ip, sd, + pOneInput, num_components, + nModeProtonIsoExchgH, + num_inp, save_opt_bits ); #if ( !defined(TARGET_API_LIB) && defined(TARGET_EXE_STANDALONE) ) @@ -10993,7 +10994,7 @@ int ConvertInChI2InChI(INPUT_PARMS* ip, int xhash1, xhash2; char szXtra1[65], szXtra2[65]; - inchi_ios_flush2(pLog, stderr); + inchi_ios_flush2( pLog, stderr ); /* post-1.02b addition - correctly treat tabbed output with InChIKey */ if (ip->bINChIOutputOptions & INCHI_OUT_TABBED_OUTPUT) @@ -11019,31 +11020,31 @@ int ConvertInChI2InChI(INPUT_PARMS* ip, } else { - char* buf = NULL; + char *buf = NULL; size_t slen = pOut->s.nUsedLength; - extract_inchi_substring(&buf, pOut->s.pStr, slen); + extract_inchi_substring( &buf, pOut->s.pStr, slen ); if (NULL != buf) { xhash1 = xhash2 = 0; - if ((ip->bCalcInChIHash == INCHIHASH_KEY_XTRA1) || - (ip->bCalcInChIHash == INCHIHASH_KEY_XTRA1_XTRA2)) + if (( ip->bCalcInChIHash == INCHIHASH_KEY_XTRA1 ) || + ( ip->bCalcInChIHash == INCHIHASH_KEY_XTRA1_XTRA2 )) { xhash1 = 1; } - if ((ip->bCalcInChIHash == INCHIHASH_KEY_XTRA2) || - (ip->bCalcInChIHash == INCHIHASH_KEY_XTRA1_XTRA2)) + if (( ip->bCalcInChIHash == INCHIHASH_KEY_XTRA2 ) || + ( ip->bCalcInChIHash == INCHIHASH_KEY_XTRA1_XTRA2 )) { xhash2 = 1; } - ik_ret = GetINCHIKeyFromINCHI(buf, - xhash1, - xhash2, - ik_string, - szXtra1, - szXtra2); - inchi_free(buf); + ik_ret = GetINCHIKeyFromINCHI( buf, + xhash1, + xhash2, + ik_string, + szXtra1, + szXtra2 ); + inchi_free( buf ); } else { @@ -11053,40 +11054,40 @@ int ConvertInChI2InChI(INPUT_PARMS* ip, if (ik_ret == INCHIKEY_OK) { - inchi_ios_print(pOut, "InChIKey=%-s\n", ik_string); + inchi_ios_print( pOut, "InChIKey=%-s\n", ik_string ); } else { - inchi_ios_print(pLog, "Warning (Could not compute InChIKey: ", num_inp); + inchi_ios_print( pLog, "Warning (Could not compute InChIKey: ", num_inp ); switch (ik_ret) { - case INCHIKEY_UNKNOWN_ERROR: - inchi_ios_print(pLog, "unresolved error)"); - break; - case INCHIKEY_EMPTY_INPUT: - inchi_ios_print(pLog, "got an empty string)"); - break; - case INCHIKEY_INVALID_INCHI_PREFIX: - case INCHIKEY_INVALID_INCHI: - case INCHIKEY_INVALID_STD_INCHI: - inchi_ios_print(pLog, "no valid InChI string found)"); - break; - case INCHIKEY_NOT_ENOUGH_MEMORY: - inchi_ios_print(pLog, "not enough memory to treat the string)"); - break; - default:inchi_ios_print(pLog, "internal program error)"); - break; + case INCHIKEY_UNKNOWN_ERROR: + inchi_ios_print( pLog, "unresolved error)" ); + break; + case INCHIKEY_EMPTY_INPUT: + inchi_ios_print( pLog, "got an empty string)" ); + break; + case INCHIKEY_INVALID_INCHI_PREFIX: + case INCHIKEY_INVALID_INCHI: + case INCHIKEY_INVALID_STD_INCHI: + inchi_ios_print( pLog, "no valid InChI string found)" ); + break; + case INCHIKEY_NOT_ENOUGH_MEMORY: + inchi_ios_print( pLog, "not enough memory to treat the string)" ); + break; + default:inchi_ios_print( pLog, "internal program error)" ); + break; } - inchi_ios_print(pLog, " structure #%-lu.\n", num_inp); + inchi_ios_print( pLog, " structure #%-lu.\n", num_inp ); if (ip->bINChIOutputOptions & INCHI_OUT_TABBED_OUTPUT) { - inchi_ios_print(pOut, "\n"); + inchi_ios_print( pOut, "\n" ); } } /* if (ip->bCalcInChIHash!=INCHIHASH_NONE) */ - inchi_ios_flush(pOut); - inchi_ios_flush2(pLog, stderr); + inchi_ios_flush( pOut ); + inchi_ios_flush2( pLog, stderr ); } } /* Calculate InChIKey if requested */ #endif @@ -11097,34 +11098,34 @@ int ConvertInChI2InChI(INPUT_PARMS* ip, if (ret < 0) { - if (*pszCurHdr && (*pszCurHdr)[0]) + if (*pszCurHdr && ( *pszCurHdr )[0]) { - inchi_ios_eprint(pLog, "Error %d creating InChI string %s\n", ret, *pszCurHdr); + inchi_ios_eprint( pLog, "Error %d creating InChI string %s\n", ret, *pszCurHdr ); } else { - inchi_ios_eprint(pLog, "Error %d creating InChI string, Structure %ld\n", ret, num_inp); + inchi_ios_eprint( pLog, "Error %d creating InChI string, Structure %ld\n", ret, num_inp ); } if (ip->bINChIOutputOptions2 & INCHI_OUT_INCHI_GEN_ERROR) {/* inchi_ios_eprint( pOut, "InChICreationError!\n"); *//* emit err string */ if (ip->bINChIOutputOptions & INCHI_OUT_STDINCHI) { - inchi_ios_eprint(pOut, "InChI=1S//\n"); + inchi_ios_eprint( pOut, "InChI=1S//\n" ); } else { - inchi_ios_eprint(pOut, "InChI=1//\n"); + inchi_ios_eprint( pOut, "InChI=1//\n" ); } } - (*num_errors)++; + ( *num_errors )++; } #if ( !defined(TARGET_API_LIB) && !defined(TARGET_EXE_STANDALONE) ) else - if (*pszCurHdr && (*pszCurHdr)[0]) + if (*pszCurHdr && ( *pszCurHdr )[0]) { - inchi_fprintf(stderr, "%s\r", *pszCurHdr); + inchi_fprintf( stderr, "%s\r", *pszCurHdr ); } #endif #endif @@ -11132,13 +11133,13 @@ int ConvertInChI2InChI(INPUT_PARMS* ip, if (*pszCurHdr) { - inchi_free(*pszCurHdr); + inchi_free( *pszCurHdr ); *pszCurHdr = NULL; } INCHI_HEAPCHK - * ulProcessingTime += InchiTimeElapsed(ic, pulTStart); + *ulProcessingTime += InchiTimeElapsed( ic, pulTStart ); return ret; } @@ -11148,59 +11149,59 @@ int ConvertInChI2InChI(INPUT_PARMS* ip, /****************************************************************************/ -int ConvertInChI2Struct(ICHICONST INPUT_PARMS* ip_inp, - INPUT_PARMS* ip, - InpInChI* pOneInput, - inp_ATOM** at, - int* num_at, - OAD_Polymer** polymer, - OAD_V3000** v3000, - INCHI_IOSTREAM* pOut, - INCHI_IOSTREAM* pLog, - STRUCT_DATA* sd, - int num_components[INCHI_NUM], - MODE_PIXH nModeProtonIsoExchgH[INCHI_NUM], - char** pszCurHdr, - char* szMsg, - int nMsgLen, - char szMessage[MAX_MSG_LEN], - int nInitLenMessage, - int nMessageLen, - int input_is_stdinchi, - int bHasSomeReconnected, - int bHasSomeFixedH, - int bHasMetal, - int nModeFlagsStereo, - int bTautFlags, - int bReqNonTaut, - unsigned long WarningFlags[2][2], - long num_inp, - long* num_errors, - unsigned char save_opt_bits, - inchiTime* pulTStart, - long* ulProcessingTime, - struct tagINCHI_CLOCK* ic, - struct tagCANON_GLOBALS* pCG) +int ConvertInChI2Struct( ICHICONST INPUT_PARMS *ip_inp, + INPUT_PARMS *ip, + InpInChI *pOneInput, + inp_ATOM **at, + int *num_at, + OAD_Polymer **polymer, + OAD_V3000 **v3000, + INCHI_IOSTREAM *pOut, + INCHI_IOSTREAM *pLog, + STRUCT_DATA *sd, + int num_components[INCHI_NUM], + MODE_PIXH nModeProtonIsoExchgH[INCHI_NUM], + char **pszCurHdr, + char *szMsg, + int nMsgLen, + char szMessage[MAX_MSG_LEN], + int nInitLenMessage, + int nMessageLen, + int input_is_stdinchi, + int bHasSomeReconnected, + int bHasSomeFixedH, + int bHasMetal, + int nModeFlagsStereo, + int bTautFlags, + int bReqNonTaut, + unsigned long WarningFlags[2][2], + long num_inp, + long *num_errors, + unsigned char save_opt_bits, + inchiTime *pulTStart, + long *ulProcessingTime, + struct tagINCHI_CLOCK *ic, + struct tagCANON_GLOBALS *pCG ) { int ret, i, j; SRM srm; /* rules how to handle bonds to metal atoms */ - StrFromINChI* pStruct[INCHI_NUM][TAUT_NUM]; + StrFromINChI *pStruct[INCHI_NUM][TAUT_NUM]; int bINChIOutputOptions = /* djb-rwth: ignoring LLVM warning: variable used */ #if ( I2S_MODIFY_OUTPUT != 1 ) 0; #else /* transfer user's InChI output options to serialization 10-12-2007 */ - ip_inp->bINChIOutputOptions& + ip_inp->bINChIOutputOptions & ( INCHI_OUT_NO_AUX_INFO | /* do not output Aux Info */ INCHI_OUT_SHORT_AUX_INFO | /* output short version of Aux Info */ INCHI_OUT_ONLY_AUX_INFO | /* output only Aux Info */ - /* INCHI_OUT_EMBED_REC |*/ /* embed reconnected INChI into disconnected INChI */ + /* INCHI_OUT_EMBED_REC |*/ /* embed reconnected INChI into disconnected INChI */ INCHI_OUT_SDFILE_ONLY | /* save input data in a Molfile instead of creating INChI */ INCHI_OUT_PLAIN_TEXT | /* output plain text INChI */ INCHI_OUT_PLAIN_TEXT_COMMENTS | /* output plain text annotation */ - /* INCHI_OUT_WINCHI_WINDOW |*/ /* output into wINChI text window */ + /* INCHI_OUT_WINCHI_WINDOW |*/ /* output into wINChI text window */ INCHI_OUT_TABBED_OUTPUT | /* tab-delimited (only for plain text) */ INCHI_OUT_SDFILE_ATOMS_DT | /* SDfile output H isotopes as D and T */ INCHI_OUT_SDFILE_SPLIT | /* Split SDfile into components */ @@ -11209,7 +11210,7 @@ int ConvertInChI2Struct(ICHICONST INPUT_PARMS* ip_inp, #endif /* Preliminaries */ - InchiTimeGet(pulTStart); + InchiTimeGet( pulTStart ); if (input_is_stdinchi) { @@ -11226,22 +11227,22 @@ int ConvertInChI2Struct(ICHICONST INPUT_PARMS* ip_inp, } } - memset(pStruct, 0, sizeof(pStruct)); /* djb-rwth: memset_s C11/Annex K variant? */ + memset( pStruct, 0, sizeof( pStruct ) ); /* djb-rwth: memset_s C11/Annex K variant? */ - SetUpSrm(&srm); /* structure restore parms */ + SetUpSrm( &srm ); /* structure restore parms */ /* Eliminate Fixed-H InChI that are exactly same as the corresponding Mobile-H structures */ - RemoveFixHInChIIdentical2MobH(pOneInput); + RemoveFixHInChIIdentical2MobH( pOneInput ); /* Recheck layers after thee elimination; get optional stereo flags */ - ret = DetectInpInchiCreationOptions(pOneInput, &bHasSomeReconnected, - &bHasMetal, &bHasSomeFixedH, - &nModeFlagsStereo, &bTautFlags); + ret = DetectInpInchiCreationOptions( pOneInput, &bHasSomeReconnected, + &bHasMetal, &bHasSomeFixedH, + &nModeFlagsStereo, &bTautFlags ); if (ret < 0) { - AddOneMsg(szMessage, (int)strlen(szMessage), nMessageLen, - "Error in detecting input InChI options", "; "); - (*num_errors)++; + AddOneMsg( szMessage, (int) strlen( szMessage ), nMessageLen, + "Error in detecting input InChI options", "; " ); + ( *num_errors )++; goto dealloc; } @@ -11251,13 +11252,13 @@ int ConvertInChI2Struct(ICHICONST INPUT_PARMS* ip_inp, } /* Set stereo flags */ - ip->nMode &= ~(REQ_MODE_STEREO | - REQ_MODE_ISO_STEREO | - REQ_MODE_RELATIVE_STEREO | - REQ_MODE_RACEMIC_STEREO | - REQ_MODE_CHIR_FLG_STEREO | - REQ_MODE_SB_IGN_ALL_UU | - REQ_MODE_SC_IGN_ALL_UU); + ip->nMode &= ~( REQ_MODE_STEREO | + REQ_MODE_ISO_STEREO | + REQ_MODE_RELATIVE_STEREO | + REQ_MODE_RACEMIC_STEREO | + REQ_MODE_CHIR_FLG_STEREO | + REQ_MODE_SB_IGN_ALL_UU | + REQ_MODE_SC_IGN_ALL_UU ); ip->nMode |= nModeFlagsStereo; @@ -11272,7 +11273,7 @@ int ConvertInChI2Struct(ICHICONST INPUT_PARMS* ip_inp, /* Disconnected will have a negative number of the reconnected component */ /* Reconnected will have a positive number of the disconnected component */ - MarkDisconectedIdenticalToReconnected(pOneInput); + MarkDisconectedIdenticalToReconnected( pOneInput ); /*****************************************************************************/ /* Pay attention to: */ @@ -11298,14 +11299,14 @@ int ConvertInChI2Struct(ICHICONST INPUT_PARMS* ip_inp, /* In case of both Fixed-H and Mobile-H layers the results are in iMobH=0 */ /* In case of only Mobile-H/Main layer the results are in iMobH=1 */ - ulProcessingTime += InchiTimeElapsed(ic, pulTStart); + ulProcessingTime += InchiTimeElapsed( ic, pulTStart ); sd->ulStructTime = 0; - ret = AllInchiToStructure(ic, pCG, ip, sd, num_inp, *pszCurHdr, &srm, bHasSomeFixedH, pStruct, pOneInput); + ret = AllInchiToStructure( ic, pCG, ip, sd, num_inp, *pszCurHdr, &srm, bHasSomeFixedH, pStruct, pOneInput ); ulProcessingTime += sd->ulStructTime; - InchiTimeGet(pulTStart); + InchiTimeGet( pulTStart ); /* ret < 0 is error code; ret > 0 is number of errors */ /* in pStruct[iInchiRec][iMobileH][iComponent].nError */ @@ -11318,40 +11319,40 @@ int ConvertInChI2Struct(ICHICONST INPUT_PARMS* ip_inp, } #endif /* conversion error */ - (*num_errors)++; + ( *num_errors )++; goto dealloc; } /* Attempt to fix the numumber of removed protons in case of Mobile-H */ if (!pOneInput->nNumProtons[INCHI_BAS][TAUT_YES].pNumProtons && - !pOneInput->nNumProtons[INCHI_REC][TAUT_YES].pNumProtons) + !pOneInput->nNumProtons[INCHI_REC][TAUT_YES].pNumProtons) { - ret = AddProtonAndIsoHBalanceToMobHStruct(ic, pCG, ip, sd, num_inp, bHasSomeFixedH, *pszCurHdr, pStruct, pOneInput); + ret = AddProtonAndIsoHBalanceToMobHStruct( ic, pCG, ip, sd, num_inp, bHasSomeFixedH, *pszCurHdr, pStruct, pOneInput ); if (ret < 0) { - AddOneMsg(szMessage, (int)strlen(szMessage), nMessageLen, "Add/Remove protons error", "; "); - (*num_errors)++; + AddOneMsg( szMessage, (int) strlen( szMessage ), nMessageLen, "Add/Remove protons error", "; " ); + ( *num_errors )++; goto dealloc; } } /* Compare InChI from the Reversed Structure to the original input InChI */ - ret = CompareAllOrigInchiToRevInChI(pStruct, pOneInput, bHasSomeFixedH, num_inp, *pszCurHdr); + ret = CompareAllOrigInchiToRevInChI( pStruct, pOneInput, bHasSomeFixedH, num_inp, *pszCurHdr ); if (ret < 0) { - AddOneMsg(szMessage, (int)strlen(szMessage), nMessageLen, "InChI compare error", "; "); - (*num_errors)++; + AddOneMsg( szMessage, (int) strlen( szMessage ), nMessageLen, "InChI compare error", "; " ); + ( *num_errors )++; goto dealloc; } /* Compare disconnected versions */ - ret = CompareAllDisconnectedOrigInchiToRevInChI(pStruct, pOneInput, - bHasSomeFixedH, num_inp, *pszCurHdr); + ret = CompareAllDisconnectedOrigInchiToRevInChI( pStruct, pOneInput, + bHasSomeFixedH, num_inp, *pszCurHdr ); if (ret < 0) { - AddOneMsg(szMessage, (int)strlen(szMessage), nMessageLen, "InChI compare2 error", "; "); - (*num_errors)++; + AddOneMsg( szMessage, (int) strlen( szMessage ), nMessageLen, "InChI compare2 error", "; " ); + ( *num_errors )++; goto dealloc; } @@ -11361,32 +11362,32 @@ int ConvertInChI2Struct(ICHICONST INPUT_PARMS* ip_inp, { for (j = 0; j < TAUT_NUM; j++) { - WarningFlags[i][j] = (unsigned long)pOneInput->CompareInchiFlags[i][j]; + WarningFlags[i][j] = (unsigned long) pOneInput->CompareInchiFlags[i][j]; } } } - ulProcessingTime += InchiTimeElapsed(ic, pulTStart); + ulProcessingTime += InchiTimeElapsed( ic, pulTStart ); #ifndef COMPILE_ANSI_ONLY - ret = DisplayStructureComponents(pCG, ip, sd, num_inp, *pszCurHdr, &srm, bReqNonTaut, pStruct, pOneInput); + ret = DisplayStructureComponents( pCG, ip, sd, num_inp, *pszCurHdr, &srm, bReqNonTaut, pStruct, pOneInput ); if (ret < 0) { - AddOneMsg(szMessage, (int)strlen(szMessage), nMessageLen, "Display structure error", "; "); + AddOneMsg( szMessage, (int) strlen( szMessage ), nMessageLen, "Display structure error", "; " ); } #endif - InchiTimeGet(pulTStart); + InchiTimeGet( pulTStart ); - ret = MergeStructureComponents(ip, sd, num_inp, *pszCurHdr, &srm, bReqNonTaut, pStruct, pOneInput); + ret = MergeStructureComponents( ip, sd, num_inp, *pszCurHdr, &srm, bReqNonTaut, pStruct, pOneInput ); - ulProcessingTime += InchiTimeElapsed(ic, pulTStart); + ulProcessingTime += InchiTimeElapsed( ic, pulTStart ); if (ret < 0) { - AddOneMsg(szMessage, (int)strlen(szMessage), nMessageLen, "Merge Components error", "; "); - (*num_errors)++; + AddOneMsg( szMessage, (int) strlen( szMessage ), nMessageLen, "Merge Components error", "; " ); + ( *num_errors )++; goto dealloc; } @@ -11417,17 +11418,17 @@ int ConvertInChI2Struct(ICHICONST INPUT_PARMS* ip_inp, } #else - InchiTimeGet(pulTStart); + InchiTimeGet( pulTStart ); - ret = OutputInChIOutOfStrFromINChI(ic, pCG, ip, sd, num_inp, bINChIOutputOptions, - pOut, NULL, pOneInput, bHasSomeFixedH, save_opt_bits); + ret = OutputInChIOutOfStrFromINChI( ic, pCG, ip, sd, num_inp, bINChIOutputOptions, + pOut, NULL, pOneInput, bHasSomeFixedH, save_opt_bits ); - ulProcessingTime += InchiTimeElapsed(ic, pulTStart); + ulProcessingTime += InchiTimeElapsed( ic, pulTStart ); if (ret < 0) { - AddOneMsg(szMessage, (int)strlen(szMessage), nMessageLen, "Restored structure to InChI conversion error", "; "); - (*num_errors)++; + AddOneMsg( szMessage, (int) strlen( szMessage ), nMessageLen, "Restored structure to InChI conversion error", "; " ); + ( *num_errors )++; goto dealloc; } #endif @@ -11435,42 +11436,42 @@ int ConvertInChI2Struct(ICHICONST INPUT_PARMS* ip_inp, if (szMessage) { int len, retcomp = 0, retcomp1 = 0; - InchiTimeGet(pulTStart); - retcomp = FillOutCompareMessage(szMessage, nMessageLen, pOneInput->CompareInchiFlags[0]); + InchiTimeGet( pulTStart ); + retcomp = FillOutCompareMessage( szMessage, nMessageLen, pOneInput->CompareInchiFlags[0] ); if (pOneInput->CompareInchiFlags[1][0] || pOneInput->CompareInchiFlags[1][1]) { - AddOneMsg(szMessage, (int)strlen(szMessage), nMessageLen, "Disconnected: ", "; "); - retcomp1 = FillOutCompareMessage(szMessage, nMessageLen, pOneInput->CompareInchiFlags[1]); + AddOneMsg( szMessage, (int) strlen( szMessage ), nMessageLen, "Disconnected: ", "; " ); + retcomp1 = FillOutCompareMessage( szMessage, nMessageLen, pOneInput->CompareInchiFlags[1] ); } /* add a metal warning */ - if (bHasMetal && nInitLenMessage < (len = (int)strlen(szMessage))) + if (bHasMetal && nInitLenMessage < ( len = (int) strlen( szMessage ) )) { char szMetal[] = " (Metal compound)"; int shift; - if (len + (int)sizeof(szMetal) > nMessageLen) + if (len + ( int )sizeof( szMetal ) > nMessageLen) { - len = nMessageLen - (int)sizeof(szMetal); + len = nMessageLen - ( int )sizeof( szMetal ); } - shift = nInitLenMessage + (int)sizeof(szMetal) - 1; + shift = nInitLenMessage + ( int )sizeof( szMetal ) - 1; memmove(szMessage + shift, szMessage + nInitLenMessage, ((long long)len - nInitLenMessage) * sizeof(szMessage[0])); /* djb-rwth: cast operator added */ memcpy(szMessage + nInitLenMessage, szMetal, sizeof(szMetal) - sizeof(szMessage[0])); szMessage[shift + len - nInitLenMessage] = '\0'; } - retcomp = inchi_min(retcomp, retcomp1); + retcomp = inchi_min( retcomp, retcomp1 ); if (retcomp < 0 && - (ip_inp->bINChIOutputOptions2 & INCHI_OUT_MISMATCH_AS_ERROR) - ) + ( ip_inp->bINChIOutputOptions2 & INCHI_OUT_MISMATCH_AS_ERROR ) + ) { ret = RI_ERR_MISMATCH; /* AddOneMsg(szMessage, (int)strlen(szMessage), nMessageLen, "* Treated as error by user supplied option", "; "); */ - (*num_errors)++; + ( *num_errors )++; goto dealloc; } - ulProcessingTime += InchiTimeElapsed(ic, pulTStart); + ulProcessingTime += InchiTimeElapsed( ic, pulTStart ); } ret = 0; @@ -11483,19 +11484,19 @@ int ConvertInChI2Struct(ICHICONST INPUT_PARMS* ip_inp, { if (ret == CT_USER_QUIT_ERR) { - AddOneMsg(szMessage, (int)strlen(szMessage), nMessageLen, "*Terminated by the user*", "; "); + AddOneMsg( szMessage, (int) strlen( szMessage ), nMessageLen, "*Terminated by the user*", "; " ); } else { - AddOneMsg(szMessage, (int)strlen(szMessage), nMessageLen, "*Conversion failed*", "; "); + AddOneMsg( szMessage, (int) strlen( szMessage ), nMessageLen, "*Conversion failed*", "; " ); } } else { int iRec, iMob, iComp, nComp, len; /* djb-rwth: ignoring LLVM warning: variable used to store function return value */ char szTemp[128]; - AddOneMsg(szMessage, (int)strlen(szMessage), nMessageLen, "*Conversion failed on component(s)", "; "); - len = (int)strlen(szMessage); /* djb-rwth: ignoring LLVM warning: variable used to store function return value */ + AddOneMsg( szMessage, (int) strlen( szMessage ), nMessageLen, "*Conversion failed on component(s)", "; " ); + len = (int) strlen( szMessage ); /* djb-rwth: ignoring LLVM warning: variable used to store function return value */ for (iRec = 0; iRec < INCHI_NUM; iRec++) { for (iMob = bHasSomeFixedH ? TAUT_NON : TAUT_YES; iMob < TAUT_NUM; iMob++) @@ -11509,7 +11510,7 @@ int ConvertInChI2Struct(ICHICONST INPUT_PARMS* ip_inp, { if (pStruct[iRec][iMob][iComp].nError) { - char* szFormula = pOneInput->pInpInChI[iRec][iMob][iComp].szHillFormula; + char *szFormula = pOneInput->pInpInChI[iRec][iMob][iComp].szHillFormula; sprintf(szTemp, #if ( FIX_DALKE_BUGS == 1 ) " %s%s%d(%.96s)", @@ -11519,7 +11520,7 @@ int ConvertInChI2Struct(ICHICONST INPUT_PARMS* ip_inp, !bHasSomeReconnected ? "" : iRec ? "R" : "D", !bHasSomeFixedH ? "" : iMob ? "M" : "F", iComp + 1, szFormula ? szFormula : "???"); - AddOneMsg(szMessage, (int)strlen(szMessage), nMessageLen, szTemp, NULL); + AddOneMsg( szMessage, (int) strlen( szMessage ), nMessageLen, szTemp, NULL ); } } } @@ -11528,12 +11529,12 @@ int ConvertInChI2Struct(ICHICONST INPUT_PARMS* ip_inp, } /* if ( ret ) */ - InchiTimeGet(pulTStart); + InchiTimeGet( pulTStart ); /* Print one structure report */ if (szMessage && szMsg && nMsgLen > 1) /* djb-rwth: additional condition for szMessage */ { - int len = inchi_min((int)strlen(szMessage), nMsgLen - 1); + int len = inchi_min( (int) strlen( szMessage ), nMsgLen - 1 ); if (len > 0) { memcpy(szMsg, szMessage, len); @@ -11545,49 +11546,49 @@ int ConvertInChI2Struct(ICHICONST INPUT_PARMS* ip_inp, } } - if (szMessage && (nInitLenMessage < (int)strlen(szMessage))) /* djb-rwth: additional condition for szMessage */ + if (szMessage && (nInitLenMessage < (int) strlen( szMessage ))) /* djb-rwth: additional condition for szMessage */ { - inchi_ios_eprint(pLog, "%s\n", szMessage); + inchi_ios_eprint( pLog, "%s\n", szMessage ); } #ifndef TARGET_API_LIB else { /*^^^inchi_ios_eprint( stderr, "%s\r", szMessage );*/ - inchi_fprintf(stderr, "%s\r", szMessage); + inchi_fprintf( stderr, "%s\r", szMessage ); } #endif - FreeStrFromINChI(pStruct, pOneInput->nNumComponents); - FreeInpInChI(pOneInput); + FreeStrFromINChI( pStruct, pOneInput->nNumComponents ); + FreeInpInChI( pOneInput ); if (*pszCurHdr) { - inchi_free(*pszCurHdr); + inchi_free( *pszCurHdr ); *pszCurHdr = NULL; } INCHI_HEAPCHK - ulProcessingTime += InchiTimeElapsed(ic, pulTStart); /* djb-rwth: ignoring LLVM warning: variable used to store function return value */ + ulProcessingTime += InchiTimeElapsed( ic, pulTStart ); /* djb-rwth: ignoring LLVM warning: variable used to store function return value */ return ret; } /****************************************************************************/ -int DetectAndExposePolymerInternals(INCHI_IOSTREAM* is) +int DetectAndExposePolymerInternals( INCHI_IOSTREAM *is ) { int i, j, elindex, ret = 0, nheavy = 0, nstars = 0, zlen = 0, star0 = 0, i_last_sym, slen = 0, i2 = 0, ninsert = 0, kinsert, lead_pos, nc, ntimes; - const char* p, * pz, * pz2, * pr, * pend, * q; + const char *p, *pz, *pz2, *pr, *pend, *q; char prev_layer_symbol = '0'; - char element[3], * tmpstr = NULL, * edited_s = NULL; - int* insert_pos = NULL; /* inserts go before insert_pos[k] */ - char* s = NULL, * s2 = NULL; + char element[3], *tmpstr = NULL, *edited_s = NULL; + int *insert_pos = NULL; /* inserts go before insert_pos[k] */ + char *s = NULL, *s2 = NULL; int slength; slength = is->s.nUsedLength; - s = (char*)inchi_calloc(2 * (long long)slength + 32, sizeof(char)); /* djb-rwth: cast operator added */ + s = (char *) inchi_calloc( 2 * (long long)slength + 32, sizeof( char ) ); /* djb-rwth: cast operator added */ if (!s) { goto endf; @@ -11597,7 +11598,7 @@ int DetectAndExposePolymerInternals(INCHI_IOSTREAM* is) strcpy(s, is->s.pStr); for (i = 0; i < slength; i++) { - if (isspace(UCINT s[i])) + if (isspace( UCINT s[i] )) { i2 = i; break; @@ -11605,20 +11606,20 @@ int DetectAndExposePolymerInternals(INCHI_IOSTREAM* is) } if (i2) { - s2 = (char*)inchi_calloc((long long)slength - (long long)i2 + 2, sizeof(char)); /* djb-rwth: cast operators added */ + s2 = (char *) inchi_calloc( (long long)slength - (long long)i2 + 2, sizeof( char ) ); /* djb-rwth: cast operators added */ if (!s2) goto endf; strcpy(s2, s + i2); s[i2] = '\0'; } - i_last_sym = strlen(s) - 1; - p = strstr(s, "InChI=1"); + i_last_sym = strlen( s ) - 1; + p = strstr( s, "InChI=1" ); if (!p) { goto endf; } - pz = strstr(p, "/z"); + pz = strstr( p, "/z" ); if (!pz) { goto endf; @@ -11626,17 +11627,17 @@ int DetectAndExposePolymerInternals(INCHI_IOSTREAM* is) pz++; /* Check formula */ - p = strchr(p, '/'); + p = strchr( p, '/' ); p++; - pend = strchr(p, '/'); + pend = strchr( p, '/' ); ntimes = 1; while (p != pend) { - if (isdigit(*p)) + if (isdigit( *p )) { - ntimes = (int)inchi_strtol(p, &q, 10); + ntimes = (int) inchi_strtol( p, &q, 10 ); #if ( CHECK_STRTOL_ATNUMB==1 ) - if (ntimes > MAX_ATOMS || ntimes < 0) + if (ntimes>MAX_ATOMS || ntimes<0) { #if (FIX_GAF_2020_25607 == 1) ret = RI_ERR_SYNTAX; @@ -11656,7 +11657,7 @@ int DetectAndExposePolymerInternals(INCHI_IOSTREAM* is) } } - if (!isupper(UCINT * p)) + if (!isupper( UCINT *p )) { ret = -1; goto endf; @@ -11664,16 +11665,16 @@ int DetectAndExposePolymerInternals(INCHI_IOSTREAM* is) j = 0; element[j++] = *p++; - if (*p && islower(UCINT * p)) + if (*p && islower( UCINT *p )) { element[j++] = *p++; } element[j++] = '\0'; - if (*p && isdigit(UCINT * p)) + if (*p && isdigit( UCINT *p )) { - elindex = (int)inchi_strtol(p, &q, 10); + elindex = (int) inchi_strtol( p, &q, 10 ); #if ( CHECK_STRTOL_ATNUMB==1 ) - if (elindex > MAX_ATOMS || elindex < 0) + if (elindex>MAX_ATOMS || elindex<0) { #if (FIX_GAF_2020_25607 == 1) ret = RI_ERR_SYNTAX; @@ -11704,7 +11705,7 @@ int DetectAndExposePolymerInternals(INCHI_IOSTREAM* is) #endif if (element[0] != 'H' || element[1]) { - nheavy += ntimes * elindex; + nheavy += ntimes*elindex; } if (*p == '.') @@ -11714,10 +11715,10 @@ int DetectAndExposePolymerInternals(INCHI_IOSTREAM* is) } #if ( FIX_GAF_2019_2==1 ) - insert_pos = (int*)inchi_calloc((long long)is->s.nUsedLength + 1, sizeof(int)); /* djb-rwth: cast operator added */ + insert_pos = (int *)inchi_calloc((long long)is->s.nUsedLength + 1, sizeof(int)); /* djb-rwth: cast operator added */ #else /* max num of insert positions is 2 in formulas + Npolymeric units, the latter may not be > nheavy */ - insert_pos = (int*)inchi_calloc(nheavy + 32, sizeof(int)); + insert_pos = (int *)inchi_calloc(nheavy + 32, sizeof(int)); #endif if (!insert_pos) { @@ -11728,7 +11729,7 @@ int DetectAndExposePolymerInternals(INCHI_IOSTREAM* is) ninsert = 0; if (pend) { - insert_pos[ninsert] = (int)(pend - s); + insert_pos[ninsert] = (int) ( pend - s ); } else { @@ -11737,24 +11738,24 @@ int DetectAndExposePolymerInternals(INCHI_IOSTREAM* is) ninsert++; /* Check hidden stars */ - lead_pos = (int)(pz - s); - pend = strchr(pz, '/'); + lead_pos = (int) ( pz - s ); + pend = strchr( pz, '/' ); if (pend) { - zlen = (int)(pend - pz); + zlen = (int) ( pend - pz ); } else { - zlen = (int)strlen(pz); + zlen = (int) strlen( pz ); } - tmpstr = (char*)inchi_calloc((long long)zlen + 32, sizeof(char)); /* djb-rwth: cast operator added */ + tmpstr = (char *) inchi_calloc( (long long)zlen + 32, sizeof( char ) ); /* djb-rwth: cast operator added */ if (!tmpstr) { ret = -2; goto endf; } memcpy(tmpstr, pz, zlen); - ret = DetectHiddenPolymerStuff(tmpstr, zlen, &ninsert, insert_pos, lead_pos, &nstars); + ret = DetectHiddenPolymerStuff( tmpstr, zlen, &ninsert, insert_pos, lead_pos, &nstars ); if (ret) { goto endf; @@ -11765,15 +11766,15 @@ int DetectAndExposePolymerInternals(INCHI_IOSTREAM* is) } /* Have second '/z' ? */ - pr = strstr(s, "/r"); + pr = strstr( s, "/r" ); if (pr) { pr++; - pend = strchr(pr, '/'); + pend = strchr( pr, '/' ); if (pend) { - insert_pos[ninsert] = (int)(pend - s); + insert_pos[ninsert] = (int) ( pend - s ); } else { @@ -11781,25 +11782,25 @@ int DetectAndExposePolymerInternals(INCHI_IOSTREAM* is) } ninsert++; - pz2 = strstr(pr, "/z"); + pz2 = strstr( pr, "/z" ); if (pz2) { pz2++; - lead_pos = (int)(pz2 - s); - pend = strchr(pz2, '/'); + lead_pos = (int) ( pz2 - s ); + pend = strchr( pz2, '/' ); if (pend) { - zlen = (int)(pend - pz2); + zlen = (int) ( pend - pz2 ); } else { - zlen = (int)strlen(pz2); + zlen = (int) strlen( pz2 ); } if (tmpstr) { - inchi_free(tmpstr); + inchi_free( tmpstr ); } - tmpstr = (char*)inchi_calloc((long long)zlen + 32, sizeof(char)); /* djb-rwth: cast operator added */ + tmpstr = (char *) inchi_calloc( (long long)zlen + 32, sizeof( char ) ); /* djb-rwth: cast operator added */ if (!tmpstr) { ret = -2; @@ -11807,7 +11808,7 @@ int DetectAndExposePolymerInternals(INCHI_IOSTREAM* is) } memcpy(tmpstr, pz2, zlen); nstars = 0; - ret = DetectHiddenPolymerStuff(tmpstr, zlen, &ninsert, insert_pos, lead_pos, &nstars); + ret = DetectHiddenPolymerStuff( tmpstr, zlen, &ninsert, insert_pos, lead_pos, &nstars ); if (ret) { goto endf; @@ -11815,8 +11816,8 @@ int DetectAndExposePolymerInternals(INCHI_IOSTREAM* is) } } - slen = (int)strlen(s); - edited_s = (char*)inchi_calloc((long long)slen * 100 + 32 * 10 * (long long)ninsert, sizeof(char)); /* high reservation */ /* djb-rwth: cast operator added */ + slen = (int) strlen( s ); + edited_s = (char *) inchi_calloc( (long long)slen * 100 + 32 * 10 * (long long)ninsert, sizeof( char ) ); /* high reservation */ /* djb-rwth: cast operator added */ if (!edited_s) { ret = -2; @@ -11843,7 +11844,7 @@ int DetectAndExposePolymerInternals(INCHI_IOSTREAM* is) star0 += 2; } kinsert++; - for (j = 0; j < (int)strlen(tmpstr); j++) + for (j = 0; j < (int) strlen( tmpstr ); j++) { edited_s[nc] = tmpstr[j]; nc++; @@ -11858,12 +11859,12 @@ int DetectAndExposePolymerInternals(INCHI_IOSTREAM* is) if (s[i] == '/' || i == i_last_sym) { if (prev_layer_symbol != '0' && - prev_layer_symbol != 'f' && - prev_layer_symbol != 'z' && - prev_layer_symbol != 'p' && - prev_layer_symbol != 'r' && - prev_layer_symbol != 's' - ) + prev_layer_symbol != 'f' && + prev_layer_symbol != 'z' && + prev_layer_symbol != 'p' && + prev_layer_symbol != 'r' && + prev_layer_symbol != 's' + ) { char addon = ';'; if (prev_layer_symbol == 'm') @@ -11880,7 +11881,7 @@ int DetectAndExposePolymerInternals(INCHI_IOSTREAM* is) if (s[i - 1] != 'f' && s[i - 2] != '/') { sprintf(tmpstr, ".%dZz", nstars); - for (j = 0; j < (int)strlen(tmpstr); j++) + for (j = 0; j < (int) strlen( tmpstr ); j++) { edited_s[nc] = tmpstr[j]; nc++; @@ -11901,29 +11902,29 @@ int DetectAndExposePolymerInternals(INCHI_IOSTREAM* is) nc++; } edited_s[nc] = '\0'; - inchi_strbuf_close(&is->s); - inchi_ios_print(is, "%-s%-s\n", edited_s, s2 ? s2 : ""); + inchi_strbuf_close( &is->s ); + inchi_ios_print( is, "%-s%-s\n", edited_s, s2 ? s2 : "" ); endf: if (s) { - inchi_free(s); + inchi_free( s ); } if (s2) { - inchi_free(s2); + inchi_free( s2 ); } if (edited_s) { - inchi_free(edited_s); + inchi_free( edited_s ); } if (tmpstr) { - inchi_free(tmpstr); + inchi_free( tmpstr ); } if (insert_pos) { - inchi_free(insert_pos); + inchi_free( insert_pos ); } return ret; @@ -11931,12 +11932,12 @@ int DetectAndExposePolymerInternals(INCHI_IOSTREAM* is) /****************************************************************************/ -int DetectHiddenPolymerStuff(char* tmpstr, - int tmpstrlen, - int* ninsert, - int* insert_pos, - int insert_lead_offset, - int* nstars) +int DetectHiddenPolymerStuff( char *tmpstr, + int tmpstrlen, + int *ninsert, + int *insert_pos, + int insert_lead_offset, + int *nstars ) { char c; int opened, skip, i, i0, closed, ret = 0; @@ -11965,9 +11966,9 @@ int DetectHiddenPolymerStuff(char* tmpstr, } if (!skip) { - (*nstars) += 2; - insert_pos[(*ninsert)] = i0 + 1 + insert_lead_offset; - (*ninsert)++; + ( *nstars ) += 2; + insert_pos[( *ninsert )] = i0 + 1 + insert_lead_offset; + ( *ninsert )++; } opened = 0; } @@ -11985,56 +11986,56 @@ int DetectHiddenPolymerStuff(char* tmpstr, /**************************************************************************** Create empty sp3 segment ****************************************************************************/ -static int SegmentSp3CreateEmpty(const char* str, - int bMobileH, - INChI* pInpInChI[], - int nNumComponents, - int state, - int* pbAbc) +static int SegmentSp3CreateEmpty( const char *str, + int bMobileH, + INChI *pInpInChI[], + int nNumComponents, + int state, + int *pbAbc ) { int ret = 0; int iComponent; int len0 = 0; - int bIso = (state == IST_MOBILE_H_ISO_SP3 || state == IST_FIXED_H_ISO_SP3); - INChI_Stereo** pStereo = NULL; - INChI* pInChI = pInpInChI[bMobileH]; + int bIso = ( state == IST_MOBILE_H_ISO_SP3 || state == IST_FIXED_H_ISO_SP3 ); + INChI_Stereo **pStereo = NULL; + INChI *pInChI = pInpInChI[bMobileH]; for (iComponent = 0; iComponent < nNumComponents; iComponent++) { - INChI* pIsoInChI = &pInChI[iComponent]; + INChI *pIsoInChI = &pInChI[iComponent]; pStereo = bIso ? &pIsoInChI->StereoIsotopic : &pIsoInChI->Stereo; if (!*pStereo) { - if (!(*pStereo = (INChI_Stereo*)inchi_calloc(1, sizeof(**pStereo)))) + if (!( *pStereo = (INChI_Stereo *) inchi_calloc( 1, sizeof( **pStereo ) ) )) { return RI_ERR_ALLOC; } } /* allocate empty sp3 stereo */ if ((!pStereo[0]->b_parity && - !(pStereo[0]->b_parity = (S_CHAR*)inchi_calloc((long long)len0 + 1, sizeof(pStereo[0]->b_parity[0])))) || - (!pStereo[0]->nBondAtom1 && - !(pStereo[0]->nBondAtom1 = (AT_NUMB*)inchi_calloc((long long)len0 + 1, sizeof(pStereo[0]->nBondAtom1[0])))) || - (!pStereo[0]->nBondAtom2 && - !(pStereo[0]->nBondAtom2 = (AT_NUMB*)inchi_calloc((long long)len0 + 1, sizeof(pStereo[0]->nBondAtom2[0]))))) /* djb-rwth: cast operator added; addressing LLVM warnings */ + !( pStereo[0]->b_parity = (S_CHAR *) inchi_calloc( (long long)len0 + 1, sizeof( pStereo[0]->b_parity[0] ) ) )) || + (!pStereo[0]->nBondAtom1 && + !( pStereo[0]->nBondAtom1 = (AT_NUMB *) inchi_calloc( (long long)len0 + 1, sizeof( pStereo[0]->nBondAtom1[0] ) ) )) || + (!pStereo[0]->nBondAtom2 && + !( pStereo[0]->nBondAtom2 = (AT_NUMB *) inchi_calloc( (long long)len0 + 1, sizeof( pStereo[0]->nBondAtom2[0] ) ) ))) /* djb-rwth: cast operator added; addressing LLVM warnings */ { /* cleanup */ if (pStereo[0]->b_parity) { INCHI_HEAPCHK - inchi_free(pStereo[0]->b_parity); + inchi_free( pStereo[0]->b_parity ); pStereo[0]->b_parity = NULL; } if (pStereo[0]->nBondAtom1) { INCHI_HEAPCHK - inchi_free(pStereo[0]->nBondAtom1); + inchi_free( pStereo[0]->nBondAtom1 ); pStereo[0]->nBondAtom1 = NULL; } if (pStereo[0]->nBondAtom2) { INCHI_HEAPCHK - inchi_free(pStereo[0]->nBondAtom2); + inchi_free( pStereo[0]->nBondAtom2 ); pStereo[0]->nBondAtom2 = NULL; } return RI_ERR_ALLOC; @@ -12048,14 +12049,14 @@ static int SegmentSp3CreateEmpty(const char* str, /****************************************************************************/ -static int SegmentSp3StoreStereoCenters(int* pbAbc, - const char* pStart, - const char* pEnd, - int pInChI_iComponent_nNumberOfAtoms, - INChI_Stereo* PStereo_0) +static int SegmentSp3StoreStereoCenters( int *pbAbc, + const char *pStart, + const char *pEnd, + int pInChI_iComponent_nNumberOfAtoms, + INChI_Stereo *PStereo_0 ) { const char parity_type[] = "-+u?"; - const char* p, * q, * r; + const char *p, *q, *r; AT_NUMB nAtom1; int iAtom; int atomParity; @@ -12063,11 +12064,11 @@ static int SegmentSp3StoreStereoCenters(int* pbAbc, if (*pbAbc == 1) { - for (p = (char*)pStart, iAtom = 0; p < pEnd; iAtom++) + for (p = (char *) pStart, iAtom = 0; p < pEnd; iAtom++) { - if ((nAtom1 = (AT_NUMB)inchi_strtol(p, &p, base)) && - (atomParity = (int)inchi_strtol(p, &p, 10), - AB_MIN_KNOWN_PARITY <= atomParity && atomParity <= AB_MAX_KNOWN_PARITY)) + if (( nAtom1 = (AT_NUMB) inchi_strtol( p, &p, base ) ) && + ( atomParity = (int) inchi_strtol( p, &p, 10 ), + AB_MIN_KNOWN_PARITY <= atomParity && atomParity <= AB_MAX_KNOWN_PARITY )) { ; /* okay */ } @@ -12081,7 +12082,7 @@ static int SegmentSp3StoreStereoCenters(int* pbAbc, } PStereo_0->t_parity[iAtom] = atomParity; PStereo_0->nNumber[iAtom] = nAtom1; - if (iAtom && !(PStereo_0->nNumber[iAtom - 1] < nAtom1)) + if (iAtom && !( PStereo_0->nNumber[iAtom - 1] < nAtom1 )) { return RI_ERR_SYNTAX; /* syntax error */ } @@ -12089,24 +12090,24 @@ static int SegmentSp3StoreStereoCenters(int* pbAbc, } else { - for (p = (char*)pStart, iAtom = 0; p < pEnd; iAtom++, p += (*p == ',')) + for (p = (char *) pStart, iAtom = 0; p < pEnd; iAtom++, p += ( *p == ',' )) { - nAtom1 = (AT_NUMB)inchi_strtol(p, &q, 10); + nAtom1 = (AT_NUMB) inchi_strtol( p, &q, 10 ); #if ( CHECK_STRTOL_ATNUMB==1 ) - if (nAtom1 > MAX_ATOMS || nAtom1 < 0) + if (nAtom1>MAX_ATOMS || nAtom1<0) { return RI_ERR_SYNTAX; } #endif - if (!(r = strchr((char*)parity_type, *q))) + if (!(r = strchr((char *)parity_type, *q))) { return RI_ERR_SYNTAX; /* syntax error */ } p = q + 1; - atomParity = (int)(r - parity_type) + 1; + atomParity = (int) ( r - parity_type ) + 1; PStereo_0->t_parity[iAtom] = atomParity; PStereo_0->nNumber[iAtom] = nAtom1; - if (iAtom && !(PStereo_0->nNumber[iAtom - 1] < nAtom1)) + if (iAtom && !( PStereo_0->nNumber[iAtom - 1] < nAtom1 )) { return RI_ERR_SYNTAX; } @@ -12128,16 +12129,16 @@ static int SegmentSp3StoreStereoCenters(int* pbAbc, /**************************************************************************** Treat multiplier-served components ****************************************************************************/ -static int SegmentSp3CopyMultiplierCovered(int mpy_component, - int iComponent, - INChI* pInChI, - int bIso, - int nCpyType) +static int SegmentSp3CopyMultiplierCovered( int mpy_component, + int iComponent, + INChI *pInChI, + int bIso, + int nCpyType ) { int i, ret = 0; for (i = 1; i < mpy_component; i++) { - ret = CopySegment(pInChI + iComponent + i, pInChI + iComponent, nCpyType, bIso, bIso); + ret = CopySegment( pInChI + iComponent + i, pInChI + iComponent, nCpyType, bIso, bIso ); if (!ret) { ret = RI_ERR_SYNTAX; @@ -12146,7 +12147,7 @@ static int SegmentSp3CopyMultiplierCovered(int mpy_component, { return ret; } - ret = CopySegment(pInChI + iComponent + i, pInChI + iComponent, CPY_SP3_M, bIso, bIso); + ret = CopySegment( pInChI + iComponent + i, pInChI + iComponent, CPY_SP3_M, bIso, bIso ); if (!ret) { ret = RI_ERR_SYNTAX; @@ -12164,21 +12165,21 @@ static int SegmentSp3CopyMultiplierCovered(int mpy_component, /**************************************************************************** Process the abbreviation ****************************************************************************/ -static int SegmentSp3ProcessAbbreviation(int* mpy_component, - int iComponent, - int nNumComponents, - int val, - const char* q, - int state, - int* pbAbc, - int bMobileH, - int nCpyType, - INChI* pInChI, - INChI* pInpInChI_ALT_TAUT_bMobileH) +static int SegmentSp3ProcessAbbreviation( int *mpy_component, + int iComponent, + int nNumComponents, + int val, + const char *q, + int state, + int *pbAbc, + int bMobileH, + int nCpyType, + INChI *pInChI, + INChI *pInpInChI_ALT_TAUT_bMobileH ) { int i, bIsoTo = -1, bIsoFrom = -1; int ret = 0; - INChI* pInChIFrom = NULL; + INChI *pInChIFrom = NULL; #if (FIX_DALKE_BUGS == 1) if (iComponent + val > nNumComponents) @@ -12195,87 +12196,46 @@ static int SegmentSp3ProcessAbbreviation(int* mpy_component, switch (bMobileH) { - case TAUT_YES: - switch (state) - { - case IST_MOBILE_H_ISO_SP3: - if (*q == 'm') - { - /* copy from mobile H to isotopic mobile H */ - pInChIFrom = pInChI; - bIsoTo = 1; - bIsoFrom = 0; - } - else - { - if (*q == 'e') - { - /* copy from mobile H to isotopic mobile H */ - pInChIFrom = pInChI; - bIsoTo = 1; - bIsoFrom = -1; /* empty */ - } - else - { - ret = RI_ERR_SYNTAX; /* syntax error */ - } - } - break; - default: - ret = RI_ERR_SYNTAX; - break; - } - break; - case TAUT_NON: - switch (state) - { - case IST_FIXED_H_SP3: - if (*q == 'm') - { - /* copy from mobile H to fixed H */ - pInChIFrom = pInpInChI_ALT_TAUT_bMobileH; - bIsoTo = 0; - bIsoFrom = 0; - } - else + case TAUT_YES: + switch (state) { - if (*q == 'e') - { - /* copy from mobile H to isotopic mobile H */ - pInChIFrom = pInChI; - bIsoTo = 1; - bIsoFrom = -1; /* empty */ - } - else - { - ret = RI_ERR_SYNTAX; /* syntax error */ - } + case IST_MOBILE_H_ISO_SP3: + if (*q == 'm') + { + /* copy from mobile H to isotopic mobile H */ + pInChIFrom = pInChI; + bIsoTo = 1; + bIsoFrom = 0; + } + else + { + if (*q == 'e') + { + /* copy from mobile H to isotopic mobile H */ + pInChIFrom = pInChI; + bIsoTo = 1; + bIsoFrom = -1; /* empty */ + } + else + { + ret = RI_ERR_SYNTAX; /* syntax error */ + } + } + break; + default: + ret = RI_ERR_SYNTAX; + break; } break; - case IST_FIXED_H_ISO_SP3: - if (*q == 'm') - { - /* copy from mobile H to fixed isotopic H */ - pInChIFrom = pInpInChI_ALT_TAUT_bMobileH; - bIsoTo = 1; - bIsoFrom = 0; - } - else + case TAUT_NON: + switch (state) { - if (*q == 'M') - { - /* copy from isotopic mobile H to fixed isotopic H */ - pInChIFrom = pInpInChI_ALT_TAUT_bMobileH; - bIsoTo = 1; - bIsoFrom = 1; - } - else - { - if (*q == 'n') + case IST_FIXED_H_SP3: + if (*q == 'm') { - /* copy from fixed H to fixed isotopic H */ - pInChIFrom = pInChI; - bIsoTo = 1; + /* copy from mobile H to fixed H */ + pInChIFrom = pInpInChI_ALT_TAUT_bMobileH; + bIsoTo = 0; bIsoFrom = 0; } else @@ -12292,18 +12252,59 @@ static int SegmentSp3ProcessAbbreviation(int* mpy_component, ret = RI_ERR_SYNTAX; /* syntax error */ } } - } + break; + case IST_FIXED_H_ISO_SP3: + if (*q == 'm') + { + /* copy from mobile H to fixed isotopic H */ + pInChIFrom = pInpInChI_ALT_TAUT_bMobileH; + bIsoTo = 1; + bIsoFrom = 0; + } + else + { + if (*q == 'M') + { + /* copy from isotopic mobile H to fixed isotopic H */ + pInChIFrom = pInpInChI_ALT_TAUT_bMobileH; + bIsoTo = 1; + bIsoFrom = 1; + } + else + { + if (*q == 'n') + { + /* copy from fixed H to fixed isotopic H */ + pInChIFrom = pInChI; + bIsoTo = 1; + bIsoFrom = 0; + } + else + { + if (*q == 'e') + { + /* copy from mobile H to isotopic mobile H */ + pInChIFrom = pInChI; + bIsoTo = 1; + bIsoFrom = -1; /* empty */ + } + else + { + ret = RI_ERR_SYNTAX; /* syntax error */ + } + } + } + } + break; + default: + ret = RI_ERR_SYNTAX; + break; } break; + default: ret = RI_ERR_SYNTAX; break; - } - break; - - default: - ret = RI_ERR_SYNTAX; - break; } if (ret < 0) @@ -12348,20 +12349,20 @@ static int SegmentSp3ProcessAbbreviation(int* mpy_component, /* Internal: a generic parser/extractor interface */ -int extract_from_inchi_string(char* sinchi, InpInChI* OneInput) +int extract_from_inchi_string(char *sinchi, InpInChI *OneInput) { int ret = _IS_OKAY; - char* strHdr = NULL; + char *strHdr = NULL; SEGM_LINE Line; - SEGM_LINE* pLine = &Line; + SEGM_LINE *pLine = &Line; int pState, nErr; const int bInChI2Structure = 1, bReadCoord = 1; int input_is_stdinchi, input_has_save_opt; unsigned char input_save_opt_bits; int end_of_data_reached, read_inchi_ok; INCHI_IOSTREAM tmpinputstream; - INCHI_IOSTREAM* pInp = &tmpinputstream; + INCHI_IOSTREAM *pInp = &tmpinputstream; INCHI_MODE nMode = 0; /* djb-rwth: removing redundant code */ @@ -12431,17 +12432,17 @@ int extract_from_inchi_string(char* sinchi, InpInChI* OneInput) /**************************************************************************** Extract_stereo_info_from_inchi_string ****************************************************************************/ -int extract_stereo_info_from_inchi_string(char* sinchi, - int nat, - int* orig, - int* at_stereo_mark_orig) +int extract_stereo_info_from_inchi_string(char *sinchi, + int nat, + int *orig, + int *at_stereo_mark_orig) { - InpInChI OneInput; + InpInChI OneInput; int ret = _IS_OKAY; int icomponent, i, bReconn = 0, bMobileH = 1, at_offset_component = 0; /* 0 is INCHI_PARITY_NONE */ - memset(at_stereo_mark_orig, 0, ((long long)nat + 1) * sizeof(int)); /* djb-rwth: cast operator added; memset_s C11/Annex K variant? */ + memset(at_stereo_mark_orig, 0, ((long long)nat+1) * sizeof(int)); /* djb-rwth: cast operator added; memset_s C11/Annex K variant? */ ret = extract_from_inchi_string(sinchi, &OneInput); if (ret == _IS_ERROR || ret == _IS_FATAL) @@ -12450,8 +12451,8 @@ int extract_stereo_info_from_inchi_string(char* sinchi, goto exit_function; } - - + + for (icomponent = 0; icomponent < OneInput.nNumComponents[bReconn][bMobileH]; icomponent++) { INChI pI = OneInput.pInpInChI[bReconn][bMobileH][icomponent]; @@ -12467,8 +12468,8 @@ int extract_stereo_info_from_inchi_string(char* sinchi, } at_offset_component += pI.nNumberOfAtoms; } - -exit_function: + +exit_function: FreeInpInChI(&OneInput); return ret; @@ -12479,16 +12480,16 @@ int extract_stereo_info_from_inchi_string(char* sinchi, Extract all backbone bonds, in all units, from InChI string NB: as units are not 'inter-crossing' any bkbond belongs to some unique CRU ****************************************************************************/ -int extract_all_backbone_bonds_from_inchi_string(char* sinchi, - int* n_all_bkb_orig, - int* orig, - int* all_bkb_orig) +int extract_all_backbone_bonds_from_inchi_string(char *sinchi, + int *n_all_bkb_orig, + int *orig, + int *all_bkb_orig) { InpInChI OneInput; int i, ret = _IS_OKAY; ret = extract_from_inchi_string(sinchi, &OneInput); - if (ret == _IS_ERROR || ret == _IS_FATAL) + if (ret== _IS_ERROR || ret== _IS_FATAL) { ret = _IS_ERROR; goto exit_function; @@ -12497,7 +12498,7 @@ int extract_all_backbone_bonds_from_inchi_string(char* sinchi, for (i = 0; i < OneInput.polymer->n; i++) { int j; - OAD_PolymerUnit* u = OneInput.polymer->units[i]; + OAD_PolymerUnit *u = OneInput.polymer->units[i]; for (j = 0; j < u->nbkbonds; j++) { int icano1, iorig1, icano2, iorig2; @@ -12506,14 +12507,14 @@ int extract_all_backbone_bonds_from_inchi_string(char* sinchi, icano2 = u->bkbonds[j][1]; iorig2 = orig[icano2]; - all_bkb_orig[2 * (*n_all_bkb_orig)] = iorig1; - all_bkb_orig[2 * (*n_all_bkb_orig) + 1] = iorig2; + all_bkb_orig[2 * (*n_all_bkb_orig)] = iorig1; + all_bkb_orig[2 * (*n_all_bkb_orig) + 1] = iorig2; (*n_all_bkb_orig)++; } } FreeInpInChI(&OneInput); - + exit_function: return ret; }