void ncurses_contacts_changed(const char *name) { window_t *w = NULL; if (in_autoexec) return; if (!xstrcasecmp(name, "ncurses:contacts_size")) config_contacts = 1; if (config_contacts_size < 0) config_contacts_size = 0; if (config_contacts_size == 0) config_contacts = 0; if (config_contacts_size > 1000) config_contacts_size = 1000; if (config_contacts_margin > 10) config_contacts_margin = 10; if (config_contacts_edge > 3) config_contacts_edge = 2; contacts_edge = (1 << config_contacts_edge); contacts_frame = (!config_contacts_frame ? 0 : contacts_edge & (WF_LEFT|WF_RIGHT) ? contacts_edge ^ (WF_LEFT|WF_RIGHT) : contacts_edge ^ (WF_TOP|WF_BOTTOM)); if (config_contacts_order) { strlcpy(contacts_order, config_contacts_order, sizeof(contacts_order)); corderlen = xstrlen(contacts_order); } else { xstrcpy(contacts_order, CONTACTS_ORDER_DEFAULT); corderlen = CONTACTS_ORDER_DEFAULT_LEN; /* xstrlen(CONTACTS_ORDER_DEFAULT) eq CONTACTS_ORDER_DEFAULT_LEN */ } /* XXX destroy window only if (!config_contacts) ? XXX */ if ((w = window_find_sa(NULL, "__contacts", 1))) { window_kill(w); w = NULL; } if (config_contacts /* && !w */) { w = window_new("__contacts", NULL, 1000); ncurses_contacts_update(w, 0); } ncurses_resize(); ncurses_commit(); }
/** * @brief Exits the toolkit. */ void toolkit_exit (void) { Window *wdw; /* Destroy the windows. */ while (windows!=NULL) { wdw = windows; windows = windows->next; window_kill(wdw); } free(windows); /* Free the VBO. */ gl_vboDestroy( toolkit_vbo ); toolkit_vbo = NULL; }
EXPORT bool glx_term(glxlink* mod) { // close matlab engine MATLABLINK *matlab = (MATLABLINK*)mod->get_data(); if ( matlab && matlab->engine ) { if ( matlab->term ) { mxArray *ans = matlab_exec(matlab,"%s",matlab->term); if ( ans && mxIsDouble(ans) && (bool)*mxGetPr(ans)==false ) { gl_error("matlab term failed"); return false; } else if ( ans && mxIsChar(ans) ) { int buflen = (mxGetM(ans) * mxGetN(ans)) + 1; char *string =(char*)malloc(buflen); int status_error = mxGetString(ans, string, buflen); if (status_error == 0) { gl_error("'%s'",string); engClose(matlab->engine)==0; return false; } else { gl_error("Did not catch Matlab error"); engClose(matlab->engine)==0; return false; } } } if ( window_kill(matlab) ) engClose(matlab->engine)==0; } return true; }
/** * @brief Purges the dead windows. */ static void toolkit_purgeDead (void) { Window *wdw, *wlast, *wkill; Widget *wgt, *wgtlast, *wgtkill; /* Only clean up if necessary. */ if (!window_dead) return; /* Must be windows. */ if (windows == NULL) return; /* Destroy what is needed. */ wlast = NULL; wdw = windows; while (wdw != NULL) { if (window_isFlag( wdw, WINDOW_KILL )) { /* Save target. */ wkill = wdw; /* Reattach linked list. */ if (wlast == NULL) windows = wdw->next; else wlast->next = wdw->next; wdw = wlast; /* Kill target. */ wkill->next = NULL; window_kill( wkill ); } else { wgtlast = NULL; wgt = wdw->widgets; while (wgt != NULL) { if (wgt_isFlag( wgt, WGT_FLAG_KILL )) { /* Save target. */ wgtkill = wgt; /* Reattach linked list. */ if (wgtlast == NULL) wdw->widgets = wgt->next; else wgtlast->next = wgt->next; wgt = wgtlast; /* Kill target. */ wgtkill->next = NULL; widget_kill( wgtkill ); } /* Save position. */ wgtlast = wgt; if (wgt == NULL) wgt = wdw->widgets; else wgt = wgt->next; } } /* Save position. */ wlast = wdw; if (wdw == NULL) wdw = windows; else wdw = wdw->next; } /* Nothing left to purge. */ window_dead = 0; }
/* * ui_readline_loop() * * g³ówna pêtla programu. wczytuje dane z klawiatury w miêdzyczasie * obs³uguj±c sieæ i takie tam. */ int ui_readline_loop(void) { char *line = my_readline(); char *rline = line; /* for freeing */ gchar *out, *p; gint len; if (!line) { /* Ctrl-D handler */ if (window_current->id == 0) { /* debug window */ window_switch(1); } else if (window_current->id == 1) { /* status window */ if (config_ctrld_quits) { return 0; } else { printf("\n"); } } else if (window_current->id > 1) { /* query window */ window_kill(window_current); } return 1; } len = strlen(line); if (G_LIKELY(len > 0)) { if (G_UNLIKELY(line[len - 1] == '\\')) { /* multi line handler */ GString *s = g_string_new_len(line, len-1); free(line); no_prompt = 1; rl_bind_key(9, rl_insert); while ((line = my_readline())) { if (!strcmp(line, ".")) break; g_string_append(s, line); g_string_append_len(s, "\r\n", 2); /* XXX */ free(line); } rl_bind_key(9, rl_complete); no_prompt = 0; if (line) { g_string_free(s, TRUE); free(line); return 1; } line = g_string_free(s, FALSE); } /* if no empty line and we save duplicate lines, add it to history */ if (config_history_savedups || !history_length || strcmp(line, history_get(history_length)->line)) add_history(line); } pager_lines = 0; /* now we can definitely recode */ out = ekg_recode_from_locale(line); if (G_LIKELY(line == rline)) free(rline); /* allocd by readline */ else g_free(line); /* allocd by us */ /* omit leading whitespace */ for (p = out; g_unichar_isspace(g_utf8_get_char(p)); p = g_utf8_next_char(p)); if (*p || config_send_white_lines) command_exec(window_current->target, window_current->session, out, 0); pager_lines = -1; g_free(out); return 1; }
/* ======================================= WinMain 程序入口 ======================================= */ int WINAPI WinMain ( __CR_IN__ HINSTANCE curt_app, __CR_IN__ HINSTANCE prev_app, __CR_IN__ LPSTR cmd_line, __CR_IN__ int cmd_show ) { CR_NOUSE(prev_app); CR_NOUSE(cmd_line); CR_NOUSE(cmd_show); /* 只允许一个例程 */ if (misc_is_running(EXE_XNAME)) return (QST_ERROR); /* 建立 CrHack 系统 */ if (!set_app_type(CR_APP_GUI)) return (QST_ERROR); mem_zero(&s_wrk_ctx, sizeof(s_wrk_ctx)); sint_t x1, y1; uint_t ww, hh; /* 生成一个可变大小的窗口 */ mtlock_init(&s_wrk_ctx.lock); qst_load_cfg(&s_wrk_ctx.cfgs); misc_desk_init(WIN_ICONF, &x1, &y1, &ww, &hh, QV2D_DEF_WIDTH, QV2D_DEF_HEIGHT); if (ww < QV2D_DEF_WIDTH) ww = QV2D_DEF_WIDTH; if (hh < QV2D_DEF_HEIGHT) hh = QV2D_DEF_HEIGHT; s_wrk_ctx.hwnd = (HWND)window_open(curt_app, (void_t*)WindowProc, x1, y1, ww, hh, WIN_TITLE, WIN_CLASS, (ansi_t*)101, CR_WSTYLE_NORMAL); if (s_wrk_ctx.hwnd == NULL) return (QST_ERROR); SetWindowLongPtr(s_wrk_ctx.hwnd, GWL_STYLE, GetWindowLongPtr(s_wrk_ctx.hwnd, GWL_STYLE) & (~WS_MAXIMIZEBOX)); iGFX2* draw; sIMAGE* imgs; /* 创建 GDI 绘制对象 (只支持32位色屏幕) */ draw = (iGFX2*)create_gdi_canvas(s_wrk_ctx.hwnd, 0, 0, FALSE); if (draw == NULL) { window_kill(s_wrk_ctx.hwnd, curt_app, WIN_CLASS); return (QST_ERROR); } imgs = CR_VCALL(draw)->lock(draw); if (imgs == NULL || imgs->fmt != CR_ARGB8888) { window_kill(s_wrk_ctx.hwnd, curt_app, WIN_CLASS); return (QST_ERROR); } CR_VCALL(draw)->unlock(draw); CR_VCALL(draw)->clear(draw, s_wrk_ctx.cfgs.bkcolor, 0); s_wrk_ctx.draw = draw; /* 初始化网络 */ if (!socket_init()) { window_kill(s_wrk_ctx.hwnd, curt_app, WIN_CLASS); return (QST_ERROR); } s_wrk_ctx.netw = netw_cli_open(EXE_XNAME); if (s_wrk_ctx.netw == NULL) { window_kill(s_wrk_ctx.hwnd, curt_app, WIN_CLASS); return (QST_ERROR); } /* 读取需要超时, 不然线程无法退出 */ socket_set_timeout(s_wrk_ctx.netw, -1, QST_TCP_TOUT); thrd_t thrd; /* 生成工作线程 */ s_wrk_ctx.send = TRUE; s_wrk_ctx.quit = FALSE; s_wrk_ctx.cur_busy = LoadCursor(NULL, IDC_WAIT); s_wrk_ctx.cur_free = LoadCursor(NULL, IDC_ARROW); s_wrk_ctx.res_loader = res_loader_get(); if (s_wrk_ctx.res_loader->init != NULL) s_wrk_ctx.res_loader->init(s_wrk_ctx.netw, NULL); qst_load_filter(&s_wrk_ctx); thrd = thread_new(0, qst_v2d_main, &s_wrk_ctx, FALSE); if (thrd == NULL) { window_kill(s_wrk_ctx.hwnd, curt_app, WIN_CLASS); return (QST_ERROR); } /* 消息循环 */ while (!s_wrk_ctx.quit) { MSG msg; if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) { s_wrk_ctx.quit = TRUE; break; } TranslateMessage(&msg); DispatchMessage(&msg); } else { qst_do_keyboard(&s_wrk_ctx); } } thread_wait(thrd); thread_del(thrd); window_kill(s_wrk_ctx.hwnd, curt_app, WIN_CLASS); netw_cli_close(s_wrk_ctx.netw); return (QST_OKAY); }