From b11b88243111a10747d0ba64f05c126abb7a4157 Mon Sep 17 00:00:00 2001 From: James Booth Date: Mon, 27 Feb 2012 01:44:09 +0000 Subject: [PATCH] Renamed input buffer to history --- Makefile | 8 +++---- command.c | 4 ++-- input_buffer.c => history.c | 48 ++++++++++++++++++------------------- input_buffer.h => history.h | 14 +++++------ input_win.c | 6 ++--- profanity.c | 4 ++-- 6 files changed, 42 insertions(+), 42 deletions(-) rename input_buffer.c => history.c (56%) rename input_buffer.h => history.h (81%) diff --git a/Makefile b/Makefile index 5b73ac8f..3b43cdea 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ WARNS = -Werror -Wall -Wextra -Wno-unused-parameter -Wno-unused-but-set-variable LIBS = -lxml2 -lexpat -lssl -lresolv -lncurses -L ~/lib -lstrophe CFLAGS = -I ~/include -O3 $(WARNS) $(LIBS) OBJS = log.o windows.o title_bar.o status_bar.o input_win.o jabber.o \ - profanity.o util.o command.o input_buffer.o main.o + profanity.o util.o command.o history.o main.o profanity: $(OBJS) $(CC) -o profanity $(OBJS) $(LIBS) @@ -14,10 +14,10 @@ title_bar.o: windows.h status_bar.o: windows.h util.h input_win.o: windows.h jabber.o: jabber.h log.h windows.h -profanity.o: log.h windows.h jabber.h command.h input_buffer.h +profanity.o: log.h windows.h jabber.h command.h history.h util.o: util.h -command.o: command.h util.h input_buffer.h -input_buffer.o: input_buffer.h +command.o: command.h util.h history.h +history.o: history.h main.o: log.h windows.h profanity.h .PHONY: clean diff --git a/command.c b/command.c index 1b1368aa..c5ef816c 100644 --- a/command.c +++ b/command.c @@ -24,7 +24,7 @@ #include #include #include "command.h" -#include "input_buffer.h" +#include "history.h" #include "jabber.h" #include "windows.h" #include "util.h" @@ -43,7 +43,7 @@ int process_input(char *inp) int result = FALSE; if (strlen(inp) > 0) - inpbuf_append(inp); + history_append(inp); if (strlen(inp) == 0) { result = TRUE; diff --git a/input_buffer.c b/history.c similarity index 56% rename from input_buffer.c rename to history.c index 0e659ad3..d47b5d07 100644 --- a/input_buffer.c +++ b/history.c @@ -1,5 +1,5 @@ /* - * input_buffer.c + * history.c * * Copyright (C) 2012 James Booth * @@ -22,48 +22,48 @@ #include -#define BUFMAX 100 +#define MAX_HISTORY 100 -static char *_inp_buf[BUFMAX]; -static int _buf_size; -static int _buf_pos; +static char *_history[MAX_HISTORY]; +static int _size; +static int _pos; -void inpbuf_init(void) +void history_init(void) { - _buf_size = 0; - _buf_pos = -1; + _size = 0; + _pos = -1; } -void inpbuf_append(char *inp) +void history_append(char *inp) { - if (_buf_size < BUFMAX) { - _inp_buf[_buf_size] = (char*) malloc(strlen(inp) * sizeof(char)); - strcpy(_inp_buf[_buf_size], inp); - _buf_pos = _buf_size; - _buf_size++; + if (_size < MAX_HISTORY) { + _history[_size] = (char*) malloc(strlen(inp) * sizeof(char)); + strcpy(_history[_size], inp); + _pos = _size; + _size++; } } -char *inpbuf_previous(void) +char *history_previous(void) { - if (_buf_size == 0 || _buf_pos == -1) + if (_size == 0 || _pos == -1) return NULL; - return _inp_buf[_buf_pos--]; + return _history[_pos--]; } -char *inpbuf_next(void) +char *history_next(void) { - if (_buf_size == 0) + if (_size == 0) return NULL; - if (_buf_pos == (_buf_size - 1)) + if (_pos == (_size - 1)) return NULL; - if (_buf_pos + 2 >= _buf_size) + if (_pos + 2 >= _size) return NULL; - int pos = _buf_pos + 2; - _buf_pos++; + int pos = _pos + 2; + _pos++; - return _inp_buf[pos]; + return _history[pos]; } diff --git a/input_buffer.h b/history.h similarity index 81% rename from input_buffer.h rename to history.h index c4384220..b96a728e 100644 --- a/input_buffer.h +++ b/history.h @@ -1,5 +1,5 @@ /* - * input_buffer.h + * history.h * * Copyright (C) 2012 James Booth * @@ -21,12 +21,12 @@ */ -#ifndef INPUT_BUFFER_H -#define INPUT_BUFFER_H +#ifndef HISTORY_H +#define HISTORY_H -void inpbuf_init(void); -void inpbuf_append(char *inp); -char *inpbuf_previous(void); -char *inpbuf_next(void); +void history_init(void); +void history_append(char *inp); +char *history_previous(void); +char *history_next(void); #endif diff --git a/input_win.c b/input_win.c index 91d98caa..84bde9be 100644 --- a/input_win.c +++ b/input_win.c @@ -23,7 +23,7 @@ #include #include #include "windows.h" -#include "input_buffer.h" +#include "history.h" static WINDOW *inp_win; @@ -125,7 +125,7 @@ void inp_poll_char(int *ch, char *input, int *size) // up arrow } else if (*ch == KEY_UP) { - char *prev = inpbuf_previous(); + char *prev = history_previous(); if (prev) { strcpy(input, prev); *size = strlen(input); @@ -137,7 +137,7 @@ void inp_poll_char(int *ch, char *input, int *size) // down arrow } else if (*ch == KEY_DOWN) { - char *next = inpbuf_next(); + char *next = history_next(); if (next) { strcpy(input, next); *size = strlen(input); diff --git a/profanity.c b/profanity.c index d9fbd257..6431ea2e 100644 --- a/profanity.c +++ b/profanity.c @@ -30,7 +30,7 @@ #include "windows.h" #include "jabber.h" #include "command.h" -#include "input_buffer.h" +#include "history.h" static void _profanity_event_loop(int *ch, char *cmd, int *size); static void _process_special_keys(int *ch); @@ -38,7 +38,7 @@ static void _process_special_keys(int *ch); static void profanity_init(int disable_tls) { jabber_init(disable_tls); - inpbuf_init(); + history_init(); } void profanity_main(int disable_tls)