2019-06-17 19:33:10 +02:00
|
|
|
#include "grid.h"
|
|
|
|
|
|
2019-07-10 16:08:53 +02:00
|
|
|
//#include <string.h>
|
2019-06-17 21:15:20 +02:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
2019-06-19 10:27:31 +02:00
|
|
|
#define LOG_MODULE "grid"
|
2019-07-03 20:21:03 +02:00
|
|
|
#define LOG_ENABLE_DBG 0
|
2019-06-19 10:27:31 +02:00
|
|
|
#include "log.h"
|
2019-07-01 12:23:38 +02:00
|
|
|
|
|
|
|
|
void
|
2019-08-22 17:33:23 +02:00
|
|
|
grid_swap_row(struct grid *grid, int row_a, int row_b, bool initialize)
|
2019-07-01 12:23:38 +02:00
|
|
|
{
|
2019-07-10 16:08:53 +02:00
|
|
|
assert(grid->offset >= 0);
|
|
|
|
|
assert(row_a != row_b);
|
2019-07-01 19:18:52 +02:00
|
|
|
|
2019-08-22 17:33:23 +02:00
|
|
|
int real_a = (grid->offset + row_a) & (grid->num_rows - 1);
|
|
|
|
|
int real_b = (grid->offset + row_b) & (grid->num_rows - 1);
|
|
|
|
|
|
|
|
|
|
struct row *a = grid->rows[real_a];
|
|
|
|
|
struct row *b = grid->rows[real_b];
|
2019-08-23 20:07:27 +02:00
|
|
|
|
2019-08-22 17:33:23 +02:00
|
|
|
grid->rows[real_a] = b;
|
|
|
|
|
grid->rows[real_b] = a;
|
2019-07-01 19:18:52 +02:00
|
|
|
}
|
2019-07-10 16:27:55 +02:00
|
|
|
|
|
|
|
|
struct row *
|
2019-08-22 17:33:23 +02:00
|
|
|
grid_row_alloc(int cols, bool initialize)
|
2019-07-10 16:27:55 +02:00
|
|
|
{
|
|
|
|
|
struct row *row = malloc(sizeof(*row));
|
2019-08-22 17:33:23 +02:00
|
|
|
row->dirty = false;
|
2020-02-14 22:39:26 +01:00
|
|
|
row->linebreak = false;
|
2019-08-22 17:33:23 +02:00
|
|
|
|
|
|
|
|
if (initialize) {
|
|
|
|
|
row->cells = calloc(cols, sizeof(row->cells[0]));
|
|
|
|
|
for (size_t c = 0; c < cols; c++)
|
|
|
|
|
row->cells[c].attrs.clean = 1;
|
|
|
|
|
} else
|
|
|
|
|
row->cells = malloc(cols * sizeof(row->cells[0]));
|
|
|
|
|
|
2019-07-10 16:27:55 +02:00
|
|
|
return row;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
grid_row_free(struct row *row)
|
|
|
|
|
{
|
|
|
|
|
if (row == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
free(row->cells);
|
|
|
|
|
free(row);
|
|
|
|
|
}
|