|
83 | 83 | REQ_MODE_SB_IGN_ALL_UU | REQ_MODE_SC_IGN_ALL_UU) |
84 | 84 |
|
85 | 85 |
|
86 | | -int DetectInputINChIFileType(FILE** inp_file, INPUT_PARMS* ip, const char* fmode); |
87 | | - |
88 | 86 | int set_common_options_by_parg(const char* pArg, |
89 | 87 | int developer_options, |
90 | 88 | INPUT_PARMS* ip, |
@@ -2872,258 +2870,3 @@ void HelpCommandLineParms(INCHI_IOSTREAM* f) |
2872 | 2870 |
|
2873 | 2871 | #endif |
2874 | 2872 | } |
2875 | | - |
2876 | | -#define fprintf2 inchi_fprintf |
2877 | | - |
2878 | | -#ifndef TARGET_API_LIB |
2879 | | -/****************************************************************************/ |
2880 | | -int OpenFiles(FILE** inp_file, |
2881 | | - FILE** out_file, |
2882 | | - FILE** log_file, |
2883 | | - FILE** prb_file, |
2884 | | - INPUT_PARMS* ip) |
2885 | | -{ |
2886 | | - /* |
2887 | | - -- Files -- |
2888 | | - ip->path[0] => Input |
2889 | | - ip->path[1] => Output (INChI) |
2890 | | - ip->path[2] => Log |
2891 | | - ip->path[3] => Problem structures |
2892 | | - ip->path[4] => Errors file (ACD Labs) |
2893 | | -
|
2894 | | - */ |
2895 | | - |
2896 | | - /* Logfile (open as early as possible) */ |
2897 | | - if (!ip->path[2] || !ip->path[2][0]) |
2898 | | - { |
2899 | | - fprintf2(stderr, "%s %-s\n%-s Build (%-s%-s) of %s %s %-s\n\n", |
2900 | | - APP_DESCRIPTION, INCHI_SRC_REV, |
2901 | | - INCHI_BUILD_PLATFORM, INCHI_BUILD_COMPILER, INCHI_BUILD_DEBUG, __DATE__, __TIME__, |
2902 | | - RELEASE_IS_FINAL ? "" : " *** pre-release, for evaluation only ***"); |
2903 | | - fprintf2(stderr, "Log file not specified. Using standard error output.\n"); |
2904 | | - *log_file = stderr; |
2905 | | - } |
2906 | | - else if (!(*log_file = fopen(ip->path[2], "w"))) |
2907 | | - { |
2908 | | - fprintf2(stderr, "%s %-s\n%-s Build (%-s%-s) of %s %s%-s\n\n", |
2909 | | - APP_DESCRIPTION, INCHI_SRC_REV, |
2910 | | - INCHI_BUILD_PLATFORM, INCHI_BUILD_COMPILER, INCHI_BUILD_DEBUG, __DATE__, __TIME__, |
2911 | | - RELEASE_IS_FINAL ? "" : " *** pre-release, for evaluation only ***"); |
2912 | | - fprintf2(stderr, "Cannot open log file '%s'. Using standard error output.\n", ip->path[2]); |
2913 | | - *log_file = stderr; |
2914 | | - } |
2915 | | - else |
2916 | | - { |
2917 | | - fprintf2(*log_file, "%s %-s\n%-s Build (%-s%-s) of %s %s%-s\n\n", |
2918 | | - APP_DESCRIPTION, INCHI_SRC_REV, |
2919 | | - INCHI_BUILD_PLATFORM, INCHI_BUILD_COMPILER, INCHI_BUILD_DEBUG, __DATE__, __TIME__, |
2920 | | - RELEASE_IS_FINAL ? "" : " *** pre-release, for evaluation only ***"); |
2921 | | - fprintf2(*log_file, "Opened log file '%s'\n", ip->path[2]); |
2922 | | - } |
2923 | | - |
2924 | | - /* Input file */ |
2925 | | - if ((ip->nInputType == INPUT_MOLFILE || ip->nInputType == INPUT_SDFILE || |
2926 | | - ip->nInputType == INPUT_INCHI || ip->nInputType == INPUT_INCHI_PLAIN) |
2927 | | - && |
2928 | | - ip->num_paths > 0) |
2929 | | - { |
2930 | | - const char* fmode = NULL; |
2931 | | - |
2932 | | -#if ( defined(_MSC_VER)&&defined(_WIN32) || defined(__BORLANDC__)&&defined(__WIN32__) || defined(__GNUC__)&&defined(__MINGW32__)&&defined(_WIN32) ) |
2933 | | - /* compilers that definitely allow fopen "rb" (binary read) mode */ |
2934 | | - fmode = "rb"; |
2935 | | - if (!ip->path[0] || !ip->path[0][0] || !(*inp_file = fopen(ip->path[0], "rb"))) |
2936 | | - { |
2937 | | - fprintf2(*log_file, "Cannot open input file '%s'. Terminating.\n", ip->path[0] ? ip->path[0] : "<No name>"); |
2938 | | - goto exit_function; |
2939 | | - } |
2940 | | - else |
2941 | | - { |
2942 | | - fprintf2(*log_file, "Opened input file '%s'\n", ip->path[0]); |
2943 | | - } |
2944 | | - |
2945 | | -#else |
2946 | | - |
2947 | | - if (!ip->path[0] || !ip->path[0][0] || !(*inp_file = fopen(ip->path[0], "r"))) |
2948 | | - { |
2949 | | - fprintf2(*log_file, "Cannot open input file '%s'. Terminating.\n", ip->path[0] ? ip->path[0] : "<No Name>"); |
2950 | | - goto exit_function; |
2951 | | - } |
2952 | | - else |
2953 | | - { |
2954 | | - fprintf2(*log_file, "Opened input file '%s'\n", ip->path[0]); |
2955 | | - } |
2956 | | - fmode = "r"; |
2957 | | -#endif /* ( defined(_MSC_VER)&&defined(_WIN32) || defined(__BORLANDC__)&&defined(__WIN32__) || defined(__GNUC__)&&defined(__MINGW32__)&&defined(_WIN32) ) */ |
2958 | | - |
2959 | | - DetectInputINChIFileType(inp_file, ip, fmode); |
2960 | | - } |
2961 | | - |
2962 | | - else if ((ip->nInputType != INPUT_MOLFILE && |
2963 | | - ip->nInputType != INPUT_SDFILE && |
2964 | | - ip->nInputType != INPUT_INCHI && |
2965 | | - /* post-1.02b */ |
2966 | | - ip->nInputType != INPUT_INCHI_PLAIN)) |
2967 | | - { |
2968 | | - fprintf2(*log_file, "Input file type not specified. Terminating.\n"); |
2969 | | - goto exit_function; |
2970 | | - } |
2971 | | - else |
2972 | | - { |
2973 | | - fprintf2(*log_file, "Input file not specified. Using standard input.\n"); |
2974 | | - *inp_file = stdin; |
2975 | | - } |
2976 | | - |
2977 | | - /* Output file */ |
2978 | | - if (!ip->path[1] || !ip->path[1][0]) |
2979 | | - { |
2980 | | - fprintf2(*log_file, "Output file not specified. Using standard output.\n"); |
2981 | | - *out_file = stdout; |
2982 | | - } |
2983 | | - else |
2984 | | - { |
2985 | | - if (!(*out_file = fopen(ip->path[1], "w"))) |
2986 | | - { |
2987 | | - fprintf2(*log_file, "Cannot open output file '%s'. Terminating.\n", ip->path[1]); |
2988 | | - goto exit_function; |
2989 | | - } |
2990 | | - else |
2991 | | - { |
2992 | | - fprintf2(*log_file, "Opened output file '%s'\n", ip->path[1]); |
2993 | | - if ((ip->bINChIOutputOptions & (INCHI_OUT_PLAIN_TEXT)) && |
2994 | | - *inp_file != stdin && |
2995 | | - !(ip->bINChIOutputOptions & INCHI_OUT_SDFILE_ONLY) && |
2996 | | - !ip->bNoStructLabels && |
2997 | | - !(ip->bINChIOutputOptions & INCHI_OUT_TABBED_OUTPUT)) |
2998 | | - { |
2999 | | - PrintFileName("* Input_File: \"%s\"\n", *out_file, ip->path[0]); |
3000 | | - } |
3001 | | - } |
3002 | | - } |
3003 | | - |
3004 | | - /* Problem file */ |
3005 | | - if (ip->path[3] && ip->path[3][0]) |
3006 | | - { |
3007 | | - const char* fmode = "w"; |
3008 | | - |
3009 | | -#if ( defined(_MSC_VER)&&defined(_WIN32) || defined(__BORLANDC__)&&defined(__WIN32__) || defined(__GNUC__)&&defined(__MINGW32__)&&defined(_WIN32) ) |
3010 | | - fmode = "wb"; |
3011 | | -#endif |
3012 | | - |
3013 | | - if (!(*prb_file = fopen(ip->path[3], fmode))) |
3014 | | - { |
3015 | | - fprintf2(*log_file, "Cannot open problem file '%s'. Terminating.\n", ip->path[3]); |
3016 | | - goto exit_function; |
3017 | | - } |
3018 | | - else |
3019 | | - { |
3020 | | - fprintf2(*log_file, "Opened problem file '%s'\n", ip->path[3]); |
3021 | | - } |
3022 | | - } |
3023 | | - |
3024 | | - /* Success */ |
3025 | | - return 1; |
3026 | | - |
3027 | | -exit_function: |
3028 | | - |
3029 | | - /* Failed */ |
3030 | | - return 0; |
3031 | | -} |
3032 | | - |
3033 | | - |
3034 | | -#define NUM_VERSIONS 7 |
3035 | | -#define LEN_VERSIONS 64 |
3036 | | - |
3037 | | - |
3038 | | -static int bMatchOnePrefix(int len, char* str, int lenPrefix[], |
3039 | | - char strPrefix[][LEN_VERSIONS], int numPrefix); |
3040 | | - |
3041 | | - |
3042 | | -/****************************************************************************/ |
3043 | | -static int bMatchOnePrefix(int len, char* str, |
3044 | | - int lenPrefix[], |
3045 | | - char strPrefix[][LEN_VERSIONS], |
3046 | | - int numPrefix) |
3047 | | -{ |
3048 | | - int i; |
3049 | | - for (i = 0; i < numPrefix; i++) |
3050 | | - { |
3051 | | - if (len >= lenPrefix[i] && |
3052 | | - !memcmp(str, strPrefix[i], lenPrefix[i])) |
3053 | | - { |
3054 | | - return 1; |
3055 | | - } |
3056 | | - } |
3057 | | - |
3058 | | - return 0; |
3059 | | -} |
3060 | | - |
3061 | | -/****************************************************************************/ |
3062 | | -int DetectInputINChIFileType(FILE** inp_file, |
3063 | | - INPUT_PARMS* ip, |
3064 | | - const char* fmode) |
3065 | | -{ |
3066 | | - char szLine[256], ret = 0; |
3067 | | - static char szPlnVersion[NUM_VERSIONS][LEN_VERSIONS]; /* = "INChI:1.1Beta/";*/ |
3068 | | - static int lenPlnVersion[NUM_VERSIONS]; |
3069 | | - static char szPlnAuxVer[NUM_VERSIONS][LEN_VERSIONS]; /* = "AuxInfo:1.1Beta/";*/ |
3070 | | - static int lenPlnAuxVer[NUM_VERSIONS]; |
3071 | | - static int bInitialized = 0; |
3072 | | - int bINChI_plain = 0, len, i; |
3073 | | - |
3074 | | - |
3075 | | - if (ip->nInputType == INPUT_INCHI_PLAIN || ip->nInputType == INPUT_INCHI) |
3076 | | - { |
3077 | | - return 1; |
3078 | | - } |
3079 | | - |
3080 | | - if (!bInitialized) |
3081 | | - { |
3082 | | - lenPlnVersion[0] = sprintf(szPlnVersion[0], "%s=%s/", INCHI_NAME, INCHI_VERSION); |
3083 | | - lenPlnVersion[1] = sprintf(szPlnVersion[1], "INChI=1.12Beta/"); |
3084 | | - lenPlnVersion[2] = sprintf(szPlnVersion[2], "INChI=1.0RC/"); |
3085 | | - lenPlnVersion[3] = sprintf(szPlnVersion[3], "InChI=1.0RC/"); |
3086 | | - lenPlnVersion[4] = sprintf(szPlnVersion[4], "InChI=1/"); |
3087 | | - lenPlnVersion[5] = sprintf(szPlnVersion[5], "MoChI=1a/"); |
3088 | | - lenPlnVersion[6] = sprintf(szPlnVersion[6], "InChI=1S/"); |
3089 | | - lenPlnAuxVer[0] = sprintf(szPlnAuxVer[0], "AuxInfo=%s/", INCHI_VERSION); |
3090 | | - lenPlnAuxVer[1] = sprintf(szPlnAuxVer[1], "AuxInfo=1.12Beta/"); |
3091 | | - lenPlnAuxVer[2] = sprintf(szPlnAuxVer[2], "AuxInfo=1.0RC/"); |
3092 | | - lenPlnAuxVer[3] = sprintf(szPlnAuxVer[3], "AuxInfo=1.0RC/"); |
3093 | | - lenPlnAuxVer[4] = sprintf(szPlnAuxVer[4], "AuxInfo=1/"); |
3094 | | - lenPlnAuxVer[5] = sprintf(szPlnAuxVer[5], "AuxInfo=1a/"); |
3095 | | - lenPlnAuxVer[6] = sprintf(szPlnAuxVer[6], "AuxInfo=1/"); |
3096 | | -#if ( FIX_DALKE_BUGS == 1 ) |
3097 | | - bInitialized = 1; |
3098 | | -#endif |
3099 | | - } |
3100 | | - |
3101 | | - for (i = 0; i < 4; i++) |
3102 | | - { |
3103 | | - len = inchi_fgetsLfTab(szLine, sizeof(szLine) - 1, *inp_file); |
3104 | | - if (len < 0) |
3105 | | - { |
3106 | | - break; |
3107 | | - } |
3108 | | - if (bMatchOnePrefix(len, szLine, lenPlnVersion, szPlnVersion, NUM_VERSIONS) || |
3109 | | - bMatchOnePrefix(len, szLine, lenPlnAuxVer, szPlnAuxVer, NUM_VERSIONS)) |
3110 | | - { |
3111 | | - bINChI_plain++; |
3112 | | - } |
3113 | | - } |
3114 | | - |
3115 | | - if (bINChI_plain >= 2) |
3116 | | - { |
3117 | | - ip->nInputType = INPUT_INCHI_PLAIN; |
3118 | | - ret = 1; |
3119 | | - } |
3120 | | - |
3121 | | - fclose(*inp_file); |
3122 | | - *inp_file = fopen(ip->path[0], fmode); |
3123 | | - |
3124 | | - return ret; |
3125 | | -} |
3126 | | -#undef NUM_VERSIONS |
3127 | | -#undef LEN_VERSIONS |
3128 | | - |
3129 | | -#endif /* TARGET_API_LIB */ |
0 commit comments