static int Python_Init(void) { if (!initialised) { #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 PyObject *site; #endif #ifdef DYNAMIC_PYTHON if (!python_enabled(TRUE)) { EMSG(_("E263: Sorry, this command is disabled, the Python library could not be loaded.")); goto fail; } #endif #ifdef PYTHON_HOME # ifdef DYNAMIC_PYTHON if (mch_getenv((char_u *)"PYTHONHOME") == NULL) # endif Py_SetPythonHome(PYTHON_HOME); #endif init_structs(); #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 /* Disable implicit 'import site', because it may cause Vim to exit * when it can't be found. */ Py_NoSiteFlag++; #endif #if !defined(MACOS) || defined(MACOS_X_UNIX) Py_Initialize(); #else PyMac_Initialize(); #endif #if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02070000 /* 'import site' explicitly. */ site = PyImport_ImportModule("site"); if (site == NULL) { EMSG(_("E887: Sorry, this command is disabled, the Python's site module could not be loaded.")); goto fail; } Py_DECREF(site); #endif /* Initialise threads, and below save the state using * PyEval_SaveThread. Without the call to PyEval_SaveThread, thread * specific state (such as the system trace hook), will be lost * between invocations of Python code. */ PyEval_InitThreads(); #ifdef DYNAMIC_PYTHON get_exceptions(); #endif if (PythonIO_Init_io()) goto fail; if (PythonMod_Init()) goto fail; globals = PyModule_GetDict(PyImport_AddModule("__main__")); /* Remove the element from sys.path that was added because of our * argv[0] value in PythonMod_Init(). Previously we used an empty * string, but depending on the OS we then get an empty entry or * the current directory in sys.path. */ PyRun_SimpleString("import sys; sys.path = filter(lambda x: x != '/must>not&exist', sys.path)"); /* lock is created and acquired in PyEval_InitThreads() and thread * state is created in Py_Initialize() * there _PyGILState_NoteThreadState() also sets gilcounter to 1 * (python must have threads enabled!) * so the following does both: unlock GIL and save thread state in TLS * without deleting thread state */ #ifndef PY_CAN_RECURSE saved_python_thread = #endif PyEval_SaveThread(); initialised = 1; } return 0; fail: /* We call PythonIO_Flush() here to print any Python errors. * This is OK, as it is possible to call this function even * if PythonIO_Init_io() has not completed successfully (it will * not do anything in this case). */ PythonIO_Flush(); return -1; }
int tgetent( char *tbuf, /* Buffer to hold termcap entry, TBUFSZ bytes max */ char *term) /* Name of terminal */ { char tcbuf[32]; /* Temp buffer to handle */ char *tcptr = tcbuf; /* extended entries */ char *tcap = TERMCAPFILE; /* Default termcap file */ char *tmp; FILE *termcap; int retval = 0; int len; if ((tmp = (char *)mch_getenv((char_u *)"TERMCAP")) != NULL) { if (*tmp == '/') /* TERMCAP = name of termcap file */ { tcap = tmp ; #if defined(AMIGA) /* Convert /usr/share/lib/termcap to usr:share/lib/termcap */ tcap++; tmp = strchr(tcap, '/'); if (tmp) *tmp = ':'; #endif } else /* TERMCAP = termcap entry itself */ { int tlen = strlen(term); while (*tmp && *tmp != ':') /* Check if TERM matches */ { char *nexttmp; while (*tmp == '|') tmp++; nexttmp = _find(tmp, ":|"); /* Rhialto */ if (tmp+tlen == nexttmp && _match(tmp, term) == tlen) { strcpy(tbuf, tmp); tent = tbuf; return 1; } else tmp = nexttmp; } } } if (!(termcap = mch_fopen(tcap, "r"))) { strcpy(tbuf, tcap); return -1; } len = 0; while (getent(tbuf + len, term, termcap, TBUFSZ - len)) { tcptr = tcbuf; /* Rhialto */ if ((term = tgetstr("tc", &tcptr))) /* extended entry */ { rewind(termcap); len = strlen(tbuf); } else { retval = 1; tent = tbuf; /* reset it back to the beginning */ break; } } fclose(termcap); return retval; }