2013-05-03 19:44:20 -07:00
|
|
|
#include "private.h"
|
|
|
|
#include <Elementary.h>
|
|
|
|
#include "termpty.h"
|
|
|
|
#include "termptysave.h"
|
2013-05-05 07:10:44 -07:00
|
|
|
#include "lz4/lz4.h"
|
|
|
|
#include <sys/mman.h>
|
2013-05-03 19:44:20 -07:00
|
|
|
|
2013-08-08 18:41:46 -07:00
|
|
|
#if defined (__MacOSX__) || (defined (__MACH__) && defined (__APPLE__))
|
|
|
|
# ifndef MAP_ANONYMOUS
|
|
|
|
# define MAP_ANONYMOUS MAP_ANON
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2013-05-05 07:10:44 -07:00
|
|
|
#define MEM_ALLOC_ALIGN 16
|
|
|
|
#define MEM_BLOCKS 1024
|
|
|
|
|
2014-09-08 11:52:07 -07:00
|
|
|
#define TS_MMAP_SIZE 131072
|
|
|
|
#define TS_ALLOC_MASK (TS_MMAP_SIZE - 1)
|
|
|
|
|
2013-05-05 07:10:44 -07:00
|
|
|
typedef struct _Alloc Alloc;
|
|
|
|
|
|
|
|
struct _Alloc
|
|
|
|
{
|
2014-09-08 11:52:07 -07:00
|
|
|
unsigned int size, last, count, allocated;
|
2013-05-05 07:10:44 -07:00
|
|
|
short slot;
|
|
|
|
unsigned char gen;
|
|
|
|
unsigned char __pad;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-11-02 15:08:20 -08:00
|
|
|
#if 0
|
2013-05-05 07:10:44 -07:00
|
|
|
static void *
|
2014-09-08 11:52:07 -07:00
|
|
|
_ts_new(int size)
|
2013-05-05 07:10:44 -07:00
|
|
|
{
|
2015-04-06 09:08:23 -07:00
|
|
|
/* TODO: RESIZE rewrite that stuff */
|
|
|
|
//void *ptr;
|
2014-09-08 11:52:07 -07:00
|
|
|
|
2013-05-05 07:10:44 -07:00
|
|
|
if (!size) return NULL;
|
2015-04-06 09:08:23 -07:00
|
|
|
//ptr = _alloc_new(size, cur_gen);
|
2014-09-08 11:52:07 -07:00
|
|
|
|
2015-04-06 09:08:23 -07:00
|
|
|
return calloc(1, size);
|
2013-05-05 07:10:44 -07:00
|
|
|
}
|
2015-11-02 15:08:20 -08:00
|
|
|
#endif
|
2013-05-05 07:10:44 -07:00
|
|
|
|
|
|
|
static void
|
2014-09-08 11:52:07 -07:00
|
|
|
_ts_free(void *ptr)
|
2013-05-05 07:10:44 -07:00
|
|
|
{
|
2015-04-06 09:08:23 -07:00
|
|
|
free(ptr);
|
2013-05-05 07:10:44 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ts_comp = 0;
|
2013-05-03 19:44:20 -07:00
|
|
|
static int ts_uncomp = 0;
|
2013-05-05 07:10:44 -07:00
|
|
|
static int ts_freeops = 0;
|
|
|
|
static int ts_compfreeze = 0;
|
2013-05-03 19:44:20 -07:00
|
|
|
static Eina_List *ptys = NULL;
|
|
|
|
|
|
|
|
void
|
|
|
|
termpty_save_register(Termpty *ty)
|
|
|
|
{
|
2015-08-01 09:37:35 -07:00
|
|
|
termpty_backlog_lock();
|
2013-05-03 19:44:20 -07:00
|
|
|
ptys = eina_list_append(ptys, ty);
|
2015-08-01 09:37:35 -07:00
|
|
|
termpty_backlog_unlock();
|
2013-05-03 19:44:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
termpty_save_unregister(Termpty *ty)
|
|
|
|
{
|
2015-08-01 09:37:35 -07:00
|
|
|
termpty_backlog_lock();
|
2013-05-03 19:44:20 -07:00
|
|
|
ptys = eina_list_remove(ptys, ty);
|
2015-08-01 09:37:35 -07:00
|
|
|
termpty_backlog_unlock();
|
2013-05-03 19:44:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Termsave *
|
|
|
|
termpty_save_extract(Termsave *ts)
|
|
|
|
{
|
|
|
|
if (!ts) return NULL;
|
2015-11-02 15:08:20 -08:00
|
|
|
#if 0
|
2015-08-06 12:39:20 -07:00
|
|
|
if (ts->z) //TODO: unused
|
2013-05-05 07:10:44 -07:00
|
|
|
{
|
|
|
|
Termsavecomp *tsc = (Termsavecomp *)ts;
|
|
|
|
Termsave *ts2;
|
|
|
|
char *buf;
|
|
|
|
int bytes;
|
2014-09-08 11:52:07 -07:00
|
|
|
|
|
|
|
ts2 = _ts_new(sizeof(Termsave) + ((tsc->wout - 1) * sizeof(Termcell)));
|
2013-05-05 07:10:44 -07:00
|
|
|
if (!ts2) return NULL;
|
|
|
|
ts2->w = tsc->wout;
|
|
|
|
buf = ((char *)tsc) + sizeof(Termsavecomp);
|
2015-04-06 09:08:23 -07:00
|
|
|
bytes = LZ4_uncompress(buf, (char *)(&(ts2->cells[0])),
|
2013-05-05 07:10:44 -07:00
|
|
|
tsc->wout * sizeof(Termcell));
|
|
|
|
if (bytes < 0)
|
|
|
|
{
|
2015-04-06 09:08:23 -07:00
|
|
|
memset(&(ts2->cells[0]), 0, tsc->wout * sizeof(Termcell));
|
2013-05-05 07:10:44 -07:00
|
|
|
// ERR("Decompress problem in row at byte %i", -bytes);
|
|
|
|
}
|
|
|
|
return ts2;
|
|
|
|
}
|
2015-11-02 15:08:20 -08:00
|
|
|
#endif
|
2013-05-03 19:44:20 -07:00
|
|
|
return ts;
|
|
|
|
}
|
|
|
|
|
|
|
|
Termsave *
|
2015-04-06 09:08:23 -07:00
|
|
|
termpty_save_new(Termsave *ts, int w)
|
2013-05-03 19:44:20 -07:00
|
|
|
{
|
2015-04-06 09:08:23 -07:00
|
|
|
termpty_save_free(ts);
|
|
|
|
|
|
|
|
Termcell *cells = calloc(1, w * sizeof(Termcell));
|
|
|
|
if (!cells ) return NULL;
|
|
|
|
ts->cells = cells;
|
2013-05-03 19:44:20 -07:00
|
|
|
ts->w = w;
|
|
|
|
return ts;
|
|
|
|
}
|
|
|
|
|
2015-04-06 09:08:23 -07:00
|
|
|
Termsave *
|
2015-08-01 09:37:35 -07:00
|
|
|
termpty_save_expand(Termsave *ts, Termcell *cells, size_t delta)
|
2015-04-06 09:08:23 -07:00
|
|
|
{
|
|
|
|
Termcell *newcells;
|
|
|
|
|
|
|
|
newcells = realloc(ts->cells, (ts->w + delta) * sizeof(Termcell));
|
|
|
|
if (!newcells)
|
|
|
|
return NULL;
|
|
|
|
newcells[ts->w - 1].att.autowrapped = 0;
|
|
|
|
memcpy(&newcells[ts->w], cells, delta * sizeof(Termcell));
|
|
|
|
ts->w += delta;
|
|
|
|
ts->cells = newcells;
|
|
|
|
return ts;
|
|
|
|
}
|
|
|
|
|
2013-05-03 19:44:20 -07:00
|
|
|
void
|
|
|
|
termpty_save_free(Termsave *ts)
|
|
|
|
{
|
|
|
|
if (!ts) return;
|
2013-05-05 07:10:44 -07:00
|
|
|
if (!ts_compfreeze)
|
|
|
|
{
|
|
|
|
if (ts->comp) ts_comp--;
|
|
|
|
else ts_uncomp--;
|
|
|
|
ts_freeops++;
|
|
|
|
}
|
2015-04-06 09:08:23 -07:00
|
|
|
_ts_free(ts->cells);
|
|
|
|
ts->cells = NULL;
|
|
|
|
ts->w = 0;
|
2013-05-03 19:44:20 -07:00
|
|
|
}
|
2015-08-01 09:37:35 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
termpty_backlog_lock(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
termpty_backlog_unlock(void)
|
|
|
|
{
|
|
|
|
}
|