4 * Copyright (c) 2009 Joshua Elsasser <josh@elsasser.org>
6 * Permission to use, copy, modify, and distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/types.h>
26 attributes_tostring(u_char attr
)
34 len
= xsnprintf(buf
, sizeof buf
, "%s%s%s%s%s%s%s",
35 attr
& GRID_ATTR_BRIGHT
? "bright," : "",
36 attr
& GRID_ATTR_DIM
? "dim," : "",
37 attr
& GRID_ATTR_UNDERSCORE
? "underscore," : "",
38 attr
& GRID_ATTR_BLINK
? "blink," : "",
39 attr
& GRID_ATTR_REVERSE
? "reverse," : "",
40 attr
& GRID_ATTR_HIDDEN
? "hidden," : "",
41 attr
& GRID_ATTR_ITALICS
? "italics," : "");
49 attributes_fromstring(const char *str
)
51 const char delimiters
[] = " ,|";
55 if (*str
== '\0' || strcspn(str
, delimiters
) == 0)
57 if (strchr(delimiters
, str
[strlen(str
) - 1]) != NULL
)
60 if (strcasecmp(str
, "default") == 0 || strcasecmp(str
, "none") == 0)
65 end
= strcspn(str
, delimiters
);
66 if ((end
== 6 && strncasecmp(str
, "bright", end
) == 0) ||
67 (end
== 4 && strncasecmp(str
, "bold", end
) == 0))
68 attr
|= GRID_ATTR_BRIGHT
;
69 else if (end
== 3 && strncasecmp(str
, "dim", end
) == 0)
70 attr
|= GRID_ATTR_DIM
;
71 else if (end
== 10 && strncasecmp(str
, "underscore", end
) == 0)
72 attr
|= GRID_ATTR_UNDERSCORE
;
73 else if (end
== 5 && strncasecmp(str
, "blink", end
) == 0)
74 attr
|= GRID_ATTR_BLINK
;
75 else if (end
== 7 && strncasecmp(str
, "reverse", end
) == 0)
76 attr
|= GRID_ATTR_REVERSE
;
77 else if (end
== 6 && strncasecmp(str
, "hidden", end
) == 0)
78 attr
|= GRID_ATTR_HIDDEN
;
79 else if (end
== 7 && strncasecmp(str
, "italics", end
) == 0)
80 attr
|= GRID_ATTR_ITALICS
;
83 str
+= end
+ strspn(str
+ end
, delimiters
);
84 } while (*str
!= '\0');