mpdm_t mpsl_mkins(wchar_t * opcode, int args, mpdm_t a1, mpdm_t a2, mpdm_t a3, mpdm_t a4) /* creates an instruction */ { mpdm_t o; mpdm_t v; v = MPDM_A(args + 1); mpdm_ref(v); /* inserts the opcode */ o = mpdm_hget_s(mpsl_opcodes, opcode); mpdm_aset(v, o, 0); switch (args) { case 4: mpdm_aset(v, a4, 4); /* no break */ case 3: mpdm_aset(v, a3, 3); /* no break */ case 2: mpdm_aset(v, a2, 2); /* no break */ case 1: mpdm_aset(v, a1, 1); /* no break */ } mpdm_unrefnd(v); v = constant_fold(v); return v; }
static void nc_sigwinch(int s) /* SIGWINCH signal handler */ { mpdm_t v; #ifdef NCURSES_VERSION /* Make sure that window size changes... */ struct winsize ws; int fd = open("/dev/tty", O_RDWR); if (fd == -1) return; /* This should never have to happen! */ if (ioctl(fd, TIOCGWINSZ, &ws) == 0) resizeterm(ws.ws_row, ws.ws_col); close(fd); #else /* restart curses */ /* ... */ #endif /* invalidate main window */ clearok(stdscr, 1); refresh(); /* re-set dimensions */ v = mpdm_hget_s(mp, L"window"); mpdm_hset_s(v, L"tx", MPDM_I(COLS)); mpdm_hset_s(v, L"ty", MPDM_I(LINES)); /* reattach */ signal(SIGWINCH, nc_sigwinch); }
static void register_functions(void) { mpdm_t drv; drv = mpdm_hget_s(mpdm_root(), L"mp_drv"); mpdm_hset_s(drv, L"main_loop", MPDM_X(kde4_drv_main_loop)); mpdm_hset_s(drv, L"shutdown", MPDM_X(kde4_drv_shutdown)); mpdm_hset_s(drv, L"clip_to_sys", MPDM_X(kde4_drv_clip_to_sys)); mpdm_hset_s(drv, L"sys_to_clip", MPDM_X(kde4_drv_sys_to_clip)); mpdm_hset_s(drv, L"update_ui", MPDM_X(kde4_drv_update_ui)); mpdm_hset_s(drv, L"timer", MPDM_X(kde4_drv_timer)); mpdm_hset_s(drv, L"busy", MPDM_X(kde4_drv_busy)); mpdm_hset_s(drv, L"alert", MPDM_X(kde4_drv_alert)); mpdm_hset_s(drv, L"confirm", MPDM_X(kde4_drv_confirm)); mpdm_hset_s(drv, L"openfile", MPDM_X(kde4_drv_openfile)); mpdm_hset_s(drv, L"savefile", MPDM_X(kde4_drv_savefile)); mpdm_hset_s(drv, L"form", MPDM_X(kde4_drv_form)); }
/** * mpsl_startup - Initializes MPSL. * * Initializes the Minimum Profit Scripting Language. Returns 0 if * everything went OK. */ int mpsl_startup(void) { mpdm_t r; mpdm_t m; /* startup MPDM */ mpdm_startup(); r = mpdm_root(); /* creates INC, unless already defined */ if (mpdm_hget_s(r, L"INC") == NULL) mpdm_hset_s(r, L"INC", MPDM_A(0)); /* the TRUE value */ mpdm_hset_s(r, L"TRUE", MPDM_I(1)); /* standard file descriptors */ mpdm_hset_s(r, L"STDIN", MPDM_F(stdin)); mpdm_hset_s(r, L"STDOUT", MPDM_F(stdout)); mpdm_hset_s(r, L"STDERR", MPDM_F(stderr)); /* home and application directories */ mpdm_hset_s(r, L"HOMEDIR", mpdm_home_dir()); mpdm_hset_s(r, L"APPDIR", mpdm_app_dir()); /* fill now the MPSL hash */ m = MPDM_H(0); mpdm_hset_s(r, L"MPSL", m); /* store things there */ mpdm_hset_s(m, L"VERSION", MPDM_MBS(VERSION)); mpdm_hset_s(m, L"OPCODE", mpsl_build_opcodes()); mpdm_hset_s(m, L"LC", MPDM_H(0)); mpdm_hset_s(m, L"CORE", mpsl_build_funcs()); mpdm_dump_1 = mpsl_dump_1; return 0; }
/** * mpsl_boolean - Returns 'true' or 'false' MPSL stock values. * @b: boolean selector * * Returns MPSL's 'false' or 'true' values depending on the value in @b. */ mpdm_t mpsl_boolean(int b) { return b ? mpdm_hget_s(mpdm_root(), L"TRUE") : NULL; }
static mpdm_t kde4_drv_form(mpdm_t a, mpdm_t ctxt) { int n; mpdm_t widget_list; QWidget *qlist[100]; mpdm_t r; KDialog *dialog = new KDialog(window); dialog->setModal(true); dialog->setButtons(KDialog::Ok | KDialog::Cancel); widget_list = mpdm_aget(a, 0); KVBox *vb = new KVBox(dialog); dialog->setMainWidget(vb); for (n = 0; n < mpdm_size(widget_list); n++) { mpdm_t w = mpdm_aget(widget_list, n); wchar_t *type; mpdm_t t; KHBox *hb = new KHBox(vb); type = mpdm_string(mpdm_hget_s(w, L"type")); if ((t = mpdm_hget_s(w, L"label")) != NULL) { QLabel *ql = new QLabel(hb); ql->setText(str_to_qstring(mpdm_gettext(t))); } t = mpdm_hget_s(w, L"value"); if (wcscmp(type, L"text") == 0) { mpdm_t h; QComboBox *ql = new QComboBox(hb); ql->setEditable(true); ql->setMinimumContentsLength(30); ql->setMaxVisibleItems(8); if (t != NULL) ql->setEditText(str_to_qstring(t)); qlist[n] = ql; if ((h = mpdm_hget_s(w, L"history")) != NULL) { int i; /* has history; fill it */ h = mp_get_history(h); for (i = mpdm_size(h) - 1; i >= 0; i--) ql->addItem(str_to_qstring(mpdm_aget(h, i))); } } else if (wcscmp(type, L"password") == 0) { QLineEdit *ql = new QLineEdit(hb); ql->setEchoMode(QLineEdit::Password); qlist[n] = ql; } else if (wcscmp(type, L"checkbox") == 0) { QCheckBox *qc = new QCheckBox(hb); if (mpdm_ival(t)) qc->setCheckState(Qt::Checked); qlist[n] = qc; } else if (wcscmp(type, L"list") == 0) { int i; QListWidget *ql = new QListWidget(hb); ql->setMinimumWidth(480); /* use a monospaced font */ ql->setFont(QFont(QString("Mono"))); mpdm_t l = mpdm_hget_s(w, L"list"); for (i = 0; i < mpdm_size(l); i++) ql->addItem(str_to_qstring(mpdm_aget(l, i))); ql->setCurrentRow(mpdm_ival(t)); qlist[n] = ql; } if (n == 0) qlist[n]->setFocus(Qt::OtherFocusReason); } n = dialog->exec(); if (!n) return NULL; r = MPDM_A(mpdm_size(widget_list)); /* fill the return values */ for (n = 0; n < mpdm_size(widget_list); n++) { mpdm_t w = mpdm_aget(widget_list, n); mpdm_t v = NULL; wchar_t *type; type = mpdm_string(mpdm_hget_s(w, L"type")); if (wcscmp(type, L"text") == 0) { mpdm_t h; QComboBox *ql = (QComboBox *) qlist[n]; v = qstring_to_str(ql->currentText()); /* if it has history, add to it */ if ((h = mpdm_hget_s(w, L"history")) != NULL && v != NULL && mpdm_cmp_s(v, L"") != 0) { h = mp_get_history(h); if (mpdm_cmp(v, mpdm_aget(h, -1)) != 0) mpdm_push(h, v); } } else if (wcscmp(type, L"password") == 0) { QLineEdit *ql = (QLineEdit *) qlist[n]; v = qstring_to_str(ql->text()); } else if (wcscmp(type, L"checkbox") == 0) { QCheckBox *qb = (QCheckBox *) qlist[n]; v = MPDM_I(qb->checkState() == Qt::Checked); } else if (wcscmp(type, L"list") == 0) { QListWidget *ql = (QListWidget *) qlist[n]; v = MPDM_I(ql->currentRow()); } mpdm_aset(r, v, n); } return r; }