1
1
mirror of https://github.com/profanity-im/profanity.git synced 2025-01-03 14:57:42 -05:00

Whitespace formatting

This commit is contained in:
James Booth 2014-07-16 22:31:25 +01:00
parent 2786b7cb26
commit 0619303abe

View File

@ -16,39 +16,47 @@
#include "ui/buffer.h" #include "ui/buffer.h"
ProfBuff* ProfBuff*
buffer_create() { buffer_create()
{
ProfBuff* new_buff = malloc(sizeof(struct prof_buff_t)); ProfBuff* new_buff = malloc(sizeof(struct prof_buff_t));
new_buff->wrap = 0; new_buff->wrap = 0;
new_buff->current = 0; new_buff->current = 0;
return new_buff; return new_buff;
} }
int buffer_size(ProfBuff* buffer) { int
buffer_size(ProfBuff* buffer)
{
if(buffer->wrap == 1) { if(buffer->wrap == 1) {
return BUFF_SIZE; return BUFF_SIZE;
} } else {
else {
return buffer->current; return buffer->current;
} }
} }
void void
buffer_free(ProfBuff* buffer) { buffer_free(ProfBuff* buffer)
{
int i = 0; int i = 0;
int imax = buffer->current; int imax = buffer->current;
if (buffer->wrap == 1) { if (buffer->wrap == 1) {
imax = BUFF_SIZE; imax = BUFF_SIZE;
} }
for (i = 0; i < imax; i++) { for (i = 0; i < imax; i++) {
free(buffer->entry[i].message); free(buffer->entry[i].message);
free(buffer->entry[i].from); free(buffer->entry[i].from);
free(buffer->entry[i].date_fmt); free(buffer->entry[i].date_fmt);
} }
free(buffer); free(buffer);
} }
void void
buffer_push(ProfBuff* buffer, const char show_char, const char * const date_fmt, int flags, int attrs, const char * const from, const char * const message) { buffer_push(ProfBuff* buffer, const char show_char, const char * const date_fmt,
int flags, int attrs, const char * const from, const char * const message)
{
int *current = &(buffer->current); int *current = &(buffer->current);
ProfBuffEntry* e = &(buffer->entry[buffer->current]); ProfBuffEntry* e = &(buffer->entry[buffer->current]);
@ -56,6 +64,7 @@ buffer_push(ProfBuff* buffer, const char show_char, const char * const date_fmt,
free(e->message); free(e->message);
free(e->from); free(e->from);
} }
e->show_char = show_char; e->show_char = show_char;
e->flags = flags; e->flags = flags;
e->attrs = attrs; e->attrs = attrs;
@ -77,33 +86,39 @@ buffer_push(ProfBuff* buffer, const char show_char, const char * const date_fmt,
} }
ProfBuffEntry ProfBuffEntry
buffer_yield_entry(ProfBuff* buffer, int entry) { buffer_yield_entry(ProfBuff* buffer, int entry)
{
return (buffer->entry)[entry]; return (buffer->entry)[entry];
if (buffer->wrap == 1) { if (buffer->wrap == 1) {
return buffer->entry[(buffer->current + entry) % BUFF_SIZE]; return buffer->entry[(buffer->current + entry) % BUFF_SIZE];
} } else {
else {
return buffer->entry[entry % (buffer->current)]; return buffer->entry[entry % (buffer->current)];
} }
} }
int int
buffer_yield(ProfBuff* buffer, int line, ProfBuffEntry** list) { buffer_yield(ProfBuff* buffer, int line, ProfBuffEntry** list)
{
//Returns the size of the (line+1)-th last line, and list contains the line //Returns the size of the (line+1)-th last line, and list contains the line
//e.g. if line == 0, returns the last line //e.g. if line == 0, returns the last line
//bug if the wrap happens in the middle of a line //bug if the wrap happens in the middle of a line
int current = buffer->current; int current = buffer->current;
int imax = current; int imax = current;
if (buffer->wrap == 1) { if (buffer->wrap == 1) {
imax = BUFF_SIZE; imax = BUFF_SIZE;
} }
int i = 1; int i = 1;
int j = 0; int j = 0;
while (i <= imax) { while (i <= imax) {
ProfBuffEntry e = buffer->entry[(current - i) % BUFF_SIZE]; ProfBuffEntry e = buffer->entry[(current - i) % BUFF_SIZE];
if (j == line && (e.flags & NO_EOL) == 0) { if (j == line && (e.flags & NO_EOL) == 0) {
//We found our line and we are at its last entry //We found our line and we are at its last entry
int nb_entries = 1; int nb_entries = 1;
while (i + nb_entries <= imax) { while (i + nb_entries <= imax) {
e = buffer->entry[(current - i - nb_entries) % BUFF_SIZE]; e = buffer->entry[(current - i - nb_entries) % BUFF_SIZE];
if ((e.flags & NO_EOL) == 0) { if ((e.flags & NO_EOL) == 0) {
@ -111,19 +126,21 @@ buffer_yield(ProfBuff* buffer, int line, ProfBuffEntry** list) {
} }
nb_entries += 1; nb_entries += 1;
} }
if ((buffer->wrap == 1) && (i + nb_entries > imax)) { if ((buffer->wrap == 1) && (i + nb_entries > imax)) {
//The line is at the top of the buffer, we don't know if it's complete //The line is at the top of the buffer, we don't know if it's complete
return 0; return 0;
} } else {
else {
*list = &(buffer->entry[(current - i - nb_entries + 1) % BUFF_SIZE]); *list = &(buffer->entry[(current - i - nb_entries + 1) % BUFF_SIZE]);
return nb_entries; return nb_entries;
} }
} }
if ((e.flags & NO_EOL) == 0) { if ((e.flags & NO_EOL) == 0) {
j++; j++;
} }
i++; i++;
} }
return 0; return 0;
} }