-/**
- * Initialize libsigrokdecode.
- *
- * This initializes the Python interpreter, and creates and initializes
- * a "sigrok" Python module with a single put() method.
- *
- * Then, it searches for sigrok protocol decoder files (*.py) in the
- * "decoders" subdirectory of the the sigrok installation directory.
- * All decoders that are found are loaded into memory and added to an
- * internal list of decoders, which can be queried via srd_list_decoders().
- *
- * The caller is responsible for calling the clean-up function srd_exit(),
- * which will properly shut down libsigrokdecode and free its allocated memory.
- *
- * Multiple calls to srd_init(), without calling srd_exit() in between,
- * are not allowed.
- *
- * @param path Path to an extra directory containing protocol decoders
- * which will be added to the python sys.path, or NULL.
- *
- * @return SRD_OK upon success, a (negative) error code otherwise.
- * Upon Python errors, return SRD_ERR_PYTHON. If the sigrok decoders
- * directory cannot be accessed, return SRD_ERR_DECODERS_DIR.
- * If not enough memory could be allocated, return SRD_ERR_MALLOC.
- */
-SRD_API int srd_init(char *path)
-{
- int ret;
- char *env_path;
-
- srd_dbg("Initializing libsigrokdecode.");
-
- /* Add our own module to the list of built-in modules. */
- PyImport_AppendInittab("sigrokdecode", PyInit_sigrokdecode);
-
- /* Initialize the Python interpreter. */
- Py_Initialize();
-
- /* Installed decoders. */
- if ((ret = add_modulepath(DECODERS_DIR)) != SRD_OK) {
- Py_Finalize();
- return ret;
- }
-
- /* Path specified by the user. */
- if (path) {
- if ((ret = add_modulepath(path)) != SRD_OK) {
- Py_Finalize();
- return ret;
- }
- }
-
- /* Environment variable overrides everything, for debugging. */
- if ((env_path = getenv("SIGROKDECODE_DIR"))) {
- if ((ret = add_modulepath(path)) != SRD_OK) {
- Py_Finalize();
- return ret;
- }
- }
-
- if ((ret = srd_load_all_decoders()) != SRD_OK) {
- Py_Finalize();
- return ret;
- }
-
- return SRD_OK;
-}