5 * (c) 2019 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of the Python interface to mLib.
12 * mLib/Python is free software: you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
17 * mLib/Python is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with mLib/Python. If not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
28 /*----- Header files ------------------------------------------------------*/
30 #include "mLib-python.h"
32 /*----- Program name ------------------------------------------------------*/
34 static int set_program_name(void)
36 PyObject *p = TEXT_FROMSTR(pn__name);
39 if (!home_module) SYSERR("home module not set");
40 if (PyObject_SetAttrString(home_module, "quis", p)) goto end;
41 pn__name = TEXT_PTR(p); p = 0; rc = 0;
47 static PyObject *meth_ego(PyObject *me, PyObject *arg)
52 if (!PyArg_ParseTuple(arg, "s:ego", &p)) goto end;
53 old = pn__name; ego(p);
54 if (set_program_name()) { pn__name = old; goto end; }
60 /*----- Error reporting ---------------------------------------------------*/
62 static PyObject *meth_moan(PyObject *me, PyObject *arg)
66 if (!PyArg_ParseTuple(arg, "s:moan", &p)) goto end;
73 static PyObject *meth_die(PyObject *me, PyObject *arg, PyObject *kw)
75 const char *const kwlist[] = { "msg", "rc", 0 };
80 if (!PyArg_ParseTupleAndKeywords(arg, kw, "s|i:moan", KWLIST, &p, &rc))
82 rcobj = PyInt_FromLong(rc); if (!rcobj) goto end;
84 PyErr_SetObject(PyExc_SystemExit, rcobj);
90 /*----- Main code ---------------------------------------------------------*/
92 static const PyMethodDef methods[] = {
93 #define METHNAME(name) meth_##name
94 METH (ego, "ego(PROG): set program name")
95 METH (moan, "moan(MSG): report a warning")
96 KWMETH(die, "die(MSG, [rc = 126]): report a fatal error and exit")
106 void ui_pyinsert(PyObject *mod)
110 int ui_pyready(void) { return (set_program_name()); }
112 /*----- That's all, folks -------------------------------------------------*/