summaryrefslogtreecommitdiff
path: root/src/server/telnet_server.c
diff options
context:
space:
mode:
authoroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2008-03-10 20:05:48 +0000
committeroharboe <oharboe@b42882b7-edfa-0310-969c-e2dbd0fdcd60>2008-03-10 20:05:48 +0000
commitcce7512ca908ab93b4effa77cb9dd01ac44edc81 (patch)
treefa244a384f3c5f8db00e2f37419427a6eb10b57a /src/server/telnet_server.c
parente378eeec3634e921405acb0cb86bde4cf53a76d7 (diff)
downloadopenocd+libswd-cce7512ca908ab93b4effa77cb9dd01ac44edc81.tar.gz
openocd+libswd-cce7512ca908ab93b4effa77cb9dd01ac44edc81.tar.bz2
openocd+libswd-cce7512ca908ab93b4effa77cb9dd01ac44edc81.tar.xz
openocd+libswd-cce7512ca908ab93b4effa77cb9dd01ac44edc81.zip
Pavel Chromy: hopefully perfection for async output and prompt/partially typed command line handling.
git-svn-id: svn://svn.berlios.de/openocd/trunk@487 b42882b7-edfa-0310-969c-e2dbd0fdcd60
Diffstat (limited to 'src/server/telnet_server.c')
-rw-r--r--src/server/telnet_server.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/src/server/telnet_server.c b/src/server/telnet_server.c
index 96bbe1d2..95fe422b 100644
--- a/src/server/telnet_server.c
+++ b/src/server/telnet_server.c
@@ -72,6 +72,7 @@ int telnet_prompt(connection_t *connection)
{
telnet_connection_t *t_con = connection->priv;
+ telnet_write(connection, "\r", 1); /* the prompt is always placed at the line beginning */
return telnet_write(connection, t_con->prompt, strlen(t_con->prompt));
}
@@ -114,12 +115,22 @@ void telnet_log_callback(void *priv, const char *file, int line,
const char *function, const char *string)
{
connection_t *connection = priv;
+ telnet_connection_t *t_con = connection->priv;
+ int i;
- telnet_write(connection, "\b\b \b\b", strlen("\b\b \b\b"));
+ /* clear the command line */
+ telnet_write(connection, "\r", 1);
+ for (i = strlen(t_con->prompt) + t_con->line_size; i>0; i-=16)
+ telnet_write(connection, " ", i>16 ? 16 : i);
+ telnet_write(connection, "\r", 1);
telnet_outputline(connection, string);
+ /* put the command line to its previous state */
telnet_prompt(connection);
+ telnet_write(connection, t_con->line, t_con->line_size);
+ for (i=t_con->line_size; i>t_con->line_cursor; i--)
+ telnet_write(connection, "\b", 1);
}
int telnet_target_callback_event_handler(struct target_s *target, enum target_event event, void *priv)
@@ -289,19 +300,11 @@ int telnet_input(connection_t *connection)
telnet_write(connection, "\r\n\x00", 3);
}
}
- telnet_prompt(connection);
t_con->line_size = 0;
t_con->line_cursor = 0;
continue;
}
- retval = command_run_line(command_context, t_con->line);
-
- if (retval == ERROR_COMMAND_CLOSE_CONNECTION)
- {
- return ERROR_SERVER_REMOTE_CLOSED;
- }
-
/* Save only non-blank lines in the history */
if (t_con->line_size > 0)
{
@@ -327,12 +330,17 @@ int telnet_input(connection_t *connection)
t_con->history[t_con->current_history] = strdup("");
}
- int t = telnet_prompt(connection);
- if (t == ERROR_SERVER_REMOTE_CLOSED)
- return t;
-
t_con->line_size = 0;
t_con->line_cursor = 0;
+
+ retval = command_run_line(command_context, t_con->line);
+ if (retval == ERROR_COMMAND_CLOSE_CONNECTION)
+ return ERROR_SERVER_REMOTE_CLOSED;
+
+ retval = telnet_prompt(connection);
+ if (retval == ERROR_SERVER_REMOTE_CLOSED)
+ return ERROR_SERVER_REMOTE_CLOSED;
+
}
else if ((*buf_p == 0x7f) || (*buf_p == 0x8)) /* delete character */
{
@@ -579,6 +587,9 @@ int telnet_set_prompt(connection_t *connection, char *prompt)
{
telnet_connection_t *t_con = connection->priv;
+ if (t_con->prompt != NULL)
+ free(t_con->prompt);
+
t_con->prompt = strdup(prompt);
return ERROR_OK;