1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-07-21 18:24:14 -04:00

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
*
* 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 @@ void log_debug(const char * const msg, ...);
void log_info(const char * const msg, ...);
void log_warning(const char * const msg, ...);
void log_error(const char * const msg, ...);
void log_msg(log_level_t level, const char * const area,
void log_msg(log_level_t level, const char * const area,
const char * const msg);
#endif

View File

@ -1,8 +1,8 @@
/*
/*
* main.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
@ -32,15 +32,15 @@ static char *log = "INFO";
int
main(int argc, char **argv)
{
static GOptionEntry entries[] =
{
static GOptionEntry entries[] =
{
{ "version", 'v', 0, G_OPTION_ARG_NONE, &version, "Show version information", NULL },
{ "disable-tls", 'd', 0, G_OPTION_ARG_NONE, &disable_tls, "Disable TLS", NULL },
{ "log",'l', 0, G_OPTION_ARG_STRING, &log, "Set logging levels, DEBUG, INFO (default), WARN, ERROR", "LEVEL" },
{ NULL }
};
GError *error = NULL;
GOptionContext *context;

View File

@ -1,8 +1,8 @@
/*
/*
* preferences.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
@ -78,7 +78,7 @@ static struct colours_t {
} colour_prefs;
static NCURSES_COLOR_T _lookup_colour(const char * const colour);
static void _set_colour(gchar *val, NCURSES_COLOR_T *pref,
static void _set_colour(gchar *val, NCURSES_COLOR_T *pref,
NCURSES_COLOR_T def);
static void _load_colours(void);
static void _save_prefs(void);
@ -92,7 +92,7 @@ prefs_load(void)
g_string_append(prefs_loc, "/.profanity/config");
prefs = g_key_file_new();
g_key_file_load_from_file(prefs, prefs_loc->str, G_KEY_FILE_KEEP_COMMENTS,
g_key_file_load_from_file(prefs, prefs_loc->str, G_KEY_FILE_KEEP_COMMENTS,
NULL);
// create the logins searchable list for autocompletion
@ -134,7 +134,7 @@ _lookup_colour(const char * const colour)
}
static void
_set_colour(gchar *val, NCURSES_COLOR_T *pref,
_set_colour(gchar *val, NCURSES_COLOR_T *pref,
NCURSES_COLOR_T def)
{
if(!val) {
@ -144,7 +144,7 @@ _set_colour(gchar *val, NCURSES_COLOR_T *pref,
if (col == -99) {
*pref = def;
} else {
*pref = col;
*pref = col;
}
}
}
@ -160,34 +160,34 @@ _load_colours(void)
gchar *online_val = g_key_file_get_string(prefs, "colours", "online", NULL);
_set_colour(online_val, &colour_prefs.online, COLOR_GREEN);
gchar *away_val = g_key_file_get_string(prefs, "colours", "away", NULL);
_set_colour(away_val, &colour_prefs.away, COLOR_GREEN);
gchar *chat_val = g_key_file_get_string(prefs, "colours", "chat", NULL);
_set_colour(chat_val, &colour_prefs.chat, COLOR_GREEN);
gchar *dnd_val = g_key_file_get_string(prefs, "colours", "dnd", NULL);
_set_colour(dnd_val, &colour_prefs.dnd, COLOR_GREEN);
gchar *xa_val = g_key_file_get_string(prefs, "colours", "xa", NULL);
_set_colour(xa_val, &colour_prefs.xa, COLOR_GREEN);
gchar *offline_val = g_key_file_get_string(prefs, "colours", "offline", NULL);
_set_colour(offline_val, &colour_prefs.offline, COLOR_CYAN);
gchar *err_val = g_key_file_get_string(prefs, "colours", "err", NULL);
_set_colour(err_val, &colour_prefs.err, COLOR_RED);
gchar *inc_val = g_key_file_get_string(prefs, "colours", "inc", NULL);
_set_colour(inc_val, &colour_prefs.inc, COLOR_YELLOW);
gchar *bar_val = g_key_file_get_string(prefs, "colours", "bar", NULL);
_set_colour(bar_val, &colour_prefs.bar, COLOR_BLUE);
gchar *bar_draw_val = g_key_file_get_string(prefs, "colours", "bar_draw", NULL);
_set_colour(bar_draw_val, &colour_prefs.bar_draw, COLOR_CYAN);
gchar *bar_text_val = g_key_file_get_string(prefs, "colours", "bar_text", NULL);
_set_colour(bar_text_val, &colour_prefs.bar_text, COLOR_WHITE);
}
@ -299,7 +299,7 @@ void
prefs_add_login(const char *jid)
{
gsize njids;
gchar **jids =
gchar **jids =
g_key_file_get_string_list(prefs, "connections", "logins", &njids, NULL);
// no logins remembered yet
@ -308,11 +308,11 @@ prefs_add_login(const char *jid)
jids = (gchar**) g_malloc(sizeof(gchar *) * 2);
jids[0] = g_strdup(jid);
jids[1] = NULL;
g_key_file_set_string_list(prefs, "connections", "logins",
g_key_file_set_string_list(prefs, "connections", "logins",
(const gchar * const *)jids, njids);
_save_prefs();
g_strfreev(jids);
return;
} else {
gsize i;
@ -322,7 +322,7 @@ prefs_add_login(const char *jid)
return;
}
}
// jid not found, add to the list
jids = (gchar **) g_realloc(jids, (sizeof(gchar *) * (njids+2)));
jids[njids] = g_strdup(jid);
@ -359,79 +359,79 @@ _save_prefs(void)
}
NCURSES_COLOR_T
prefs_get_bkgnd()
prefs_get_bkgnd()
{
return colour_prefs.bkgnd;
}
NCURSES_COLOR_T
prefs_get_text()
prefs_get_text()
{
return colour_prefs.text;
}
NCURSES_COLOR_T
prefs_get_online()
prefs_get_online()
{
return colour_prefs.online;
}
NCURSES_COLOR_T
prefs_get_away()
prefs_get_away()
{
return colour_prefs.away;
}
NCURSES_COLOR_T
prefs_get_chat()
prefs_get_chat()
{
return colour_prefs.chat;
}
NCURSES_COLOR_T
prefs_get_dnd()
prefs_get_dnd()
{
return colour_prefs.dnd;
}
NCURSES_COLOR_T
prefs_get_xa()
prefs_get_xa()
{
return colour_prefs.xa;
}
NCURSES_COLOR_T
prefs_get_offline()
prefs_get_offline()
{
return colour_prefs.offline;
}
NCURSES_COLOR_T
prefs_get_err()
prefs_get_err()
{
return colour_prefs.err;
}
NCURSES_COLOR_T
prefs_get_inc()
prefs_get_inc()
{
return colour_prefs.inc;
}
NCURSES_COLOR_T
prefs_get_bar()
prefs_get_bar()
{
return colour_prefs.bar;
}
NCURSES_COLOR_T
prefs_get_bar_draw()
prefs_get_bar_draw()
{
return colour_prefs.bar_draw;
}
NCURSES_COLOR_T
prefs_get_bar_text()
prefs_get_bar_text()
{
return colour_prefs.bar_text;
}

View File

@ -1,8 +1,8 @@
/*
/*
* preferences.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 @@
/*
/*
* prof_autocomplete.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
@ -47,7 +47,7 @@ p_autocomplete_new(void)
}
PAutocomplete
p_obj_autocomplete_new(PStrFunc str_func, PCopyFunc copy_func,
p_obj_autocomplete_new(PStrFunc str_func, PCopyFunc copy_func,
PEqualDeepFunc equal_deep_func, GDestroyNotify free_func)
{
PAutocomplete new = malloc(sizeof(struct p_autocomplete_t));
@ -105,15 +105,15 @@ p_autocomplete_add(PAutocomplete ac, void *item)
return TRUE;
} else {
GSList *curr = ac->items;
while(curr) {
// insert
if (g_strcmp0(ac->str_func(curr->data), ac->str_func(item)) > 0) {
ac->items = g_slist_insert_before(ac->items,
curr, item);
return TRUE;
// update
} else if (g_strcmp0(ac->str_func(curr->data), ac->str_func(item)) == 0) {
// only update if data different
@ -125,7 +125,7 @@ p_autocomplete_add(PAutocomplete ac, void *item)
return FALSE;
}
}
curr = g_slist_next(curr);
}
@ -148,13 +148,13 @@ p_autocomplete_remove(PAutocomplete ac, const char * const item)
return FALSE;
} else {
GSList *curr = ac->items;
while(curr) {
if (g_strcmp0(ac->str_func(curr->data), item) == 0) {
void *current_item = curr->data;
ac->items = g_slist_remove(ac->items, curr->data);
ac->free_func(current_item);
return TRUE;
}
@ -190,14 +190,14 @@ p_autocomplete_complete(PAutocomplete ac, gchar *search_str)
// first search attempt
if (ac->last_found == NULL) {
ac->search_str =
ac->search_str =
(gchar *) malloc((strlen(search_str) + 1) * sizeof(gchar));
strcpy(ac->search_str, search_str);
found = _search_from(ac, ac->items);
return found;
// subsequent search attempt
// subsequent search attempt
} else {
// search from here+1 tp end
found = _search_from(ac, g_slist_next(ac->last_found));
@ -208,7 +208,7 @@ p_autocomplete_complete(PAutocomplete ac, gchar *search_str)
found = _search_from(ac, ac->items);
if (found != NULL)
return found;
// we found nothing, reset search
p_autocomplete_reset(ac);
return NULL;
@ -219,14 +219,14 @@ static gchar *
_search_from(PAutocomplete ac, GSList *curr)
{
while(curr) {
// match found
if (strncmp(ac->str_func(curr->data),
ac->search_str,
strlen(ac->search_str)) == 0) {
gchar *result =
gchar *result =
(gchar *) malloc((strlen(ac->str_func(curr->data)) + 1) * sizeof(gchar));
// set pointer to last found
ac->last_found = curr;
@ -242,7 +242,7 @@ _search_from(PAutocomplete ac, GSList *curr)
}
static const char *
_str_func_default(const char *orig)
_str_func_default(const char *orig)
{
return orig;
}

View File

@ -1,8 +1,8 @@
/*
/*
* prof_autocomplete.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
@ -32,7 +32,7 @@ typedef int (*PEqualFunc)(const void *o1, const void *o2);
typedef int (*PEqualDeepFunc)(const void *o1, const void *o2);
PAutocomplete p_autocomplete_new(void);
PAutocomplete p_obj_autocomplete_new(PStrFunc str_func, PCopyFunc copy_func,
PAutocomplete p_obj_autocomplete_new(PStrFunc str_func, PCopyFunc copy_func,
PEqualDeepFunc equal_deep_func, GDestroyNotify free_func);
void p_autocomplete_clear(PAutocomplete ac);
void p_autocomplete_reset(PAutocomplete ac);

View File

@ -1,8 +1,8 @@
/*
/*
* prof_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
@ -59,7 +59,7 @@ p_history_new(unsigned int size)
PHistory new_history = malloc(sizeof(struct p_history_t));
new_history->items = NULL;
new_history->max_size = size;
_reset_session(new_history);
return new_history;
@ -77,12 +77,12 @@ p_history_append(PHistory history, char *item)
_add_to_history(history, copied);
return;
}
if (!_has_session(history)) {
if (g_list_length(history->items) == history->max_size) {
_remove_first(history);
}
_add_to_history(history, copied);
} else {
@ -92,15 +92,15 @@ p_history_append(PHistory history, char *item)
if (strcmp(history->session.sess_curr->data, "") == 0) {
_remove_last_session_item(history);
}
_replace_history_with_session(history);
} else {
_remove_last_session_item(history);
char *new = strdup(history->session.sess_curr->data);
history->session.items = g_list_append(history->session.items, new);
_replace_current_with_original(history);
_replace_history_with_session(history);
}
@ -119,10 +119,10 @@ p_history_previous(PHistory history, char *item)
if (item != NULL) {
copied = strdup(item);
}
if (!_has_session(history)) {
_create_session(history);
// add the new item
history->session.items = g_list_append(history->session.items, copied);
history->session.sess_new = g_list_last(history->session.items);
@ -153,7 +153,7 @@ p_history_next(PHistory history, char *item)
_update_current_session_item(history, copied);
_session_next(history);
char *result = strdup(history->session.sess_curr->data);
return result;
}
@ -163,9 +163,9 @@ _replace_history_with_session(PHistory history)
{
g_list_free(history->items);
history->items = g_list_copy(history->session.items);
if (g_list_length(history->items) > history->max_size) {
_remove_first(history);
_remove_first(history);
}
_reset_session(history);
@ -174,7 +174,7 @@ _replace_history_with_session(PHistory history)
static gboolean
_adding_new(PHistory history)
{
return (history->session.sess_curr ==
return (history->session.sess_curr ==
g_list_last(history->session.items));
}
@ -218,7 +218,7 @@ _remove_last_session_item(PHistory history)
{
history->session.items = g_list_reverse(history->session.items);
GList *first = g_list_first(history->session.items);
history->session.items =
history->session.items =
g_list_remove(history->session.items, first->data);
history->session.items = g_list_reverse(history->session.items);
}
@ -240,12 +240,12 @@ _create_session(PHistory history)
static void
_session_previous(PHistory history)
{
history->session.sess_curr =
history->session.sess_curr =
g_list_previous(history->session.sess_curr);
if (history->session.orig_curr == NULL)
history->session.orig_curr = g_list_last(history->items);
else
history->session.orig_curr =
else
history->session.orig_curr =
g_list_previous(history->session.orig_curr);
if (history->session.sess_curr == NULL) {

View File

@ -1,8 +1,8 @@
/*
/*
* prof_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 @@
/*
/*
* profanity.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
@ -65,7 +65,7 @@ prof_run(const int disable_tls, char *log_level)
while(ch != '\n') {
gdouble elapsed = g_timer_elapsed(timer, NULL);
gint remind_period = prefs_get_remind();
// 0 means to not remind
@ -79,10 +79,10 @@ prof_run(const int disable_tls, char *log_level)
if (ch == KEY_RESIZE) {
gui_resize(ch, inp, size);
}
gui_refresh();
jabber_process_events();
inp_get_char(&ch, inp, &size);
}
@ -103,15 +103,15 @@ prof_handle_incoming_message(char *from, char *message)
{
win_show_incomming_msg(from, message);
win_page_off();
if (prefs_get_chlog()) {
char from_cpy[strlen(from) + 1];
strcpy(from_cpy, from);
char *short_from = strtok(from_cpy, "/");
const char *jid = jabber_get_jid();
chat_log_chat(jid, short_from, message, IN);
}
if (prefs_get_chlog()) {
char from_cpy[strlen(from) + 1];
strcpy(from_cpy, from);
char *short_from = strtok(from_cpy, "/");
const char *jid = jabber_get_jid();
chat_log_chat(jid, short_from, message, IN);
}
}
void
@ -189,16 +189,16 @@ prof_handle_roster(GSList *roster)
{
while (roster != NULL) {
jabber_roster_entry *entry = roster->data;
// if contact not in contact list add them as offline
if (find_contact(entry->jid) == NULL) {
contact_list_add(entry->jid, "offline", NULL);
}
roster = g_slist_next(roster);
}
g_slist_free_full(roster, (GDestroyNotify)_free_roster_entry);
g_slist_free_full(roster, (GDestroyNotify)_free_roster_entry);
}
static void
@ -220,7 +220,7 @@ _free_roster_entry(jabber_roster_entry *entry)
free(entry->jid);
}
static log_level_t
static log_level_t
_get_log_level(char *log_level)
{
if (strcmp(log_level, "DEBUG") == 0) {
@ -234,8 +234,8 @@ _get_log_level(char *log_level)
}
}
/*
* Take a line of input and process it, return TRUE if profanity is to
/*
* Take a line of input and process it, return TRUE if profanity is to
* continue, FALSE otherwise
*/
static gboolean
@ -244,7 +244,7 @@ _process_input(char *inp)
log_debug("Input recieved: %s", inp);
gboolean result = FALSE;
g_strstrip(inp);
// add line to history if something typed
if (strlen(inp) > 0) {
history_append(inp);
@ -308,8 +308,8 @@ _shutdown_init(void)
static void
_shutdown(void)
{
gui_close();
chat_log_close();
prefs_close();
log_close();
gui_close();
chat_log_close();
prefs_close();
log_close();
}

View File

@ -1,8 +1,8 @@
/*
/*
* profanity.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 @@
/*
/*
* status_bar.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
@ -86,7 +86,7 @@ status_bar_refresh(void)
g_date_time_unref(now_time);
}
void
status_bar_resize(void)
{
@ -124,7 +124,7 @@ status_bar_inactive(const int win)
int active_pos = 1 + ((win -1) * 3);
int cols = getmaxx(stdscr);
mvwaddch(status_bar, 0, cols - 29 + active_pos, ' ');
if (win == 9)
mvwaddch(status_bar, 0, cols - 29 + active_pos + 1, ' ');
@ -141,7 +141,7 @@ status_bar_active(const int win)
int active_pos = 1 + ((win -1) * 3);
int cols = getmaxx(stdscr);
wattron(status_bar, COLOUR_BAR_DRAW);
if (win < 9)
mvwprintw(status_bar, 0, cols - 29 + active_pos, "%d", win+1);
@ -161,7 +161,7 @@ status_bar_new(const int win)
int active_pos = 1 + ((win -1) * 3);
int cols = getmaxx(stdscr);
wattron(status_bar, COLOUR_BAR_TEXT);
wattron(status_bar, A_BLINK);
if (win < 9)
@ -187,7 +187,7 @@ status_bar_print_message(const char * const msg)
if (message != NULL)
free(message);
message = (char *) malloc((strlen(msg) + 1) * sizeof(char));
message = (char *) malloc((strlen(msg) + 1) * sizeof(char));
strcpy(message, msg);
mvwprintw(status_bar, 0, 9, message);
@ -201,7 +201,7 @@ status_bar_clear(void)
free(message);
message = NULL;
}
int i;
for (i = 0; i < 9; i++) {
is_active[i] = FALSE;

View File

@ -1,8 +1,8 @@
/*
/*
* tinyurl.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 @@ static size_t _data_callback(void *ptr, size_t size, size_t nmemb, void *data);
gboolean
tinyurl_valid(char *url)
{
return (g_str_has_prefix(url, "http://") ||
return (g_str_has_prefix(url, "http://") ||
g_str_has_prefix(url, "https://"));
}
@ -49,14 +49,14 @@ tinyurl_get(char *url)
g_string_append(full_url, url);
CURL *handle = curl_easy_init();
struct curl_data_t output;
struct curl_data_t output;
output.buffer = NULL;
output.size = 0;
curl_easy_setopt(handle, CURLOPT_URL, full_url->str);
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, _data_callback);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, (void *)&output);
curl_easy_perform(handle);
curl_easy_cleanup(handle);
@ -66,7 +66,7 @@ tinyurl_get(char *url)
return output.buffer;
}
static size_t
static size_t
_data_callback(void *ptr, size_t size, size_t nmemb, void *data)
{
size_t realsize = size * nmemb;
@ -79,6 +79,6 @@ _data_callback(void *ptr, size_t size, size_t nmemb, void *data)
mem->size += realsize;
mem->buffer[ mem->size ] = 0;
}
return realsize;
}

View File

@ -1,8 +1,8 @@
/*
/*
* tinyurl.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 @@
/*
/*
* title_bar.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
@ -79,7 +79,7 @@ title_bar_refresh(void)
gdouble seconds = g_timer_elapsed(typing_elapsed, NULL);
if (seconds >= 10) {
if (current_title != NULL) {
free(current_title);
}
@ -88,7 +88,7 @@ title_bar_refresh(void)
strcpy(current_title, recipient);
title_bar_draw();
dirty = TRUE;
}
}
@ -124,7 +124,7 @@ title_bar_set_recipient(char *from)
{
typing_elapsed = NULL;
recipient = from;
if (current_title != NULL) {
free(current_title);
}
@ -157,7 +157,7 @@ title_bar_set_typing(gboolean is_typing)
current_title = (char *) malloc((strlen(recipient) + 1) * sizeof(char));
strcpy(current_title, recipient);
}
dirty = TRUE;
}
@ -190,11 +190,11 @@ _title_bar_draw_status(void)
} else {
mvwprintw(title_bar, 0, cols - 13, " ..offline ");
}
wattron(title_bar, COLOUR_BAR_DRAW);
mvwaddch(title_bar, 0, cols - 2, ']');
wattroff(title_bar, COLOUR_BAR_DRAW);
dirty = TRUE;
}
@ -206,6 +206,6 @@ _title_bar_draw_title(void)
for (i = 0; i < 45; i++)
waddch(title_bar, ' ');
mvwprintw(title_bar, 0, 0, " %s", current_title);
dirty = TRUE;
}

View File

@ -1,8 +1,8 @@
/*
/*
* ui.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
@ -89,13 +89,13 @@ char *win_get_recipient(void);
void win_show_typing(const char * const from);
void win_show_incomming_msg(const char * const from, const char * const message);
void win_show_error_msg(const char * const from, const char *err_msg);
void win_show_outgoing_msg(const char * const from, const char * const to,
void win_show_outgoing_msg(const char * const from, const char * const to,
const char * const message);
void win_handle_special_keys(const int * const ch);
void win_page_off(void);
void win_contact_online(const char * const from, const char * const show,
void win_contact_online(const char * const from, const char * const show,
const char * const status);
void win_contact_offline(const char * const from, const char * const show,
void win_contact_offline(const char * const from, const char * const show,
const char * const status);
void win_disconnected(void);
void win_show(const char * const msg);

View File

@ -1,8 +1,8 @@
/*
/*
* windows.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
@ -74,21 +74,21 @@ static void _win_show_time(WINDOW *win);
static void _win_show_user(WINDOW *win, const char * const user, const int colour);
static void _win_show_message(WINDOW *win, const char * const message);
static void _win_show_error_msg(WINDOW *win, const char * const message);
static void _show_status_string(WINDOW *win, const char * const from,
const char * const show, const char * const status, const char * const pre,
static void _show_status_string(WINDOW *win, const char * const from,
const char * const show, const char * const status, const char * const pre,
const char * const default_show);
static void _cons_show_typing(const char * const short_from);
static void _cons_show_incoming_message(const char * const short_from,
static void _cons_show_incoming_message(const char * const short_from,
const int win_index);
static void _win_handle_switch(const int * const ch);
static void _win_handle_page(const int * const ch);
static void _win_resize_all(void);
static gint _win_get_unread(void);
static void _win_show_history(WINDOW *win, int win_index,
static void _win_show_history(WINDOW *win, int win_index,
const char * const contact);
#ifdef HAVE_LIBNOTIFY
static void _win_notify(const char * const message, int timeout,
static void _win_notify(const char * const message, int timeout,
const char * const category);
static void _win_notify_remind(gint unread);
static void _win_notify_message(char * short_from);
@ -103,7 +103,7 @@ gui_init(void)
cbreak();
keypad(stdscr, TRUE);
if (has_colors()) {
if (has_colors()) {
use_default_colors();
start_color();
@ -180,13 +180,13 @@ win_close_win(void)
// set it as inactive in the status bar
status_bar_inactive(_curr_prof_win);
// go back to console window
_curr_prof_win = 0;
title_bar_title();
dirty = TRUE;
// success
return 1;
} else {
@ -198,7 +198,7 @@ win_close_win(void)
int
win_in_chat(void)
{
return ((_curr_prof_win != 0) &&
return ((_curr_prof_win != 0) &&
(strcmp(_wins[_curr_prof_win].from, "") != 0));
}
@ -211,7 +211,7 @@ win_get_recipient(void)
return recipient;
}
void
void
win_show_typing(const char * const from)
{
char from_cpy[strlen(from) + 1];
@ -256,7 +256,7 @@ win_remind(void)
}
void
win_show_incomming_msg(const char * const from, const char * const message)
win_show_incomming_msg(const char * const from, const char * const message)
{
char from_cpy[strlen(from) + 1];
strcpy(from_cpy, from);
@ -267,7 +267,7 @@ win_show_incomming_msg(const char * const from, const char * const message)
win_index = _new_prof_win(short_from);
WINDOW *win = _wins[win_index].win;
// currently viewing chat window with sender
if (win_index == _curr_prof_win) {
_win_show_time(win);
@ -289,7 +289,7 @@ win_show_incomming_msg(const char * const from, const char * const message)
if (prefs_get_chlog() && prefs_get_history()) {
_win_show_history(win, win_index, short_from);
}
_win_show_time(win);
_win_show_user(win, short_from, 1);
_win_show_message(win, message);
@ -326,7 +326,7 @@ win_show_error_msg(const char * const from, const char *err_msg)
#ifdef HAVE_LIBNOTIFY
static void
_win_notify(const char * const message, int timeout,
_win_notify(const char * const message, int timeout,
const char * const category)
{
gboolean notify_initted = notify_is_initted();
@ -364,7 +364,7 @@ _win_notify_remind(gint unread)
} else {
sprintf(message, "%d unread messages", unread);
}
_win_notify(message, 5000, "Incoming message");
}
@ -373,8 +373,8 @@ _win_notify_message(char * short_from)
{
char message[strlen(short_from) + 1 + 10];
sprintf(message, "%s: message.", short_from);
_win_notify(message, 10000, "Incoming message");
_win_notify(message, 10000, "Incoming message");
}
static void
@ -382,13 +382,13 @@ _win_notify_typing(char * short_from)
{
char message[strlen(short_from) + 1 + 11];
sprintf(message, "%s: typing...", short_from);
_win_notify(message, 10000, "Incoming message");
}
#endif
void
win_show_outgoing_msg(const char * const from, const char * const to,
win_show_outgoing_msg(const char * const from, const char * const to,
const char * const message)
{
// if the contact is offline, show a message
@ -429,7 +429,7 @@ win_show(const char * const msg)
{
WINDOW *win = _wins[_curr_prof_win].win;
_win_show_time(win);
wprintw(win, "%s\n", msg);
wprintw(win, "%s\n", msg);
dirty = TRUE;
}
@ -442,12 +442,12 @@ win_bad_show(const char * const msg)
wattron(win, COLOUR_ERR);
wprintw(win, "%s\n", msg);
wattroff(win, COLOUR_ERR);
dirty = TRUE;
}
void
win_contact_online(const char * const from, const char * const show,
win_contact_online(const char * const from, const char * const show,
const char * const status)
{
_show_status_string(_cons_win, from, show, status, "++", "online");
@ -457,13 +457,13 @@ win_contact_online(const char * const from, const char * const show,
WINDOW *win = _wins[win_index].win;
_show_status_string(win, from, show, status, "++", "online");
}
if (win_index == _curr_prof_win)
dirty = TRUE;
}
void
win_contact_offline(const char * const from, const char * const show,
win_contact_offline(const char * const from, const char * const show,
const char * const status)
{
_show_status_string(_cons_win, from, show, status, "--", "offline");
@ -473,7 +473,7 @@ win_contact_offline(const char * const from, const char * const show,
WINDOW *win = _wins[win_index].win;
_show_status_string(win, from, show, status, "--", "offline");
}
if (win_index == _curr_prof_win)
dirty = TRUE;
}
@ -490,7 +490,7 @@ win_disconnected(void)
wattron(win, COLOUR_ERR);
wprintw(win, "%s\n", "Lost connection.");
wattroff(win, COLOUR_ERR);
// if current win, set dirty
if (i == _curr_prof_win) {
dirty = TRUE;
@ -505,41 +505,41 @@ cons_prefs(void)
cons_show("");
cons_show("Current preferences:");
cons_show("");
if (prefs_get_beep())
cons_show("Terminal beep : ON");
else
cons_show("Terminal beep : OFF");
cons_show("Terminal beep : OFF");
if (prefs_get_flash())
cons_show("Terminal flash : ON");
else
cons_show("Terminal flash : OFF");
cons_show("Terminal flash : OFF");
if (prefs_get_notify())
cons_show("Message notifications : ON");
else
cons_show("Message notifications : OFF");
cons_show("Message notifications : OFF");
if (prefs_get_typing())
cons_show("Typing notifications : ON");
else
cons_show("Typing notifications : OFF");
cons_show("Typing notifications : OFF");
if (prefs_get_showsplash())
cons_show("Splash screen : ON");
else
cons_show("Splash screen : OFF");
cons_show("Splash screen : OFF");
if (prefs_get_chlog())
cons_show("Chat logging : ON");
else
cons_show("Chat logging : OFF");
cons_show("Chat logging : OFF");
if (prefs_get_history())
cons_show("Chat history : ON");
else
cons_show("Chat history : OFF");
cons_show("Chat history : OFF");
gint remind_period = prefs_get_remind();
if (remind_period == 0) {
@ -621,8 +621,8 @@ cons_show_contacts(GSList *list)
while(curr) {
PContact contact = curr->data;
const char *show = p_contact_show(contact);
const char *show = p_contact_show(contact);
_win_show_time(_cons_win);
if (strcmp(show, "online") == 0) {
@ -641,10 +641,10 @@ cons_show_contacts(GSList *list)
wprintw(_cons_win, "%s", p_contact_name(contact));
wprintw(_cons_win, " is %s", show);
if (p_contact_status(contact))
wprintw(_cons_win, ", \"%s\"", p_contact_status(contact));
wprintw(_cons_win, "\n");
if (strcmp(show, "online") == 0) {
@ -672,7 +672,7 @@ cons_bad_show(const char * const msg)
wattron(_cons_win, COLOUR_ERR);
wprintw(_cons_win, "%s\n", msg);
wattroff(_cons_win, COLOUR_ERR);
if (_curr_prof_win == 0)
dirty = TRUE;
}
@ -685,10 +685,10 @@ cons_show(const char * const msg, ...)
GString *fmt_msg = g_string_new(NULL);
g_string_vprintf(fmt_msg, msg, arg);
_win_show_time(_cons_win);
wprintw(_cons_win, "%s\n", fmt_msg->str);
wprintw(_cons_win, "%s\n", fmt_msg->str);
g_string_free(fmt_msg, TRUE);
va_end(arg);
if (_curr_prof_win == 0)
dirty = TRUE;
}
@ -698,7 +698,7 @@ cons_bad_command(const char * const cmd)
{
_win_show_time(_cons_win);
wprintw(_cons_win, "Unknown command: %s\n", cmd);
if (_curr_prof_win == 0)
dirty = TRUE;
}
@ -715,7 +715,7 @@ win_page_off(void)
{
int rows = getmaxy(stdscr);
_wins[_curr_prof_win].paged = 0;
int y = getcury(_wins[_curr_prof_win].win);
int size = rows - 3;
@ -747,7 +747,7 @@ _create_windows(void)
_wins[0] = cons;
_cons_win = _wins[0].win;
if (prefs_get_showsplash()) {
_cons_splash_logo();
} else {
@ -771,11 +771,11 @@ _create_windows(void)
wprintw(_cons_win, "Type '/help' to show complete help.\n");
_win_show_time(_cons_win);
wprintw(_cons_win, "\n");
prefresh(_cons_win, 0, 0, 1, 0, rows-3, cols-1);
dirty = TRUE;
// create the chat windows
int i;
for (i = 1; i < NUM_WINS; i++) {
@ -789,7 +789,7 @@ _create_windows(void)
chat.history_shown = 0;
scrollok(chat.win, TRUE);
_wins[i] = chat;
}
}
}
static void
@ -875,7 +875,7 @@ _win_switch_if_active(const int i)
if (strcmp(_wins[i].from, "") != 0) {
_curr_prof_win = i;
win_page_off();
_wins[i].unread = 0;
if (i == 0) {
@ -893,7 +893,7 @@ _win_switch_if_active(const int i)
static void
_win_show_time(WINDOW *win)
{
GDateTime *time = g_date_time_new_now_local();
GDateTime *time = g_date_time_new_now_local();
gchar *date_fmt = g_date_time_format(time, "%H:%M:%S");
wprintw(win, "%s - ", date_fmt);
g_date_time_unref(time);
@ -953,18 +953,18 @@ _win_resize_all(void)
wresize(_wins[i].win, PAD_SIZE, cols);
}
}
WINDOW *current = _wins[_curr_prof_win].win;
prefresh(current, _wins[_curr_prof_win].y_pos, 0, 1, 0, rows-3, cols-1);
}
static void
_show_status_string(WINDOW *win, const char * const from,
const char * const show, const char * const status, const char * const pre,
_show_status_string(WINDOW *win, const char * const from,
const char * const show, const char * const status, const char * const pre,
const char * const default_show)
{
_win_show_time(win);
_win_show_time(win);
if (show != NULL) {
if (strcmp(show, "away") == 0) {
wattron(win, COLOUR_AWAY);
@ -987,17 +987,17 @@ _show_status_string(WINDOW *win, const char * const from,
wprintw(win, "%s %s", pre, from);
if (show != NULL)
if (show != NULL)
wprintw(win, " is %s", show);
else
wprintw(win, " is %s", default_show);
if (status != NULL)
wprintw(win, ", \"%s\"", status);
wprintw(win, "\n");
if (show != NULL) {
if (show != NULL) {
if (strcmp(show, "away") == 0) {
wattroff(win, COLOUR_AWAY);
} else if (strcmp(show, "chat") == 0) {
@ -1070,15 +1070,15 @@ _win_handle_page(const int * const ch)
int page_space = rows - 4;
int *page_start = &_wins[_curr_prof_win].y_pos;
// page up
if (*ch == KEY_PPAGE) {
*page_start -= page_space;
// went past beginning, show first page
if (*page_start < 0)
*page_start = 0;
_wins[_curr_prof_win].paged = 1;
dirty = TRUE;
@ -1093,7 +1093,7 @@ _win_handle_page(const int * const ch)
// went past end, show full screen
else if (*page_start >= y)
*page_start = y - page_space;
_wins[_curr_prof_win].paged = 1;
dirty = TRUE;
}

View File

@ -59,10 +59,10 @@ static void first_and_second_elements_correct(void)
contact_list_add("James", NULL, NULL);
contact_list_add("Dave", NULL, NULL);
GSList *list = get_contact_list();
PContact dave = list->data;
PContact james = (g_slist_next(list))->data;
assert_string_equals("James", p_contact_name(james));
assert_string_equals("Dave", p_contact_name(dave));
}
@ -73,7 +73,7 @@ static void contains_three_elements(void)
contact_list_add("Bob", NULL, NULL);
contact_list_add("Dave", NULL, NULL);
GSList *list = get_contact_list();
assert_int_equals(3, g_slist_length(list));
}
@ -86,7 +86,7 @@ static void first_three_elements_correct(void)
PContact bob = list->data;
PContact dave = (g_slist_next(list))->data;
PContact james = (g_slist_next(g_slist_next(list)))->data;
assert_string_equals("James", p_contact_name(james));
assert_string_equals("Dave", p_contact_name(dave));
assert_string_equals("Bob", p_contact_name(bob));
@ -102,8 +102,8 @@ static void add_twice_at_beginning_adds_once(void)
PContact bob = list->data;
PContact dave = (g_slist_next(list))->data;
PContact james = (g_slist_next(g_slist_next(list)))->data;
assert_int_equals(3, g_slist_length(list));
assert_int_equals(3, g_slist_length(list));
assert_string_equals("James", p_contact_name(james));
assert_string_equals("Dave", p_contact_name(dave));
assert_string_equals("Bob", p_contact_name(bob));
@ -119,8 +119,8 @@ static void add_twice_in_middle_adds_once(void)
PContact bob = list->data;
PContact dave = (g_slist_next(list))->data;
PContact james = (g_slist_next(g_slist_next(list)))->data;
assert_int_equals(3, g_slist_length(list));
assert_int_equals(3, g_slist_length(list));
assert_string_equals("James", p_contact_name(james));
assert_string_equals("Dave", p_contact_name(dave));
assert_string_equals("Bob", p_contact_name(bob));
@ -136,8 +136,8 @@ static void add_twice_at_end_adds_once(void)
PContact bob = list->data;
PContact dave = (g_slist_next(list))->data;
PContact james = (g_slist_next(g_slist_next(list)))->data;
assert_int_equals(3, g_slist_length(list));
assert_int_equals(3, g_slist_length(list));
assert_string_equals("James", p_contact_name(james));
assert_string_equals("Dave", p_contact_name(dave));
assert_string_equals("Bob", p_contact_name(bob));
@ -156,7 +156,7 @@ static void remove_when_one_removes(void)
contact_list_add("James", NULL, NULL);
contact_list_remove("James");
GSList *list = get_contact_list();
assert_int_equals(0, g_slist_length(list));
}
@ -167,7 +167,7 @@ static void remove_first_when_two(void)
contact_list_remove("James");
GSList *list = get_contact_list();
assert_int_equals(1, g_slist_length(list));
PContact dave = list->data;
assert_string_equals("Dave", p_contact_name(dave));
@ -180,7 +180,7 @@ static void remove_second_when_two(void)
contact_list_remove("Dave");
GSList *list = get_contact_list();
assert_int_equals(1, g_slist_length(list));
PContact james = list->data;
assert_string_equals("James", p_contact_name(james));
@ -194,11 +194,11 @@ static void remove_first_when_three(void)
contact_list_remove("James");
GSList *list = get_contact_list();
assert_int_equals(2, g_slist_length(list));
PContact bob = list->data;
PContact dave = (g_slist_next(list))->data;
assert_string_equals("Dave", p_contact_name(dave));
assert_string_equals("Bob", p_contact_name(bob));
}
@ -211,11 +211,11 @@ static void remove_second_when_three(void)
contact_list_remove("Dave");
GSList *list = get_contact_list();
assert_int_equals(2, g_slist_length(list));
PContact bob = list->data;
PContact james = (g_slist_next(list))->data;
assert_string_equals("James", p_contact_name(james));
assert_string_equals("Bob", p_contact_name(bob));
}
@ -228,11 +228,11 @@ static void remove_third_when_three(void)
contact_list_remove("Bob");
GSList *list = get_contact_list();
assert_int_equals(2, g_slist_length(list));
PContact dave = list->data;
PContact james = (g_slist_next(list))->data;
assert_string_equals("James", p_contact_name(james));
assert_string_equals("Dave", p_contact_name(dave));
}
@ -242,7 +242,7 @@ static void test_show_when_value(void)
contact_list_add("James", "away", NULL);
GSList *list = get_contact_list();
PContact james = list->data;
assert_string_equals("away", p_contact_show(james));
}
@ -251,7 +251,7 @@ static void test_show_online_when_no_value(void)
contact_list_add("James", NULL, NULL);
GSList *list = get_contact_list();
PContact james = list->data;
assert_string_equals("online", p_contact_show(james));
}
@ -260,7 +260,7 @@ static void test_show_online_when_empty_string(void)
contact_list_add("James", "", NULL);
GSList *list = get_contact_list();
PContact james = list->data;
assert_string_equals("online", p_contact_show(james));
}
@ -269,7 +269,7 @@ static void test_status_when_value(void)
contact_list_add("James", NULL, "I'm not here right now");
GSList *list = get_contact_list();
PContact james = list->data;
assert_string_equals("I'm not here right now", p_contact_status(james));
}
@ -278,7 +278,7 @@ static void test_status_when_no_value(void)
contact_list_add("James", NULL, NULL);
GSList *list = get_contact_list();
PContact james = list->data;
assert_is_null(p_contact_status(james));
}

View File

@ -15,7 +15,7 @@ static void clear_empty(void)
static void clear_empty_with_free_func(void)
{
PAutocomplete ac =
PAutocomplete ac =
p_obj_autocomplete_new((PStrFunc)p_contact_name,
(PCopyFunc)p_contact_copy,
(PEqualDeepFunc)p_contacts_equal_deep,
@ -49,7 +49,7 @@ static void get_after_create_returns_null(void)
static void get_after_create_with_copy_func_returns_null(void)
{
PAutocomplete ac =
PAutocomplete ac =
p_obj_autocomplete_new((PStrFunc)p_contact_name,
(PCopyFunc)p_contact_copy,
(PEqualDeepFunc)p_contacts_equal_deep,
@ -57,7 +57,7 @@ static void get_after_create_with_copy_func_returns_null(void)
GSList *result = p_autocomplete_get_list(ac);
assert_is_null(result);
p_autocomplete_clear(ac);
}
@ -76,7 +76,7 @@ static void add_one_and_complete(void)
static void add_one_and_complete_with_funcs(void)
{
PContact contact = p_contact_new("James", "Online", "I'm here");
PAutocomplete ac =
PAutocomplete ac =
p_obj_autocomplete_new((PStrFunc)p_contact_name,
(PCopyFunc)p_contact_copy,
(PEqualDeepFunc)p_contacts_equal_deep,
@ -85,7 +85,7 @@ static void add_one_and_complete_with_funcs(void)
char *result = p_autocomplete_complete(ac, "Jam");
assert_string_equals("James", result);
p_autocomplete_clear(ac);
}
@ -99,7 +99,7 @@ static void add_two_and_complete_returns_first(void)
char *result = p_autocomplete_complete(ac, "Hel");
assert_string_equals("Hello", result);
p_autocomplete_clear(ac);
}
@ -107,7 +107,7 @@ static void add_two_and_complete_returns_first_with_funcs(void)
{
PContact contact1 = p_contact_new("James", "Online", "I'm here");
PContact contact2 = p_contact_new("Jamie", "Away", "Out to lunch");
PAutocomplete ac =
PAutocomplete ac =
p_obj_autocomplete_new((PStrFunc)p_contact_name,
(PCopyFunc)p_contact_copy,
(PEqualDeepFunc)p_contacts_equal_deep,
@ -117,7 +117,7 @@ static void add_two_and_complete_returns_first_with_funcs(void)
char *result = p_autocomplete_complete(ac, "Jam");
assert_string_equals("James", result);
p_autocomplete_clear(ac);
}
@ -132,7 +132,7 @@ static void add_two_and_complete_returns_second(void)
char *result2 = p_autocomplete_complete(ac, result1);
assert_string_equals("Help", result2);
p_autocomplete_clear(ac);
}
@ -140,7 +140,7 @@ static void add_two_and_complete_returns_second_with_funcs(void)
{
PContact contact1 = p_contact_new("James", "Online", "I'm here");
PContact contact2 = p_contact_new("Jamie", "Away", "Out to lunch");
PAutocomplete ac =
PAutocomplete ac =
p_obj_autocomplete_new((PStrFunc)p_contact_name,
(PCopyFunc)p_contact_copy,
(PEqualDeepFunc)p_contacts_equal_deep,
@ -151,7 +151,7 @@ static void add_two_and_complete_returns_second_with_funcs(void)
char *result2 = p_autocomplete_complete(ac, result1);
assert_string_equals("Jamie", result2);
p_autocomplete_clear(ac);
}
@ -173,7 +173,7 @@ static void add_two_adds_two_with_funcs(void)
{
PContact contact1 = p_contact_new("James", "Online", "I'm here");
PContact contact2 = p_contact_new("Jamie", "Away", "Out to lunch");
PAutocomplete ac =
PAutocomplete ac =
p_obj_autocomplete_new((PStrFunc)p_contact_name,
(PCopyFunc)p_contact_copy,
(PEqualDeepFunc)p_contacts_equal_deep,
@ -183,7 +183,7 @@ static void add_two_adds_two_with_funcs(void)
GSList *result = p_autocomplete_get_list(ac);
assert_int_equals(2, g_slist_length(result));
p_autocomplete_clear(ac);
}
@ -205,7 +205,7 @@ static void add_two_same_adds_one_with_funcs(void)
{
PContact contact1 = p_contact_new("James", "Online", "I'm here");
PContact contact2 = p_contact_new("James", "Away", "Out to lunch");
PAutocomplete ac =
PAutocomplete ac =
p_obj_autocomplete_new((PStrFunc)p_contact_name,
(PCopyFunc)p_contact_copy,
(PEqualDeepFunc)p_contacts_equal_deep,
@ -215,7 +215,7 @@ static void add_two_same_adds_one_with_funcs(void)
GSList *result = p_autocomplete_get_list(ac);
assert_int_equals(1, g_slist_length(result));
p_autocomplete_clear(ac);
}
@ -241,7 +241,7 @@ static void add_two_same_updates_with_funcs(void)
{
PContact contact1 = p_contact_new("James", "Online", "I'm here");
PContact contact2 = p_contact_new("James", "Away", "Out to lunch");
PAutocomplete ac =
PAutocomplete ac =
p_obj_autocomplete_new((PStrFunc)p_contact_name,
(PCopyFunc)p_contact_copy,
(PEqualDeepFunc)p_contacts_equal_deep,
@ -274,7 +274,7 @@ static void add_one_returns_true(void)
static void add_one_returns_true_with_funcs(void)
{
PContact contact = p_contact_new("James", "Online", "I'm here");
PAutocomplete ac =
PAutocomplete ac =
p_obj_autocomplete_new((PStrFunc)p_contact_name,
(PCopyFunc)p_contact_copy,
(PEqualDeepFunc)p_contacts_equal_deep,
@ -282,7 +282,7 @@ static void add_one_returns_true_with_funcs(void)
int result = p_autocomplete_add(ac, contact);
assert_true(result);
p_autocomplete_clear(ac);
}
@ -304,7 +304,7 @@ static void add_two_different_returns_true_with_funcs(void)
{
PContact contact1 = p_contact_new("James", "Online", "I'm here");
PContact contact2 = p_contact_new("JamesB", "Away", "Out to lunch");
PAutocomplete ac =
PAutocomplete ac =
p_obj_autocomplete_new((PStrFunc)p_contact_name,
(PCopyFunc)p_contact_copy,
(PEqualDeepFunc)p_contacts_equal_deep,
@ -336,7 +336,7 @@ static void add_two_same_returns_false_with_funcs(void)
{
PContact contact1 = p_contact_new("James", "Online", "I'm here");
PContact contact2 = p_contact_new("James", "Online", "I'm here");
PAutocomplete ac =
PAutocomplete ac =
p_obj_autocomplete_new((PStrFunc)p_contact_name,
(PCopyFunc)p_contact_copy,
(PEqualDeepFunc)p_contacts_equal_deep,
@ -354,7 +354,7 @@ static void add_two_same_different_data_returns_true(void)
{
PContact contact1 = p_contact_new("James", "Online", "I'm here");
PContact contact2 = p_contact_new("James", "Away", "I'm not here right now");
PAutocomplete ac =
PAutocomplete ac =
p_obj_autocomplete_new((PStrFunc)p_contact_name,
(PCopyFunc)p_contact_copy,
(PEqualDeepFunc)p_contacts_equal_deep,

View File

@ -67,8 +67,8 @@ void previous_goes_to_correct_element(void)
char *item1 = p_history_previous(history, NULL);
char *item2 = p_history_previous(history, item1);
char *item3 = p_history_previous(history, item2);
assert_string_equals("going", item3);
assert_string_equals("going", item3);
}
void prev_then_next_returns_empty(void)
@ -128,7 +128,7 @@ void navigate_then_append_new(void)
char *item5 = p_history_next(history, item4);
assert_string_equals("append", item5);
char *item6 = p_history_next(history, item5);
assert_string_equals("new text", item6);
}
@ -144,22 +144,22 @@ void edit_item_mid_history(void)
char *item1 = p_history_previous(history, "new item");
assert_string_equals("append", item1);
char *item2 = p_history_previous(history, item1);
assert_string_equals("history", item2);
char *item3 = p_history_previous(history, item2);
assert_string_equals("testing", item3);
char *item4 = p_history_previous(history, "EDITED");
assert_string_equals("again", item4);
assert_string_equals("again", item4);
char *item5 = p_history_previous(history, item4);
assert_string_equals("Hello", item5);
char *item6 = p_history_next(history, item5);
assert_string_equals("again", item6);
char *item7 = p_history_next(history, item6);
assert_string_equals("EDITED", item7);
@ -184,13 +184,13 @@ void edit_previous_and_append(void)
char *item1 = p_history_previous(history, "new item");
assert_string_equals("append", item1);
char *item2 = p_history_previous(history, item1);
assert_string_equals("history", item2);
char *item3 = p_history_previous(history, item2);
assert_string_equals("testing", item3);
p_history_append(history, "EDITED");
char *item4 = p_history_previous(history, NULL);
@ -204,7 +204,7 @@ void start_session_add_new_submit_previous(void)
char *item1 = p_history_previous(history, NULL);
assert_string_equals("hello", item1);
char *item2 = p_history_next(history, item1);
assert_string_equals("", item2);