summaryrefslogtreecommitdiffstats
path: root/xlib
diff options
context:
space:
mode:
authorjan.nijtmans <jan.nijtmans@noemail.net>2012-02-26 21:35:52 (GMT)
committerjan.nijtmans <jan.nijtmans@noemail.net>2012-02-26 21:35:52 (GMT)
commitd11a3ef2cd88b9a6b467bf8a0f1cc5ad882e55a9 (patch)
treeacc5eb75a48b7ec6ff3f60f71d7192bb09070f3e /xlib
parent97fe921947e27c243b5b2d2500032d17297af4fc (diff)
parentd35b622cd0673d2cd2579942974aa71df9176c3a (diff)
downloadtk-d11a3ef2cd88b9a6b467bf8a0f1cc5ad882e55a9.zip
tk-d11a3ef2cd88b9a6b467bf8a0f1cc5ad882e55a9.tar.gz
tk-d11a3ef2cd88b9a6b467bf8a0f1cc5ad882e55a9.tar.bz2
Provide fallback for _strtoi64
FossilOrigin-Name: 19eec190b83f777c2d2b57aa96d2cbd1cb4f6a7f
Diffstat (limited to 'xlib')
-rw-r--r--xlib/xcolors.c57
1 files changed, 33 insertions, 24 deletions
diff --git a/xlib/xcolors.c b/xlib/xcolors.c
index b1d1f27..3a48faa 100644
--- a/xlib/xcolors.c
+++ b/xlib/xcolors.c
@@ -10,14 +10,7 @@
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*/
-#include <tkInt.h>
-
-/*
- * This value will be set to the number of colors in the color table
- * the first time it is needed.
- */
-
-static int numXColors = 0;
+#include "tkInt.h"
/*
* Forward declarations for functions used only in this file.
@@ -32,11 +25,11 @@ static int FindColor(const char *name, XColor *colorPtr);
*/
typedef struct {
- char *name;
+ const char *name;
unsigned char red, green, blue;
} XColorEntry;
-static XColorEntry xColors[] = {
+static const XColorEntry xColors[] = {
{ "alice blue", 240, 248, 255 },
{ "AliceBlue", 240, 248, 255 },
{ "antique white", 250, 235, 215 },
@@ -789,7 +782,6 @@ static XColorEntry xColors[] = {
{ "yellow3", 205, 205, 0 },
{ "yellow4", 139, 139, 0 },
{ "YellowGreen", 154, 205, 50 },
- { NULL, 0, 0, 0 }
};
/*
@@ -818,23 +810,11 @@ FindColor(
int l, u, r, i = 0;
/*
- * Count the number of elements in the color array if we haven't done so
- * yet.
- */
-
- if (numXColors == 0) {
- XColorEntry *ePtr;
- for (ePtr = xColors; ePtr->name != NULL; ePtr++) {
- numXColors++;
- }
- }
-
- /*
* Perform a binary search on the sorted array of colors.
*/
l = 0;
- u = numXColors - 1;
+ u = sizeof(xColors)/sizeof(xColors[0]) - 1;
while (l <= u) {
i = (l + u) / 2;
r = strcasecmp(name, xColors[i].name);
@@ -871,6 +851,35 @@ FindColor(
*----------------------------------------------------------------------
*/
+#ifdef __WIN32__
+# ifdef NO_STRTOI64
+/* This version only handles hex-strings without 0x prefix */
+static __int64
+_strtoi64(const char *spec, char **p, int base)
+{
+ __int64 result = 0;
+ char c;
+ while ((c = *spec)) {
+ if ((c >= '0') && (c <= '9')) {
+ c -= '0';
+ } else if ((c >= 'A') && (c <= 'F')) {
+ c += (10 - 'A');
+ } else if ((c >= 'a') && (c <= 'f')) {
+ c += (10 - 'a');
+ } else {
+ break;
+ }
+ result = (result << 4) + c;
+ ++spec;
+ }
+ *p = (char *) spec;
+ return result;
+}
+# endif
+#else
+# define _strtoi64 strtoll
+#endif
+
Status
XParseColor(
Display *display,