Added non persitent history
This commit is contained in:
parent
42749e506a
commit
c970268dfb
10
lw12ctl.c
10
lw12ctl.c
|
@ -11,6 +11,7 @@
|
|||
#include <unistd.h>
|
||||
|
||||
#include <readline/readline.h>
|
||||
#include <readline/history.h>
|
||||
|
||||
#include "lw12.h"
|
||||
|
||||
|
@ -156,8 +157,7 @@ int parse_commands(int argc, char *argv[]) {
|
|||
void cmd_loop() {
|
||||
#define max_args 10
|
||||
#define buf_size 256
|
||||
char cmdbuf[buf_size];
|
||||
char *cmd;
|
||||
char *cmd, *cmd_start;
|
||||
char *pos;
|
||||
char *argv[max_args];
|
||||
int argc;
|
||||
|
@ -167,7 +167,7 @@ void cmd_loop() {
|
|||
if (cmd == NULL)
|
||||
break;
|
||||
|
||||
pos = cmd;
|
||||
cmd_start = pos = cmd;
|
||||
while (*pos != '\0') {
|
||||
// convert \n to separate argument
|
||||
if (*pos == '\n') {
|
||||
|
@ -202,8 +202,8 @@ void cmd_loop() {
|
|||
}
|
||||
|
||||
parse_commands(argc, argv);
|
||||
add_history(cmd_start);
|
||||
|
||||
if (cmd != cmdbuf)
|
||||
free(cmd);
|
||||
|
||||
} while (!exit_interactive_session);
|
||||
|
@ -213,6 +213,8 @@ int main() {
|
|||
char serverip[] = "192.168.178.24";
|
||||
uint16_t serverport = 5000;
|
||||
|
||||
rl_bind_key('\t', rl_abort);
|
||||
|
||||
lw12_connect(&sockfd, &server_addr, serverport, serverip);
|
||||
cmd_loop();
|
||||
close(sockfd);
|
||||
|
|
Loading…
Reference in New Issue