xref: /minix3/external/bsd/tmux/dist/grid-cell.c (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /* $OpenBSD$ */
2*0a6a1f1dSLionel Sambuc 
3*0a6a1f1dSLionel Sambuc /*
4*0a6a1f1dSLionel Sambuc  * Copyright (c) 2012 Nicholas Marriott <nicm@users.sourceforge.net>
5*0a6a1f1dSLionel Sambuc  *
6*0a6a1f1dSLionel Sambuc  * Permission to use, copy, modify, and distribute this software for any
7*0a6a1f1dSLionel Sambuc  * purpose with or without fee is hereby granted, provided that the above
8*0a6a1f1dSLionel Sambuc  * copyright notice and this permission notice appear in all copies.
9*0a6a1f1dSLionel Sambuc  *
10*0a6a1f1dSLionel Sambuc  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11*0a6a1f1dSLionel Sambuc  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12*0a6a1f1dSLionel Sambuc  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13*0a6a1f1dSLionel Sambuc  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14*0a6a1f1dSLionel Sambuc  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15*0a6a1f1dSLionel Sambuc  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16*0a6a1f1dSLionel Sambuc  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*0a6a1f1dSLionel Sambuc  */
18*0a6a1f1dSLionel Sambuc 
19*0a6a1f1dSLionel Sambuc #include <sys/types.h>
20*0a6a1f1dSLionel Sambuc 
21*0a6a1f1dSLionel Sambuc #include <string.h>
22*0a6a1f1dSLionel Sambuc 
23*0a6a1f1dSLionel Sambuc #include "tmux.h"
24*0a6a1f1dSLionel Sambuc 
25*0a6a1f1dSLionel Sambuc /* Get cell width. */
26*0a6a1f1dSLionel Sambuc u_int
grid_cell_width(const struct grid_cell * gc)27*0a6a1f1dSLionel Sambuc grid_cell_width(const struct grid_cell *gc)
28*0a6a1f1dSLionel Sambuc {
29*0a6a1f1dSLionel Sambuc 	return (gc->xstate >> 4);
30*0a6a1f1dSLionel Sambuc }
31*0a6a1f1dSLionel Sambuc 
32*0a6a1f1dSLionel Sambuc /* Get cell data. */
33*0a6a1f1dSLionel Sambuc void
grid_cell_get(const struct grid_cell * gc,struct utf8_data * ud)34*0a6a1f1dSLionel Sambuc grid_cell_get(const struct grid_cell *gc, struct utf8_data *ud)
35*0a6a1f1dSLionel Sambuc {
36*0a6a1f1dSLionel Sambuc 	ud->size = gc->xstate & 0xf;
37*0a6a1f1dSLionel Sambuc 	ud->width = gc->xstate >> 4;
38*0a6a1f1dSLionel Sambuc 	memcpy(ud->data, gc->xdata, ud->size);
39*0a6a1f1dSLionel Sambuc }
40*0a6a1f1dSLionel Sambuc 
41*0a6a1f1dSLionel Sambuc /* Set cell data. */
42*0a6a1f1dSLionel Sambuc void
grid_cell_set(struct grid_cell * gc,const struct utf8_data * ud)43*0a6a1f1dSLionel Sambuc grid_cell_set(struct grid_cell *gc, const struct utf8_data *ud)
44*0a6a1f1dSLionel Sambuc {
45*0a6a1f1dSLionel Sambuc 	memcpy(gc->xdata, ud->data, ud->size);
46*0a6a1f1dSLionel Sambuc 	gc->xstate = (ud->width << 4) | ud->size;
47*0a6a1f1dSLionel Sambuc }
48*0a6a1f1dSLionel Sambuc 
49*0a6a1f1dSLionel Sambuc /* Set a single character as cell data. */
50*0a6a1f1dSLionel Sambuc void
grid_cell_one(struct grid_cell * gc,u_char ch)51*0a6a1f1dSLionel Sambuc grid_cell_one(struct grid_cell *gc, u_char ch)
52*0a6a1f1dSLionel Sambuc {
53*0a6a1f1dSLionel Sambuc 	*gc->xdata = ch;
54*0a6a1f1dSLionel Sambuc 	gc->xstate = (1 << 4) | 1;
55*0a6a1f1dSLionel Sambuc }
56