mirror of
https://github.com/profanity-im/profanity.git
synced 2024-09-01 19:24:15 -04:00
Renamed history modules
This commit is contained in:
parent
80e62cfa5f
commit
c72d7ad6a6
@ -4,8 +4,8 @@ profanity_SOURCES = src/command.c src/contact.c src/command_history.c src/xmpp.h
|
||||
src/command.h src/contact.h src/log.c src/preferences.h \
|
||||
src/autocomplete.h src/ui_titlebar.c src/ui_windows.c src/common.c \
|
||||
src/contact_list.c src/ui_inputwin.c src/log.h src/profanity.c \
|
||||
src/prof_history.c src/ui.h src/common.h src/ contact_list.h src/xmpp_conn.c \
|
||||
src/main.c src/profanity.h src/prof_history.h src/chat_log.c \
|
||||
src/history.c src/ui.h src/common.h src/ contact_list.h src/xmpp_conn.c \
|
||||
src/main.c src/profanity.h src/history.h src/chat_log.c \
|
||||
src/chat_log.h src/tinyurl.c src/tinyurl.h src/chat_session.c \
|
||||
src/chat_session.h src/release.c src/release.h src/muc.c \
|
||||
src/muc.h src/xmpp_stanza.c src/parser.c src/parser.h \
|
||||
@ -16,7 +16,7 @@ profanity_SOURCES = src/command.c src/contact.c src/command_history.c src/xmpp.h
|
||||
TESTS = tests/testsuite
|
||||
check_PROGRAMS = tests/testsuite
|
||||
tests_testsuite_SOURCES = tests/test_contact_list.c src/contact_list.c src/contact.c \
|
||||
tests/test_common.c tests/test_prof_history.c src/prof_history.c src/common.c \
|
||||
tests/test_common.c tests/test_history.c src/history.c src/common.c \
|
||||
tests/test_autocomplete.c src/autocomplete.c tests/testsuite.c \
|
||||
tests/test_parser.c src/parser.c tests/test_jid.c src/jid.c
|
||||
tests_testsuite_LDADD = -lheadunit -lstdc++
|
||||
|
@ -743,7 +743,7 @@ cmd_init(void)
|
||||
autocomplete_add(who_ac, strdup("available"));
|
||||
autocomplete_add(who_ac, strdup("unavailable"));
|
||||
|
||||
history_init();
|
||||
cmd_history_init();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -45,9 +45,9 @@ GSList * cmd_get_basic_help(void);
|
||||
GSList * cmd_get_settings_help(void);
|
||||
GSList * cmd_get_presence_help(void);
|
||||
|
||||
void history_init(void);
|
||||
void history_append(char *inp);
|
||||
char *history_previous(char *inp, int *size);
|
||||
char *history_next(char *inp, int *size);
|
||||
void cmd_history_init(void);
|
||||
void cmd_history_append(char *inp);
|
||||
char *cmd_history_previous(char *inp, int *size);
|
||||
char *cmd_history_next(char *inp, int *size);
|
||||
|
||||
#endif
|
||||
|
@ -20,42 +20,42 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "prof_history.h"
|
||||
#include "history.h"
|
||||
|
||||
#define MAX_HISTORY 100
|
||||
|
||||
static PHistory history;
|
||||
static History history;
|
||||
|
||||
void _stringify_input(char *inp, int size, char *string);
|
||||
|
||||
void
|
||||
history_init(void)
|
||||
cmd_history_init(void)
|
||||
{
|
||||
history = p_history_new(MAX_HISTORY);
|
||||
history = history_new(MAX_HISTORY);
|
||||
}
|
||||
|
||||
void
|
||||
history_append(char *inp)
|
||||
cmd_history_append(char *inp)
|
||||
{
|
||||
p_history_append(history, inp);
|
||||
history_append(history, inp);
|
||||
}
|
||||
|
||||
char *
|
||||
history_previous(char *inp, int *size)
|
||||
cmd_history_previous(char *inp, int *size)
|
||||
{
|
||||
char inp_str[*size + 1];
|
||||
_stringify_input(inp, *size, inp_str);
|
||||
|
||||
return p_history_previous(history, inp_str);
|
||||
return history_previous(history, inp_str);
|
||||
}
|
||||
|
||||
char *
|
||||
history_next(char *inp, int *size)
|
||||
cmd_history_next(char *inp, int *size)
|
||||
{
|
||||
char inp_str[*size + 1];
|
||||
_stringify_input(inp, *size, inp_str);
|
||||
|
||||
return p_history_next(history, inp_str);
|
||||
return history_next(history, inp_str);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* prof_history.c
|
||||
* history.c
|
||||
*
|
||||
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
|
||||
*
|
||||
@ -25,38 +25,38 @@
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "prof_history.h"
|
||||
#include "history.h"
|
||||
|
||||
struct p_history_session_t {
|
||||
struct history_session_t {
|
||||
GList *items;
|
||||
GList *sess_curr;
|
||||
GList *sess_new;
|
||||
GList *orig_curr;
|
||||
};
|
||||
|
||||
struct p_history_t {
|
||||
struct history_t {
|
||||
GList *items;
|
||||
guint max_size;
|
||||
struct p_history_session_t session;
|
||||
struct history_session_t session;
|
||||
};
|
||||
|
||||
static void _replace_history_with_session(PHistory history);
|
||||
static gboolean _adding_new(PHistory history);
|
||||
static void _reset_session(PHistory history);
|
||||
static gboolean _has_session(PHistory history);
|
||||
static void _remove_first(PHistory history);
|
||||
static void _update_current_session_item(PHistory history, char *item);
|
||||
static void _add_to_history(PHistory history, char *item);
|
||||
static void _remove_last_session_item(PHistory history);
|
||||
static void _replace_current_with_original(PHistory history);
|
||||
static void _create_session(PHistory history);
|
||||
static void _session_previous(PHistory history);
|
||||
static void _session_next(PHistory history);
|
||||
static void _replace_history_with_session(History history);
|
||||
static gboolean _adding_new(History history);
|
||||
static void _reset_session(History history);
|
||||
static gboolean _has_session(History history);
|
||||
static void _remove_first(History history);
|
||||
static void _update_current_session_item(History history, char *item);
|
||||
static void _add_to_history(History history, char *item);
|
||||
static void _remove_last_session_item(History history);
|
||||
static void _replace_current_with_original(History history);
|
||||
static void _create_session(History history);
|
||||
static void _session_previous(History history);
|
||||
static void _session_next(History history);
|
||||
|
||||
PHistory
|
||||
p_history_new(unsigned int size)
|
||||
History
|
||||
history_new(unsigned int size)
|
||||
{
|
||||
PHistory new_history = malloc(sizeof(struct p_history_t));
|
||||
History new_history = malloc(sizeof(struct history_t));
|
||||
new_history->items = NULL;
|
||||
new_history->max_size = size;
|
||||
|
||||
@ -66,7 +66,7 @@ p_history_new(unsigned int size)
|
||||
}
|
||||
|
||||
void
|
||||
p_history_append(PHistory history, char *item)
|
||||
history_append(History history, char *item)
|
||||
{
|
||||
char *copied = "";
|
||||
if (item != NULL) {
|
||||
@ -108,7 +108,7 @@ p_history_append(PHistory history, char *item)
|
||||
}
|
||||
|
||||
char *
|
||||
p_history_previous(PHistory history, char *item)
|
||||
history_previous(History history, char *item)
|
||||
{
|
||||
// no history
|
||||
if (history->items == NULL) {
|
||||
@ -139,7 +139,7 @@ p_history_previous(PHistory history, char *item)
|
||||
}
|
||||
|
||||
char *
|
||||
p_history_next(PHistory history, char *item)
|
||||
history_next(History history, char *item)
|
||||
{
|
||||
// no history, or no session, return NULL
|
||||
if ((history->items == NULL) || (history->session.items == NULL)) {
|
||||
@ -159,7 +159,7 @@ p_history_next(PHistory history, char *item)
|
||||
}
|
||||
|
||||
static void
|
||||
_replace_history_with_session(PHistory history)
|
||||
_replace_history_with_session(History history)
|
||||
{
|
||||
g_list_free(history->items);
|
||||
history->items = g_list_copy(history->session.items);
|
||||
@ -172,14 +172,14 @@ _replace_history_with_session(PHistory history)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_adding_new(PHistory history)
|
||||
_adding_new(History history)
|
||||
{
|
||||
return (history->session.sess_curr ==
|
||||
g_list_last(history->session.items));
|
||||
}
|
||||
|
||||
static void
|
||||
_reset_session(PHistory history)
|
||||
_reset_session(History history)
|
||||
{
|
||||
history->session.items = NULL;
|
||||
history->session.sess_curr = NULL;
|
||||
@ -188,13 +188,13 @@ _reset_session(PHistory history)
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_has_session(PHistory history)
|
||||
_has_session(History history)
|
||||
{
|
||||
return (history->session.items != NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
_remove_first(PHistory history)
|
||||
_remove_first(History history)
|
||||
{
|
||||
GList *first = g_list_first(history->items);
|
||||
char *first_item = first->data;
|
||||
@ -202,19 +202,19 @@ _remove_first(PHistory history)
|
||||
}
|
||||
|
||||
static void
|
||||
_update_current_session_item(PHistory history, char *item)
|
||||
_update_current_session_item(History history, char *item)
|
||||
{
|
||||
history->session.sess_curr->data = item;
|
||||
}
|
||||
|
||||
static void
|
||||
_add_to_history(PHistory history, char *item)
|
||||
_add_to_history(History history, char *item)
|
||||
{
|
||||
history->items = g_list_append(history->items, item);
|
||||
}
|
||||
|
||||
static void
|
||||
_remove_last_session_item(PHistory history)
|
||||
_remove_last_session_item(History history)
|
||||
{
|
||||
history->session.items = g_list_reverse(history->session.items);
|
||||
GList *first = g_list_first(history->session.items);
|
||||
@ -224,13 +224,13 @@ _remove_last_session_item(PHistory history)
|
||||
}
|
||||
|
||||
static void
|
||||
_replace_current_with_original(PHistory history)
|
||||
_replace_current_with_original(History history)
|
||||
{
|
||||
history->session.sess_curr->data = strdup(history->session.orig_curr->data);
|
||||
}
|
||||
|
||||
static void
|
||||
_create_session(PHistory history)
|
||||
_create_session(History history)
|
||||
{
|
||||
history->session.items = g_list_copy(history->items);
|
||||
history->session.sess_curr = g_list_last(history->session.items);
|
||||
@ -238,7 +238,7 @@ _create_session(PHistory history)
|
||||
}
|
||||
|
||||
static void
|
||||
_session_previous(PHistory history)
|
||||
_session_previous(History history)
|
||||
{
|
||||
history->session.sess_curr =
|
||||
g_list_previous(history->session.sess_curr);
|
||||
@ -255,7 +255,7 @@ _session_previous(PHistory history)
|
||||
}
|
||||
|
||||
static void
|
||||
_session_next(PHistory history)
|
||||
_session_next(History history)
|
||||
{
|
||||
history->session.sess_curr = g_list_next(history->session.sess_curr);
|
||||
history->session.orig_curr = g_list_next(history->session.orig_curr);
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* prof_history.h
|
||||
* history.h
|
||||
*
|
||||
* Copyright (C) 2012, 2013 James Booth <boothj5@gmail.com>
|
||||
*
|
||||
@ -20,14 +20,14 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PROF_HISTORY_H
|
||||
#define PROF_HISTORY_H
|
||||
#ifndef HISTORY_H
|
||||
#define HISTORY_H
|
||||
|
||||
typedef struct p_history_t *PHistory;
|
||||
typedef struct history_t *History;
|
||||
|
||||
PHistory p_history_new(unsigned int size);
|
||||
char * p_history_previous(PHistory history, char *item);
|
||||
char * p_history_next(PHistory history, char *item);
|
||||
void p_history_append(PHistory history, char *item);
|
||||
History history_new(unsigned int size);
|
||||
char * history_previous(History history, char *item);
|
||||
char * history_next(History history, char *item);
|
||||
void history_append(History history, char *item);
|
||||
|
||||
#endif
|
@ -432,7 +432,7 @@ _process_input(char *inp)
|
||||
|
||||
// add line to history if something typed
|
||||
if (strlen(inp) > 0) {
|
||||
history_append(inp);
|
||||
cmd_history_append(inp);
|
||||
}
|
||||
|
||||
// just carry on if no input
|
||||
|
@ -514,14 +514,14 @@ _handle_edit(int result, const wint_t ch, char *input, int *size)
|
||||
return 1;
|
||||
|
||||
case KEY_UP:
|
||||
prev = history_previous(input, size);
|
||||
prev = cmd_history_previous(input, size);
|
||||
if (prev) {
|
||||
inp_replace_input(input, prev, size);
|
||||
}
|
||||
return 1;
|
||||
|
||||
case KEY_DOWN:
|
||||
next = history_next(input, size);
|
||||
next = cmd_history_next(input, size);
|
||||
if (next) {
|
||||
inp_replace_input(input, next, size);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <head-unit.h>
|
||||
#include "prof_history.h"
|
||||
#include "history.h"
|
||||
|
||||
void previous_on_empty_returns_null(void)
|
||||
{
|
||||
@ -214,9 +214,9 @@ void start_session_add_new_submit_previous(void)
|
||||
p_history_append(history, item3);
|
||||
}
|
||||
|
||||
void register_prof_history_tests(void)
|
||||
void register_history_tests(void)
|
||||
{
|
||||
TEST_MODULE("prof_history tests");
|
||||
TEST_MODULE("history tests");
|
||||
TEST(previous_on_empty_returns_null);
|
||||
TEST(next_on_empty_returns_null);
|
||||
TEST(previous_once_returns_last);
|
@ -3,7 +3,7 @@
|
||||
|
||||
int main(void)
|
||||
{
|
||||
register_prof_history_tests();
|
||||
register_history_tests();
|
||||
register_contact_list_tests();
|
||||
register_common_tests();
|
||||
register_autocomplete_tests();
|
||||
|
@ -1,7 +1,7 @@
|
||||
#ifndef TESTSUITE_H
|
||||
#define TESTSUITE_H
|
||||
|
||||
void register_prof_history_tests(void);
|
||||
void register_history_tests(void);
|
||||
void register_contact_list_tests(void);
|
||||
void register_common_tests(void);
|
||||
void register_autocomplete_tests(void);
|
||||
|
Loading…
Reference in New Issue
Block a user