]> ncurses.scripts.mit.edu Git - ncurses.git/blob - test/color_name.h
ncurses 6.1 - patch 20180519
[ncurses.git] / test / color_name.h
1 /****************************************************************************
2  * Copyright (c) 2011-2012,2016 Free Software Foundation, Inc.              *
3  *                                                                          *
4  * Permission is hereby granted, free of charge, to any person obtaining a  *
5  * copy of this software and associated documentation files (the            *
6  * "Software"), to deal in the Software without restriction, including      *
7  * without limitation the rights to use, copy, modify, merge, publish,      *
8  * distribute, distribute with modifications, sublicense, and/or sell       *
9  * copies of the Software, and to permit persons to whom the Software is    *
10  * furnished to do so, subject to the following conditions:                 *
11  *                                                                          *
12  * The above copyright notice and this permission notice shall be included  *
13  * in all copies or substantial portions of the Software.                   *
14  *                                                                          *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22  *                                                                          *
23  * Except as contained in this notice, the name(s) of the above copyright   *
24  * holders shall not be used in advertising or otherwise to promote the     *
25  * sale, use or other dealings in this Software without prior written       *
26  * authorization.                                                           *
27  ****************************************************************************/
28 /*
29  * $Id: color_name.h,v 1.5 2016/09/04 20:11:36 tom Exp $
30  */
31
32 #ifndef __COLORNAME_H
33 #define __COLORNAME_H 1
34
35 #ifndef __TEST_PRIV_H
36 #include <test.priv.h>
37 #endif
38
39 static NCURSES_CONST char *the_color_names[] =
40 {
41     "black",
42     "red",
43     "green",
44     "yellow",
45     "blue",
46     "magenta",
47     "cyan",
48     "white",
49     "BLACK",
50     "RED",
51     "GREEN",
52     "YELLOW",
53     "BLUE",
54     "MAGENTA",
55     "CYAN",
56     "WHITE"
57 };
58
59 #ifdef NEED_COLOR_CODE
60 static int
61 color_code(const char *color)
62 {
63     int result = 0;
64     char *endp = 0;
65     size_t n;
66
67     if ((result = (int) strtol(color, &endp, 0)) >= 0
68         && (endp == 0 || *endp == 0)) {
69         ;
70     } else if (!strcmp(color, "default")) {
71         result = -1;
72     } else {
73         for (n = 0; n < SIZEOF(the_color_names); ++n) {
74             if (!strcmp(the_color_names[n], color)) {
75                 result = (int) n;
76                 break;
77             }
78         }
79     }
80     return result;
81 }
82 #endif /* NEED_COLOR_NAME */
83
84 #ifdef NEED_COLOR_NAME
85 static const char *
86 color_name(int color)
87 {
88     static char temp[20];
89     const char *result = 0;
90
91     if (color >= (int) SIZEOF(the_color_names)) {
92         _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(result)) "%d", color);
93         result = temp;
94     } else if (color < 0) {
95         result = "default";
96     } else {
97         result = the_color_names[color];
98     }
99     return result;
100 }
101 #endif /* NEED_COLOR_NAME */
102
103 #endif /* __COLORNAME_H */