mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Renamed input buffer to history
This commit is contained in:
parent
8f48685930
commit
b11b882431
8
Makefile
8
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
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <ncurses.h>
|
||||
#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;
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* input_buffer.c
|
||||
* history.c
|
||||
*
|
||||
* Copyright (C) 2012 James Booth <boothj5@gmail.com>
|
||||
*
|
||||
@ -22,48 +22,48 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#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];
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* input_buffer.h
|
||||
* history.h
|
||||
*
|
||||
* Copyright (C) 2012 James Booth <boothj5@gmail.com>
|
||||
*
|
||||
@ -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
|
@ -23,7 +23,7 @@
|
||||
#include <string.h>
|
||||
#include <ncurses.h>
|
||||
#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);
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user