1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
/* This file is part of ksquirrel-libs (http://ksquirrel.sf.net)
Copyright (c) 2004 Dmitry Baryshev <ksquirrel@tut.by>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later
version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
as32 with this library; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <cctype>
#define KEY_LENGTH 25
RGBA fmt_codec::hex2rgb(const s8 *hex)
{
RGBA rgba;
s8 c[3];
const s8 add = (const s8)strlen(hex+1) / 3 - 2;
if(!strncasecmp(hex, "none", 4) || !strncasecmp(hex, "one", 3)) // not pretty hack
{
memset(&rgba, 0, sizeof(RGBA));
return rgba;
}
if(isalpha(*hex))
{
RGBA trgba;
bool f;// = BinSearch(named, 0, sizeof(named) / sizeof(XPM_NAMED_COLOR) - 1, hex);
std::map<std::string, RGBA>::const_iterator it = named.find(hex);
f = (it != named.end());
if(!f)
{
cerr << "XPM decoder: WARNING: named color \"" << hex << "\" not found, assuming transparent instead" << endl;
memset(&rgba, 0, sizeof(RGBA));
return rgba;
}
trgba = named[std::string(hex)];
return trgba;
}
hex++;
memcpy(c, hex, 2);
c[2] = 0;
rgba.r = (s8)strtol(c, NULL, 16);
hex = hex + 2 + add;
memcpy(c, hex, 2);
c[2] = 0;
rgba.g = (s8)strtol(c, NULL, 16);
hex = hex + 2 + add;
memcpy(c, hex, 2);
c[2] = 0;
rgba.b = (s8)strtol(c, NULL, 16);
rgba.a = 255;
return rgba;
}
/* skip a single line C-like comment */
s32 skip_comments(ifstreamK &ff)
{
s8 str[4096];
fstream::pos_type pos;
bool skipped = false;
pos = ff.tellg();
ff.getline(str, sizeof(str)-1);
if(ff.eof()) return 2;
if((*str == '\n' && *(str+1) == '\0') || (*str == '\n' && *(str+1) == '\r' && *(str+2) == '\0') || (*str == '\r' && *(str+1) == '\n' && *(str+2) == '\0'))
skipped = true;
if(strstr(str, "/*") || *str == '#' || !strlen(str))
skipped = true;
if(!skipped)
ff.seekg(pos);
return (int)skipped;
}
|