let each sl_func return an int indicate if sl_loop should return or not
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@2428 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
12
lib/sl/sl.c
12
lib/sl/sl.c
@@ -135,6 +135,7 @@ sl_loop (SL_cmd *cmds, char *prompt)
|
|||||||
{
|
{
|
||||||
unsigned max_count;
|
unsigned max_count;
|
||||||
char **ptr;
|
char **ptr;
|
||||||
|
int ret;
|
||||||
|
|
||||||
max_count = 17;
|
max_count = 17;
|
||||||
ptr = malloc(max_count * sizeof(*ptr));
|
ptr = malloc(max_count * sizeof(*ptr));
|
||||||
@@ -149,6 +150,7 @@ sl_loop (SL_cmd *cmds, char *prompt)
|
|||||||
unsigned count;
|
unsigned count;
|
||||||
SL_cmd *c;
|
SL_cmd *c;
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
buf = readline(prompt);
|
buf = readline(prompt);
|
||||||
if(buf == NULL)
|
if(buf == NULL)
|
||||||
break;
|
break;
|
||||||
@@ -178,9 +180,13 @@ sl_loop (SL_cmd *cmds, char *prompt)
|
|||||||
}
|
}
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
c = sl_match (cmds, ptr[0], 0);
|
c = sl_match (cmds, ptr[0], 0);
|
||||||
if (c)
|
if (c) {
|
||||||
(*c->func)(count, ptr);
|
ret = (*c->func)(count, ptr);
|
||||||
else
|
if (ret != 0) {
|
||||||
|
free (buf);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else
|
||||||
printf ("Unrecognized command: %s\n", ptr[0]);
|
printf ("Unrecognized command: %s\n", ptr[0]);
|
||||||
}
|
}
|
||||||
free(buf);
|
free(buf);
|
||||||
|
@@ -41,7 +41,7 @@
|
|||||||
#ifndef _SL_H
|
#ifndef _SL_H
|
||||||
#define _SL_H
|
#define _SL_H
|
||||||
|
|
||||||
typedef void (*cmd_func)(int, char **);
|
typedef int (*cmd_func)(int, char **);
|
||||||
|
|
||||||
struct sl_cmd {
|
struct sl_cmd {
|
||||||
char *name;
|
char *name;
|
||||||
|
Reference in New Issue
Block a user