about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-08-10 23:18:02 +0100
committerJames Booth <boothj5@gmail.com>2012-08-10 23:18:02 +0100
commit6644fa953eeecf5ca1dcc7236b3f4b0afddf2b78 (patch)
tree34f5ee512a21a49ff8b85b3de0bd8e5d00c70d55 /src
parentcd3a0ddeb8d3e2713dee302f6d6e2de3709707c2 (diff)
downloadprofani-tty-6644fa953eeecf5ca1dcc7236b3f4b0afddf2b78.tar.gz
Command list size now calculated
No longer have to specify size, and keep it up to date
when adding new commands
Diffstat (limited to 'src')
-rw-r--r--src/command.c11
-rw-r--r--src/common.h2
2 files changed, 7 insertions, 6 deletions
diff --git a/src/command.c b/src/command.c
index bbc77574..8d906b15 100644
--- a/src/command.c
+++ b/src/command.c
@@ -25,6 +25,7 @@
 
 #include <glib.h>
 
+#include "common.h"
 #include "command.h"
 #include "contact_list.h"
 #include "history.h"
@@ -88,8 +89,6 @@ static struct cmd_t commands[] = {
     { "/xa", _cmd_xa },
     { "/help", _cmd_help }
 };
-
-static const int num_cmds = 19;
     
 gboolean
 process_input(char *inp)
@@ -124,8 +123,8 @@ command_init(void)
 {
     commands_ac = p_autocomplete_new();
 
-    int i;
-    for (i = 0; i < num_cmds; i++) {
+    unsigned int i;
+    for (i = 0; i < ARRAY_SIZE(commands); i++) {
         struct cmd_t *pcmd = commands+i;
         p_autocomplete_add(commands_ac, (gchar *)pcmd->cmd);
     }
@@ -148,8 +147,8 @@ reset_command_completer(void)
 static gboolean
 _handle_command(const char * const command, const char * const inp)
 {
-    int i;
-    for (i = 0; i < num_cmds; i++) {
+    unsigned int i;
+    for (i = 0; i < ARRAY_SIZE(commands); i++) {
         struct cmd_t *pcmd = commands+i;
         if (strcmp(pcmd->cmd, command) == 0) {
             return (pcmd->func(inp));
diff --git a/src/common.h b/src/common.h
index 3cc5b766..ae99b165 100644
--- a/src/common.h
+++ b/src/common.h
@@ -49,6 +49,8 @@ typedef enum {
 #define notify_notification_new(summary, body, icon) notify_notification_new(summary, body, icon, NULL)
 #endif
 
+#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
+
 void p_slist_free_full(GSList *items, GDestroyNotify free_func);
 void create_config_directory(void);
 void create_dir(char *name);