tex: expect a non-NULL string in ex_command() - neatvi - [fork] simple vi-type editor with UTF-8 support
(HTM) git clone git://src.adamsgaard.dk/neatvi
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) commit bc9dd7dfbc434e6260ca5002cbc6501ced9adcb6
(DIR) parent 0a858aba4cababc83b862da41aa8c8c07a564ea9
(HTM) Author: Ali Gholami Rudi <ali@rudi.ir>
Date: Tue, 12 May 2015 16:42:53 +0430
ex: expect a non-NULL string in ex_command()
Diffstat:
M ex.c | 24 +++++++++++++-----------
1 file changed, 13 insertions(+), 11 deletions(-)
---
(DIR) diff --git a/ex.c b/ex.c
t@@ -17,7 +17,8 @@ static char *ex_read(char *msg)
char c;
if (xled) {
char *s = led_prompt(msg, "");
- printf("\n");
+ if (s)
+ printf("\n");
return s;
}
sb = sbuf_make();
t@@ -36,10 +37,12 @@ static char *ex_read(char *msg)
/* print an output line; ex's output function */
static void ex_show(char *msg)
{
- if (xled)
+ if (xled) {
led_print(msg, -1);
- else
+ term_chr('\n');
+ } else {
printf("%s", msg);
+ }
}
/* read ex command location */
t@@ -447,13 +450,10 @@ static struct excmd {
};
/* execute a single ex command */
-void ex_command(char *ln0)
+void ex_command(char *ln)
{
char cmd[EXLEN];
- char *ln = ln0 ? ln0 : ex_read(":");
int i;
- if (!ln)
- return;
ex_cmd(ln, cmd);
for (i = 0; i < LEN(excmds); i++) {
if (!strcmp(excmds[i].abbr, cmd) || !strcmp(excmds[i].name, cmd)) {
t@@ -461,8 +461,6 @@ void ex_command(char *ln0)
break;
}
}
- if (!ln0)
- free(ln);
lbuf_undomark(xb);
}
t@@ -471,8 +469,12 @@ void ex(void)
{
if (xled)
term_init();
- while (!xquit)
- ex_command(NULL);
+ while (!xquit) {
+ char *ln = ex_read(":");
+ if (ln)
+ ex_command(ln);
+ free(ln);
+ }
if (xled)
term_done();
}