if (mdata == NULL)
return HPCS_E_NULLPTR;
- datafile = fopen(filename, "rb");
+ datafile = open_measurement_file(filename);
if (datafile == NULL)
return HPCS_E_CANT_OPEN;
if (mdata == NULL)
return HPCS_E_NULLPTR;
- datafile = fopen(filename, "rb");
+ datafile = open_measurement_file(filename);
if (datafile == NULL)
return HPCS_E_CANT_OPEN;
static enum HPCS_ChemStationVer detect_chemstation_version(const char*const version_string)
{
- PR_DEBUGF("ChemStation ersion string: %s\n", version_string);
+ PR_DEBUGF("ChemStation version string: %s\n", version_string);
if (!strcmp(version_string, CHEMSTAT_B0625_STR)) {
PR_DEBUG("ChemStation B.06.25\n");
#endif
}
+static FILE* open_measurement_file(const char* filename)
+{
+#ifdef _WIN32
+ FILE* f;
+ wchar_t *win_filename;
+
+ if (!__win32_utf8_to_wchar(&win_filename, filename))
+ return NULL;
+
+ f = _wfopen(win_filename, L"rb");
+ free(win_filename);
+ return f;
+#else
+ return fopen(filename, "rb");
+#endif
+}
+
static bool p_means_pressure(const enum HPCS_ChemStationVer version)
{
if (version == CHEMSTAT_B0625)
return PARSE_OK;
}
+static bool __win32_utf8_to_wchar(wchar_t** target, const char *s)
+{
+ size_t w_size = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, s, -1, NULL, 0);
+ if (w_size == 0) {
+ PR_DEBUGF("Count MultiByteToWideChar() error 0x%x\n", GetLastError());
+ return false;
+ }
+ PR_DEBUGF("w_size: %d\n", w_size);
+ *target = malloc(sizeof(wchar_t) * w_size);
+ if (*target == NULL)
+ return false;
+
+ if (MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, s, -1, *target, w_size) == 0) {
+ free(*target);
+ PR_DEBUGF("Convert MultiByteToWideChar() error 0x%x\n", GetLastError());
+ return false;
+ }
+
+ return true;
+}
+
static enum HPCS_ParseCode __win32_wchar_to_utf8(char** target, const WCHAR* s)
{
int mb_size;
return PARSE_OK;
}
+
#else
static void __unix_hpcs_initialize()
{
static bool file_type_description_is_readable(const char*const description);
static enum HPCS_ParseCode next_native_line(HPCS_UFH fh, HPCS_NChar* line, int32_t length);
static HPCS_UFH open_data_file(const char* filename);
+static FILE* open_measurement_file(const char* filename);
static enum HPCS_ParseCode parse_native_method_info_line(char** name, char** value, HPCS_NChar* line);
static enum HPCS_ParseCode read_dad_wavelength(FILE* datafile, struct HPCS_Wavelength* const measured, struct HPCS_Wavelength* const reference);
static uint8_t month_to_number(const char* month);
static enum HPCS_ParseCode __win32_next_native_line(FILE* fh, WCHAR* line, int32_t length);
static HPCS_UFH __win32_open_data_file(const char* filename);
static enum HPCS_ParseCode __win32_parse_native_method_info_line(char** name, char** value, WCHAR* line);
+static bool __win32_utf8_to_wchar(wchar_t** target, const char* s);
static enum HPCS_ParseCode __win32_wchar_to_utf8(char** target, const WCHAR* s);
#else
static void __attribute((constructor)) __unix_hpcs_initialize();