cmdline: new build system
[libcmdline.git] / src / lib / cmdline_parse.c
index c056833..ceb22d6 100644 (file)
@@ -312,7 +312,7 @@ match_inst(cmdline_parse_inst_t *inst, const char *linebuf,
                linebuf++;
 
        /* end of buf, we match all inst  */
-       if (isendofline(*linebuf) || iscomment(*linebuf))
+       if (*linebuf == '\0' || isendofline(*linebuf) || iscomment(*linebuf))
                return 0;
 
        /* garbage after inst */
@@ -489,7 +489,7 @@ int cmdline_help(cmdline_parse_ctx_t *ctx, const char *buf,
 
                /* end of inst */
                if (token == NULL) {
-                       n = snprintf(helpbuf, sizeof(helpbuf), "[RETURN]\n");
+                       n = snprintf(helpbuf, sizeof(helpbuf), "[Return]\n");
                        if (n > 0)
                                write_buf(opaque, helpbuf, n);
                        continue;
@@ -542,7 +542,7 @@ int cmdline_help(cmdline_parse_ctx_t *ctx, const char *buf,
                while (token->ops->complete_iterate(token,
                                                    &preparse.opaque,
                                                    tmpbuf,
-                                                   sizeof(tmpbuf)) == 0) {
+                                                   sizeof(tmpbuf)) >= 0) {
 
 
                        debug_printf("   choice <%s>\n", tmpbuf);
@@ -641,7 +641,6 @@ cmdline_complete(cmdline_parse_ctx_t *ctx, const char *buf,
                        debug_printf("Completion %s\n", tmpbuf);
 
                        /* we kept at least the room for one char */
-                       /* XXX to be updated for non-final completion */
                        if (ret == 0)
                                strcat(tmpbuf, " ");
 
@@ -693,8 +692,8 @@ cmdline_complete(cmdline_parse_ctx_t *ctx, const char *buf,
                if (completion_len >= dstsize)
                        completion_len = dstsize - 1;
                strncpy(dst, completion_buf + preparse.comp_tok_len,
-                       completion_len);
-               dst[completion_len] = '\0';
+                       completion_len - preparse.comp_tok_len);
+               dst[completion_len - preparse.comp_tok_len] = '\0';
                return CMDLINE_COMPLETE_APPEND;
        }