JNIEXPORT jboolean JNICALL Java_org_gnu_readline_Readline_parseAndBindImpl (JNIEnv *env, jclass theClass, jstring jline) { const char *line; jboolean is_copy; /* retrieve line argument and convert to ucs -------------------------- */ line = (*env)->GetStringUTFChars(env,jline,&is_copy); if (!utf2ucs(line)) { jclass newExcCls; if (is_copy == JNI_TRUE) (*env)->ReleaseStringUTFChars(env,jline,line); newExcCls = (*env)->FindClass(env,"java/io/UnsupportedEncodingException"); if (newExcCls != NULL) (*env)->ThrowNew(env,newExcCls,""); return (jboolean) JNI_FALSE; } if (is_copy == JNI_TRUE) (*env)->ReleaseStringUTFChars(env,jline,line); /* pass to readline function ---------------------------------------------- */ if (rl_parse_and_bind(buffer)) return (jboolean) JNI_FALSE; else return (jboolean) JNI_TRUE; }
static PyObject * parse_and_bind(PyObject *self, PyObject *args) { char *s, *copy; if (!PyArg_ParseTuple(args, "s:parse_and_bind", &s)) return NULL; /* Make a copy -- rl_parse_and_bind() modifies its argument */ /* Bernard Herzog */ copy = malloc(1 + strlen(s)); if (copy == NULL) return PyErr_NoMemory(); strcpy(copy, s); rl_parse_and_bind(copy); free(copy); /* Free the copy */ Py_RETURN_NONE; }
static PyObject * parse_and_bind(PyObject *self, PyObject *string) { char *copy; PyObject *encoded = encode(string); if (encoded == NULL) { return NULL; } /* Make a copy -- rl_parse_and_bind() modifies its argument */ /* Bernard Herzog */ copy = PyMem_Malloc(1 + PyBytes_GET_SIZE(encoded)); if (copy == NULL) { Py_DECREF(encoded); return PyErr_NoMemory(); } strcpy(copy, PyBytes_AS_STRING(encoded)); Py_DECREF(encoded); rl_parse_and_bind(copy); PyMem_Free(copy); /* Free the copy */ Py_RETURN_NONE; }
static int setinput(lua_State *L) { int out = lua_tointeger(L, 1); char c[32]; switch(out) { case 0: rl_instream = NULL; strcpy(c, "set show-all-if-ambiguous off"); rl_completion_display_matches_hook = NULL; break; default: rl_instream = tmpinstream; strcpy(c, "set show-all-if-ambiguous on"); rl_completion_display_matches_hook = display_hook; break; } rl_parse_and_bind(c); /* reinitialize editline */ rl_initialize(); return 0; }