mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-06-02 19:40:08 +00:00
tweak for editline stuff
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5175 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
1dcf86fa65
commit
d2002bd07c
@ -133,7 +133,7 @@ freeswitch_LDADD = libfreeswitch.la libs/apr/libapr-1.la
|
|||||||
if ADD_LIBEDIT
|
if ADD_LIBEDIT
|
||||||
CORE_CFLAGS += -Ilibs/libedit/src -DSWITCH_HAVE_LIBEDIT
|
CORE_CFLAGS += -Ilibs/libedit/src -DSWITCH_HAVE_LIBEDIT
|
||||||
CORE_LIBS += libs/libedit/src/.libs/libedit.a
|
CORE_LIBS += libs/libedit/src/.libs/libedit.a
|
||||||
freeswitch_LDADD += -ltermcap
|
freeswitch_LDADD += -lcurses
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -176,6 +176,7 @@ SWITCH_DECLARE(void) switch_console_printf(switch_text_channel_t channel, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
static char hostname[256] = "";
|
static char hostname[256] = "";
|
||||||
|
static int32_t running = 1;
|
||||||
|
|
||||||
#ifdef SWITCH_HAVE_LIBEDIT
|
#ifdef SWITCH_HAVE_LIBEDIT
|
||||||
#include <histedit.h>
|
#include <histedit.h>
|
||||||
@ -191,33 +192,16 @@ char * prompt(EditLine *e) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SWITCH_DECLARE(void) switch_console_loop(void)
|
static EditLine *el;
|
||||||
|
static History *myhistory;
|
||||||
|
static HistEvent ev;
|
||||||
|
static char *hfile = NULL;
|
||||||
|
|
||||||
|
static void *SWITCH_THREAD_FUNC console_thread(switch_thread_t *thread, void *obj)
|
||||||
{
|
{
|
||||||
EditLine *el;
|
|
||||||
History *myhistory;
|
|
||||||
int count;
|
int count;
|
||||||
const char *line;
|
const char *line;
|
||||||
HistEvent ev;
|
switch_memory_pool_t *pool = (switch_memory_pool_t *) obj;
|
||||||
int32_t running = 1;
|
|
||||||
char *hfile;
|
|
||||||
|
|
||||||
el = el_init(__FILE__, switch_core_get_console(), switch_core_get_console(), switch_core_get_console());
|
|
||||||
el_set(el, EL_PROMPT, &prompt);
|
|
||||||
el_set(el, EL_EDITOR, "emacs");
|
|
||||||
|
|
||||||
myhistory = history_init();
|
|
||||||
if (myhistory == 0) {
|
|
||||||
fprintf(stderr, "history could not be initialized\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
hfile = switch_mprintf("%s%sfreeswitch.history", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR);
|
|
||||||
assert(hfile != NULL);
|
|
||||||
|
|
||||||
|
|
||||||
history(myhistory, &ev, H_SETSIZE, 800);
|
|
||||||
el_set(el, EL_HIST, history, myhistory);
|
|
||||||
history(myhistory, &ev, H_LOAD, hfile);
|
|
||||||
|
|
||||||
while (running) {
|
while (running) {
|
||||||
uint32_t arg;
|
uint32_t arg;
|
||||||
@ -245,15 +229,63 @@ SWITCH_DECLARE(void) switch_console_loop(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch_core_destroy_memory_pool(&pool);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SWITCH_DECLARE(void) switch_console_loop(void)
|
||||||
|
{
|
||||||
|
switch_thread_t *thread;
|
||||||
|
switch_threadattr_t *thd_attr = NULL;
|
||||||
|
switch_memory_pool_t *pool;
|
||||||
|
|
||||||
|
if (switch_core_new_memory_pool(&pool) != SWITCH_STATUS_SUCCESS) {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
el = el_init(__FILE__, switch_core_get_console(), switch_core_get_console(), switch_core_get_console());
|
||||||
|
el_set(el, EL_PROMPT, &prompt);
|
||||||
|
el_set(el, EL_EDITOR, "emacs");
|
||||||
|
|
||||||
|
myhistory = history_init();
|
||||||
|
if (myhistory == 0) {
|
||||||
|
fprintf(stderr, "history could not be initialized\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
hfile = switch_mprintf("%s%sfreeswitch.history", SWITCH_GLOBAL_dirs.log_dir, SWITCH_PATH_SEPARATOR);
|
||||||
|
assert(hfile != NULL);
|
||||||
|
|
||||||
|
|
||||||
|
history(myhistory, &ev, H_SETSIZE, 800);
|
||||||
|
el_set(el, EL_HIST, history, myhistory);
|
||||||
|
history(myhistory, &ev, H_LOAD, hfile);
|
||||||
|
|
||||||
|
|
||||||
|
switch_threadattr_create(&thd_attr, pool);
|
||||||
|
switch_threadattr_detach_set(thd_attr, 1);
|
||||||
|
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
|
||||||
|
switch_thread_create(&thread, thd_attr, console_thread, pool, pool);
|
||||||
|
|
||||||
|
while (running) {
|
||||||
|
uint32_t arg = 0;
|
||||||
|
switch_core_session_ctl(SCSC_CHECK_RUNNING, &arg);
|
||||||
|
if (!arg) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
switch_yield(1000000);
|
||||||
|
}
|
||||||
|
|
||||||
history(myhistory, &ev, H_SAVE, hfile);
|
history(myhistory, &ev, H_SAVE, hfile);
|
||||||
|
|
||||||
free(hfile);
|
free(hfile);
|
||||||
|
|
||||||
/* Clean up our memory */
|
/* Clean up our memory */
|
||||||
history_end(myhistory);
|
history_end(myhistory);
|
||||||
el_end(el);
|
el_end(el);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@ -262,7 +294,7 @@ SWITCH_DECLARE(void) switch_console_loop(void)
|
|||||||
{
|
{
|
||||||
|
|
||||||
char cmd[2048];
|
char cmd[2048];
|
||||||
int32_t activity = 1, running = 1;
|
int32_t activity = 1;
|
||||||
switch_size_t x = 0;
|
switch_size_t x = 0;
|
||||||
|
|
||||||
gethostname(hostname, sizeof(hostname));
|
gethostname(hostname, sizeof(hostname));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user