Exemple #1
0
    void
do_pyeval (char_u *str, typval_T *rettv)
{
    DoPyCommand((char *) str,
	    (rangeinitializer) init_range_eval,
	    (runner) run_eval,
	    (void *) rettv);
    switch(rettv->v_type)
    {
	case VAR_DICT: ++rettv->vval.v_dict->dv_refcount; break;
	case VAR_LIST: ++rettv->vval.v_list->lv_refcount; break;
	case VAR_FUNC: func_ref(rettv->vval.v_string);    break;
	case VAR_PARTIAL: ++rettv->vval.v_partial->pt_refcount; break;
	case VAR_UNKNOWN:
	    rettv->v_type = VAR_NUMBER;
	    rettv->vval.v_number = 0;
	    break;
	case VAR_NUMBER:
	case VAR_STRING:
	case VAR_FLOAT:
	case VAR_SPECIAL:
	case VAR_JOB:
	case VAR_CHANNEL:
	    break;
    }
}
Exemple #2
0
    void
ex_pydo(exarg_T *eap)
{
    DoPyCommand((char *)eap->arg,
	    (rangeinitializer) init_range_cmd,
	    (runner)run_do,
	    (void *)eap);
}
Exemple #3
0
/*
 * ":py3file"
 */
void
ex_py3file(exarg_T *eap)
{
	static char buffer[BUFFER_SIZE];
	const char *file;
	char *p;
	int i;

	/* Have to do it like this. PyRun_SimpleFile requires you to pass a
	 * stdio file pointer, but Vim and the Python DLL are compiled with
	 * different options under Windows, meaning that stdio pointers aren't
	 * compatible between the two. Yuk.
	 *
	 * construct: exec(compile(open('a_filename', 'rb').read(), 'a_filename', 'exec'))
	 *
	 * Using bytes so that Python can detect the source encoding as it normally
	 * does. The doc does not say "compile" accept bytes, though.
	 *
	 * We need to escape any backslashes or single quotes in the file name, so that
	 * Python won't mangle the file name.
	 */

	strcpy(buffer, "exec(compile(open('");
	p = buffer + 19; /* size of "exec(compile(open('" */

	for (i=0; i<2; ++i) {
		file = (char *)eap->arg;
		while (*file && p < buffer + (BUFFER_SIZE - 3)) {
			if (*file == '\\' || *file == '\'')
				*p++ = '\\';
			*p++ = *file++;
		}
		/* If we didn't finish the file name, we hit a buffer overflow */
		if (*file != '\0')
			return;
		if (i==0) {
			strcpy(p,"','rb').read(),'");
			p += 16;
		} else {
			strcpy(p,"','exec'))");
			p += 10;
		}
	}


	/* Execute the file */
	DoPyCommand(buffer,
				(rangeinitializer) init_range_cmd,
				(runner) run_cmd,
				(void *) eap);
}
Exemple #4
0
/*
 * ":py3"
 */
void
ex_py3(exarg_T *eap)
{
	char_u *script;

	script = script_get(eap, eap->arg);
	if (!eap->skip) {
		DoPyCommand(script == NULL ? (char *) eap->arg : (char *) script,
					(rangeinitializer) init_range_cmd,
					(runner) run_cmd,
					(void *) eap);
	}
	vim_free(script);
}
Exemple #5
0
/*
 * ":pyfile"
 */
    void
ex_pyfile(exarg_T *eap)
{
    static char buffer[BUFFER_SIZE];
    const char *file = (char *)eap->arg;
    char *p;

    if (p_pyx == 0)
	p_pyx = 2;

    /* Have to do it like this. PyRun_SimpleFile requires you to pass a
     * stdio file pointer, but Vim and the Python DLL are compiled with
     * different options under Windows, meaning that stdio pointers aren't
     * compatible between the two. Yuk.
     *
     * Put the string "execfile('file')" into buffer. But, we need to
     * escape any backslashes or single quotes in the file name, so that
     * Python won't mangle the file name.
     */
    strcpy(buffer, "execfile('");
    p = buffer + 10; /* size of "execfile('" */

    while (*file && p < buffer + (BUFFER_SIZE - 3))
    {
	if (*file == '\\' || *file == '\'')
	    *p++ = '\\';
	*p++ = *file++;
    }

    /* If we didn't finish the file name, we hit a buffer overflow */
    if (*file != '\0')
	return;

    /* Put in the terminating "')" and a null */
    *p++ = '\'';
    *p++ = ')';
    *p++ = '\0';

    /* Execute the file */
    DoPyCommand(buffer,
	    (rangeinitializer) init_range_cmd,
	    (runner) run_cmd,
	    (void *) eap);
}
Exemple #6
0
void
do_py3eval (char_u *str, typval_T *rettv)
{
	DoPyCommand((char *) str,
				(rangeinitializer) init_range_eval,
				(runner) run_eval,
				(void *) rettv);
	switch(rettv->v_type) {
	case VAR_DICT:
		++rettv->vval.v_dict->dv_refcount;
		break;
	case VAR_LIST:
		++rettv->vval.v_list->lv_refcount;
		break;
	case VAR_FUNC:
		func_ref(rettv->vval.v_string);
		break;
	case VAR_UNKNOWN:
		rettv->v_type = VAR_NUMBER;
		rettv->vval.v_number = 0;
		break;
	}
}