From 3a5af2fac2e7f86b6fa0027a38b9f93ad6ea50fa Mon Sep 17 00:00:00 2001
From: Guillaume Chanel <Guillaume.Chanel@unige.ch>
Date: Fri, 14 Oct 2022 10:35:00 +0200
Subject: [PATCH] Handle inputs made of delimiters only

---
 interface.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/interface.c b/interface.c
index 4463e09..4576224 100644
--- a/interface.c
+++ b/interface.c
@@ -109,6 +109,18 @@ int parse_command(char *user_input, cmd_t *cmd) {
   return 0;
 }
 
+//Check is a string is composed only of a set of characters
+//OUT:
+//  str:    the string to check (does it contains some chars ?)
+//  of:     a string containing the set of characters to verify
+//  return: true is the string str is made only of chars in of, false otherwise
+static bool str_made_only_of(const char *str, const char *of) {
+  while(*str)
+    if(strchr(of, *str++) == NULL)
+      return false;
+  return true;
+}
+
 //Wait for the user input and return it
 //OUT:
 //  user_input: a string with the user input. The user should take care of the
@@ -123,6 +135,10 @@ int ask_user_input(char* user_input) {
   //Ensure that the end of line chars are removed
   user_input[strcspn(user_input, "\r\n")] = 0;
 
+  // if string is only made of delimiters -> replace by empty string
+  if(str_made_only_of(user_input, DELIMIERS))
+    user_input[0] = '\0';
+
   return user_input[0];
 }
 
-- 
GitLab