From mboxrd@z Thu Jan 1 00:00:00 1970 From: Olivier Matz Subject: Re: [PATCH v2] cmdline: rework as a wrapper to libedit Date: Tue, 26 Jun 2018 15:33:13 +0200 Message-ID: <20180626133313.5ciboen7of44qlej@platinum> References: <20180417152016.5163-1-adrien.mazarguil@6wind.com> <20180419151155.5680-1-adrien.mazarguil@6wind.com> <20180626132121.6qm3m3mx2ubkxyn3@platinum> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: dev@dpdk.org, Keith Wiles , Jingjing Wu , Thomas Monjalon , Ferruh Yigit , Jim Thompson , Anatoly Burakov To: Adrien Mazarguil Return-path: Received: from mail.droids-corp.org (zoll.droids-corp.org [94.23.50.67]) by dpdk.org (Postfix) with ESMTP id 0E0AE1B5F7 for ; Tue, 26 Jun 2018 15:33:16 +0200 (CEST) Content-Disposition: inline In-Reply-To: <20180626132121.6qm3m3mx2ubkxyn3@platinum> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" > I noticed a bad behavior change (in addition to many good ones): > ctrl-c now quits the application, and this was not the case before. > I often use ctrl-c to delete the line I'm currently editing. Please > see at the end a proposition to restore this feature. And now, ladies and gentlemen, the proposition I was talking about :) diff --git a/examples/vhost_crypto/main.c b/examples/vhost_crypto/main.c index f334d7123..860457dc6 100644 --- a/examples/vhost_crypto/main.c +++ b/examples/vhost_crypto/main.c @@ -15,7 +15,6 @@ #include #include -#include #include #include #include diff --git a/lib/librte_cmdline/Makefile b/lib/librte_cmdline/Makefile index feb1f1bca..052934b69 100644 --- a/lib/librte_cmdline/Makefile +++ b/lib/librte_cmdline/Makefile @@ -23,6 +23,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_socket.c SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_parse_portlist.c LDLIBS += -lrte_eal +LDLIBS += $(shell pkg-config --libs libedit) # install includes INCS := cmdline.h cmdline_parse.h cmdline_parse_num.h cmdline_parse_ipaddr.h diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c index 1c45cd9ff..af72f394f 100644 --- a/lib/librte_cmdline/cmdline.c +++ b/lib/librte_cmdline/cmdline.c @@ -4,8 +4,9 @@ * All rights reserved. */ +#include #include -#include +#include #include #include #include @@ -16,6 +17,8 @@ #include #include +#include + #include #include "cmdline_parse.h" @@ -60,6 +63,32 @@ cmdline_el_prompt(EditLine *el) return cl->prompt; } +static int +editline_break(EditLine *el, int c) +{ + struct cmdline *cl; + + (void)c; + + if (el_get(el, EL_CLIENTDATA, &cl)) + return CC_FATAL; + + fprintf(cl->f_out, "\n"); + + return CC_NEWLINE; +} + +static int +editline_suspend(EditLine *editline, int c) +{ + (void)editline; + (void)c; + + kill(getpid(), SIGSTOP); + + return CC_NORM; +} + static unsigned char cmdline_el_execute(EditLine *el, int c) { @@ -224,6 +253,20 @@ cmdline_new(cmdline_parse_ctx_t *ctx, const char *prompt, int s_in, int s_out) if (el_set(cl->el, EL_ADDFN, "ed-execute", "Execute command", cmdline_el_execute)) goto error; + if (el_set(cl->el, EL_SETTY, "-d", "-isig", NULL)) + goto error; + if (el_set(cl->el, EL_ADDFN, "ed-break", + "Break and flush the buffer", + editline_break)) + goto error; + if (el_set(cl->el, EL_BIND, "^C", "ed-break", NULL)) + goto error; + if (el_set(cl->el, EL_ADDFN, "ed-suspend", + "Suspend the terminal", + editline_suspend)) + goto error; + if (el_set(cl->el, EL_BIND, "^Z", "ed-suspend", NULL)) + goto error; if (el_set(cl->el, EL_BIND, "^J", "ed-execute", NULL)) goto error; if (el_set(cl->el, EL_BIND, "^M", "ed-execute", NULL)) diff --git a/mk/rte.app.mk b/mk/rte.app.mk index e5caefb08..f7d9f6f2c 100644 --- a/mk/rte.app.mk +++ b/mk/rte.app.mk @@ -81,8 +81,6 @@ _LDLIBS-$(CONFIG_RTE_LIBRTE_RING) += -lrte_ring _LDLIBS-$(CONFIG_RTE_LIBRTE_PCI) += -lrte_pci _LDLIBS-$(CONFIG_RTE_LIBRTE_EAL) += -lrte_eal _LDLIBS-$(CONFIG_RTE_LIBRTE_CMDLINE) += -lrte_cmdline - -_LDLIBS-$(CONFIG_RTE_LIBRTE_CMDLINE) += $(shell pkg-config --libs libedit) _LDLIBS-$(CONFIG_RTE_LIBRTE_REORDER) += -lrte_reorder _LDLIBS-$(CONFIG_RTE_LIBRTE_SCHED) += -lrte_sched @@ -267,6 +265,7 @@ ifeq ($(CONFIG_RTE_LIBRTE_VHOST_NUMA),y) _LDLIBS-$(CONFIG_RTE_LIBRTE_VHOST) += -lnuma endif _LDLIBS-$(CONFIG_RTE_PORT_PCAP) += -lpcap +_LDLIBS-$(CONFIG_RTE_LIBRTE_CMDLINE) += $(shell pkg-config --libs libedit) endif # !CONFIG_RTE_BUILD_SHARED_LIBS _LDLIBS-y += $(EXECENV_LDLIBS)