1
0
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

Seperated command functions into module

This commit is contained in:
James Booth 2013-12-15 16:10:32 +00:00
parent 447d235868
commit 2490f5b417
7 changed files with 2566 additions and 2492 deletions

View File

@ -31,6 +31,7 @@ core_sources = \
src/ui/windows.c src/ui/windows.h \
src/ui/muc_window.c src/ui/muc_window.h \
src/command/command.h src/command/command.c src/command/history.c \
src/command/commands.h src/command/commands.c \
src/command/history.h src/tools/parser.c \
src/tools/parser.h \
src/tools/autocomplete.c src/tools/autocomplete.h \
@ -50,6 +51,7 @@ test_sources = \
src/xmpp/xmpp.h \
src/ui/ui.h \
src/command/command.h src/command/command.c src/command/history.c \
src/command/commands.h src/command/commands.c \
src/command/history.h src/tools/parser.c \
src/tools/parser.h \
src/tools/autocomplete.c src/tools/autocomplete.h \

File diff suppressed because it is too large Load Diff

View File

@ -25,15 +25,10 @@
#include <glib.h>
// Command help strings
typedef struct cmd_help_t {
const gchar *usage;
const gchar *short_help;
const gchar *long_help[50];
} CommandHelp;
GHashTable *commands;
void cmd_init(void);
void cmd_close(void);
void cmd_uninit(void);
void cmd_autocomplete(char *input, int *size);
void cmd_reset_autocomplete(void);
@ -49,6 +44,4 @@ void cmd_history_append(char *inp);
char *cmd_history_previous(char *inp, int *size);
char *cmd_history_next(char *inp, int *size);
gboolean _cmd_rooms(gchar **args, struct cmd_help_t help);
#endif

2384
src/command/commands.c Normal file

File diff suppressed because it is too large Load Diff

112
src/command/commands.h Normal file
View File

@ -0,0 +1,112 @@
/*
* commands.h
*
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Profanity. If not, see <http://www.gnu.org/licenses/>.
*
*/
#ifndef COMMANDS_H
#define COMMANDS_H
// Command help strings
typedef struct cmd_help_t {
const gchar *usage;
const gchar *short_help;
const gchar *long_help[50];
} CommandHelp;
/*
* Command structure
*
* cmd - The command string including leading '/'
* func - The function to execute for the command
* parser - The function used to parse arguments
* min_args - Minimum number of arguments
* max_args - Maximum number of arguments
* help - A help struct containing usage info etc
*/
typedef struct cmd_t {
gchar *cmd;
gboolean (*func)(gchar **args, struct cmd_help_t help);
gchar** (*parser)(const char * const inp, int min, int max);
int min_args;
int max_args;
void (*setting_func)(void);
CommandHelp help;
} Command;
gboolean cmd_about(gchar **args, struct cmd_help_t help);
gboolean cmd_account(gchar **args, struct cmd_help_t help);
gboolean cmd_autoaway(gchar **args, struct cmd_help_t help);
gboolean cmd_autoconnect(gchar **args, struct cmd_help_t help);
gboolean cmd_autoping(gchar **args, struct cmd_help_t help);
gboolean cmd_away(gchar **args, struct cmd_help_t help);
gboolean cmd_beep(gchar **args, struct cmd_help_t help);
gboolean cmd_caps(gchar **args, struct cmd_help_t help);
gboolean cmd_chat(gchar **args, struct cmd_help_t help);
gboolean cmd_chlog(gchar **args, struct cmd_help_t help);
gboolean cmd_clear(gchar **args, struct cmd_help_t help);
gboolean cmd_close(gchar **args, struct cmd_help_t help);
gboolean cmd_connect(gchar **args, struct cmd_help_t help);
gboolean cmd_decline(gchar **args, struct cmd_help_t help);
gboolean cmd_disco(gchar **args, struct cmd_help_t help);
gboolean cmd_disconnect(gchar **args, struct cmd_help_t help);
gboolean cmd_dnd(gchar **args, struct cmd_help_t help);
gboolean cmd_duck(gchar **args, struct cmd_help_t help);
gboolean cmd_flash(gchar **args, struct cmd_help_t help);
gboolean cmd_gone(gchar **args, struct cmd_help_t help);
gboolean cmd_grlog(gchar **args, struct cmd_help_t help);
gboolean cmd_group(gchar **args, struct cmd_help_t help);
gboolean cmd_help(gchar **args, struct cmd_help_t help);
gboolean cmd_history(gchar **args, struct cmd_help_t help);
gboolean cmd_info(gchar **args, struct cmd_help_t help);
gboolean cmd_intype(gchar **args, struct cmd_help_t help);
gboolean cmd_invite(gchar **args, struct cmd_help_t help);
gboolean cmd_invites(gchar **args, struct cmd_help_t help);
gboolean cmd_join(gchar **args, struct cmd_help_t help);
gboolean cmd_leave(gchar **args, struct cmd_help_t help);
gboolean cmd_log(gchar **args, struct cmd_help_t help);
gboolean cmd_mouse(gchar **args, struct cmd_help_t help);
gboolean cmd_msg(gchar **args, struct cmd_help_t help);
gboolean cmd_nick(gchar **args, struct cmd_help_t help);
gboolean cmd_notify(gchar **args, struct cmd_help_t help);
gboolean cmd_online(gchar **args, struct cmd_help_t help);
gboolean cmd_outtype(gchar **args, struct cmd_help_t help);
gboolean cmd_prefs(gchar **args, struct cmd_help_t help);
gboolean cmd_priority(gchar **args, struct cmd_help_t help);
gboolean cmd_quit(gchar **args, struct cmd_help_t help);
gboolean cmd_reconnect(gchar **args, struct cmd_help_t help);
gboolean cmd_rooms(gchar **args, struct cmd_help_t help);
gboolean cmd_bookmark(gchar **args, struct cmd_help_t help);
gboolean cmd_roster(gchar **args, struct cmd_help_t help);
gboolean cmd_software(gchar **args, struct cmd_help_t help);
gboolean cmd_splash(gchar **args, struct cmd_help_t help);
gboolean cmd_states(gchar **args, struct cmd_help_t help);
gboolean cmd_status(gchar **args, struct cmd_help_t help);
gboolean cmd_statuses(gchar **args, struct cmd_help_t help);
gboolean cmd_sub(gchar **args, struct cmd_help_t help);
gboolean cmd_theme(gchar **args, struct cmd_help_t help);
gboolean cmd_tiny(gchar **args, struct cmd_help_t help);
gboolean cmd_titlebar(gchar **args, struct cmd_help_t help);
gboolean cmd_vercheck(gchar **args, struct cmd_help_t help);
gboolean cmd_who(gchar **args, struct cmd_help_t help);
gboolean cmd_win(gchar **args, struct cmd_help_t help);
gboolean cmd_wins(gchar **args, struct cmd_help_t help);
gboolean cmd_xa(gchar **args, struct cmd_help_t help);
#endif

View File

@ -687,7 +687,7 @@ _shutdown(void)
prefs_close();
theme_close();
accounts_close();
cmd_close();
cmd_uninit();
log_close();
}

View File

@ -7,7 +7,7 @@
#include "xmpp/xmpp.h"
#include "ui/ui.h"
#include "command/command.h"
#include "command/commands.h"
static void test_with_connection_status(jabber_conn_status_t status)
{
@ -16,7 +16,7 @@ static void test_with_connection_status(jabber_conn_status_t status)
will_return(jabber_get_connection_status, status);
expect_string(cons_show, msg, "You are not currently connected.");
gboolean result = _cmd_rooms(NULL, *help);
gboolean result = cmd_rooms(NULL, *help);
assert_true(result);
free(help);
@ -59,7 +59,7 @@ void cmd_rooms_uses_account_default_when_no_arg(void **state)
will_return(accounts_get_account, account);
expect_string(iq_room_list_request, conferencejid, "default_conf_server");
gboolean result = _cmd_rooms(args, *help);
gboolean result = cmd_rooms(args, *help);
assert_true(result);
@ -75,7 +75,7 @@ void cmd_arg_used_when_passed(void **state)
will_return(jabber_get_connection_status, JABBER_CONNECTED);
expect_string(iq_room_list_request, conferencejid, "conf_server_arg");
gboolean result = _cmd_rooms(args, *help);
gboolean result = cmd_rooms(args, *help);
assert_true(result);