[syslinux:master] hdt: Adding say command

syslinux-bot for Erwan Velu erwanaliasr1 at gmail.com
Sun May 27 13:00:07 PDT 2012


Commit-ID:  30abec4d70d34875b0ca312d62eed5e264f9050d
Gitweb:     http://www.syslinux.org/commit/30abec4d70d34875b0ca312d62eed5e264f9050d
Author:     Erwan Velu <erwanaliasr1 at gmail.com>
AuthorDate: Sun, 27 May 2012 11:46:54 +0200
Committer:  Erwan Velu <erwanaliasr1 at gmail.com>
CommitDate: Sun, 27 May 2012 11:46:54 +0200

hdt: Adding say command

This command is just for displaing a message to the cli during a defined
period of time.

Syntax is like the following : say `my message`%<number_of_seconds>
An example :

say `This is my text message to display during 5 seconds`%5

---
 com32/hdt/hdt-cli-hdt.c |   61 +++++++++++++++++++++++++++++++++++++++++++++++
 com32/hdt/hdt-cli.h     |    1 +
 2 files changed, 62 insertions(+), 0 deletions(-)

diff --git a/com32/hdt/hdt-cli-hdt.c b/com32/hdt/hdt-cli-hdt.c
index 555237e..f7f7e94 100644
--- a/com32/hdt/hdt-cli-hdt.c
+++ b/com32/hdt/hdt-cli-hdt.c
@@ -259,6 +259,61 @@ static void do_dump(int argc __unused, char **argv __unused,
     dump(hardware);
 }
 
+/**
+ * do_say - say message to user
+ **/
+static void do_say(int argc , char **argv ,
+		      struct s_hardware *hardware)
+{
+   (void) hardware;
+   if (argc == 0) return;
+
+   char text_to_say[255]={0};
+   int arg=0;
+   int sleep_time=0;
+#if DEBUG
+   for (int i=0; i<argc;i++) dprintf("SAY: arg[%d]={%s}\n",i,argv[i]);
+#endif
+   char *argument = strchr(argv[arg],'`');
+   if ( argument != NULL) {
+	argument++;
+   	strcat(text_to_say, argument);
+
+   	while ((strchr(argument, '`') == NULL) && (arg+1<argc)) {
+		arg++;
+		argument = (char *)argv[arg];
+		strcat(text_to_say, " ");
+		strcat(text_to_say, argument);
+   	}
+    
+	/* Removing last ` if any */
+    	char *last_quote = strrchr(text_to_say,'`');
+    	if ( last_quote != NULL ) {
+	*last_quote='\0';
+	dprintf("SAY CMD = [%s]\n",text_to_say);	   
+    	}
+
+	/* The % char can be in the same argument, let's consider it again */
+    	arg--;
+
+	/* Searching for a % argument to determine the time to show the message */
+    	char *time_to_display = NULL;
+    	/* Search for a requested time to display */
+    	while ( ((time_to_display=strchr(argument, '%')) == NULL) && (arg+1<argc)) {
+		arg++;
+		argument = (char *)argv[arg];
+    	}
+
+    	if (time_to_display != NULL) {
+		sleep_time=atoi(time_to_display+1);
+		dprintf("SAY CMD :Time to display = %d\n",sleep_time);	   
+    	}
+
+  	printf("%s\n",text_to_say);
+  	sleep(sleep_time);
+  }
+}
+
 /* Default hdt mode */
 struct cli_callback_descr list_hdt_default_modules[] = {
     {
@@ -294,6 +349,12 @@ struct cli_callback_descr list_hdt_default_modules[] = {
     {
      .name = CLI_DUMP,
      .exec = do_dump,
+     .nomodule = false,
+     },
+    {
+     .name = CLI_SAY,
+     .exec = do_say,
+     .nomodule = true,
      },
     {
      .name = NULL,
diff --git a/com32/hdt/hdt-cli.h b/com32/hdt/hdt-cli.h
index 1e21941..30fe518 100644
--- a/com32/hdt/hdt-cli.h
+++ b/com32/hdt/hdt-cli.h
@@ -66,6 +66,7 @@
 #define CLI_ENABLE "enable"
 #define CLI_DISABLE "disable"
 #define CLI_DUMP "dump"
+#define CLI_SAY "say"
 
 typedef enum {
     INVALID_MODE,


More information about the Syslinux-commits mailing list