From ac6694278baa63067e548deee7c2df49aca1435e Mon Sep 17 00:00:00 2001 From: WebsterXC Date: Thu, 9 Mar 2017 22:47:57 -0500 Subject: [PATCH] Fixed issue #15 - no match displays user input. --- main.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/main.c b/main.c index c220140..7f85b2b 100644 --- a/main.c +++ b/main.c @@ -128,6 +128,29 @@ static int action_end_of_line(MENU menu) { } static int action_confirm(MENU menu) { + /* Bugfix: 03/09/2017 | Will Burgin (WebsterXC) + * ISSUE #15 + * + * If the N characters in the buffer string don't + * match the first N characters of the menu selection, + * then we should return the user input, not the first + * random menu selection. + * + * If the user enters >64 chars in the buffer string, + * only the first 64 chars of user input will be printed. + */ + + size_t buflen = 64; + char *retstring = (char *)malloc(sizeof(char) * buflen); + + retstring = Buffer.string( Menu.buffer(menu), &retstring, &buflen ); + + // Match fail. Return user input. + if(strncmp( Menu.selection(menu), retstring, strlen(retstring) ) != 0){ + fprintf(stdout, "No match found for: %s\n", retstring); + return 0; + } + // Match exists, return menu selection. fprintf(stdout, "%s\n", Menu.selection(menu)); return 0; }