/** * * Get file association * * @param __filename - a file name * @param __extcmd - a pointer of structures encapsulate file action * @return TCL_OK if successful, TCL_ERROR otherwise */ int _get_file_associations (wchar_t *__filename, extension_action_t **__extcmd) { Tcl_Obj *value, *associate = Tcl_GetVar2Ex (interpreter, "association", NULL, TCL_GLOBAL_ONLY); char *filename; if (associate == NULL) { return TCL_ERROR; } wcs2mbs(&filename, __filename); if (tcllib_fa_get_object (interpreter, associate, Tcl_NewStringObj (filename, -1), &value) != TCL_OK) { return TCL_ERROR; } *__extcmd = tcllib_extcmd_from_object (value); SAFE_FREE (filename); return TCL_OK; }
/** * * Load file's contents into TCL interpreter * * @param __filename - a name loads file * @return TCL_OK if successful, TCL_ERROR otherwise */ int tcllib_load_file (const wchar_t *__filename) { char *filename; wcs2mbs(&filename, __filename); if (Tcl_EvalFile (interpreter, filename) != TCL_OK) { return TCL_ERROR; } SAFE_FREE (filename); return TCL_OK; }
BOOL chkerr(BOOL b, char *m, int n, char *f, char *e) { if(b) return b; DWORD code = GetLastError(); WCHAR *buf; FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&buf, 0, NULL); fprintf(stderr, "ASSERT in %08x module %s(%d) @%s: %s\n", code, m, n, f, e); // fwprintf(stderr, L"error: %s", buf); // Some wchars can't see on console. char *mbs = wcs2mbs(buf); if(!mbs) MessageBoxW(NULL, buf, L"error", MB_ICONEXCLAMATION | MB_OK); else fprintf(stderr, "error: %s", mbs); free(mbs); LocalFree(buf); return b; }
palo_err utf82mbs(struct conversions *convs, char **mbs, const char *utf8_str) { #if defined(WIN32) || defined(WIN64) palo_err result; wchar_t *t; result = utf82wcs(convs, &t, utf8_str); if (result != PALO_SUCCESS) { return PALO_ERR_STRING; } result = wcs2mbs(mbs, t); free(t); if (result != PALO_SUCCESS) { return result; } return PALO_SUCCESS; #else return do_iconv(convs->utf82local, utf8_str, (strlen(utf8_str) + 1)*sizeof(char), mbs); #endif }
static void wperror(wchar_t *s) { perror(wcs2mbs(s)); }
/** * Precompile options for faster usage * (i.e. compile regular expressions, ) * * @param __options - pointer to options to be precompiled * @return zero on success, non-zero otherwise */ static int precompile_options (action_find_options_t *__options) { wchar_t *file_mask, *regexp; int result = ACTION_OK; BOOL case_insens; /* Validate file name mask */ if (wcscmp (__options->file_mask, L"") && !TEST_FLAG (__options->flags, AFF_MASK_REGEXP)) { file_mask = L"*"; } /* Precompile regexp for file name mask */ case_insens = !TEST_FLAG (__options->flags, AFF_MASK_CASE_SENSITIVE); if (TEST_FLAG (__options->flags, AFF_MASK_REGEXP)) { __options->re_file_count = 1; __options->re_file = malloc (sizeof (regexp_t*)); regexp = build_regexp (__options->file_mask, case_insens); __options->re_file[0] = wregexp_compile (regexp); if (!__options->re_file[0]) { /* * TODO: Add error handling here */ result = ACTION_ERR; } free (regexp); } else { wchar_t **masks; long i, count; count = explode (__options->file_mask, L";", &masks); __options->re_file_count = count; __options->re_file = malloc (count * sizeof (regexp_t*)); for (i = 0; i < count; ++i) { regexp = file_mask_to_regexp (masks[i], case_insens); __options->re_file[i] = wregexp_compile (regexp); if (!__options->re_file[i]) { /* * TODO: Add error handling here */ result = ACTION_ERR; } free (regexp); } free_explode_array (masks); } /* Process regexp for file's content */ if (wcscmp (__options->content, L"")) { case_insens = !TEST_FLAG (__options->flags, AFF_CONTENT_CASE_SENSITIVE); /* We should compile regular expression for content */ if (TEST_FLAG (__options->flags, AFF_CONTENT_REGEXP)) { regexp = build_regexp (__options->content, case_insens); /* Compile regexp */ __options->re_content = wregexp_compile (regexp); if (!__options->re_content) { /* * TODO: Add error handling here */ result = ACTION_ERR; } free (regexp); } else { /* For speed improvement we won't use regular expressions */ /* for searching substrings in files. */ /* But we'd better convert wide-char content string to */ /* multi-byte string because we wouldn't convert file's content */ /* to multi-byte string. */ wcs2mbs (&__options->mb_content, __options->content); if (case_insens) { /* If searching is case-insensitive, we should */ /* compare buffers in the same cases. */ lowercase_buffer (__options->mb_content, strlen (__options->mb_content)); } } } return result; }