1
0
Fork 0

Removed trailing whitespace from src and tests

This commit is contained in:
James Booth 2012-10-21 20:02:20 +01:00
parent 382e961563
commit 6bad38c2d5
35 changed files with 446 additions and 446 deletions

View File

@ -1,8 +1,8 @@
/*
/*
* chat_log.c
*
* Copyright (C) 2012 James Booth <boothj5@gmail.com>
*
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
@ -44,25 +44,25 @@ static gboolean _log_roll_needed(struct dated_chat_log *dated_log);
static struct dated_chat_log *_create_log(char *other, const char * const login);
static void _free_chat_log(struct dated_chat_log *dated_log);
static gboolean _key_equals(void *key1, void *key2);
static char * _get_log_filename(const char * const other, const char * const login,
static char * _get_log_filename(const char * const other, const char * const login,
GDateTime *dt, gboolean create);
void
chat_log_init(void)
{
{
session_started = g_date_time_new_now_local();
log_info("Initialising chat logs");
logs = g_hash_table_new_full(g_str_hash, (GEqualFunc) _key_equals, g_free,
logs = g_hash_table_new_full(g_str_hash, (GEqualFunc) _key_equals, g_free,
(GDestroyNotify)_free_chat_log);
}
void
chat_log_chat(const gchar * const login, gchar *other,
chat_log_chat(const gchar * const login, gchar *other,
const gchar * const msg, chat_log_direction_t direction)
{
gchar *other_copy = strdup(other);
struct dated_chat_log *dated_log = g_hash_table_lookup(logs, other_copy);
// no log for user
if (dated_log == NULL) {
dated_log = _create_log(other_copy, login);
@ -94,24 +94,24 @@ chat_log_chat(const gchar * const login, gchar *other,
}
GSList *
chat_log_get_previous(const gchar * const login, const gchar * const recipient,
chat_log_get_previous(const gchar * const login, const gchar * const recipient,
GSList *history)
{
GTimeZone *tz = g_time_zone_new_local();
GDateTime *now = g_date_time_new_now_local();
GDateTime *log_date = g_date_time_new(tz,
GDateTime *log_date = g_date_time_new(tz,
g_date_time_get_year(session_started),
g_date_time_get_month(session_started),
g_date_time_get_month(session_started),
g_date_time_get_day_of_month(session_started),
g_date_time_get_hour(session_started),
g_date_time_get_minute(session_started),
g_date_time_get_second(session_started));
// get data from all logs from the day the session was started to today
while (g_date_time_get_day_of_year(log_date) <= g_date_time_get_day_of_year(now)) {
char *filename = _get_log_filename(recipient, login, log_date, FALSE);
FILE *logp = fopen(filename, "r");
char *line = NULL;
size_t read = 0;
@ -136,10 +136,10 @@ chat_log_get_previous(const gchar * const login, const gchar * const recipient,
read = 0;
length = getline(&line, &read, logp);
}
fclose(logp);
}
free(filename);
GDateTime *next = g_date_time_add_days(log_date, 1);
g_date_time_unref(log_date);
@ -208,12 +208,12 @@ gboolean _key_equals(void *key1, void *key2)
{
gchar *str1 = (gchar *) key1;
gchar *str2 = (gchar *) key2;
return (g_strcmp0(str1, str2) == 0);
}
static char *
_get_log_filename(const char * const other, const char * const login,
_get_log_filename(const char * const other, const char * const login,
GDateTime *dt, gboolean create)
{
GString *log_file = g_string_new(getenv("HOME"));

View File

@ -1,8 +1,8 @@
/*
/*
* chat_log.h
*
* Copyright (C) 2012 James Booth <boothj5@gmail.com>
*
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
@ -31,10 +31,10 @@ typedef enum {
} chat_log_direction_t;
void chat_log_init(void);
void chat_log_chat(const gchar * const login, gchar *other,
void chat_log_chat(const gchar * const login, gchar *other,
const gchar * const msg, chat_log_direction_t direction);
void chat_log_close(void);
GSList * chat_log_get_previous(const gchar * const login,
GSList * chat_log_get_previous(const gchar * const login,
const gchar * const recipient, GSList *history);
#endif

View File

@ -1,8 +1,8 @@
/*
/*
* command.c
*
* Copyright (C) 2012 James Booth <boothj5@gmail.com>
*
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
@ -38,7 +38,7 @@
#include "tinyurl.h"
#include "ui.h"
/*
/*
* Command structure
*
* cmd - The command string including leading '/'
@ -52,11 +52,11 @@ struct cmd_t {
};
static struct cmd_t * _cmd_get_command(const char * const command);
static void _update_presence(const jabber_presence_t presence,
static void _update_presence(const jabber_presence_t presence,
const char * const show, const char * const inp);
static gboolean
_cmd_set_boolean_preference(const char * const inp, struct cmd_help_t help,
const char * const cmd_str, const char * const display,
const char * const cmd_str, const char * const display,
void (*set_func)(gboolean));
// command prototypes
@ -88,10 +88,10 @@ static gboolean _cmd_xa(const char * const inp, struct cmd_help_t help);
* Commands to change preferences
* Commands to change users status
*/
static struct cmd_t main_commands[] =
static struct cmd_t main_commands[] =
{
{ "/help",
_cmd_help,
{ "/help",
_cmd_help,
{ "/help [command]", "Show help summary, or help on a specific command",
{ "/help [command]",
"---------------",
@ -101,8 +101,8 @@ static struct cmd_t main_commands[] =
"Example : /help connect",
NULL } } },
{ "/connect",
_cmd_connect,
{ "/connect",
_cmd_connect,
{ "/connect user@host", "Login to jabber.",
{ "/connect user@host",
"------------------",
@ -110,11 +110,11 @@ static struct cmd_t main_commands[] =
"Profanity should work with any XMPP (Jabber) compliant chat host.",
"You can use tab completion to autocomplete any logins you have used before.",
"",
"Example: /connect myuser@gmail.com",
"Example: /connect myuser@gmail.com",
NULL } } },
{ "/prefs",
_cmd_prefs,
{ "/prefs",
_cmd_prefs,
{ "/prefs", "Show current preferences.",
{ "/prefs",
"------",
@ -127,8 +127,8 @@ static struct cmd_t main_commands[] =
"you will need to restart Profanity for config file edits to take effect.",
NULL } } },
{ "/msg",
_cmd_msg,
{ "/msg",
_cmd_msg,
{ "/msg user@host mesg", "Send mesg to user.",
{ "/msg user@host mesg",
"-------------------",
@ -142,8 +142,8 @@ static struct cmd_t main_commands[] =
"Example : /msg boothj5@gmail.com Hey, here's a message!",
NULL } } },
{ "/tiny",
_cmd_tiny,
{ "/tiny",
_cmd_tiny,
{ "/tiny url", "Send url as tinyurl in current chat.",
{ "/tiny url",
"---------",
@ -154,7 +154,7 @@ static struct cmd_t main_commands[] =
"Example : /tiny http://www.google.com",
NULL } } },
{ "/who",
{ "/who",
_cmd_who,
{ "/who [status]", "Show contacts with chosen status.",
{ "/who [status]",
@ -164,8 +164,8 @@ static struct cmd_t main_commands[] =
"online includes: chat, dnd, away, xa.",
NULL } } },
{ "/close",
_cmd_close,
{ "/close",
_cmd_close,
{ "/close", "Close current chat window.",
{ "/close",
"------",
@ -173,8 +173,8 @@ static struct cmd_t main_commands[] =
"The chat window will become available for new chats.",
NULL } } },
{ "/quit",
_cmd_quit,
{ "/quit",
_cmd_quit,
{ "/quit", "Quit Profanity.",
{ "/quit",
"-----",
@ -182,7 +182,7 @@ static struct cmd_t main_commands[] =
NULL } } }
};
static struct cmd_t setting_commands[] =
static struct cmd_t setting_commands[] =
{
{ "/beep",
_cmd_set_beep,
@ -237,7 +237,7 @@ static struct cmd_t setting_commands[] =
"Config file value : remind=seconds",
NULL } } },
{ "/flash",
{ "/flash",
_cmd_set_flash,
{ "/flash on|off", "Enable/disable screen flash notifications.",
{ "/flash on|off",
@ -251,8 +251,8 @@ static struct cmd_t setting_commands[] =
"Config file value : flash=true|false",
NULL } } },
{ "/showsplash",
_cmd_set_showsplash,
{ "/showsplash",
_cmd_set_showsplash,
{ "/showsplash on|off", "Enable/disable splash logo on startup.",
{ "/showsplash on|off",
"------------------",
@ -262,7 +262,7 @@ static struct cmd_t setting_commands[] =
"Config file value : showsplash=true|false",
NULL } } },
{ "/chlog",
{ "/chlog",
_cmd_set_chlog,
{ "/chlog on|off", "Enable/disable chat logging.",
{ "/chlog on|off",
@ -278,7 +278,7 @@ static struct cmd_t setting_commands[] =
" ~/.profanity/log/someuser_at_chatserv.com/myfriend_at_chatserv.com",
NULL } } },
{ "/history",
{ "/history",
_cmd_set_history,
{ "/history on|off", "Enable/disable chat history.",
{ "/history on|off",
@ -291,7 +291,7 @@ static struct cmd_t setting_commands[] =
NULL } } }
};
static struct cmd_t status_commands[] =
static struct cmd_t status_commands[] =
{
{ "/away",
_cmd_away,
@ -328,7 +328,7 @@ static struct cmd_t status_commands[] =
"Example : /dnd I'm in the zone",
NULL } } },
{ "/online",
{ "/online",
_cmd_online,
{ "/online [msg]", "Set status to online.",
{ "/online [msg]",
@ -351,7 +351,7 @@ static struct cmd_t status_commands[] =
"Example : /xa This meeting is going to be a long one",
NULL } } },
};
static PAutocomplete commands_ac;
/*
@ -443,7 +443,7 @@ gboolean
cmd_execute(const char * const command, const char * const inp)
{
struct cmd_t *cmd = _cmd_get_command(command);
if (cmd != NULL) {
return (cmd->func(inp, cmd->help));
} else {
@ -457,7 +457,7 @@ cmd_execute_default(const char * const inp)
if (win_in_chat()) {
char *recipient = win_get_recipient();
jabber_send(inp, recipient);
if (prefs_get_chlog()) {
const char *jid = jabber_get_jid();
chat_log_chat(jid, recipient, inp, OUT);
@ -499,7 +499,7 @@ _cmd_connect(const char * const inp, struct cmd_help_t help)
inp_non_block();
log_debug("Connecting as %s", lower);
conn_status = jabber_connect(lower, passwd);
if (conn_status == JABBER_CONNECTING) {
cons_show("Connecting...");
@ -512,7 +512,7 @@ _cmd_connect(const char * const inp, struct cmd_help_t help)
result = TRUE;
}
return result;
}
@ -540,7 +540,7 @@ _cmd_help(const char * const inp, struct cmd_help_t help)
if (command != NULL) {
help_text = command->help.long_help;
}
cons_show("");
if (help_text != NULL) {
@ -574,7 +574,7 @@ _cmd_who(const char * const inp, struct cmd_help_t help)
if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected.");
} else {
// copy input
// copy input
char inp_cpy[strlen(inp) + 1];
strcpy(inp_cpy, inp);
@ -595,7 +595,7 @@ _cmd_who(const char * const inp, struct cmd_help_t help)
// valid arg
} else {
GSList *list = get_contact_list();
// no arg, show all contacts
if (show == NULL) {
cons_show("All contacts:");
@ -653,7 +653,7 @@ _cmd_msg(const char * const inp, struct cmd_help_t help)
if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected.");
} else {
// copy input
// copy input
char inp_cpy[strlen(inp) + 1];
strcpy(inp_cpy, inp);
@ -719,7 +719,7 @@ _cmd_tiny(const char * const inp, struct cmd_help_t help)
}
} else {
cons_show("Usage: %s", help.usage);
if (win_in_chat()) {
char usage[strlen(help.usage + 8)];
sprintf(usage, "Usage: %s", help.usage);
@ -735,7 +735,7 @@ _cmd_close(const char * const inp, struct cmd_help_t help)
{
if (!win_close_win())
cons_bad_command(inp);
return TRUE;
}
@ -749,42 +749,42 @@ _cmd_set_beep(const char * const inp, struct cmd_help_t help)
static gboolean
_cmd_set_notify(const char * const inp, struct cmd_help_t help)
{
return _cmd_set_boolean_preference(inp, help, "/notify",
return _cmd_set_boolean_preference(inp, help, "/notify",
"Desktop notifications", prefs_set_notify);
}
static gboolean
_cmd_set_typing(const char * const inp, struct cmd_help_t help)
{
return _cmd_set_boolean_preference(inp, help, "/typing",
return _cmd_set_boolean_preference(inp, help, "/typing",
"Incoming typing notifications", prefs_set_typing);
}
static gboolean
_cmd_set_flash(const char * const inp, struct cmd_help_t help)
{
return _cmd_set_boolean_preference(inp, help, "/flash",
return _cmd_set_boolean_preference(inp, help, "/flash",
"Screen flash", prefs_set_flash);
}
static gboolean
_cmd_set_showsplash(const char * const inp, struct cmd_help_t help)
{
return _cmd_set_boolean_preference(inp, help, "/showsplash",
return _cmd_set_boolean_preference(inp, help, "/showsplash",
"Splash screen", prefs_set_showsplash);
}
static gboolean
_cmd_set_chlog(const char * const inp, struct cmd_help_t help)
{
return _cmd_set_boolean_preference(inp, help, "/chlog",
return _cmd_set_boolean_preference(inp, help, "/chlog",
"Chat logging", prefs_set_chlog);
}
static gboolean
_cmd_set_history(const char * const inp, struct cmd_help_t help)
{
return _cmd_set_boolean_preference(inp, help, "/history",
return _cmd_set_boolean_preference(inp, help, "/history",
"Chat history", prefs_set_history);
}
@ -794,7 +794,7 @@ _cmd_set_remind(const char * const inp, struct cmd_help_t help)
if ((strncmp(inp, "/remind ", 8) != 0) || (strlen(inp) < 9)) {
cons_show("Usage: %s", help.usage);
} else {
// copy input
// copy input
char inp_cpy[strlen(inp) + 1];
strcpy(inp_cpy, inp);
@ -813,7 +813,7 @@ _cmd_set_remind(const char * const inp, struct cmd_help_t help)
}
}
return TRUE;
return TRUE;
}
static gboolean
@ -854,7 +854,7 @@ _cmd_xa(const char * const inp, struct cmd_help_t help)
// helper function for status change commands
static void
_update_presence(const jabber_presence_t presence,
_update_presence(const jabber_presence_t presence,
const char * const show, const char * const inp)
{
char *msg;
@ -865,7 +865,7 @@ _update_presence(const jabber_presence_t presence,
}
jabber_conn_status_t conn_status = jabber_get_connection_status();
if (conn_status != JABBER_CONNECTED) {
cons_show("You are not currently connected.");
} else {
@ -879,18 +879,18 @@ _update_presence(const jabber_presence_t presence,
}
}
}
}
// helper function for boolean preference commands
static gboolean
_cmd_set_boolean_preference(const char * const inp, struct cmd_help_t help,
const char * const cmd_str, const char * const display,
const char * const cmd_str, const char * const display,
void (*set_func)(gboolean))
{
GString *on = g_string_new(cmd_str);
g_string_append(on, " on");
GString *off = g_string_new(cmd_str);
g_string_append(off, " off");
@ -910,7 +910,7 @@ _cmd_set_boolean_preference(const char * const inp, struct cmd_help_t help,
char usage[strlen(help.usage + 8)];
sprintf(usage, "Usage: %s", help.usage);
cons_show(usage);
}
}
g_string_free(on, TRUE);
g_string_free(off, TRUE);

View File

@ -1,8 +1,8 @@
/*
/*
* command.h
*
* Copyright (C) 2012 James Booth <boothj5@gmail.com>
*
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify

View File

@ -1,8 +1,8 @@
/*
/*
* common.c
*
* Copyright (C) 2012 James Booth <boothj5@gmail.com>
*
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
@ -50,20 +50,20 @@ create_dir(char *name)
}
char *
str_replace(const char *string, const char *substr,
const char *replacement)
str_replace(const char *string, const char *substr,
const char *replacement)
{
char *tok = NULL;
char *newstr = NULL;
char *oldstr = NULL;
char *head = NULL;
if (string == NULL)
return NULL;
if ( substr == NULL ||
replacement == NULL ||
(strcmp(substr, "") == 0))
if ( substr == NULL ||
replacement == NULL ||
(strcmp(substr, "") == 0))
return strdup (string);
newstr = strdup (string);
@ -71,26 +71,26 @@ str_replace(const char *string, const char *substr,
while ( (tok = strstr ( head, substr ))) {
oldstr = newstr;
newstr = malloc ( strlen ( oldstr ) - strlen ( substr ) +
newstr = malloc ( strlen ( oldstr ) - strlen ( substr ) +
strlen ( replacement ) + 1 );
if ( newstr == NULL ) {
if ( newstr == NULL ) {
free (oldstr);
return NULL;
}
memcpy ( newstr, oldstr, tok - oldstr );
memcpy ( newstr + (tok - oldstr), replacement, strlen ( replacement ) );
memcpy ( newstr + (tok - oldstr) + strlen( replacement ),
tok + strlen ( substr ),
memcpy ( newstr + (tok - oldstr) + strlen( replacement ),
tok + strlen ( substr ),
strlen ( oldstr ) - strlen ( substr ) - ( tok - oldstr ) );
memset ( newstr + strlen ( oldstr ) - strlen ( substr ) +
memset ( newstr + strlen ( oldstr ) - strlen ( substr ) +
strlen ( replacement ) , 0, 1 );
head = newstr + (tok - oldstr) + strlen( replacement );
free (oldstr);
}
return newstr;
}

View File

@ -1,8 +1,8 @@
/*
/*
* common.h
*
* Copyright (C) 2012 James Booth <boothj5@gmail.com>
*
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
@ -37,7 +37,7 @@
void p_slist_free_full(GSList *items, GDestroyNotify free_func);
void create_dir(char *name);
char * str_replace(const char *string, const char *substr,
char * str_replace(const char *string, const char *substr,
const char *replacement);
int str_contains(char str[], int size, char ch);

View File

@ -1,8 +1,8 @@
/*
/*
* contact.c
*
* Copyright (C) 2012 James Booth <boothj5@gmail.com>
*
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
@ -34,7 +34,7 @@ struct p_contact_t {
};
PContact
p_contact_new(const char * const name, const char * const show,
p_contact_new(const char * const name, const char * const show,
const char * const status)
{
PContact contact = malloc(sizeof(struct p_contact_t));
@ -59,12 +59,12 @@ p_contact_copy(PContact contact)
PContact copy = malloc(sizeof(struct p_contact_t));
copy->name = strdup(contact->name);
copy->show = strdup(contact->show);
if (contact->status != NULL)
copy->status = strdup(contact->status);
else
copy->status = NULL;
return copy;
}

View File

@ -1,8 +1,8 @@
/*
/*
* contact.h
*
* Copyright (C) 2012 James Booth <boothj5@gmail.com>
*
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
@ -25,7 +25,7 @@
typedef struct p_contact_t *PContact;
PContact p_contact_new(const char * const name, const char * const show,
PContact p_contact_new(const char * const name, const char * const show,
const char * const status);
PContact p_contact_copy(PContact contact);
void p_contact_free(PContact contact);

View File

@ -1,8 +1,8 @@
/*
/*
* contact_list.c
*
* Copyright (C) 2012 James Booth <boothj5@gmail.com>
*
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
@ -30,7 +30,7 @@ static PAutocomplete ac;
void
contact_list_init(void)
{
ac = p_obj_autocomplete_new((PStrFunc)p_contact_name,
ac = p_obj_autocomplete_new((PStrFunc)p_contact_name,
(PCopyFunc)p_contact_copy,
(PEqualDeepFunc)p_contacts_equal_deep,
(GDestroyNotify)p_contact_free);
@ -55,7 +55,7 @@ contact_list_remove(const char * const name)
}
gboolean
contact_list_add(const char * const name, const char * const show,
contact_list_add(const char * const name, const char * const show,
const char * const status)
{
return p_autocomplete_add(ac, p_contact_new(name, show, status));
@ -77,7 +77,7 @@ PContact
contact_list_get_contact(const char const *jid)
{
GSList *contacts = get_contact_list();
while (contacts != NULL) {
PContact contact = contacts->data;
if (strcmp(p_contact_name(contact), jid) == 0) {

View File

@ -1,8 +1,8 @@
/*
/*
* contact_list.h
*
* Copyright (C) 2012 James Booth <boothj5@gmail.com>
*
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify

View File

@ -1,8 +1,8 @@
/*
/*
* history.c
*
* Copyright (C) 2012 James Booth <boothj5@gmail.com>
*
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
@ -45,7 +45,7 @@ history_previous(char *inp, int *size)
{
char inp_str[*size + 1];
_stringify_input(inp, *size, inp_str);
return p_history_previous(history, inp_str);
}

View File

@ -1,8 +1,8 @@
/*
/*
* history.h
*
* Copyright (C) 2012 James Booth <boothj5@gmail.com>
*
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify

View File

@ -1,8 +1,8 @@
/*
* input_win.c
/*
* input_win.c
*
* Copyright (C) 2012 James Booth <boothj5@gmail.com>
*
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
@ -26,11 +26,11 @@
* *size - holds the current size of input
* *input - holds the current input string, NOT null terminated at this point
* *ch - getch will put a charater here if there was any input
*
*
* The example below shows the values of size, input, a call to wgetyx to
* find the current cursor location, and the index of the input string.
*
* view : |mple|
* view : |mple|
* input : "example te"
* index : "0123456789"
* inp_x : "0123456789"
@ -84,7 +84,7 @@ inp_win_resize(const char * const input, const int size)
int rows, cols, inp_x;
getmaxyx(stdscr, rows, cols);
inp_x = getcurx(inp_win);
// if lost cursor off screen, move contents to show it
if (inp_x >= pad_start + cols) {
pad_start = inp_x - (cols / 2);
@ -125,7 +125,7 @@ inp_get_char(int *ch, char *input, int *size)
int inp_y = 0;
int inp_x = 0;
int i;
// echo off, and get some more input
noecho();
*ch = wgetch(inp_win);
@ -134,7 +134,7 @@ inp_get_char(int *ch, char *input, int *size)
if (!_handle_edit(*ch, input, size)) {
if (_printable(*ch)) {
getyx(inp_win, inp_y, inp_x);
// handle insert if not at end of input
if (inp_x < *size) {
winsch(inp_win, *ch);
@ -150,7 +150,7 @@ inp_get_char(int *ch, char *input, int *size)
} else {
waddch(inp_win, *ch);
input[(*size)++] = *ch;
// if gone over screen size follow input
int rows, cols;
getmaxyx(stdscr, rows, cols);
@ -174,7 +174,7 @@ inp_get_password(char *passwd)
{
int rows, cols;
getmaxyx(stdscr, rows, cols);
wclear(inp_win);
prefresh(inp_win, 0, pad_start, rows-1, 0, rows-1, cols-1);
noecho();
@ -208,12 +208,12 @@ _handle_edit(const int ch, char *input, int *size)
int inp_y = 0;
int inp_x = 0;
char inp_cpy[*size];
getmaxyx(stdscr, rows, cols);
getyx(inp_win, inp_y, inp_x);
switch(ch) {
case 127:
case KEY_BACKSPACE:
reset_search_attempts();
@ -252,12 +252,12 @@ _handle_edit(const int ch, char *input, int *size)
case KEY_DC: // DEL
if (inp_x < *size) {
wdelch(inp_win);
// if not last char, shift chars left
if (inp_x < *size - 1)
for (i = inp_x; i < *size; i++)
input[i] = input[i+1];
(*size)--;
}
return 1;
@ -265,7 +265,7 @@ _handle_edit(const int ch, char *input, int *size)
case KEY_LEFT:
if (inp_x > 0)
wmove(inp_win, inp_y, inp_x-1);
// current position off screen to left
if (inp_x - 1 < pad_start) {
pad_start--;
@ -276,7 +276,7 @@ _handle_edit(const int ch, char *input, int *size)
case KEY_RIGHT:
if (inp_x < *size) {
wmove(inp_win, inp_y, inp_x+1);
// current position off screen to right
if ((inp_x + 1 - pad_start) >= cols) {
pad_start++;
@ -367,7 +367,7 @@ _handle_edit(const int ch, char *input, int *size)
}
}
return 1;
default:
return 0;
}
@ -376,9 +376,9 @@ _handle_edit(const int ch, char *input, int *size)
static int
_printable(const int ch)
{
return (ch != ERR && ch != '\n' &&
return (ch != ERR && ch != '\n' &&
ch != KEY_PPAGE && ch != KEY_NPAGE &&
ch != KEY_F(1) && ch != KEY_F(2) && ch != KEY_F(3) &&
ch != KEY_F(1) && ch != KEY_F(2) && ch != KEY_F(3) &&
ch != KEY_F(4) && ch != KEY_F(5) && ch != KEY_F(6) &&
ch != KEY_F(7) && ch != KEY_F(8) && ch != KEY_F(9) &&
ch != KEY_F(10) && ch!= KEY_F(11) && ch != KEY_F(12) &&

View File

@ -1,8 +1,8 @@
/*
/*
* jabber.c
*
* Copyright (C) 2012 James Booth <boothj5@gmail.com>
*
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
@ -44,20 +44,20 @@ static struct _jabber_conn_t {
static log_level_t _get_log_level(xmpp_log_level_t xmpp_level);
static xmpp_log_level_t _get_xmpp_log_level();
static void _xmpp_file_logger(void * const userdata,
const xmpp_log_level_t level, const char * const area,
static void _xmpp_file_logger(void * const userdata,
const xmpp_log_level_t level, const char * const area,
const char * const msg);
static xmpp_log_t * _xmpp_get_file_logger();
// XMPP event handlers
static void _connection_handler(xmpp_conn_t * const conn,
const xmpp_conn_event_t status, const int error,
static void _connection_handler(xmpp_conn_t * const conn,
const xmpp_conn_event_t status, const int error,
xmpp_stream_error_t * const stream_error, void * const userdata);
static int _message_handler(xmpp_conn_t * const conn,
static int _message_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _roster_handler(xmpp_conn_t * const conn,
static int _roster_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _presence_handler(xmpp_conn_t * const conn,
static int _presence_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata);
static int _ping_timed_handler(xmpp_conn_t * const conn, void * const userdata);
@ -71,7 +71,7 @@ jabber_init(const int disable_tls)
}
jabber_conn_status_t
jabber_connect(const char * const user,
jabber_connect(const char * const user,
const char * const passwd)
{
log_info("Connecting as %s", user);
@ -87,12 +87,12 @@ jabber_connect(const char * const user,
if (jabber_conn.tls_disabled)
xmpp_conn_disable_tls(jabber_conn.conn);
int connect_status = xmpp_connect_client(jabber_conn.conn, NULL, 0,
int connect_status = xmpp_connect_client(jabber_conn.conn, NULL, 0,
_connection_handler, jabber_conn.ctx);
if (connect_status == 0)
jabber_conn.conn_status = JABBER_CONNECTING;
else
else
jabber_conn.conn_status = JABBER_DISCONNECTED;
return jabber_conn.conn_status;
@ -122,7 +122,7 @@ jabber_disconnect(void)
void
jabber_process_events(void)
{
if (jabber_conn.conn_status == JABBER_CONNECTED
if (jabber_conn.conn_status == JABBER_CONNECTED
|| jabber_conn.conn_status == JABBER_CONNECTING
|| jabber_conn.conn_status == JABBER_DISCONNECTING)
xmpp_run_once(jabber_conn.ctx, 10);
@ -136,7 +136,7 @@ jabber_send(const char * const msg, const char * const recipient)
char *coded_msg3 = str_replace(coded_msg2, ">", "&gt;");
xmpp_stanza_t *reply, *body, *text, *active;
active = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_name(active, "active");
xmpp_stanza_set_ns(active, "http://jabber.org/protocol/chatstates");
@ -191,7 +191,7 @@ jabber_update_presence(jabber_presence_t status, const char * const msg)
pres = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_name(pres, "presence");
if (status != PRESENCE_ONLINE) {
show = xmpp_stanza_new(jabber_conn.ctx);
xmpp_stanza_set_name(show, "show");
@ -205,7 +205,7 @@ jabber_update_presence(jabber_presence_t status, const char * const msg)
xmpp_stanza_set_text(text, "chat");
else if (status == PRESENCE_XA)
xmpp_stanza_set_text(text, "xa");
else
else
xmpp_stanza_set_text(text, "online");
xmpp_stanza_add_child(show, text);
@ -252,7 +252,7 @@ jabber_free_resources(void)
}
static int
_message_handler(xmpp_conn_t * const conn,
_message_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata)
{
char *type;
@ -294,7 +294,7 @@ _message_handler(xmpp_conn_t * const conn,
prof_handle_typing(from);
}
}
return 1;
}
@ -306,15 +306,15 @@ _message_handler(xmpp_conn_t * const conn,
}
static void
_connection_handler(xmpp_conn_t * const conn,
const xmpp_conn_event_t status, const int error,
_connection_handler(xmpp_conn_t * const conn,
const xmpp_conn_event_t status, const int error,
xmpp_stream_error_t * const stream_error, void * const userdata)
{
xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
if (status == XMPP_CONN_CONNECT) {
const char *jid = xmpp_conn_get_jid(conn);
prof_handle_login_success(jid);
prof_handle_login_success(jid);
xmpp_stanza_t* pres;
xmpp_handler_add(conn, _message_handler, NULL, "message", NULL, ctx);
@ -331,15 +331,15 @@ _connection_handler(xmpp_conn_t * const conn,
jabber_conn.presence = PRESENCE_ONLINE;
jabber_roster_request();
} else {
// received close stream response from server after disconnect
if (jabber_conn.conn_status == JABBER_DISCONNECTING) {
jabber_conn.conn_status = JABBER_DISCONNECTED;
jabber_conn.presence = PRESENCE_OFFLINE;
// lost connection for unkown reason
} else if (jabber_conn.conn_status == JABBER_CONNECTED) {
prof_handle_lost_connection();
prof_handle_lost_connection();
xmpp_stop(ctx);
jabber_conn.conn_status = JABBER_DISCONNECTED;
jabber_conn.presence = PRESENCE_OFFLINE;
@ -355,19 +355,19 @@ _connection_handler(xmpp_conn_t * const conn,
}
static int
_roster_handler(xmpp_conn_t * const conn,
_roster_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata)
{
xmpp_stanza_t *query, *item;
char *type = xmpp_stanza_get_type(stanza);
if (strcmp(type, "error") == 0)
log_error("Roster query failed");
else {
query = xmpp_stanza_get_child_by_name(stanza, "query");
GSList *roster = NULL;
item = xmpp_stanza_get_children(query);
while (item != NULL) {
const char *name = xmpp_stanza_get_attribute(item, "name");
const char *jid = xmpp_stanza_get_attribute(item, "jid");
@ -387,7 +387,7 @@ _roster_handler(xmpp_conn_t * const conn,
prof_handle_roster(roster);
}
return 1;
}
@ -396,7 +396,7 @@ _ping_timed_handler(xmpp_conn_t * const conn, void * const userdata)
{
if (jabber_conn.conn_status == JABBER_CONNECTED) {
xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata;
xmpp_stanza_t *iq, *ping;
iq = xmpp_stanza_new(ctx);
@ -419,20 +419,20 @@ _ping_timed_handler(xmpp_conn_t * const conn, void * const userdata)
}
static int
_presence_handler(xmpp_conn_t * const conn,
_presence_handler(xmpp_conn_t * const conn,
xmpp_stanza_t * const stanza, void * const userdata)
{
const char *jid = xmpp_conn_get_jid(jabber_conn.conn);
char jid_cpy[strlen(jid) + 1];
strcpy(jid_cpy, jid);
char *short_jid = strtok(jid_cpy, "/");
char *from = xmpp_stanza_get_attribute(stanza, "from");
char *short_from = strtok(from, "/");
char *type = xmpp_stanza_get_attribute(stanza, "type");
char *show_str, *status_str;
xmpp_stanza_t *show = xmpp_stanza_get_child_by_name(stanza, "show");
if (show != NULL)
show_str = xmpp_stanza_get_text(show);
@ -440,9 +440,9 @@ _presence_handler(xmpp_conn_t * const conn,
show_str = NULL;
xmpp_stanza_t *status = xmpp_stanza_get_child_by_name(stanza, "status");
if (status != NULL)
if (status != NULL)
status_str = xmpp_stanza_get_text(status);
else
else
status_str = NULL;
if (strcmp(short_jid, short_from) !=0) {

View File

@ -1,8 +1,8 @@
/*
/*
* jabber.h
*
* Copyright (C) 2012 James Booth <boothj5@gmail.com>
*
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
@ -41,7 +41,7 @@ typedef enum {
} jabber_presence_t;
void jabber_init(const int disable_tls);
jabber_conn_status_t jabber_connect(const char * const user,
jabber_conn_status_t jabber_connect(const char * const user,
const char * const passwd);
gboolean jabber_disconnect(void);
void jabber_roster_request(void);

View File

@ -1,8 +1,8 @@
/*
/*
* log.c
*
* Copyright (C) 2012 James Booth <boothj5@gmail.com>
*
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
@ -37,7 +37,7 @@ static GDateTime *dt;
static log_level_t level_filter;
void
log_debug(const char * const msg, ...)
log_debug(const char * const msg, ...)
{
va_list arg;
va_start(arg, msg);
@ -49,7 +49,7 @@ log_debug(const char * const msg, ...)
}
void
log_info(const char * const msg, ...)
log_info(const char * const msg, ...)
{
va_list arg;
va_start(arg, msg);
@ -61,7 +61,7 @@ log_info(const char * const msg, ...)
}
void
log_warning(const char * const msg, ...)
log_warning(const char * const msg, ...)
{
va_list arg;
va_start(arg, msg);
@ -73,7 +73,7 @@ log_warning(const char * const msg, ...)
}
void
log_error(const char * const msg, ...)
log_error(const char * const msg, ...)
{
va_list arg;
va_start(arg, msg);
@ -116,10 +116,10 @@ log_msg(log_level_t level, const char * const area, const char * const msg)
if (level >= level_filter) {
dt = g_date_time_new_now(tz);
gchar *date_fmt = g_date_time_format(dt, "%d/%m/%Y %H:%M:%S");
gchar *date_fmt = g_date_time_format(dt, "%d/%m/%Y %H:%M:%S");
fprintf(logp, "%s: %s: %s\n", date_fmt, area, msg);
g_date_time_unref(dt);
fflush(logp);
g_free(date_fmt);
}

View File

@ -1,8 +1,8 @@
/*
/*
* log.h
*