diff options
author | Tiago Cunha <tcunha@gmx.com> | 2009-11-28 14:54:12 +0000 |
---|---|---|
committer | Tiago Cunha <tcunha@gmx.com> | 2009-11-28 14:54:12 +0000 |
commit | fabf40b3b3c9f37930aa99e40771a069a9c94adf (patch) | |
tree | f1aa668369ce2d47db3dae1390a057143d4136b7 /paste.c | |
parent | 66bf2e2f040b9fc1a6f06f5076858c810b54b194 (diff) | |
download | rtmux-fabf40b3b3c9f37930aa99e40771a069a9c94adf.tar.gz rtmux-fabf40b3b3c9f37930aa99e40771a069a9c94adf.tar.bz2 rtmux-fabf40b3b3c9f37930aa99e40771a069a9c94adf.zip |
Sync OpenBSD patchset 569:
Tidy up various bits of the paste code, make the data buffer char * and add
comments.
Diffstat (limited to 'paste.c')
-rw-r--r-- | paste.c | 30 |
1 files changed, 26 insertions, 4 deletions
@@ -1,4 +1,4 @@ -/* $Id: paste.c,v 1.11 2009-11-04 22:39:20 tcunha Exp $ */ +/* $Id: paste.c,v 1.12 2009-11-28 14:54:12 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -23,6 +23,11 @@ #include "tmux.h" +/* + * Stack of paste buffers. Note that paste buffer data is not necessarily a C + * string! + */ + void paste_init_stack(struct paste_stack *ps) { @@ -36,6 +41,7 @@ paste_free_stack(struct paste_stack *ps) ; } +/* Return each item of the stack in turn. */ struct paste_buffer * paste_walk_stack(struct paste_stack *ps, uint *idx) { @@ -46,6 +52,7 @@ paste_walk_stack(struct paste_stack *ps, uint *idx) return (pb); } +/* Get the top item on the stack. */ struct paste_buffer * paste_get_top(struct paste_stack *ps) { @@ -54,6 +61,7 @@ paste_get_top(struct paste_stack *ps) return (ARRAY_FIRST(ps)); } +/* Get an item by its index. */ struct paste_buffer * paste_get_index(struct paste_stack *ps, u_int idx) { @@ -62,6 +70,7 @@ paste_get_index(struct paste_stack *ps, u_int idx) return (ARRAY_ITEM(ps, idx)); } +/* Free the top item on the stack. */ int paste_free_top(struct paste_stack *ps) { @@ -79,6 +88,7 @@ paste_free_top(struct paste_stack *ps) return (0); } +/* Free an item by index. */ int paste_free_index(struct paste_stack *ps, u_int idx) { @@ -96,12 +106,16 @@ paste_free_index(struct paste_stack *ps, u_int idx) return (0); } +/* + * Add an item onto the top of the stack, freeing the bottom if at limit. Note + * that the caller is responsible for allocating data. + */ void -paste_add(struct paste_stack *ps, u_char *data, size_t size, u_int limit) +paste_add(struct paste_stack *ps, char *data, size_t size, u_int limit) { struct paste_buffer *pb; - if (*data == '\0') + if (size == 0) return; while (ARRAY_LENGTH(ps) >= limit) { @@ -118,11 +132,19 @@ paste_add(struct paste_stack *ps, u_char *data, size_t size, u_int limit) pb->size = size; } + +/* + * Replace an item on the stack. Note that the caller is responsible for + * allocating data. + */ int -paste_replace(struct paste_stack *ps, u_int idx, u_char *data, size_t size) +paste_replace(struct paste_stack *ps, u_int idx, char *data, size_t size) { struct paste_buffer *pb; + if (size == 0) + return (0); + if (idx >= ARRAY_LENGTH(ps)) return (-1); |