/* ======================================= 工作线程 ======================================= */ CR_API uint_t STDCALL qst_com_main ( __CR_IN__ void_t* param ) { exec_t obj; sQstComm* ctx; /* 加载命令表 */ obj = cmd_exec_init(s_cmdz, cntsof(s_cmdz)); if (obj == NULL) { qst_com_app_exit(param, 0, NULL); return (QST_ERROR); } ctx = (sQstComm*)param; /* 工作循环 */ while (!ctx->quit) { ansi_t* string; /* 接收一条命令 */ /* 即使是出错也要继续运行 */ string = netw_cmd_recv(ctx->netw); if (string == NULL) { thread_sleep(1); continue; } /* 非命令直接交由发送函数处理 */ if (!cmd_type_okay(string) && ctx->comm.thrd != NULL) { if (ctx->comm.send != NULL) { if (ctx->comm.tran == NULL) { /* 直接发送 */ ctx->comm.send(ctx->comm.obj.parm, string, str_lenA(string)); } else { uint_t size; void_t* send; /* 变换后发送 */ send = ctx->comm.tran(string, &size); if (send != NULL) { ctx->comm.send(ctx->comm.obj.parm, send, size); mem_free(send); } } } mem_free(string); continue; } /* 执行这条命令 */ cmd_exec_main(obj, ctx, string); mem_free(string); } /* 等待通讯线程结束 */ if (ctx->comm.thrd != NULL) { ctx->comm.quit = TRUE; thread_wait(ctx->comm.thrd); thread_del(ctx->comm.thrd); } cmd_exec_free(obj); return (QST_OKAY); }
/* --------------------------------------- 根据像素格式查找转换函数 --------------------------------------- */ extern pixcnvt_t pixel_find_cnvt ( __CR_IN__ uint_t fcrh ) { if (fcrh >= cntsof(s_pixel_cnvt)) return (NULL); return (s_pixel_cnvt[fcrh]); }
/* ======================================= LocaleName 转 LCID ======================================= */ LCID __stdcall myLocaleNameToLCID ( __CR_IN__ LPCWSTR localeName ) { int index; if (localeName == NULL) return (0); index = GetTableIndexFromLocaleName(localeName); if ((index < 0) || (index >= cntsof(LcidToLocaleNameTable))) return (0); return (LcidToLocaleNameTable[index].lcid); }
/* --------------------------------------- 查找 LocaleName 的索引 --------------------------------------- */ static int GetTableIndexFromLocaleName ( __CR_IN__ const wchar_t* localeName ) { LOCALENAMEINDEX* localeNamesIndex; int middle, testIndex, bottom = 0; int top = cntsof(LocaleNameToIndexTable) - 1; localeNamesIndex = (LOCALENAMEINDEX*)LocaleNameToIndexTable; while (bottom <= top) { middle = (bottom + top) / 2; testIndex = __wcsnicmp_ascii(localeName, localeNamesIndex[middle].name, LOCALE_NAME_MAX_LENGTH); if (testIndex == 0) return (localeNamesIndex[middle].index); if (testIndex < 0) top = middle - 1; else bottom = middle + 1; } return (-1); }