Tk Source Code

Check-in [2f32e4e8]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Provide fallback for _strtoi64
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | core-8-4-branch
Files: files | file ages | folders
SHA1: 2f32e4e804e97fd140bdc30c86952709409e6997
User & Date: jan.nijtmans 2012-02-26 21:23:21
Context
2012-02-28
13:45
[Bug 3495198]: Corrected types of canvas bitmap options. check-in: b585e983 user: dkf tags: core-8-4-branch
2012-02-26
21:35
Provide fallback for _strtoi64 check-in: 19eec190 user: jan.nijtmans tags: core-8-5-branch
21:23
Provide fallback for _strtoi64 check-in: 2f32e4e8 user: jan.nijtmans tags: core-8-4-branch
2012-02-21
05:38
_Xconst -> CONST check-in: 38c69518 user: jan.nijtmans tags: core-8-4-branch
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to ChangeLog.







1
2
3
4
5
6
7






2012-02-15  Jan Nijtmans  <[email protected]>

	* xlib/xcolors.c: [Bug 3486474]: Inconsistent color scaling
	* generic/tkColor.c: new internal function TkParseColor
	* generic/tkInt.h:
	* generic/tk*.c:   Change XParseColor() to TkParseColor() everywhere.

>
>
>
>
>
>







1
2
3
4
5
6
7
8
9
10
11
12
13
2012-02-26  Jan Nijtmans  <[email protected]>

	* xlib/xcolors.c: Provide fallback for _strtoi64
	* win/configure.in: Detect whether _strtoi64 is available
	* win/configure: (regenerated)

2012-02-15  Jan Nijtmans  <[email protected]>

	* xlib/xcolors.c: [Bug 3486474]: Inconsistent color scaling
	* generic/tkColor.c: new internal function TkParseColor
	* generic/tkInt.h:
	* generic/tk*.c:   Change XParseColor() to TkParseColor() everywhere.

Changes to win/configure.

1743
1744
1745
1746
1747
1748
1749
1750






































1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
  :
else
  echo "$ac_t""no" 1>&6
MAN2TCLFLAGS="-DNO_ERRNO_H"
fi









































#--------------------------------------------------------------------
# Set the default compiler switches based on the --enable-symbols 
# option.  This macro depends on C flags, and should be called
# after SC_CONFIG_CFLAGS macro is called.
#--------------------------------------------------------------------


    echo $ac_n "checking for build with symbols""... $ac_c" 1>&6
echo "configure:1760: checking for build with symbols" >&5
    # Check whether --enable-symbols or --disable-symbols was given.
if test "${enable_symbols+set}" = set; then
  enableval="$enable_symbols"
  tcl_ok=$enableval
else
  tcl_ok=no
fi








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

|






|







1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
  :
else
  echo "$ac_t""no" 1>&6
MAN2TCLFLAGS="-DNO_ERRNO_H"
fi



#-------------------------------------------
#     Check for _strtoi64
#-------------------------------------------

echo $ac_n "checking availability of _strtoi64""... $ac_c" 1>&6
echo "configure:1757: checking availability of _strtoi64" >&5
if eval "test \"`echo '$''{'tcl_have_strtoi64'+set}'`\" = set"; then
  echo $ac_n "(cached) $ac_c" 1>&6
else
  
    cat > conftest.$ac_ext <<EOF
#line 1763 "configure"
#include "confdefs.h"
#include <stdlib.h>
int main() {
_strtoi64(0,0,0)
; return 0; }
EOF
if { (eval echo configure:1770: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
  rm -rf conftest*
  tcl_have_strtoi64=yes
else
  echo "configure: failed program was:" >&5
  cat conftest.$ac_ext >&5
  rm -rf conftest*
  tcl_have_strtoi64=no
fi
rm -f conftest*
fi

echo "$ac_t""$tcl_have_strtoi64" 1>&6
if test $tcl_have_strtoi64 = no; then
    cat >> confdefs.h <<\EOF
#define NO_STRTOI64 1
EOF

fi

#--------------------------------------------------------------------
# Set the default compiler switches based on the --enable-symbols
# option.  This macro depends on C flags, and should be called
# after SC_CONFIG_CFLAGS macro is called.
#--------------------------------------------------------------------


    echo $ac_n "checking for build with symbols""... $ac_c" 1>&6
echo "configure:1798: checking for build with symbols" >&5
    # Check whether --enable-symbols or --disable-symbols was given.
if test "${enable_symbols+set}" = set; then
  enableval="$enable_symbols"
  tcl_ok=$enableval
else
  tcl_ok=no
fi
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844

#--------------------------------------------------------------------
# Embed the manifest if we can determine how
#--------------------------------------------------------------------


    echo $ac_n "checking whether to embed manifest""... $ac_c" 1>&6
echo "configure:1821: checking whether to embed manifest" >&5
    # Check whether --enable-embedded-manifest or --disable-embedded-manifest was given.
if test "${enable_embedded_manifest+set}" = set; then
  enableval="$enable_embedded_manifest"
  embed_ok=$enableval
else
  embed_ok=yes
fi


	VC_MANIFEST_EMBED_DLL=
	VC_MANIFEST_EMBED_EXE=
    result=no
    if test "$embed_ok" = "yes" -a "${SHARED_BUILD}" = "1" \
       -a "$GCC" != "yes" ; then
	# Add the magic to embed the manifest into the dll/exe
	cat > conftest.$ac_ext <<EOF
#line 1838 "configure"
#include "confdefs.h"

#if defined(_MSC_VER) && _MSC_VER >= 1400
print("manifest needed")
#endif
	
EOF







|
















|







1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882

#--------------------------------------------------------------------
# Embed the manifest if we can determine how
#--------------------------------------------------------------------


    echo $ac_n "checking whether to embed manifest""... $ac_c" 1>&6
echo "configure:1859: checking whether to embed manifest" >&5
    # Check whether --enable-embedded-manifest or --disable-embedded-manifest was given.
if test "${enable_embedded_manifest+set}" = set; then
  enableval="$enable_embedded_manifest"
  embed_ok=$enableval
else
  embed_ok=yes
fi


	VC_MANIFEST_EMBED_DLL=
	VC_MANIFEST_EMBED_EXE=
    result=no
    if test "$embed_ok" = "yes" -a "${SHARED_BUILD}" = "1" \
       -a "$GCC" != "yes" ; then
	# Add the magic to embed the manifest into the dll/exe
	cat > conftest.$ac_ext <<EOF
#line 1876 "configure"
#include "confdefs.h"

#if defined(_MSC_VER) && _MSC_VER >= 1400
print("manifest needed")
#endif
	
EOF
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881

#--------------------------------------------------------------------
# Locate and source the tclConfig.sh file.
#--------------------------------------------------------------------


    echo $ac_n "checking the location of tclConfig.sh""... $ac_c" 1>&6
echo "configure:1875: checking the location of tclConfig.sh" >&5

    if test -d ../../tcl8.4$TK_PATCH_LEVEL/win;  then
	TCL_BIN_DIR_DEFAULT=../../tcl8.4$TK_PATCH_LEVEL/win
    elif test -d ../../tcl8.4/win;  then
	TCL_BIN_DIR_DEFAULT=../../tcl8.4/win
    else
	TCL_BIN_DIR_DEFAULT=../../tcl/win







|







1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919

#--------------------------------------------------------------------
# Locate and source the tclConfig.sh file.
#--------------------------------------------------------------------


    echo $ac_n "checking the location of tclConfig.sh""... $ac_c" 1>&6
echo "configure:1913: checking the location of tclConfig.sh" >&5

    if test -d ../../tcl8.4$TK_PATCH_LEVEL/win;  then
	TCL_BIN_DIR_DEFAULT=../../tcl8.4$TK_PATCH_LEVEL/win
    elif test -d ../../tcl8.4/win;  then
	TCL_BIN_DIR_DEFAULT=../../tcl8.4/win
    else
	TCL_BIN_DIR_DEFAULT=../../tcl/win
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
    if test ! -f $TCL_BIN_DIR/tclConfig.sh; then
	{ echo "configure: error: There is no tclConfig.sh in $TCL_BIN_DIR:  perhaps you did not specify the Tcl *build* directory (not the toplevel Tcl directory) or you forgot to configure Tcl?" 1>&2; exit 1; }
    fi
    echo "$ac_t""$TCL_BIN_DIR/tclConfig.sh" 1>&6


    echo $ac_n "checking for existence of $TCL_BIN_DIR/tclConfig.sh""... $ac_c" 1>&6
echo "configure:1903: checking for existence of $TCL_BIN_DIR/tclConfig.sh" >&5

    if test -f "$TCL_BIN_DIR/tclConfig.sh" ; then
        echo "$ac_t""loading" 1>&6
	. $TCL_BIN_DIR/tclConfig.sh
    else
        echo "$ac_t""file not found" 1>&6
    fi







|







1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
    if test ! -f $TCL_BIN_DIR/tclConfig.sh; then
	{ echo "configure: error: There is no tclConfig.sh in $TCL_BIN_DIR:  perhaps you did not specify the Tcl *build* directory (not the toplevel Tcl directory) or you forgot to configure Tcl?" 1>&2; exit 1; }
    fi
    echo "$ac_t""$TCL_BIN_DIR/tclConfig.sh" 1>&6


    echo $ac_n "checking for existence of $TCL_BIN_DIR/tclConfig.sh""... $ac_c" 1>&6
echo "configure:1941: checking for existence of $TCL_BIN_DIR/tclConfig.sh" >&5

    if test -f "$TCL_BIN_DIR/tclConfig.sh" ; then
        echo "$ac_t""loading" 1>&6
	. $TCL_BIN_DIR/tclConfig.sh
    else
        echo "$ac_t""file not found" 1>&6
    fi
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
    

    



    echo $ac_n "checking for tclsh in Tcl build directory""... $ac_c" 1>&6
echo "configure:1956: checking for tclsh in Tcl build directory" >&5
    BUILD_TCLSH=${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}${EXEEXT}
    echo "$ac_t""$BUILD_TCLSH" 1>&6
    


    echo $ac_n "checking for tclsh""... $ac_c" 1>&6
echo "configure:1963: checking for tclsh" >&5

    if eval "test \"`echo '$''{'ac_cv_path_tclsh'+set}'`\" = set"; then
  echo $ac_n "(cached) $ac_c" 1>&6
else
  
	search_path=`echo ${PATH} | sed -e 's/:/ /g'`
	for dir in $search_path ; do







|






|







1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
    

    



    echo $ac_n "checking for tclsh in Tcl build directory""... $ac_c" 1>&6
echo "configure:1994: checking for tclsh in Tcl build directory" >&5
    BUILD_TCLSH=${TCL_BIN_DIR}/tclsh${TCL_MAJOR_VERSION}${TCL_MINOR_VERSION}${TCL_DBGX}${EXEEXT}
    echo "$ac_t""$BUILD_TCLSH" 1>&6
    


    echo $ac_n "checking for tclsh""... $ac_c" 1>&6
echo "configure:2001: checking for tclsh" >&5

    if eval "test \"`echo '$''{'ac_cv_path_tclsh'+set}'`\" = set"; then
  echo $ac_n "(cached) $ac_c" 1>&6
else
  
	search_path=`echo ${PATH} | sed -e 's/:/ /g'`
	for dir in $search_path ; do

Changes to win/configure.in.

105
106
107
108
109
110
111
112












113
114
115
116
117
118
119
120
121

#--------------------------------------------------------------------
# man2tcl needs this so that it can use errno.h
#--------------------------------------------------------------------

AC_CHECK_HEADER(errno.h, , MAN2TCLFLAGS="-DNO_ERRNO_H")
AC_SUBST(MAN2TCLFLAGS)













#--------------------------------------------------------------------
# Set the default compiler switches based on the --enable-symbols 
# option.  This macro depends on C flags, and should be called
# after SC_CONFIG_CFLAGS macro is called.
#--------------------------------------------------------------------

SC_ENABLE_SYMBOLS

TK_DBGX=${DBGX}








>
>
>
>
>
>
>
>
>
>
>
>

|







105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133

#--------------------------------------------------------------------
# man2tcl needs this so that it can use errno.h
#--------------------------------------------------------------------

AC_CHECK_HEADER(errno.h, , MAN2TCLFLAGS="-DNO_ERRNO_H")
AC_SUBST(MAN2TCLFLAGS)

#-------------------------------------------
#     Check for _strtoi64
#-------------------------------------------

AC_CACHE_CHECK([availability of _strtoi64], tcl_have_strtoi64, [
    AC_TRY_LINK([#include <stdlib.h>],
	    [_strtoi64(0,0,0)],
	    tcl_have_strtoi64=yes, tcl_have_strtoi64=no)])
if test $tcl_have_strtoi64 = no; then
    AC_DEFINE(NO_STRTOI64, 1, [Is _strtoi64 function available?])
fi

#--------------------------------------------------------------------
# Set the default compiler switches based on the --enable-symbols
# option.  This macro depends on C flags, and should be called
# after SC_CONFIG_CFLAGS macro is called.
#--------------------------------------------------------------------

SC_ENABLE_SYMBOLS

TK_DBGX=${DBGX}

Changes to xlib/xcolors.c.

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
/* 
 * xcolors.c --
 *
 *	This file contains the routines used to map from X color
 *	names to RGB and pixel values.
 *
 * Copyright (c) 1996 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include <tkInt.h>

/*






 * Define an array that defines the mapping from color names to RGB values.
 * Note that this array must be kept sorted alphabetically so that the
 * binary search used in XParseColor will succeed.
 */

typedef struct {
    char *name;
    unsigned char red;
    unsigned char green;
    unsigned char blue;
} XColorEntry;

static XColorEntry xColors[] = {
     { "alice blue", 240, 248, 255 },
     { "AliceBlue", 240, 248, 255 },
     { "antique white", 250, 235, 215 },
     { "AntiqueWhite", 250, 235, 215 },
     { "AntiqueWhite1", 255, 239, 219 },
     { "AntiqueWhite2", 238, 223, 204 },
     { "AntiqueWhite3", 205, 192, 176 },
|


|
|



|
|


|


>
>
>
>
>
>

|
|



|
|
<
<


|







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
/*
 * xcolors.c --
 *
 *	This file contains the routines used to map from X color names to RGB
 *	and pixel values.
 *
 * Copyright (c) 1996 by Sun Microsystems, Inc.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 */

#include "tkInt.h"

/*
 * Forward declarations for functions used only in this file.
 */

static int	FindColor(const char *name, XColor *colorPtr);

/*
 * Define an array that defines the mapping from color names to RGB values.
 * Note that this array must be kept sorted alphabetically so that the binary
 * search used in XParseColor will succeed.
 */

typedef struct {
    const char *name;
    unsigned char red, green, blue;


} XColorEntry;

static const XColorEntry xColors[] = {
     { "alice blue", 240, 248, 255 },
     { "AliceBlue", 240, 248, 255 },
     { "antique white", 250, 235, 215 },
     { "AntiqueWhite", 250, 235, 215 },
     { "AntiqueWhite1", 255, 239, 219 },
     { "AntiqueWhite2", 238, 223, 204 },
     { "AntiqueWhite3", 205, 192, 176 },
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
     { "yellow", 255, 255, 0 },
     { "yellow green", 154, 205, 50 },
     { "yellow1", 255, 255, 0 },
     { "yellow2", 238, 238, 0 },
     { "yellow3", 205, 205, 0 },
     { "yellow4", 139, 139, 0 },
     { "YellowGreen", 154, 205, 50 },
     { NULL, 0, 0, 0 }
};


/*
 * This value will be set to the number of colors in the color table
 * the first time it is needed.
 */

static int numXColors = 0;

/*
 * Forward declarations for functions used only in this file.
 */

static int	FindColor _ANSI_ARGS_((const char *name, XColor *colorPtr));

/*
 *----------------------------------------------------------------------
 *
 * FindColor --
 *
 *	This routine finds the color entry that corresponds to the
 *	specified color.
 *
 * Results:
 *	Returns non-zero on success.  The RGB values of the XColor
 *	will be initialized to the proper values on success.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
FindColor(name, colorPtr)
    const char *name;
    XColor *colorPtr;
{
    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;
    while (l <= u) {
	i = (l + u) / 2;
	r = strcasecmp(name, xColors[i].name);
	if (r == 0) {
	    break;
	} else if (r < 0) {
	    u = i-1;







<

<
<
<
<
<
<
<
<
<
<
<
<
<
<






|
|


|
|








|
|
|



<
<
<
<
<
<
<
<
<
<
<
<





|







778
779
780
781
782
783
784

785














786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811












812
813
814
815
816
817
818
819
820
821
822
823
824
     { "yellow", 255, 255, 0 },
     { "yellow green", 154, 205, 50 },
     { "yellow1", 255, 255, 0 },
     { "yellow2", 238, 238, 0 },
     { "yellow3", 205, 205, 0 },
     { "yellow4", 139, 139, 0 },
     { "YellowGreen", 154, 205, 50 },

};















/*
 *----------------------------------------------------------------------
 *
 * FindColor --
 *
 *	This routine finds the color entry that corresponds to the specified
 *	color.
 *
 * Results:
 *	Returns non-zero on success. The RGB values of the XColor will be
 *	initialized to the proper values on success.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static int
FindColor(
    const char *name,
    XColor *colorPtr)
{
    int l, u, r, i = 0;













    /*
     * Perform a binary search on the sorted array of colors.
     */

    l = 0;
    u = sizeof(xColors)/sizeof(xColors[0]) - 1;
    while (l <= u) {
	i = (l + u) / 2;
	r = strcasecmp(name, xColors[i].name);
	if (r == 0) {
	    break;
	} else if (r < 0) {
	    u = i-1;
870
871
872
873
874
875
876





























877
878
879
880
881
882
883
884
885
886
887
888
889
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */






























Status
XParseColor(display, map, spec, colorPtr)
    Display *display;
    Colormap map;
    const char* spec;
    XColor *colorPtr;
{
    if (spec[0] == '#') {
	char *p;
	Tcl_WideInt value = _strtoi64(++spec, &p, 16);

	switch ((int)(p-spec)) {
	case 3:







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

|
|
|
|
|







847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

#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,
    Colormap map,
    const char *spec,
    XColor *colorPtr)
{
    if (spec[0] == '#') {
	char *p;
	Tcl_WideInt value = _strtoi64(++spec, &p, 16);

	switch ((int)(p-spec)) {
	case 3:
915
916
917
918
919
920
921








	}
    }
    colorPtr->pixel = TkpGetPixel(colorPtr);
    colorPtr->flags = DoRed|DoGreen|DoBlue;
    colorPtr->pad = 0;
    return 1;
}















>
>
>
>
>
>
>
>
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
	}
    }
    colorPtr->pixel = TkpGetPixel(colorPtr);
    colorPtr->flags = DoRed|DoGreen|DoBlue;
    colorPtr->pad = 0;
    return 1;
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */