2009-06-01 22:58:49 +00:00
|
|
|
/* $OpenBSD$ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2009 Joshua Elsasser <josh@elsasser.org>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
|
|
|
const char *
|
2017-03-22 07:16:54 +00:00
|
|
|
attributes_tostring(int attr)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2018-10-18 07:57:57 +00:00
|
|
|
static char buf[512];
|
2012-03-17 21:45:25 +00:00
|
|
|
size_t len;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-11-26 21:22:31 +00:00
|
|
|
if (attr == 0)
|
2010-05-14 18:56:21 +00:00
|
|
|
return ("none");
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2020-05-16 14:13:37 +00:00
|
|
|
len = xsnprintf(buf, sizeof buf, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
|
|
|
|
(attr & GRID_ATTR_CHARSET) ? "acs," : "",
|
2017-02-16 10:53:25 +00:00
|
|
|
(attr & GRID_ATTR_BRIGHT) ? "bright," : "",
|
|
|
|
(attr & GRID_ATTR_DIM) ? "dim," : "",
|
|
|
|
(attr & GRID_ATTR_UNDERSCORE) ? "underscore," : "",
|
|
|
|
(attr & GRID_ATTR_BLINK)? "blink," : "",
|
|
|
|
(attr & GRID_ATTR_REVERSE) ? "reverse," : "",
|
|
|
|
(attr & GRID_ATTR_HIDDEN) ? "hidden," : "",
|
2017-03-22 07:16:54 +00:00
|
|
|
(attr & GRID_ATTR_ITALICS) ? "italics," : "",
|
2018-10-18 07:57:57 +00:00
|
|
|
(attr & GRID_ATTR_STRIKETHROUGH) ? "strikethrough," : "",
|
|
|
|
(attr & GRID_ATTR_UNDERSCORE_2) ? "double-underscore," : "",
|
|
|
|
(attr & GRID_ATTR_UNDERSCORE_3) ? "curly-underscore," : "",
|
|
|
|
(attr & GRID_ATTR_UNDERSCORE_4) ? "dotted-underscore," : "",
|
2019-05-13 20:10:23 +00:00
|
|
|
(attr & GRID_ATTR_UNDERSCORE_5) ? "dashed-underscore," : "",
|
|
|
|
(attr & GRID_ATTR_OVERLINE) ? "overline," : "");
|
2012-03-17 21:45:25 +00:00
|
|
|
if (len > 0)
|
|
|
|
buf[len - 1] = '\0';
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
return (buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
attributes_fromstring(const char *str)
|
|
|
|
{
|
|
|
|
const char delimiters[] = " ,|";
|
2017-03-22 07:16:54 +00:00
|
|
|
int attr;
|
2009-06-01 22:58:49 +00:00
|
|
|
size_t end;
|
2018-10-18 07:57:57 +00:00
|
|
|
u_int i;
|
|
|
|
struct {
|
2019-12-03 10:47:22 +00:00
|
|
|
const char *name;
|
|
|
|
int attr;
|
2018-10-18 07:57:57 +00:00
|
|
|
} table[] = {
|
2020-05-16 14:13:37 +00:00
|
|
|
{ "acs", GRID_ATTR_CHARSET },
|
2018-10-18 07:57:57 +00:00
|
|
|
{ "bright", GRID_ATTR_BRIGHT },
|
|
|
|
{ "bold", GRID_ATTR_BRIGHT },
|
|
|
|
{ "dim", GRID_ATTR_DIM },
|
|
|
|
{ "underscore", GRID_ATTR_UNDERSCORE },
|
|
|
|
{ "blink", GRID_ATTR_BLINK },
|
|
|
|
{ "reverse", GRID_ATTR_REVERSE },
|
|
|
|
{ "hidden", GRID_ATTR_HIDDEN },
|
|
|
|
{ "italics", GRID_ATTR_ITALICS },
|
|
|
|
{ "strikethrough", GRID_ATTR_STRIKETHROUGH },
|
|
|
|
{ "double-underscore", GRID_ATTR_UNDERSCORE_2 },
|
|
|
|
{ "curly-underscore", GRID_ATTR_UNDERSCORE_3 },
|
|
|
|
{ "dotted-underscore", GRID_ATTR_UNDERSCORE_4 },
|
2019-05-13 20:10:23 +00:00
|
|
|
{ "dashed-underscore", GRID_ATTR_UNDERSCORE_5 },
|
|
|
|
{ "overline", GRID_ATTR_OVERLINE }
|
2018-10-18 07:57:57 +00:00
|
|
|
};
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
if (*str == '\0' || strcspn(str, delimiters) == 0)
|
|
|
|
return (-1);
|
|
|
|
if (strchr(delimiters, str[strlen(str) - 1]) != NULL)
|
|
|
|
return (-1);
|
|
|
|
|
2010-05-14 18:56:21 +00:00
|
|
|
if (strcasecmp(str, "default") == 0 || strcasecmp(str, "none") == 0)
|
2009-06-01 22:58:49 +00:00
|
|
|
return (0);
|
|
|
|
|
2009-11-26 21:22:31 +00:00
|
|
|
attr = 0;
|
2009-06-01 22:58:49 +00:00
|
|
|
do {
|
|
|
|
end = strcspn(str, delimiters);
|
2018-10-18 07:57:57 +00:00
|
|
|
for (i = 0; i < nitems(table); i++) {
|
|
|
|
if (end != strlen(table[i].name))
|
|
|
|
continue;
|
|
|
|
if (strncasecmp(str, table[i].name, end) == 0) {
|
|
|
|
attr |= table[i].attr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == nitems(table))
|
2009-06-01 22:58:49 +00:00
|
|
|
return (-1);
|
|
|
|
str += end + strspn(str + end, delimiters);
|
|
|
|
} while (*str != '\0');
|
|
|
|
|
2009-11-26 21:22:31 +00:00
|
|
|
return (attr);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|