mcabber/src/commands.c
author mikael
Fri, 22 Apr 2005 22:06:53 +0000
changeset 108 7fb72bc13732
parent 104 fe7257d251ac
child 113 8ac67e951eab
permissions -rw-r--r--
[/trunk] Changeset 122 by mikael * Add /clear command.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
     1
/*
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
     2
 * commands.c     -- user commands handling
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
     3
 * 
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
     4
 * Copyright (C) 2005 Mikael Berthe <bmikael@lists.lilotux.net>
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
     5
 *
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
     6
 * This program is free software; you can redistribute it and/or modify
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
     7
 * it under the terms of the GNU General Public License as published by
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
     8
 * the Free Software Foundation; either version 2 of the License, or (at
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
     9
 * your option) any later version.
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    10
 *
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    11
 * This program is distributed in the hope that it will be useful, but
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    12
 * WITHOUT ANY WARRANTY; without even the implied warranty of
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    14
 * General Public License for more details.
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    15
 *
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    17
 * along with this program; if not, write to the Free Software
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    19
 * USA
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    20
 */
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    21
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    22
#include <string.h>
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    23
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    24
#include "commands.h"
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    25
#include "jabglue.h"
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
    26
#include "roster.h"
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    27
#include "screen.h"
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    28
#include "compl.h"
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
    29
#include "utf8.h"
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    30
#include "utils.h"
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    31
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
    32
// Commands callbacks
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
    33
void do_roster(char *arg);
108
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 104
diff changeset
    34
void do_clear(char *arg);
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
    35
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
    36
// Global variable for the commands list
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    37
static GSList *Commands;
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    38
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
    39
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    40
//  cmd_add()
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    41
// Adds a command to the commands list and to the CMD completion list
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    42
void cmd_add(const char *name, const char *help,
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
    43
        guint flags_row1, guint flags_row2, void (*f)())
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    44
{
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    45
  cmd *n_cmd = g_new0(cmd, 1);
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    46
  strncpy(n_cmd->name, name, 32-1);
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    47
  n_cmd->help = help;
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    48
  n_cmd->completion_flags[0] = flags_row1;
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    49
  n_cmd->completion_flags[1] = flags_row2;
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    50
  n_cmd->func = f;
102
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
    51
  Commands = g_slist_append(Commands, n_cmd);
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    52
  // Add to completion CMD category
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    53
  compl_add_category_word(COMPL_CMD, name);
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    54
}
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    55
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    56
//  cmd_init()
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    57
// ...
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    58
void cmd_init(void)
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    59
{
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    60
  //cmd_add("add");
108
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 104
diff changeset
    61
  cmd_add("clear", "Clear the dialog window", 0, 0, &do_clear);
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    62
  //cmd_add("del");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    63
  //cmd_add("group");
108
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 104
diff changeset
    64
  //cmd_add("help");
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    65
  //cmd_add("info");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    66
  //cmd_add("move");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    67
  //cmd_add("nick");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    68
  cmd_add("quit", "Exit the software", 0, 0, NULL);
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    69
  //cmd_add("rename");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    70
  //cmd_add("request_auth");
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
    71
  cmd_add("roster", "Manipulate the roster/buddylist", COMPL_ROSTER, 0, &do_roster);
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    72
  cmd_add("say", "Say something to the selected buddy", 0, 0, NULL);
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    73
  //cmd_add("search");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    74
  //cmd_add("send_auth");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    75
  cmd_add("status", "Show or set your status", COMPL_STATUS, 0, NULL);
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    76
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    77
  // Status category
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    78
  compl_add_category_word(COMPL_STATUS, "online");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    79
  compl_add_category_word(COMPL_STATUS, "avail");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    80
  compl_add_category_word(COMPL_STATUS, "invisible");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    81
  compl_add_category_word(COMPL_STATUS, "free");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    82
  compl_add_category_word(COMPL_STATUS, "dnd");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    83
  compl_add_category_word(COMPL_STATUS, "busy");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    84
  compl_add_category_word(COMPL_STATUS, "notavail");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    85
  compl_add_category_word(COMPL_STATUS, "away");
103
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
    86
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
    87
  // Roster category
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
    88
  compl_add_category_word(COMPL_ROSTER, "bottom");
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
    89
  compl_add_category_word(COMPL_ROSTER, "hide_offline");
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
    90
  compl_add_category_word(COMPL_ROSTER, "show_offline");
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
    91
  compl_add_category_word(COMPL_ROSTER, "top");
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
    92
}
94
9a4aa2797f02 [/trunk] Changeset 108 by mikael
mikael
parents: 81
diff changeset
    93
102
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
    94
//  cmd_get
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
    95
// Finds command in the command list structure.
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
    96
// Returns a pointer to the cmd entry, or NULL if command not found.
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
    97
cmd *cmd_get(char *command)
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
    98
{
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
    99
  char *p1, *p2;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   100
  char *com;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   101
  GSList *sl_com;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   102
  // Ignore leading '/'
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   103
  for (p1 = command ; *p1 == '/' ; p1++)
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   104
    ;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   105
  // Locate the end of the command
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   106
  for (p2 = p1 ; *p2 && (*p2 != ' ') ; p2++)
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   107
    ;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   108
  // Copy the clean command
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   109
  com = g_strndup(p1, p2-p1);
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   110
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   111
  // Look for command in the list
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   112
  for (sl_com=Commands; sl_com; sl_com = g_slist_next(sl_com)) {
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   113
    if (!strcasecmp(com, ((cmd*)sl_com->data)->name))
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   114
      break;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   115
  }
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   116
  g_free(com);
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   117
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   118
  if (sl_com)       // Command has been found.
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   119
    return (cmd*)sl_com->data;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   120
  return NULL;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   121
}
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
   122
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   123
//  send_message(msg)
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   124
// Write the message in the buddy's window and send the message on
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   125
// the network.
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   126
void send_message(char *msg)
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   127
{
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   128
  char *buffer;
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   129
  const char *jid;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   130
      
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   131
  if (!current_buddy) {
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   132
    scr_LogPrint("No buddy currently selected.");
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   133
    return;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   134
  }
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   135
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   136
  jid = CURRENT_JID;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   137
  if (!jid) {
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   138
    scr_LogPrint("No buddy currently selected.");
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   139
    return;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   140
  }
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   141
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   142
  // UI part
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   143
  scr_WriteOutgoingMessage(jid, msg);
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   144
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   145
  // Network part
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   146
  buffer = utf8_encode(msg);
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
   147
  jb_send_msg(jid, buffer);
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   148
  free(buffer);
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   149
}
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   150
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   151
//  process_line(line)
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   152
// Process a command/message line.
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   153
// If this isn't a command, this is a message and it is sent to the
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   154
// currently selected buddy.
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   155
int process_line(char *line)
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   156
{
101
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
   157
  char *p;
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   158
  cmd *curcmd;
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   159
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   160
  if (*line != '/') {
98
f20831f7d349 [/trunk] Changeset 112 by mikael
mikael
parents: 96
diff changeset
   161
    send_message(line); // FIXME: are we talking to a _buddy_?
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   162
    return 0;
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   163
  }
101
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
   164
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
   165
  /* It is a command */
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
   166
  // Remove trailing spaces:
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
   167
  for (p=line ; *p ; p++)
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
   168
    ;
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
   169
  for (p-- ; p>line && (*p == ' ') ; p--)
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
   170
    *p = 0;
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
   171
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
   172
  // Command "quit"?
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   173
  if (!strcasecmp(line, "/quit")) {
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   174
    return 255;
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   175
  }
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   176
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   177
  // Commands handling
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   178
  curcmd = cmd_get(line);
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   179
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   180
  if (!curcmd) {
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   181
    scr_LogPrint("Unrecognized command, sorry.");
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   182
    return 0;
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   183
  }
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   184
  if (!curcmd->func) {
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   185
    scr_LogPrint("Not yet implemented, sorry.");
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   186
    return 0;
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   187
  }
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   188
  // Lets go to the command parameters
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   189
  for (line++; *line && (*line != ' ') ; line++)
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   190
    ;
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   191
  // Skip spaces
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   192
  while (*line && (*line == ' '))
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   193
    line++;
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   194
  // Call command-specific function
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   195
  (*curcmd->func)(line);
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   196
  return 0;
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   197
}
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
   198
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   199
/* Commands callback functions */
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   200
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   201
void do_roster(char *arg)
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   202
{
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   203
  if (!strcasecmp(arg, "top")) {
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   204
    scr_RosterTop();
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   205
    scr_DrawRoster();
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   206
  } else if (!strcasecmp(arg, "bottom")) {
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   207
    scr_RosterBottom();
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   208
    scr_DrawRoster();
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   209
  } else if (!strcasecmp(arg, "hide_offline")) {
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   210
    buddylist_hide_offline_buddies(TRUE);
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   211
    if (current_buddy)
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   212
      buddylist_build();
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   213
    scr_DrawRoster();
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   214
  } else if (!strcasecmp(arg, "show_offline")) {
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   215
    buddylist_hide_offline_buddies(FALSE);
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   216
    if (current_buddy)
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   217
      buddylist_build();
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   218
    scr_DrawRoster();
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   219
  } else
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   220
    scr_LogPrint("Unrecognized parameter!");
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
   221
}
108
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 104
diff changeset
   222
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 104
diff changeset
   223
void do_clear(char *arg)
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 104
diff changeset
   224
{
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 104
diff changeset
   225
  scr_Clear();
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 104
diff changeset
   226
}
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 104
diff changeset
   227