From 0619303abe8a5eba2fe4e70d0e52a06fafc6a455 Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 16 Jul 2014 22:31:25 +0100 Subject: Whitespace formatting --- src/ui/buffer.c | 207 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 112 insertions(+), 95 deletions(-) diff --git a/src/ui/buffer.c b/src/ui/buffer.c index 6fc6394f..88d7eb42 100644 --- a/src/ui/buffer.c +++ b/src/ui/buffer.c @@ -16,114 +16,131 @@ #include "ui/buffer.h" ProfBuff* -buffer_create() { - ProfBuff* new_buff = malloc(sizeof(struct prof_buff_t)); - new_buff->wrap = 0; - new_buff->current = 0; - return new_buff; +buffer_create() +{ + ProfBuff* new_buff = malloc(sizeof(struct prof_buff_t)); + new_buff->wrap = 0; + new_buff->current = 0; + return new_buff; } -int buffer_size(ProfBuff* buffer) { - if(buffer->wrap == 1) { - return BUFF_SIZE; - } - else { - return buffer->current; - } +int +buffer_size(ProfBuff* buffer) +{ + if(buffer->wrap == 1) { + return BUFF_SIZE; + } else { + return buffer->current; + } } void -buffer_free(ProfBuff* buffer) { - int i = 0; - int imax = buffer->current; - if(buffer->wrap == 1) { - imax = BUFF_SIZE; - } - for(i = 0; i < imax; i++) { - free(buffer->entry[i].message); - free(buffer->entry[i].from); - free(buffer->entry[i].date_fmt); - } - free(buffer); +buffer_free(ProfBuff* buffer) +{ + int i = 0; + int imax = buffer->current; + + if (buffer->wrap == 1) { + imax = BUFF_SIZE; + } + + for (i = 0; i < imax; i++) { + free(buffer->entry[i].message); + free(buffer->entry[i].from); + free(buffer->entry[i].date_fmt); + } + + free(buffer); } 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) { - int *current = &(buffer->current); - ProfBuffEntry* e = &(buffer->entry[buffer->current]); - - if(buffer->wrap == 1) { - free(e->message); - free(e->from); - } - e->show_char = show_char; - e->flags = flags; - e->attrs = attrs; - - e->date_fmt = malloc(strlen(date_fmt)+1); - strcpy(e->date_fmt, date_fmt); - - e->from = malloc(strlen(from)+1); - strcpy(e->from, from); - - e->message = malloc(strlen(message)+1); - strcpy(e->message, message); - - *current += 1; - if(*current >= BUFF_SIZE) { - *current = 0; - buffer->wrap = 1; - } +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); + ProfBuffEntry* e = &(buffer->entry[buffer->current]); + + if (buffer->wrap == 1) { + free(e->message); + free(e->from); + } + + e->show_char = show_char; + e->flags = flags; + e->attrs = attrs; + + e->date_fmt = malloc(strlen(date_fmt)+1); + strcpy(e->date_fmt, date_fmt); + + e->from = malloc(strlen(from)+1); + strcpy(e->from, from); + + e->message = malloc(strlen(message)+1); + strcpy(e->message, message); + + *current += 1; + if (*current >= BUFF_SIZE) { + *current = 0; + buffer->wrap = 1; + } } ProfBuffEntry -buffer_yield_entry(ProfBuff* buffer, int entry) { - return (buffer->entry)[entry]; - if(buffer->wrap == 1) { - return buffer->entry[(buffer->current + entry) % BUFF_SIZE]; - } - else { - return buffer->entry[entry % (buffer->current)]; - } +buffer_yield_entry(ProfBuff* buffer, int entry) +{ + return (buffer->entry)[entry]; + + if (buffer->wrap == 1) { + return buffer->entry[(buffer->current + entry) % BUFF_SIZE]; + } else { + return buffer->entry[entry % (buffer->current)]; + } } int -buffer_yield(ProfBuff* buffer, int line, ProfBuffEntry** list) { - //Returns the size of the (line+1)-th last line, and list contains the line - //e.g. if line == 0, returns the last line - //bug if the wrap happens in the middle of a line - int current = buffer->current; - int imax = current; - if(buffer->wrap == 1) { - imax = BUFF_SIZE; - } - int i = 1; - int j = 0; - while(i <= imax) { - ProfBuffEntry e = buffer->entry[(current - i) % BUFF_SIZE]; - if(j == line && (e.flags & NO_EOL) == 0) { - //We found our line and we are at its last entry - int nb_entries = 1; - while(i + nb_entries <= imax) { - e = buffer->entry[(current - i - nb_entries) % BUFF_SIZE]; - if((e.flags & NO_EOL) == 0) { - break; - } - nb_entries += 1; - } - 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 - return 0; - } - else { - *list = &(buffer->entry[(current - i - nb_entries + 1) % BUFF_SIZE]); - return nb_entries; - } +buffer_yield(ProfBuff* buffer, int line, ProfBuffEntry** list) +{ + //Returns the size of the (line+1)-th last line, and list contains the line + //e.g. if line == 0, returns the last line + //bug if the wrap happens in the middle of a line + int current = buffer->current; + int imax = current; + + if (buffer->wrap == 1) { + imax = BUFF_SIZE; } - if((e.flags & NO_EOL) == 0) { - j++; + + int i = 1; + int j = 0; + while (i <= imax) { + ProfBuffEntry e = buffer->entry[(current - i) % BUFF_SIZE]; + + if (j == line && (e.flags & NO_EOL) == 0) { + //We found our line and we are at its last entry + int nb_entries = 1; + + while (i + nb_entries <= imax) { + e = buffer->entry[(current - i - nb_entries) % BUFF_SIZE]; + if ((e.flags & NO_EOL) == 0) { + break; + } + nb_entries += 1; + } + + 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 + return 0; + } else { + *list = &(buffer->entry[(current - i - nb_entries + 1) % BUFF_SIZE]); + return nb_entries; + } + } + + if ((e.flags & NO_EOL) == 0) { + j++; + } + i++; } - i++; - } - return 0; -} + + return 0; +} \ No newline at end of file -- cgit 1.4.1-2-gfad0 lioat@tilde.institute> 2024-03-22 07:59:26 -0400 committer elioat <elioat@tilde.institute> 2024-03-22 07:59:26 -0400 *' href='/elioat/tour/commit/lisp/js/l.html?id=1f6f62c739b170dbfdd531bb5e4be5dca419c1c4'>1f6f62c ^
1b103d0 ^
1b103d0 ^


23f5e09 ^


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40