Skip to content

Commit

Permalink
move from google code
Browse files Browse the repository at this point in the history
  • Loading branch information
radiumce committed Aug 3, 2012
1 parent ac017fe commit 7eefb84
Show file tree
Hide file tree
Showing 8 changed files with 819 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Emakefile
@@ -0,0 +1,5 @@
{'src/*',
[debug_info,
{i,"include"},
{outdir,"ebin"}
]}.
9 changes: 9 additions & 0 deletions HowTo
@@ -0,0 +1,9 @@
RUN:
erl -noinput -pa $ESSH_HOME/ebin -run essh start $LD_LIBRARY_PATH $PATH_TO_SERVER_LST_FILE

SERVER_LST_FILE's Format:
#------------
server-1
server-2
server-3
#------------
Binary file added native/linux/.DS_Store
Binary file not shown.
7 changes: 7 additions & 0 deletions native/linux/README
@@ -0,0 +1,7 @@
denpendency:
libreadline.so.5.2
libhistory.so.5.2

--------------------------
compiled under 64bit debian
readline_drv.so
60 changes: 60 additions & 0 deletions native/linux/readline_drv.c
@@ -0,0 +1,60 @@
#include <stdio.h>
#include "erl_driver.h"
#include <readline/history.h>
#include <readline/readline.h>

typedef struct {
ErlDrvPort port;
} readline_data;

static char *line_read = (char*)NULL;
static char *prompt = "essh>: ";

static ErlDrvData readline_drv_start(ErlDrvPort port, char *buff){

readline_data* d = (readline_data*)driver_alloc(sizeof(readline_data));
d->port = port;
return (ErlDrvData)d;
}

static void readline_drv_stop(ErlDrvData handle)
{
driver_free((char*)handle);
}

static void readline_drv_output(ErlDrvData handle, char *buff, int bufflen)
{
readline_data* d = (readline_data*)handle;

if (line_read)
{
free(line_read);
line_read = (char *)NULL;
}

line_read = readline(prompt);

if (line_read && *line_read)
add_history(line_read);

driver_output(d->port, line_read, strlen(line_read));
}

ErlDrvEntry readline_driver_entry = {
NULL, /* F_PTR init, N/A */
readline_drv_start, /* L_PTR start, called when port is opened */
readline_drv_stop, /* F_PTR stop, called when port is closed */
readline_drv_output, /* F_PTR output, called when erlang has sent */
NULL, /* F_PTR ready_input, called when input descriptor ready */
NULL, /* F_PTR ready_output, called when output descriptor ready */
"readline_drv", /* char *driver_name, the argument to open_port */
NULL, /* F_PTR finish, called when unloaded */
NULL, /* F_PTR control, port_command callback */
NULL, /* F_PTR timeout, reserved */
NULL /* F_PTR outputv, reserved */
};

DRIVER_INIT(readline_drv) /* must match name in driver_entry */
{
return &readline_driver_entry;
}

0 comments on commit 7eefb84

Please sign in to comment.