changeset 95:9e6b7897ec37

[/trunk] Changeset 109 by mikael * Work on compl.* integration. No big change yet...
author mikael
date Wed, 20 Apr 2005 19:06:25 +0000
parents 9a4aa2797f02
children 8b2703ccc4be
files mcabber/src/TODO mcabber/src/commands.c mcabber/src/compl.c mcabber/src/compl.h mcabber/src/screen.c
diffstat 5 files changed, 63 insertions(+), 38 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/TODO	Tue Apr 19 20:09:54 2005 +0000
+++ b/mcabber/src/TODO	Wed Apr 20 19:06:25 2005 +0000
@@ -18,6 +18,7 @@
   - /add <jid> [Name]
   - /del [jid]
   - /move [\<jid\>] <group>
+  - /nick (== rename <me> $@)
   - /rename [\<jid\>] Name
   - /info [jid]
   - /request_auth [jid]
--- a/mcabber/src/commands.c	Tue Apr 19 20:09:54 2005 +0000
+++ b/mcabber/src/commands.c	Wed Apr 20 19:06:25 2005 +0000
@@ -19,10 +19,13 @@
  * USA
  */
 
+#include <string.h>
+
 #include "commands.h"
 #include "jabglue.h"
 #include "roster.h"
 #include "screen.h"
+#include "compl.h"
 #include "utf8.h"
 #include "utils.h"
 
@@ -30,11 +33,60 @@
 // Command structure
 typedef struct {
   char name[32];
-  char *help;       // ?
-  guint completion_flags;
+  const char *help;
+  guint completion_flags[2];
   void *(*func)();
 } cmd;
 
+static GSList *Commands;
+
+//  cmd_add()
+// Adds a command to the commands list and to the CMD completion list
+void cmd_add(const char *name, const char *help,
+        guint flags_row1, guint flags_row2, void *(*f)())
+{
+  cmd *n_cmd = g_new0(cmd, 1);
+  strncpy(n_cmd->name, name, 32-1);
+  n_cmd->help = help;
+  n_cmd->completion_flags[0] = flags_row1;
+  n_cmd->completion_flags[1] = flags_row2;
+  n_cmd->func = f;
+  g_slist_append(Commands, n_cmd);
+  // Add to completion CMD category
+  compl_add_category_word(COMPL_CMD, name);
+}
+
+//  cmd_init()
+// ...
+void cmd_init(void)
+{
+  guint cflags[4];
+
+  //cmd_add("add");
+  //cmd_add("clear");
+  //cmd_add("del");
+  //cmd_add("group");
+  //cmd_add("info");
+  //cmd_add("move");
+  //cmd_add("nick");
+  cmd_add("quit", "Exit the software", 0, 0, NULL);
+  //cmd_add("rename");
+  //cmd_add("request_auth");
+  cmd_add("say", "Say something to the selected buddy", 0, 0, NULL);
+  //cmd_add("search");
+  //cmd_add("send_auth");
+  cmd_add("status", "Show or set your status", COMPL_STATUS, 0, NULL);
+
+  // Status category
+  compl_add_category_word(COMPL_STATUS, "online");
+  compl_add_category_word(COMPL_STATUS, "avail");
+  compl_add_category_word(COMPL_STATUS, "invisible");
+  compl_add_category_word(COMPL_STATUS, "free");
+  compl_add_category_word(COMPL_STATUS, "dnd");
+  compl_add_category_word(COMPL_STATUS, "busy");
+  compl_add_category_word(COMPL_STATUS, "notavail");
+  compl_add_category_word(COMPL_STATUS, "away");
+}
 
 //  send_message(msg)
 // Write the message in the buddy's window and send the message on
--- a/mcabber/src/compl.c	Tue Apr 19 20:09:54 2005 +0000
+++ b/mcabber/src/compl.c	Wed Apr 20 19:06:25 2005 +0000
@@ -122,9 +122,9 @@
 
 /* Categories functions */
 
-//  compl_add_category_command(categ, command)
-// Adds command as a possible completion in category categ.
-void compl_add_category_command(guint categ, char *command)
+//  compl_add_category_word(categ, command)
+// Adds a keyword as a possible completion in category categ.
+void compl_add_category_word(guint categ, const char *word)
 {
   GSList *sl_cat;
   category *cat;
@@ -141,9 +141,11 @@
     cat = (category*)sl_cat->data;
 
   // TODO Check word does not already exist
-  cat->words = g_slist_append(cat->words, g_strdup(command)); // TODO sort
+  cat->words = g_slist_append(cat->words, g_strdup(word)); // TODO sort
 }
 
+//  compl_get_category_list()
+// Returns a slist of all words in the categories specified by the given flags
 GSList *compl_get_category_list(guint cat_flags)
 {
   GSList *sl_cat;
@@ -199,35 +201,4 @@
     done_completion();
   }
 }
-
-int main()
-{
-  compl_add_category_command(COMPL_CMD, "add");
-  compl_add_category_command(COMPL_CMD, "clear");
-  compl_add_category_command(COMPL_CMD, "del");
-  compl_add_category_command(COMPL_CMD, "group");
-  compl_add_category_command(COMPL_CMD, "info");
-  compl_add_category_command(COMPL_CMD, "move");
-  compl_add_category_command(COMPL_CMD, "rename");
-  compl_add_category_command(COMPL_CMD, "request_auth");
-  compl_add_category_command(COMPL_CMD, "say");
-  compl_add_category_command(COMPL_CMD, "search");
-  compl_add_category_command(COMPL_CMD, "send_auth");
-  compl_add_category_command(COMPL_CMD, "status");
-  compl_add_category_command(COMPL_STATUS, "online");
-  compl_add_category_command(COMPL_STATUS, "avail");
-  compl_add_category_command(COMPL_STATUS, "invisible");
-  compl_add_category_command(COMPL_STATUS, "free");
-  compl_add_category_command(COMPL_STATUS, "dnd");
-  compl_add_category_command(COMPL_STATUS, "busy");
-  compl_add_category_command(COMPL_STATUS, "notavail");
-  compl_add_category_command(COMPL_STATUS, "away");
-
-  //test_dump_categories();
-
-  test_comp(COMPL_STATUS, "d");
-  test_comp(COMPL_CMD, "s");
-
-  return 0;
-}
 */
--- a/mcabber/src/compl.h	Tue Apr 19 20:09:54 2005 +0000
+++ b/mcabber/src/compl.h	Wed Apr 20 19:06:25 2005 +0000
@@ -10,7 +10,7 @@
 #define COMPL_STATUS    16      // Not implemented yet
 #define COMPL_FILENAME  32      // Not implemented yet
 
-void compl_add_category_command(guint, char *command);
+void compl_add_category_word(guint, const char *command);
 
 void new_completion(char *prefix, GSList *compl_cat);
 void done_completion(void);
--- a/mcabber/src/screen.c	Tue Apr 19 20:09:54 2005 +0000
+++ b/mcabber/src/screen.c	Wed Apr 20 19:06:25 2005 +0000
@@ -10,6 +10,7 @@
 #include "screen.h"
 #include "hbuf.h"
 #include "commands.h"
+#include "compl.h"
 #include "roster.h"
 #include "parsecfg.h"
 #include "lang.h"