Refactor: Simplify parsing logic
authorDenis Kenzior <denkenz@gmail.com>
Thu, 25 Mar 2010 00:40:59 +0000 (19:40 -0500)
committerDenis Kenzior <denkenz@gmail.com>
Thu, 25 Mar 2010 00:41:19 +0000 (19:41 -0500)
It isn't actually necessary to check the basic command prefixes, if the
extended prefix doesn't match we try to parse it like a basic command.
That one does the same exact check anyway.  If that fails, then this is
not a recognized command line anyway.

gatchat/gatserver.c

index 711bf78..c75fbf5 100644 (file)
@@ -194,17 +194,6 @@ static inline gboolean is_extended_command_prefix(const char c)
        }
 }
 
-static gboolean is_basic_command_prefix(const char *buf)
-{
-       if (g_ascii_isalpha(buf[0]))
-               return TRUE;
-
-       if (buf[0] == '&' && g_ascii_isalpha(buf[1]))
-               return TRUE;
-
-       return FALSE;
-}
-
 static void at_command_notify(GAtServer *server, char *command,
                                char *prefix, GAtServerRequestType type)
 {
@@ -440,10 +429,8 @@ static void server_parse_line(GAtServer *server, char *line)
 
                if (is_extended_command_prefix(line[pos]))
                        consumed = parse_extended_command(server, line + pos);
-               else if (is_basic_command_prefix(line + pos))
-                       consumed = parse_basic_command(server, line + pos);
                else
-                       consumed = 0;
+                       consumed = parse_basic_command(server, line + pos);
 
                if (consumed == 0) {
                        g_at_server_send_final(server,