Added non persitent history

This commit is contained in:
jpk 2017-10-30 18:44:50 +01:00
parent 42749e506a
commit c970268dfb
1 changed files with 7 additions and 5 deletions

View File

@ -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,9 +202,9 @@ void cmd_loop() {
}
parse_commands(argc, argv);
add_history(cmd_start);
if (cmd != cmdbuf)
free(cmd);
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);