Hey Sasha,

New patch is attached.

Al

On Tue, 2008-08-19 at 02:01 +0300, Sasha Khapyorsky wrote:
> On 15:50 Mon 18 Aug     , Al Chu wrote:
> > 
> > The reason is that the ordering of the if statements now matters.  If I
> > add a new command called "DoSomething", it must come after the "Dump"
> > comparison, otherwise the command "D" could take the "DoSomething"
> > branch.
> 
> Sure, order will matter - new commands will be at end.
> 
> Sasha
> 
> > We can add a comments or something to document this.  It's
> > obviously just a style difference.
> > 
> > > >
> > > > But we would require
> > > > whitespace between the command and options for that to work.
> > > 
> > > This is fine.
> > > 
> > > What I meant is follow:
> > > 
> > >   unsigned cmd_len = 0;
> > > 
> > >   while (isalpha(line[cmd_len]))
> > >           cmd_len++;
> > > 
> > >   if (!strncasecmp(line, "Dump", cmdlen))
> > >           ...
> > > 
> > > In this case strings "D", "du", etc. will be resolved as "Dump" command.
> > 
> > Ok.  I see what you were thinking now.  
> > 
> > Al
> > 
> > > Sasha
> > -- 
> > Albert Chu
> > [EMAIL PROTECTED]
> > 925-422-5311
> > Computer Scientist
> > High Performance Systems Division
> > Lawrence Livermore National Laboratory
> > 
-- 
Albert Chu
[EMAIL PROTECTED]
925-422-5311
Computer Scientist
High Performance Systems Division
Lawrence Livermore National Laboratory
>From 8a1f05b353469054564da75663e3a95744a1f8ec Mon Sep 17 00:00:00 2001
From: Albert Chu <[EMAIL PROTECTED]>
Date: Wed, 13 Aug 2008 13:53:14 -0700
Subject: [PATCH] parse sim cmds via full name


Signed-off-by: Albert Chu <[EMAIL PROTECTED]>
---
 ibsim/sim_cmd.c |  111 +++++++++++++++++++++++-------------------------------
 1 files changed, 47 insertions(+), 64 deletions(-)

diff --git a/ibsim/sim_cmd.c b/ibsim/sim_cmd.c
index 1f6ba88..0dc544c 100644
--- a/ibsim/sim_cmd.c
+++ b/ibsim/sim_cmd.c
@@ -757,91 +757,74 @@ int netstarted = 0;
 
 int do_cmd(char *buf, FILE *f)
 {
+	unsigned int cmd_len = 0;
 	char *line;
 	int r = 0;
 
 	for (line = buf; *line && isspace(*line); line++) ;
 
-	switch (*line) {
-	case '!':
+	/* special cases */
+	if (*line == '!')
 		r = sim_cmd_file(f, line);
-		break;
-	case 'd':
-	case 'D':
+	else if (*line == '#' || *line == '\n' || *line == '\0')
+		goto out;
+
+	while (!isspace(line[cmd_len]))
+		cmd_len++;
+
+	if (!strncasecmp(line, "Dump", cmd_len))
 		r = dump_net(f, line);
-		break;
-	case 'r':
-	case 'R':
+	else if (!strncasecmp(line, "Route", cmd_len))
 		r = dump_route(f, line);
-		break;
-	case 'l':
-	case 'L':
+	else if (!strncasecmp(line, "Link", cmd_len))
 		r = do_link(f, line);
-		break;
-	case 'B':
-	case 'b':
-		r = do_change_baselid(f, line);
-		break;
-	case 'u':
-	case 'U':
+	else if (!strncasecmp(line, "Unlink", cmd_len))
 		r = do_unlink(f, line, 0);
-		break;
-	case 'G':
-	case 'g':
+	else if (!strncasecmp(line, "Clear", cmd_len))
+		r = do_unlink(f, line, 1);
+	else if (!strncasecmp(line, "Guid", cmd_len))
 		r = do_set_guid(f, line);
-		break;
-	case 'e':
-	case 'E':
+	else if (!strncasecmp(line, "Error", cmd_len))
 		r = do_seterror(f, line);
-		break;
-	case 'c':
-	case 'C':
-		r = do_unlink(f, line, 1);
-		break;
-	case 'q':
-	case 'Q':
-		fprintf(f, "Exiting network simulator.\n");
-		free_core();
-		exit(0);
-		break;
-	case 'h':
-	case 'H':
-	case '?':
-		r = dump_help(f);
-		break;
-	case 'V':
-	case 'v':
-		r = change_verbose(f, line);
-		break;
-	case 'S':
-	case 's':
+	else if (!strncasecmp(line, "Baselid", cmd_len))
+		r = do_change_baselid(f, line);
+	else if (!strncasecmp(line, "Start", cmd_len)) {
 		if (!netstarted) {
 			DEBUG("starting...");
 			netstarted = 1;
 			return 0;
 		}
-		break;
-	case 'W':
-	case 'w':
+	}
+	else if (!strncasecmp(line, "Verbose", cmd_len))
+		r = change_verbose(f, line);
+	else if (!strncasecmp(line, "Wait", cmd_len))
 		r = do_wait(f, line);
-		break;
-	case 'A':
-	case 'a':
+	else if (!strncasecmp(line, "Attached", cmd_len))
 		r = list_connections(f);
-		break;
-	case 'X':
-	case 'x':
+	else if (!strncasecmp(line, "X", cmd_len))
 		r = do_disconnect_client(f, strtol(line + 2, 0, 0));
-		break;
-	case '#':
-		fprintf(f, line);
-		// fall through
-	case '\n':
-	case 0:
-		break;
-	default:
-		fprintf(f, "op %c unknown - skipped\n", line[0]);
+	else if (!strncasecmp(line, "Help", cmd_len)
+		 || !strncasecmp(line, "?", cmd_len))
+		r = dump_help(f);
+	else if (!strncasecmp(line, "Quit", cmd_len)) {
+		fprintf(f, "Exiting network simulator.\n");
+		free_core();
+		exit(0);
 	}
+	/* commands specified above support legacy single
+	 * character options.  For example, 'g' or 'G' for "Guid"
+	 * and 'l' or 'L' for "Link".
+	 * 
+	 * please specify new command support below this comment.
+	 */
+	else {
+		char cmdbuf[cmd_len+1];
 
+		memset(cmdbuf, '\0', cmd_len+1);
+		strncpy(cmdbuf, line, cmd_len);
+
+		fprintf(f, "command %s unknown - skipped\n", cmdbuf);
+	}
+out:
 	return r;
 }
-- 
1.5.4.5

_______________________________________________
general mailing list
[email protected]
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/general

To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general

Reply via email to