The buffer API should use unsigned types.
Either there are buffer entries or there are none. No need to have negative values in the API. Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
This commit is contained in:
@@ -50,7 +50,7 @@ buffer_create(void)
|
|||||||
return new_buff;
|
return new_buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
unsigned int
|
||||||
buffer_size(ProfBuff buffer)
|
buffer_size(ProfBuff buffer)
|
||||||
{
|
{
|
||||||
return g_slist_length(buffer->entries);
|
return g_slist_length(buffer->entries);
|
||||||
@@ -114,7 +114,7 @@ buffer_remove_entry_by_id(ProfBuff buffer, const char* const id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
buffer_remove_entry(ProfBuff buffer, int entry)
|
buffer_remove_entry(ProfBuff buffer, unsigned int entry)
|
||||||
{
|
{
|
||||||
GSList* node = g_slist_nth(buffer->entries, entry);
|
GSList* node = g_slist_nth(buffer->entries, entry);
|
||||||
ProfBuffEntry* e = node->data;
|
ProfBuffEntry* e = node->data;
|
||||||
@@ -142,7 +142,7 @@ buffer_mark_received(ProfBuff buffer, const char* const id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
ProfBuffEntry*
|
ProfBuffEntry*
|
||||||
buffer_get_entry(ProfBuff buffer, int entry)
|
buffer_get_entry(ProfBuff buffer, unsigned int entry)
|
||||||
{
|
{
|
||||||
GSList* node = g_slist_nth(buffer->entries, entry);
|
GSList* node = g_slist_nth(buffer->entries, entry);
|
||||||
return node->data;
|
return node->data;
|
||||||
|
|||||||
@@ -49,9 +49,9 @@ void buffer_free(ProfBuff buffer);
|
|||||||
void buffer_append(ProfBuff buffer, const char* show_char, int pad_indent, GDateTime* time, int flags, theme_item_t theme_item, const char* const display_from, const char* const barejid, const char* const message, DeliveryReceipt* receipt, const char* const id, int y_start_pos, int y_end_pos);
|
void buffer_append(ProfBuff buffer, const char* show_char, int pad_indent, GDateTime* time, int flags, theme_item_t theme_item, const char* const display_from, const char* const barejid, const char* const message, DeliveryReceipt* receipt, const char* const id, int y_start_pos, int y_end_pos);
|
||||||
void buffer_prepend(ProfBuff buffer, const char* show_char, int pad_indent, GDateTime* time, int flags, theme_item_t theme_item, const char* const display_from, const char* const barejid, const char* const message, DeliveryReceipt* receipt, const char* const id, int y_start_pos, int y_end_pos);
|
void buffer_prepend(ProfBuff buffer, const char* show_char, int pad_indent, GDateTime* time, int flags, theme_item_t theme_item, const char* const display_from, const char* const barejid, const char* const message, DeliveryReceipt* receipt, const char* const id, int y_start_pos, int y_end_pos);
|
||||||
void buffer_remove_entry_by_id(ProfBuff buffer, const char* const id);
|
void buffer_remove_entry_by_id(ProfBuff buffer, const char* const id);
|
||||||
void buffer_remove_entry(ProfBuff buffer, int entry);
|
void buffer_remove_entry(ProfBuff buffer, unsigned int entry);
|
||||||
int buffer_size(ProfBuff buffer);
|
unsigned int buffer_size(ProfBuff buffer);
|
||||||
ProfBuffEntry* buffer_get_entry(ProfBuff buffer, int entry);
|
ProfBuffEntry* buffer_get_entry(ProfBuff buffer, unsigned int entry);
|
||||||
ProfBuffEntry* buffer_get_entry_by_id(ProfBuff buffer, const char* const id);
|
ProfBuffEntry* buffer_get_entry_by_id(ProfBuff buffer, const char* const id);
|
||||||
gboolean buffer_mark_received(ProfBuff buffer, const char* const id);
|
gboolean buffer_mark_received(ProfBuff buffer, const char* const id);
|
||||||
|
|
||||||
|
|||||||
@@ -637,7 +637,7 @@ win_page_up(ProfWin* window, int scroll_size)
|
|||||||
iq_mam_request_older(chatwin);
|
iq_mam_request_older(chatwin);
|
||||||
}
|
}
|
||||||
|
|
||||||
int buff_size = buffer_size(window->layout->buffer);
|
unsigned int buff_size = buffer_size(window->layout->buffer);
|
||||||
int offset_entry_id = buff_size > 10 ? 10 : buff_size - 1;
|
int offset_entry_id = buff_size > 10 ? 10 : buff_size - 1;
|
||||||
int offset = buffer_get_entry(window->layout->buffer, offset_entry_id)->y_end_pos;
|
int offset = buffer_get_entry(window->layout->buffer, offset_entry_id)->y_end_pos;
|
||||||
*page_start = offset - page_space;
|
*page_start = offset - page_space;
|
||||||
@@ -678,8 +678,8 @@ win_page_down(ProfWin* window, int scroll_size)
|
|||||||
|
|
||||||
// Scrolled down after reaching the bottom of the page
|
// Scrolled down after reaching the bottom of the page
|
||||||
if ((*page_start > total_rows - page_space || (*page_start == page_space && *page_start >= total_rows)) && window->type == WIN_CHAT) {
|
if ((*page_start > total_rows - page_space || (*page_start == page_space && *page_start >= total_rows)) && window->type == WIN_CHAT) {
|
||||||
int bf_size = buffer_size(window->layout->buffer);
|
unsigned int bf_size = buffer_size(window->layout->buffer);
|
||||||
if (bf_size > 0) {
|
if (bf_size != 0) {
|
||||||
ProfBuffEntry* last_entry = buffer_get_entry(window->layout->buffer, bf_size - 1);
|
ProfBuffEntry* last_entry = buffer_get_entry(window->layout->buffer, bf_size - 1);
|
||||||
auto_gchar gchar* start = g_date_time_format_iso8601(last_entry->time);
|
auto_gchar gchar* start = g_date_time_format_iso8601(last_entry->time);
|
||||||
GDateTime* now = g_date_time_new_now_local();
|
GDateTime* now = g_date_time_new_now_local();
|
||||||
@@ -1954,10 +1954,10 @@ win_print_trackbar(ProfWin* window)
|
|||||||
void
|
void
|
||||||
win_redraw(ProfWin* window)
|
win_redraw(ProfWin* window)
|
||||||
{
|
{
|
||||||
int size = buffer_size(window->layout->buffer);
|
unsigned int size = buffer_size(window->layout->buffer);
|
||||||
werase(window->layout->win);
|
werase(window->layout->win);
|
||||||
|
|
||||||
for (int i = 0; i < size; i++) {
|
for (unsigned int i = 0; i < size; i++) {
|
||||||
ProfBuffEntry* e = buffer_get_entry(window->layout->buffer, i);
|
ProfBuffEntry* e = buffer_get_entry(window->layout->buffer, i);
|
||||||
|
|
||||||
e->y_start_pos = getcury(window->layout->win);
|
e->y_start_pos = getcury(window->layout->win);
|
||||||
@@ -2185,11 +2185,11 @@ win_handle_command_exec_result_note(ProfWin* window, const char* const type, con
|
|||||||
void
|
void
|
||||||
win_insert_last_read_position_marker(ProfWin* window, char* id)
|
win_insert_last_read_position_marker(ProfWin* window, char* id)
|
||||||
{
|
{
|
||||||
int size = buffer_size(window->layout->buffer);
|
unsigned int size = buffer_size(window->layout->buffer);
|
||||||
|
|
||||||
// TODO: this is somewhat costly. We should improve this later.
|
// TODO: this is somewhat costly. We should improve this later.
|
||||||
// check if we already have a separator present
|
// check if we already have a separator present
|
||||||
for (int i = 0; i < size; i++) {
|
for (unsigned int i = 0; i < size; i++) {
|
||||||
ProfBuffEntry* e = buffer_get_entry(window->layout->buffer, i);
|
ProfBuffEntry* e = buffer_get_entry(window->layout->buffer, i);
|
||||||
|
|
||||||
// if yes, don't print a new one
|
// if yes, don't print a new one
|
||||||
|
|||||||
Reference in New Issue
Block a user