Keep buffer creation time and add accessors for it and the order number.

This commit is contained in:
nicm 2016-10-05 12:34:05 +00:00
parent b4f95c43fc
commit 4117a7ed19
2 changed files with 22 additions and 1 deletions

21
paste.c
View File

@ -35,6 +35,7 @@ struct paste_buffer {
size_t size; size_t size;
char *name; char *name;
time_t created;
int automatic; int automatic;
u_int order; u_int order;
@ -79,6 +80,20 @@ paste_buffer_name(struct paste_buffer *pb)
return (pb->name); return (pb->name);
} }
/* Get paste buffer order. */
u_int
paste_buffer_order(struct paste_buffer *pb)
{
return (pb->order);
}
/* Get paste buffer created. */
time_t
paste_buffer_created(struct paste_buffer *pb)
{
return (pb->created);
}
/* Get paste buffer data. */ /* Get paste buffer data. */
const char * const char *
paste_buffer_data(struct paste_buffer *pb, size_t *size) paste_buffer_data(struct paste_buffer *pb, size_t *size)
@ -88,7 +103,7 @@ paste_buffer_data(struct paste_buffer *pb, size_t *size)
return (pb->data); return (pb->data);
} }
/* Walk paste buffers by name. */ /* Walk paste buffers by time. */
struct paste_buffer * struct paste_buffer *
paste_walk(struct paste_buffer *pb) paste_walk(struct paste_buffer *pb)
{ {
@ -174,6 +189,8 @@ paste_add(char *data, size_t size)
pb->automatic = 1; pb->automatic = 1;
paste_num_automatic++; paste_num_automatic++;
pb->created = time(NULL);
pb->order = paste_next_order++; pb->order = paste_next_order++;
RB_INSERT(paste_name_tree, &paste_by_name, pb); RB_INSERT(paste_name_tree, &paste_by_name, pb);
RB_INSERT(paste_time_tree, &paste_by_time, pb); RB_INSERT(paste_time_tree, &paste_by_time, pb);
@ -264,6 +281,8 @@ paste_set(char *data, size_t size, const char *name, char **cause)
pb->automatic = 0; pb->automatic = 0;
pb->order = paste_next_order++; pb->order = paste_next_order++;
pb->created = time(NULL);
if ((old = paste_get_name(name)) != NULL) if ((old = paste_get_name(name)) != NULL)
paste_free(old); paste_free(old);

2
tmux.h
View File

@ -1587,6 +1587,8 @@ void cfg_show_causes(struct session *);
/* paste.c */ /* paste.c */
struct paste_buffer; struct paste_buffer;
const char *paste_buffer_name(struct paste_buffer *); const char *paste_buffer_name(struct paste_buffer *);
u_int paste_buffer_order(struct paste_buffer *);
time_t paste_buffer_created(struct paste_buffer *);
const char *paste_buffer_data(struct paste_buffer *, size_t *); const char *paste_buffer_data(struct paste_buffer *, size_t *);
struct paste_buffer *paste_walk(struct paste_buffer *); struct paste_buffer *paste_walk(struct paste_buffer *);
struct paste_buffer *paste_get_top(const char **); struct paste_buffer *paste_get_top(const char **);