O_TYPE O_blkframe(O_ARGS) /* runs an instruction under a block frame */ { mpdm_t ret; /* no context? create one */ if (l == NULL) l = MPDM_A(0); RF(l); /* create a new local symbol table */ mpdm_push(l, MPDM_H(0)); /* creates the arguments (if any) as local variables */ set_local_symbols(M2, a, l); /* execute instruction */ ret = RF(M1); /* destroy the local symbol table */ mpdm_adel(l, -1); UF(l); return UFND(ret); }
O_TYPE O_hash(O_ARGS) /* build hash from instructions */ { mpdm_t ret = RF(mpdm_size(c) == 3 ? MPDM_H(0) : M(3)); mpdm_hset(ret, M1, M2); return UFND(ret); }
/** * 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; }
extern "C" int kde4_drv_detect(int *argc, char ***argv) { mpdm_t drv; KCmdLineOptions opts; Display *x11_display; int n; for (n = 0; n < *argc; n++) { if (strcmp(argv[0][n], "-txt") == 0 || strcmp(argv[0][n], "-h") == 0) return 0; } /* try connecting directly to the Xserver */ if ((x11_display = XOpenDisplay((char *) NULL)) == NULL) return 0; KAboutData aboutData("mp", 0, ki18n("Minimum Profit"), VERSION, ki18n("A programmer's text editor"), KAboutData::License_GPL, ki18n("Copyright (c) 1991-2009 Angel Ortega"), ki18n(""), "http://triptico.com", "*****@*****.**"); KCmdLineArgs::init(*argc, *argv, &aboutData); /* command line options should be inserted here (I don't like this) */ opts.add("t {tag}", ki18n("Edits the file where tag is defined")); opts.add("e {mpsl_code}", ki18n("Executes MPSL code")); opts.add("f {mpsl_script}", ki18n("Executes MPSL script file")); opts.add("d {directory}", ki18n("Sets working directory")); opts.add("x {file}", ki18n("Open file in the hexadecimal viewer")); opts.add(" +NNN", ki18n("Moves to line number NNN of last file")); opts.add("txt", ki18n("Use text mode instead of GUI")); opts.add("+[file(s)]", ki18n("Documents to open")); KCmdLineArgs::addCmdLineOptions(opts); /* this is where it crashes if no X server */ app = new KApplication(x11_display); drv = mpdm_hset_s(mpdm_root(), L"mp_drv", MPDM_H(0)); mpdm_hset_s(drv, L"id", MPDM_LS(L"kde4")); mpdm_hset_s(drv, L"startup", MPDM_X(kde4_drv_startup)); return 1; }
mpdm_t mpsl_build_opcodes(void) /* builds the table of opcodes */ { int n; mpdm_t r = MPDM_H(0); mpdm_ref(r); for (n = 0; op_table[n].name != NULL; n++) { mpdm_t v = MPDM_LS(op_table[n].name); mpdm_set_ival(v, n); /* keys and values are the same */ mpdm_hset(r, v, v); } mpdm_unrefnd(r); return r; }