comparison mcabber/src/commands.c @ 102:2b4cc6bc5bf2

[/trunk] Changeset 116 by mikael * Can now complete command parameters :-)
author mikael
date Thu, 21 Apr 2005 19:06:27 +0000
parents 4f3ad00b5187
children 93dcc4e15d4a
comparison
equal deleted inserted replaced
101:4f3ad00b5187 102:2b4cc6bc5bf2
28 #include "compl.h" 28 #include "compl.h"
29 #include "utf8.h" 29 #include "utf8.h"
30 #include "utils.h" 30 #include "utils.h"
31 31
32 32
33 // Command structure
34 typedef struct {
35 char name[32];
36 const char *help;
37 guint completion_flags[2];
38 void *(*func)();
39 } cmd;
40
41 static GSList *Commands; 33 static GSList *Commands;
42 34
43 // cmd_add() 35 // cmd_add()
44 // Adds a command to the commands list and to the CMD completion list 36 // Adds a command to the commands list and to the CMD completion list
45 void cmd_add(const char *name, const char *help, 37 void cmd_add(const char *name, const char *help,
49 strncpy(n_cmd->name, name, 32-1); 41 strncpy(n_cmd->name, name, 32-1);
50 n_cmd->help = help; 42 n_cmd->help = help;
51 n_cmd->completion_flags[0] = flags_row1; 43 n_cmd->completion_flags[0] = flags_row1;
52 n_cmd->completion_flags[1] = flags_row2; 44 n_cmd->completion_flags[1] = flags_row2;
53 n_cmd->func = f; 45 n_cmd->func = f;
54 g_slist_append(Commands, n_cmd); 46 Commands = g_slist_append(Commands, n_cmd);
55 // Add to completion CMD category 47 // Add to completion CMD category
56 compl_add_category_word(COMPL_CMD, name); 48 compl_add_category_word(COMPL_CMD, name);
57 } 49 }
58 50
59 // cmd_init() 51 // cmd_init()
82 compl_add_category_word(COMPL_STATUS, "free"); 74 compl_add_category_word(COMPL_STATUS, "free");
83 compl_add_category_word(COMPL_STATUS, "dnd"); 75 compl_add_category_word(COMPL_STATUS, "dnd");
84 compl_add_category_word(COMPL_STATUS, "busy"); 76 compl_add_category_word(COMPL_STATUS, "busy");
85 compl_add_category_word(COMPL_STATUS, "notavail"); 77 compl_add_category_word(COMPL_STATUS, "notavail");
86 compl_add_category_word(COMPL_STATUS, "away"); 78 compl_add_category_word(COMPL_STATUS, "away");
79 }
80
81 // cmd_get
82 // Finds command in the command list structure.
83 // Returns a pointer to the cmd entry, or NULL if command not found.
84 cmd *cmd_get(char *command)
85 {
86 char *p1, *p2;
87 char *com;
88 GSList *sl_com;
89 // Ignore leading '/'
90 for (p1 = command ; *p1 == '/' ; p1++)
91 ;
92 // Locate the end of the command
93 for (p2 = p1 ; *p2 && (*p2 != ' ') ; p2++)
94 ;
95 // Copy the clean command
96 com = g_strndup(p1, p2-p1);
97
98 // Look for command in the list
99 for (sl_com=Commands; sl_com; sl_com = g_slist_next(sl_com)) {
100 if (!strcasecmp(com, ((cmd*)sl_com->data)->name))
101 break;
102 }
103 g_free(com);
104
105 if (sl_com) // Command has been found.
106 return (cmd*)sl_com->data;
107 return NULL;
87 } 108 }
88 109
89 // send_message(msg) 110 // send_message(msg)
90 // Write the message in the buddy's window and send the message on 111 // Write the message in the buddy's window and send the message on
91 // the network. 112 // the network.