Ver código fonte

Fixes to compile for wince

mingodad 13 anos atrás
pai
commit
f6e26b9388

+ 1217 - 0
SquiLu-ext/celibc.c

@@ -0,0 +1,1217 @@
+///////////////////////////////////////////////////////////////////////////////
+//
+// Legalese:
+// This file is part of the OpenNETCF time.h port for Windows CE.
+// You are free to use, modify or distribute this code or any
+// derivative work that you create.  This code is provided WITHOUT
+// WARRANTY and OpenNETCF does NOT claim in any way that this code
+// is fit for any specific or general use and holds NO RESPONSIBILITY
+// for consequences of using any of it.  It is simply provided as-is.
+//
+// About:
+// This is part of a free and open project to provide a simply way to
+// port that uses time.h functions to Windows CE.  For the latest
+// code, or to submit fixes, feature additions, etc. visit:
+//
+// http://www.opennetcf.com
+//
+// Version 0.01 - March 22, 2007
+//                Initial Release
+//
+// Version 0.02 - July 5, 2007
+//                Bug fixes.  UTC offset not properly accounted for unless SetTz had been previously called.
+//                            UTC offset used for functions like localtime using old, rather than current data
+//
+///////////////////////////////////////////////////////////////////////////////
+// Many but not all of the functions were created from the following source:
+//
+// Copyright (C) 2002 Michael Ringgaard. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// 1. Redistributions of source code must retain the above copyright
+//    notice, this list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright
+//    notice, this list of conditions and the following disclaimer in the
+//    documentation and/or other materials provided with the distribution.
+// 3. Neither the name of the project nor the names of its contributors
+//    may be used to endorse or promote products derived from this software
+//    without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+// ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+// SUCH DAMAGE.
+///////////////////////////////////////////////////////////////////////////////
+
+
+
+#include <windows.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "celibc.h"
+
+#ifndef __GNUC__
+///////////////////////////////////////////////////////////////////////////////
+// Macros
+///////////////////////////////////////////////////////////////////////////////
+#define TIME_FAILURE	0xFFFFFFFF
+#define ASC_BUFF_SIZE	26  // Ascii buffer size is 26 bytes, (24 chars and CR+LF)
+#define SEC_IN_HOUR     3600L
+#define SECS_IN_MIN		60L
+#define DAYSPERWEEK		7
+#define YEAR0           1900
+#define EPOCH_YR        1970
+#define SECS_DAY        (24L * 60L * 60L)
+#define LEAPYEAR(year)  (!((year) % 4) && (((year) % 100) || !((year) % 400)))
+#define TIME_MAX        2147483647L
+
+///////////////////////////////////////////////////////////////////////////////
+// Local Variables
+///////////////////////////////////////////////////////////////////////////////
+
+// Number of seconds between local time and UTC time, includes DST bias
+//
+LONG _localtime;
+
+// Is the local time in daylight savings time
+//
+DWORD _isdst;
+
+// Bias for daylight savings time
+//
+int _dstBias;
+
+// Contains the time zone string
+//
+char tz_name[2][32];
+
+// Contains the 1/1/1970 reference date/time
+//
+const SYSTEMTIME st1970 = {1970, 1,	4, 1, 0, 0, 0, 0};
+
+// Contains the number of days per month for
+// non leap and leap years
+//
+const int _ytab[2][12] =
+{
+  {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
+  {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
+};
+
+// Contains the days of the week abreviation
+//
+static char *aday[] = {
+    "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
+};
+
+// Contains the days of the week full name
+//
+static char *day[] = {
+    "Sunday", "Monday", "Tuesday", "Wednesday",
+    "Thursday", "Friday", "Saturday"
+};
+
+// Contains the months of the year abreviation
+//
+static char *amonth[] = {
+    "Jan", "Feb", "Mar", "Apr", "May", "Jun",
+    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
+};
+
+// Contains the months of the year full name
+//
+static char *month[] = {
+    "January", "February", "March", "April", "May", "June",
+    "July", "August", "September", "October", "November", "December"
+};
+
+///////////////////////////////////////////////////////////////////////////////
+// Forward declaration of internal functions
+///////////////////////////////////////////////////////////////////////////////
+
+// Convert system time into seconds since 1970
+//
+LONGLONG SystemTimeToSecondsSince1970(SYSTEMTIME * st);
+
+// Convert seconds since 1970 into a system time
+//
+void SecondsSince1970ToSystemTime(const time_t * timer, SYSTEMTIME * st,
+								  BOOLEAN local);
+
+// Initialize the time zone information needed for the time methods
+//
+void SetTz(SYSTEMTIME *_st);
+
+// Copy system time structure to tm structure
+//
+void SystemTimeToTm(SYSTEMTIME *st, struct tm * tmbuffer);
+void TmToSystemTime(struct tm * tmbuffer, SYSTEMTIME *st);
+
+// Get Julian Days from the begining of the year
+//
+DWORD JulianDays(SYSTEMTIME * st);
+
+// Method parses and formats strings
+//
+static void strfmt(char *str, const char *fmt, ...);
+
+// Reentrant version of gmttime
+//
+struct tm *gmtime_r_ce(const time_t *timer, struct tm *tmbuf, BOOLEAN local);
+
+// Reentrant version of localtime
+//
+struct tm *localtime_r_ce(const time_t *timer, struct tm *tmbuf);
+
+///////////////////////////////////////////////////////////////////////////////
+// Methods - The meat
+///////////////////////////////////////////////////////////////////////////////
+
+// Convert tm to a string in the format "Www Mmm dd hh:mm:ss yyyy",
+// where Www is the weekday, Mmm the month in letters, dd the day
+// of the month, hh:mm:ss the time, and yyyy the year. The string
+// is followed by a newline and a terminating null character,
+// conforming a total of 26 characters.
+//
+char *asctime(const struct tm* tmptr)
+{
+	static char ascbuf[ASC_BUFF_SIZE];
+    strftime(ascbuf, ASC_BUFF_SIZE, "%c\n", tmptr);
+    return ascbuf;
+}
+#endif //__GNUC__
+
+// Return number of clock ticks since process start.
+// NOTE: This differs from standard clock since GetTickCount is the
+//       number of milliseconds since system startup not process start.
+//       This will also rollover after 49.7 days of continuous system
+//       runtime.
+//
+clock_t clock(void)
+{
+	return GetTickCount();
+}
+
+#ifndef __GNUC__
+// Convert time_t value to string in the same format as asctime.
+//
+char* ctime(const time_t* timer)
+{
+	return asctime(localtime(timer));
+}
+
+// Reentrant version of gmttime_ce
+//
+struct tm *gmtime_r_ce(const time_t *timer, struct tm *tmbuf, BOOLEAN local)
+{
+  SYSTEMTIME	st;
+
+  SecondsSince1970ToSystemTime(timer, &st, local);
+  SetTz(&st);
+  if(_isdst) {
+    SecondsSince1970ToSystemTime(timer, &st, local);
+  }
+
+  // copy SYSTEMTIME data to tm structure
+  //
+  SystemTimeToTm(&st, tmbuf);
+
+  return tmbuf;
+
+}
+
+// Reentrant version of localtime
+//
+struct tm *localtime_r_ce(const time_t *timer, struct tm *tmbuf)
+{
+	return gmtime_r_ce(timer, tmbuf, TRUE);
+}
+
+// Convert a time_t value to a tm structure as UTC time.
+//
+struct tm *gmtime(const time_t *timer)
+{
+	return gmtime_r_ce(timer, &tmbuf, FALSE);
+}
+
+// Convert a time_t value to a tm structure as local time.
+//
+struct tm *localtime(const time_t *timer)
+{
+	return localtime_r_ce(timer, &tmbuf);
+}
+
+// time_t represents seconds since midnight January 1, 1970 UTC
+// (coordinated universal time) in 32-bits Win32 FILETIME structure is 64-bit,
+// which represents the number of 100-nanosecond (hns) intervals since
+// January 1, 1601 UTC (coordinate universal time) the time difference
+// between midnight January 1, 1970 and midnight January 1, 1601 is 11644473600 seconds
+//
+time_t mktime(struct tm *tptr)
+{
+	SYSTEMTIME st;
+
+	int day = 0;
+	int year = 0;
+	int seconds = 0;
+	int overflow;
+	int tm_year;
+	int yday, month;
+
+	TmToSystemTime(tptr, &st);
+	SetTz(&st);
+
+	// see if seconds are < 0
+	while(tptr->tm_sec < 0)
+	{
+		// steal 60 seconds from the minutes
+		tptr->tm_sec += 60;
+		tptr->tm_min--;
+	}
+	// roll any seconds > 60 into the minutes
+	tptr->tm_min += tptr->tm_sec / 60;
+	// then crop them off
+	tptr->tm_sec %= 60;
+
+	// see if minutes are < 0
+	while(tptr->tm_min < 0)
+	{
+		// steal 60 minutes from the hours
+		tptr->tm_min += 60;
+		tptr->tm_hour--;
+	}
+	// roll any minutes > 60 into the hours
+	tptr->tm_hour += tptr->tm_min / 60;
+	// then crop them off
+	tptr->tm_min %= 60;
+
+	// see if hours are < 0
+	while(tptr->tm_hour < 0)
+	{
+		// steal 24 hours from the days
+		tptr->tm_hour += 24;
+		day--;
+	}
+	// keep any "excess" days (tm doesn't have a convenient place for this)
+	day += tptr->tm_hour / 24;
+	// crop
+	tptr->tm_hour %= 24;
+
+	// roll any months > 12 into the years
+	tptr->tm_year += tptr->tm_mon / 12;
+	// then crop the off
+	tptr->tm_mon %= 12;
+
+	// see if months are < 0
+	if (tptr->tm_mon < 0)
+	{
+		// steal 12 months from the years
+		tptr->tm_mon += 12;
+		tptr->tm_year--;
+	}
+
+	// add number of days into the month to total day
+	day += (tptr->tm_mday - 1);
+
+	// if days are < 0 then calculate the number of days
+	// checking to see if the month is a leap year month
+	while (day < 0)
+	{
+		// If months are < 0 then steal 12 months from number of years
+		// for the day calculation
+		if(--tptr->tm_mon < 0)
+		{
+			tptr->tm_year--;
+			tptr->tm_mon = 11;
+		}
+		day += _ytab[LEAPYEAR(YEAR0 + tptr->tm_year)][tptr->tm_mon];
+	}
+	// if day is greater then the number of days in the month
+	// subtract the number of days in the month and adjust the
+	// month
+	while (day >= _ytab[LEAPYEAR(YEAR0 + tptr->tm_year)][tptr->tm_mon])
+	{
+		day -= _ytab[LEAPYEAR(YEAR0 + tptr->tm_year)][tptr->tm_mon];
+		if (++(tptr->tm_mon) == 12)
+		{
+			tptr->tm_mon = 0;
+			tptr->tm_year++;
+		}
+	}
+	tptr->tm_mday = day + 1;
+	year = EPOCH_YR;
+
+	// if year is less then 1970 then return error
+	if (tptr->tm_year < year - YEAR0) return (time_t) -1;
+
+	seconds = 0;
+	day = 0;                      // Means days since day 0 now
+	overflow = 0;
+
+	// Assume that when day becomes negative, there will certainly
+	// be overflow on seconds.
+	// The check for overflow needs not to be done for leapyears
+	// divisible by 400.
+	// The code only works when year (1970) is not a leapyear.
+	tm_year = tptr->tm_year + YEAR0;
+
+	// make sure we are not past the max year for 32-bit number
+	if (TIME_MAX / 365 < tm_year - year) overflow++;
+
+	// calculate number of days since EPOCH
+	day = (tm_year - year) * 365;
+
+	if (TIME_MAX - day < (tm_year - year) / 4 + 1) overflow++;
+
+	day += (tm_year - year) / 4 + ((tm_year % 4) && tm_year % 4 < year % 4);
+	day -= (tm_year - year) / 100 + ((tm_year % 100) && tm_year % 100 < year % 100);
+	day += (tm_year - year) / 400 + ((tm_year % 400) && tm_year % 400 < year % 400);
+
+	// setup for calculation of the yday or Julian day since Jan 1
+	yday = month = 0;
+
+	// add up the number of days for the preceding months
+	while (month < tptr->tm_mon)
+	{
+		yday += _ytab[LEAPYEAR(tm_year)][month];
+		month++;
+	}
+	// add the number of days in the current month
+	yday += (tptr->tm_mday - 1);
+
+	// make sure the didn't overflow
+	if (day + yday < 0) overflow++;
+
+	day += yday;
+
+	// set the year day in the structure
+	tptr->tm_yday = yday;
+
+	// calculate the weekday
+	tptr->tm_wday = (day + 4) % 7;               // Day 0 was thursday (4)
+
+	// start the seconds calculation by totaling the hours, min, seconds
+	seconds = ((tptr->tm_hour * 60L) + tptr->tm_min) * 60L + tptr->tm_sec;
+
+	// make sure we are not going to overflow
+	if ((TIME_MAX - seconds) / SECS_DAY < day) overflow++;
+
+	// calculate the number of seconds for the number of days
+	seconds += day * SECS_DAY;
+
+	// Now adjust according to timezone and daylight saving time
+	if (((_localtime > 0) && (TIME_MAX - _localtime < seconds))
+	  || ((_localtime < 0) && (seconds < -_localtime)))
+		  overflow++;
+
+	// Adjust for local time zone
+  seconds += _localtime;
+
+	// return error if we are going to blow the max values
+	if (overflow) return (time_t) -1;
+
+	if ((time_t) seconds != seconds) return (time_t) -1;
+
+	// return the number of seconds since EPOCH
+	return (time_t) seconds;
+}
+
+
+// Get the current system time and convert to seconds since
+// 1/1/1970.  Store the seconds value in tloc if not a NULL pointer then
+// return the seconds value.
+//
+time_t time(time_t *tloc)
+{
+	SYSTEMTIME	st;
+	LONGLONG	secs = 0;
+
+	// Get current system time
+	GetSystemTime(&st);
+
+  // Set time zone information
+	//
+	SetTz(&st);
+
+	// convert system time to number of seconds since 1970
+	//
+	secs = SystemTimeToSecondsSince1970(&st);
+
+	// check for failure
+	//
+	if(secs == TIME_FAILURE)
+	{
+		return TIME_FAILURE;
+	}
+
+	// If tloc is not NULL, the return value is also stored in the location to which tloc points
+	//
+	if(tloc != NULL)
+	{
+		if(IsBadWritePtr(tloc, sizeof(time_t)))
+		{
+			return TIME_FAILURE;
+		}
+		memcpy(tloc, &secs, sizeof(time_t));
+	}
+
+	return secs;
+}
+
+// The strftime function is a modified version created by the following:
+// written 6 september 1989 by jim nutt
+// released into the public domain by jim nutt
+//
+// modified 21-Oct-89 by Rob Duff
+//
+//
+// size_t strftime(char *str,
+//                 size_t maxs,
+//                 const char *fmt,
+//                 const struct tm *t)
+//
+//      this functions acts much like a sprintf for time/date output.
+//      given a pointer to an output buffer, a format string and a
+//      time, it copies the time to the output buffer formatted in
+//      accordance with the format string.  the parameters are used
+//      as follows:
+//
+//          str is a pointer to the output buffer, there should
+//          be at least maxs characters available at the address
+//          pointed to by str.
+//
+//          maxs is the maximum number of characters to be copied
+//          into the output buffer, included the '\0' terminator
+//
+//          fmt is the format string.  a percent sign (%) is used
+//          to indicate that the following character is a special
+//          format character.  the following are valid format
+//          characters:
+//
+//              %A      full weekday name (Monday)
+//              %a      abbreviated weekday name (Mon)
+//              %B      full month name (January)
+//              %b      abbreviated month name (Jan)
+//              %c      standard date and time representation
+//              %d      day-of-month (01-31)
+//              %H      hour (24 hour clock) (00-23)
+//              %I      hour (12 hour clock) (01-12)
+//              %j      day-of-year (001-366)
+//              %M      minute (00-59)
+//              %m      month (01-12)
+//              %p      local equivalent of AM or PM
+//              %S      second (00-59)
+//              %U      week-of-year, first day sunday (00-53)
+//              %W      week-of-year, first day monday (00-53)
+//              %w      weekday (0-6, sunday is 0)
+//              %X      standard time representation
+//              %x      standard date representation
+//              %Y      year with century
+//              %y      year without century (00-99)
+//              %Z      timezone name
+//              %%      percent sign
+//
+//      the standard date string is equivalent to:
+//
+//          %a %b %d %Y
+//
+//      the standard time string is equivalent to:
+//
+//          %H:%M:%S
+//
+//      the standard date and time string is equivalent to:
+//
+//          %a %b %d %H:%M:%S %Y
+//
+//      strftime returns the number of characters placed in the
+//      buffer, not including the terminating \0, or zero if more
+//      than maxs characters were produced.
+//
+size_t strftime(char *s, size_t maxs, const char *f, const struct tm *t)
+{
+	int			w;
+	char		*p, *q, *r;
+	static char	buf[26];
+
+	p = s;
+	q = s + maxs - 1;
+	while ((*f != '\0'))
+	{
+		if (*f++ == '%')
+		{
+			r = buf;
+			switch (*f++)
+			{
+				case '%' :
+					r = "%";
+					break;
+
+				case 'a' :
+					r = aday[t->tm_wday];
+					break;
+
+				case 'A' :
+					r = day[t->tm_wday];
+					break;
+
+				case 'b' :
+					r = amonth[t->tm_mon];
+					break;
+
+				case 'B' :
+					r = month[t->tm_mon];
+					break;
+
+				case 'c' :
+					strfmt(r, "%0 %0 %2 %2:%2:%2 %4",
+						  aday[t->tm_wday], amonth[t->tm_mon],
+						  t->tm_mday,t->tm_hour, t->tm_min,
+						  t->tm_sec, t->tm_year+1900);
+					break;
+
+				case 'd' :
+					strfmt(r,"%2",t->tm_mday);
+					break;
+
+				case 'H' :
+					strfmt(r,"%2",t->tm_hour);
+					break;
+
+				case 'I' :
+					strfmt(r,"%2",(t->tm_hour%12)?t->tm_hour%12:12);
+					break;
+
+				case 'j' :
+					strfmt(r,"%3",t->tm_yday+1);
+					break;
+
+				case 'm' :
+					strfmt(r,"%2",t->tm_mon+1);
+					break;
+
+				case 'M' :
+					strfmt(r,"%2",t->tm_min);
+					break;
+
+				case 'p' :
+					r = (t->tm_hour>11)?"PM":"AM";
+					break;
+
+				case 'S' :
+					strfmt(r,"%2",t->tm_sec);
+					break;
+
+				case 'U' :
+					w = t->tm_yday/7;
+					if (t->tm_yday%7 > t->tm_wday)
+						w++;
+					strfmt(r, "%2", w);
+					break;
+
+				case 'W' :
+					w = (t->tm_yday + DAYSPERWEEK -
+						(t->tm_wday ?
+						(t->tm_wday - 1) :
+						(DAYSPERWEEK - 1))) / DAYSPERWEEK;
+					strfmt(r, "%2", w);
+					break;
+
+				case 'w' :
+					strfmt(r,"%1",t->tm_wday);
+					break;
+
+				case 'x' :
+					strfmt(r, "%2/%2/%2", t->tm_mon + 1,
+						   t->tm_mday, t->tm_year+1900);
+					break;
+
+				case 'X' :
+					strfmt(r, "%2:%2:%2", t->tm_hour,
+						   t->tm_min, t->tm_sec);
+					break;
+
+				case 'y' :
+					strfmt(r,"%2",t->tm_year%100);
+					break;
+
+				case 'Y' :
+					strfmt(r,"%4",t->tm_year+1900);
+					break;
+
+				case 'Z' :
+					r = (t->tm_isdst && tz_name[1][0])?tz_name[1]:tz_name[0];
+					break;
+
+				default:
+					buf[0] = '%';		// reconstruct the format
+					buf[1] = f[-1];
+					buf[2] = '\0';
+					if (buf[1] == 0)
+						f--;			// back up if at end of string
+			}
+			while (*r)
+			{
+				if (p == q)
+				{
+					*q = '\0';
+					return 0;
+				}
+				*p++ = *r++;
+			}
+		}
+		else
+		{
+			if (p == q)
+			{
+				*q = '\0';
+				return 0;
+			}
+			*p++ = f[-1];
+		}
+	}
+	*p = '\0';
+	return p - s;
+}
+
+//
+// static void strfmt(char *str, char *fmt);
+//
+// simple sprintf for strftime
+//
+// each format descriptor is of the form %n
+// where n goes from zero to four
+//
+// 0    -- string %s
+// 1..4 -- int %?.?d
+//
+static void strfmt(char *str, const char *fmt, ...)
+{
+	int ival, ilen;
+	char *sval;
+	static int pow[5] = { 1, 10, 100, 1000, 10000 };
+	va_list vp;
+
+	va_start(vp, fmt);
+	while (*fmt)
+	{
+		if (*fmt++ == '%')
+		{
+			ilen = *fmt++ - '0';
+			if (ilen == 0)                // zero means string arg
+			{
+				sval = va_arg(vp, char*);
+				while (*sval)
+					*str++ = *sval++;
+			}
+			else                          // always leading zeros
+			{
+				ival = va_arg(vp, int);
+				while (ilen)
+				{
+					ival %= pow[ilen--];
+					*str++ = (char)('0' + ival / pow[ilen]);
+				}
+			}
+		}
+		else  *str++ = fmt[-1];
+	}
+	*str = '\0';
+	va_end(vp);
+}
+
+// internal functions
+//-----------------------------------------------------------------------------
+// Convert 100ns units since 1601 to seconds since 1970
+//
+LONGLONG SystemTimeToSecondsSince1970(SYSTEMTIME *st)
+{
+	ULARGE_INTEGER	uli;
+	FILETIME		ft;
+	ULARGE_INTEGER	uli1970;
+	FILETIME		ft1970;
+
+	// convert to a FILETIME
+	// Gives number of 100-nanosecond intervals since January 1, 1601 (UTC)
+	//
+	if(!SystemTimeToFileTime(st, &ft))
+	{
+		return TIME_FAILURE;
+	}
+
+	// convert to a FILETIME
+	// Gives number of 100-nanosecond intervals since January 1, 1970 (UTC)
+	//
+	if(!SystemTimeToFileTime(&st1970, &ft1970))
+	{
+		return TIME_FAILURE;
+	}
+
+	// Copy file time structures into ularge integer so we can do
+	// the math more easily
+	//
+	memcpy(&uli, &ft, sizeof(uli));
+	memcpy(&uli1970, &ft1970, sizeof(uli1970));
+
+	// Subtract the 1970 number of 100 ns value from the 1601 100 ns value
+	// so we can get the number of 100 ns value between 1970 and now
+	// then devide be 10,000,000 to get the number of seconds since 1970
+	//
+	uli.QuadPart = ((uli.QuadPart - uli1970.QuadPart) / 10000000);
+
+	return (LONGLONG)uli.QuadPart;
+}
+
+// Convert seconds since 1970 to a file time in 100ns units since 1601
+// then to a system time.
+//
+void SecondsSince1970ToSystemTime(const time_t * timer, SYSTEMTIME * st,
+								  BOOLEAN local)
+{
+	ULARGE_INTEGER	uli;
+	FILETIME		ft;
+	ULARGE_INTEGER	uli1970;
+	FILETIME		ft1970;
+
+	// Convert system time to file time
+	//
+	if(!SystemTimeToFileTime(&st1970, &ft1970))
+	{
+		st = NULL;
+		return;
+	}
+
+	// convert hundreds of nanosecs to secs: 1 sec = 1e7 100ns
+	// Gives number of seconds since 1/1/1601 (UTC)
+	//
+  memcpy(&uli, timer, sizeof(uli));
+  memcpy(&uli1970, &ft1970, sizeof(uli1970));
+
+	// If we want local time then subtract the number of seconds between
+	// UTC and current local time
+	//
+	if (local)
+	{
+		// Calculate 100ns since 1/1/1601 local time
+		//
+    uli.QuadPart = (((uli.QuadPart - _localtime)*10000000) + uli1970.QuadPart);
+	}
+	else
+	{
+		// Calculate 100ns since 1/1/1601 UTC
+		//
+		uli.QuadPart = ((uli.QuadPart)*10000000 + uli1970.QuadPart);
+	}
+
+	// copy data back into the ft
+	//
+	memcpy(&ft, &uli, sizeof(uli));
+
+	// convert to a SYSTEMTIME
+	//
+	if(!FileTimeToSystemTime(&ft, st))
+	{
+		st = NULL;
+		return;
+	}
+
+	return;
+}
+
+// Set the time zone information needed for the rest of the methods
+//
+void SetTz(SYSTEMTIME *_st)
+{
+	TIME_ZONE_INFORMATION	tz;
+	SYSTEMTIME				st = *_st;
+	FILETIME				ftDT; // Daylight savings file time
+	FILETIME				ftST; // Standard time file time
+	FILETIME				ft;   // file time to compare
+	int						i;
+
+	GetTimeZoneInformation(&tz);
+
+	// Convert current system time, daylight savings changover time
+	// and standard time to file time to see if current time is between
+	// the two dates.  If so then we are in daylight savings otherwise we
+	// are not.
+	//
+	SystemTimeToFileTime(&st, &ft);
+	tz.DaylightDate.wYear = st.wYear;
+	tz.StandardDate.wYear = st.wYear;
+  SystemTimeToFileTime(&tz.DaylightDate, &ftDT);
+	SystemTimeToFileTime(&tz.StandardDate, &ftST);
+
+  // -1 First file time is earlier than second file time.
+  //  0 First file time is equal to second file time.
+  //  1 First file time is later than second file time.
+	//
+	if ((CompareFileTime(&ft,&ftDT) >= 0) && (CompareFileTime(&ft,&ftST) <= 0) )
+	{
+		_isdst = TRUE;
+	}
+	else
+	{
+		_isdst = FALSE;
+	}
+
+	// Set localtime difference in seconds from UTC
+	//
+	if (_isdst)
+	{
+		// Adjust for Daylight Savings Time and convert to seconds
+		//
+		_localtime = (tz.Bias + tz.DaylightBias) * SECS_IN_MIN;
+	}
+	else
+	{
+		// Convert to seconds
+		//
+		_localtime = tz.Bias * SECS_IN_MIN;
+	}
+
+	_dstBias = tz.DaylightBias;
+
+	// Set the standard and daylight strings
+	//
+	for (i=0;i<32;i++)
+	{
+		tz_name[0][i] = (char)tz.StandardName[i];
+		tz_name[1][i] = (char)tz.DaylightName[i];
+	}
+}
+
+// Copy system time structure to tm structure
+//
+void SystemTimeToTm(SYSTEMTIME *st, struct tm * tmbuffer)
+{
+	tmbuffer->tm_hour = st->wHour;
+    tmbuffer->tm_mday = st->wDay;
+    tmbuffer->tm_min = st->wMinute;
+    tmbuffer->tm_mon = st->wMonth - 1;
+    tmbuffer->tm_sec = st->wSecond;
+    tmbuffer->tm_wday = st->wDayOfWeek;
+    tmbuffer->tm_yday = JulianDays(st);		// Julian days, numer of days since Jan 1
+	tmbuffer->tm_year = st->wYear - 1900;
+	tmbuffer->tm_isdst = _isdst;			// Is Daylight Savings Time
+}
+
+void TmToSystemTime(struct tm * tmbuffer, SYSTEMTIME *st)
+{
+  st->wHour = tmbuffer->tm_hour;
+  st->wDay = tmbuffer->tm_mday;
+  st->wMinute = tmbuffer->tm_min;
+  st->wMonth = tmbuffer->tm_mon + 1;
+  st->wSecond = tmbuffer->tm_sec;
+  st->wDayOfWeek = tmbuffer->tm_wday;
+  st->wYear = tmbuffer->tm_year + 1900;
+  st->wMilliseconds = 0;
+}
+
+// Get the JulianDay from a Gregorian Date for number of days into the current
+// year
+// Algorithm from: http://www.vsg.cape.com/~pbaum/date/jdalg2.htm
+//
+DWORD JulianDays(SYSTEMTIME * st)
+{
+	int m = 0;
+	int y = 0;
+	double jdd = 0;
+	double jddYearStart = 0;
+
+	// Calculate the Julian day for the beginning of the year
+	//
+    m = 13;
+	y = st->wYear - 1;
+    jddYearStart = 1 + (153 * m - 457) / 5 + 365 * y + (y / 4) - (y / 100) + (y / 400) + 1721118.5;
+
+	// Calculate Julian Day for Current Date
+	//
+	if (st->wMonth >= 3)
+	{
+		m = st->wMonth;
+		y = st->wYear;
+	}
+    jdd = st->wDay + (153 * m - 457) / 5 + 365 * y + (y / 4) - (y / 100) + (y / 400) + 1721118.5;
+
+	// Subract the year start Julian date from the Current Julian date to get
+	// the number of Julian days from the year start
+	//
+	return (DWORD)(jdd - jddYearStart);
+}
+#endif //__GNUC__
+
+
+/**
+ * LuaCE
+ *
+ *      Pedro Miller Rabinovitch, <[email protected]>
+ *      http://www.inf.puc-rio.br/~miller/luace
+ *
+ * A quick port of Lua for Windows CE.
+ **/
+
+
+
+//int errno = 0;
+
+const char *getenv( const char *name ) {
+	return NULL;
+}
+
+
+char *strdup( const char *str ) {
+	char *ptr = (char *)malloc( sizeof(char) * strlen( str ) + 1 );
+	strcpy( ptr, str );
+	return ptr;
+}
+
+FILE *tmpfile() {
+	return NULL;
+}
+
+char *tmpnam( char *str ) {
+	return NULL;
+}
+
+#define _tcslen wcslen
+#define _tcsncpy wcsncpy
+#define _T(a) L##a
+
+int system( const char *cmd ) {
+	TCHAR tpath[MAX_PATH], args[1024], cmds[1024];
+	BOOL ret, cont = TRUE;
+	int i, len, exit_code = -100;
+    PROCESS_INFORMATION pi;
+
+    ZeroMemory( &pi, sizeof(pi) );
+
+	memset(tpath,0,MAX_PATH*sizeof(TCHAR));
+	memset(cmds,0,1024*sizeof(TCHAR));
+	memset(args,0,1024*sizeof(TCHAR));
+
+	mbstowcs(cmds, cmd, 1024);
+	len = _tcslen(cmds);
+
+	if (cmds[0] == _T('"')) {
+		for (i = 1; i < len; i++) {
+			if (cmds[i] == _T('"'))
+				break;
+		}
+		if (i >= len)
+			return -1;
+		i++;
+		_tcsncpy(tpath, cmds + 1, i - 2);
+		_tcsncpy(args, cmds + i, len - i);
+	}
+	else {
+		for (i = 0; i < len; i++) {
+			if (cmds[i] == _T(' '))
+				break;
+		}
+		_tcsncpy(tpath, cmds, i);
+		_tcsncpy(args, cmds + i, len - i);
+	}
+
+#ifdef DEBUGGING_PROCESS
+	ret = CreateProcess(tpath, args, NULL, NULL, FALSE, DEBUG_PROCESS, NULL, NULL, NULL, &pi);
+#else
+	ret = CreateProcess(tpath, args, NULL, NULL, FALSE, 0, NULL, NULL, NULL, &pi);
+#endif
+
+	if (!ret) {
+		return GetLastError();
+	}
+
+#ifdef DEBUGGING_PROCESS
+	// Enter debug loop
+	while (cont) {
+
+		DEBUG_EVENT dbgEvt;
+
+		if ( WaitForDebugEvent( &dbgEvt, INFINITE ) ) {
+
+			switch (dbgEvt.dwDebugEventCode) {
+
+				case EXCEPTION_DEBUG_EVENT:
+					exit_code = (int) (dbgEvt.u.Exception.ExceptionRecord.ExceptionCode - 0xC0000000);
+					TerminateProcess( pi.hProcess, exit_code + (1 << 16) );
+					break;
+
+				case EXIT_PROCESS_DEBUG_EVENT:
+					cont = FALSE;
+					break;
+			}
+
+			ContinueDebugEvent( dbgEvt.dwProcessId, dbgEvt.dwThreadId, DBG_CONTINUE );
+		}
+	}
+#else
+    // Wait until child process exits.
+    WaitForSingleObject( pi.hProcess, INFINITE );
+#endif
+
+    GetExitCodeProcess( pi.hProcess, &exit_code );
+
+    // Close process and thread handles.
+    CloseHandle( pi.hProcess );
+
+ 	return exit_code;
+}
+
+/* alloc's and returns a converted wide-char string from a normal one */
+wchar_t *atowcs( const char *str ) {
+	int len;
+	wchar_t *wstr;
+	if( str == NULL )
+		return NULL;
+	len = strlen( str );
+	wstr = (wchar_t *)malloc( sizeof( wchar_t )*2*(len + 1) );
+	wsprintf( wstr, L"%hs", str );
+	return wstr;
+}
+
+int rename( const char *src, const char *dst ) {
+	wchar_t *wsrc = atowcs( src ),
+		    *wdst = atowcs( dst );
+	int res = 0;
+
+	if( !MoveFile( wsrc, wdst ))
+		res = GetLastError();
+
+	free( wsrc );
+	free( wdst );
+
+	return res;
+}
+
+int remove( const char *fname ) {
+	wchar_t *wfname = atowcs( fname );
+	int res = 0;
+
+	if( !DeleteFile( wfname ))
+		res = GetLastError();
+
+	free( wfname );
+
+	return res;
+}
+
+char *setlocale( int category, const char *locale ) {
+	return NULL;
+}
+
+struct lconv *localeconv( void )
+{
+	return NULL;
+}
+
+
+static int file_exists(const char* filename) {
+  FILE* f = fopen(filename, "r");
+  if(f != NULL)
+  {
+    fclose(f);
+    return 1;
+  }
+  return 0;
+}
+
+static char* conv_filename(char *filename) {
+  size_t i;
+  for (i = 0; i < strlen(filename); i++) {
+    if (filename[i] == '/')
+      filename[i] = '\\';
+  }
+  return filename;
+}
+
+static char* find_file(const char* filename) {
+  char* fullpath = malloc(sizeof(char) * (MAX_PATH + 1));
+  if(!fullpath)
+    return NULL;
+
+  if (filename != NULL && strlen(filename) > 0)
+  {
+    if (filename[0] == '\\' || filename[0] == '/')//absolute path
+    {
+      strcpy(fullpath, filename);
+      return conv_filename(fullpath);
+    }
+    else
+    {
+      TCHAR tpath[MAX_PATH + 1];
+      char* lastDash;
+      memset(tpath, 0, (MAX_PATH+1) * sizeof(TCHAR));
+      GetModuleFileName(NULL, tpath, MAX_PATH);
+      wcstombs(fullpath, tpath, MAX_PATH);
+      lastDash = strrchr(fullpath,'\\');
+      fullpath[lastDash - fullpath+1] = 0;
+      strncat(fullpath, filename, MAX_PATH - strlen(filename));
+      return conv_filename(fullpath);
+    }
+  }
+  free(fullpath);
+  return NULL;
+}
+
+FILE* _fopen(const char *filename, const char *flags) {
+  FILE *fp = NULL;
+  char *full_path = find_file(filename);
+  if (full_path) {
+    fp = fopen(full_path, flags);
+    free(full_path);
+  }
+  return fp;
+}
+
+#if 0
+int chdir(const char *path) {
+	wchar_t *wpath = atowcs( path );
+	int res = 0;
+
+	if( !_wchdir( wpath ))
+		res = GetLastError();
+
+	free( wpath );
+
+	return res;
+}
+#endif
+
+int mkdir(const char *path) {
+	wchar_t *wpath = atowcs( path );
+	int res = 0;
+
+	if( !CreateDirectory(wpath, NULL))
+		res = GetLastError();
+
+	free( wpath );
+
+	return res;
+}
+
+HINSTANCE LoadLibraryA(LPCSTR path)
+{
+	wchar_t *wpath = atowcs( path );
+	HINSTANCE res = LoadLibrary( wpath );
+	free( wpath );
+	return res;
+}
+
+HMODULE GetModuleHandleA(LPCSTR module)
+{
+	wchar_t *wmodule = atowcs( module );
+	HMODULE res = GetModuleHandle( module );
+	free( module );
+	return res;
+}

+ 158 - 0
SquiLu-ext/celibc.h

@@ -0,0 +1,158 @@
+
+#ifndef LUA_WINCE_H
+#define LUA_WINCE_H
+
+#ifndef _WIN32_WCE
+#error "_WIN32_WCE should be defined first"
+#endif
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <windef.h>
+
+// these pragmas help Studio to build for some CE platforms - use as necessary
+
+#ifndef __GNUC__
+// Number of clock ticks per second. Used by the clock() function.
+//
+#define CLOCKS_PER_SEC		1000
+
+// Macro for CLK_PER_SEC
+//
+#define CLK_TICK			CLOCKS_PER_SEC
+
+// structure definitions
+//
+#ifndef _TM_DEFINED
+struct tm {
+    int tm_sec;			// seconds
+    int tm_min;			// minutes
+    int tm_hour;		// hours
+    int tm_mday;		// day of the month
+    int tm_mon;			// month
+    int tm_year;		// years since 1900 (from 0)
+    int tm_wday;		// days since Sunday (from 0)
+    int tm_yday;		// days since Jan 1
+    int tm_isdst;		// daylight savings (summertime) flag
+    };
+#define _TM_DEFINED
+#endif
+
+// typedefs
+//
+
+// since time_t is already defined in CE as a ULONG, we need a new definition
+//
+typedef LONGLONG time_t;
+
+static struct tm tmbuf;
+
+// Convert tm to a string in the format "Www Mmm dd hh:mm:ss yyyy",
+// where Www is the weekday, Mmm the month in letters, dd the day
+// of the month, hh:mm:ss the time, and yyyy the year. The string
+// is followed by a newline and a terminating null character,
+// conforming a total of 26 characters.
+//
+char *asctime(const struct tm* tmptr);
+
+#endif //__GNUC__
+
+#define clock_t DWORD
+// Return number of clock ticks since process start.
+//
+clock_t clock(void);
+
+#ifndef __GNUC__
+// Convert time_t value to string in the same format as asctime.
+//
+char* ctime(const time_t* timer);
+
+// Convert a time_t value to a tm structure as UTC time.
+//
+struct tm* gmtime(const time_t* timer);
+
+// Convert a time_t value to a tm structure as local time.
+//
+struct tm* localtime(const time_t* timer);
+
+// Returns the Unix timestamp corresponding to the arguments given.
+// This timestamp is a long integer containing the number of seconds between the Unix Epoch
+// (January 1 1970 00:00:00 GMT) and the time specified.
+//
+time_t mktime(struct tm *tptr);
+
+// Get the current time from the system clock. Stores that value in timer.
+// If timer is null, the value is not stored, but it is still returned by
+// the function.
+//
+time_t time(time_t* timer);
+
+// Format tm into a date/time string
+//
+size_t strftime(char *s, size_t maxs, const char *f, const struct tm *t);
+#endif
+
+
+/* these are terrible, but just for CE quick-dirty (pedro) */
+#define strcoll strcmp
+#ifndef isalpha
+#define isalpha(c)			( ('a' <= (c) && (c) <= 'z') || ('A' <= (c) && (c) <= 'Z') )
+#define isdigit(c)			( '0' <= (c) && (c) <= '9' )
+#define isalnum(c)			( isalpha(c) || isdigit(c) )
+#define isspace(c)			( (c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r' )
+#define iscntrl(c)			( (0x00 <= (c) && (c) <= 0x1F) || (c) == 0x7F)
+#define islower(c)			( 'a' <= (c) && (c) <= 'z' )
+#define isprint(c)			( (0x20 <= (c) && (c) <= 0x7E) )
+#define ispunct(c)			( isprint(c) && ( !isalnum(c) && !isspace(c) ))
+#define isupper(c)			( 'A' <= (c) && (c) <= 'Z' )
+#define isxdigit(c)			( isdigit(c) || ('a' <= (c) && (c) <= 'f') || ('a' <= (c) && (c) <= 'f') )
+#endif
+
+#ifndef BUFSIZ
+#define BUFSIZ 1024
+#endif
+
+#ifndef MAX_PATH
+#define MAX_PATH 2048
+#endif
+
+#ifndef L_tmpnam
+#define L_tmpnam MAX_PATH
+#endif
+
+
+char *strdup( const char *str );
+const char *getenv( const char *name );
+FILE *tmpfile();
+
+int system( const char * );
+int rename( const char *, const char * );
+int remove( const char * );
+char *tmpnam( char * );
+
+//int chdir(const char *path);
+int mkdir(const char *path);
+
+char *setlocale( int category, const char *locale );
+struct lconv *localeconv( void );
+
+HINSTANCE LoadLibraryA(LPCSTR);
+HMODULE GetModuleHandleA(LPCSTR);
+
+#define strerror(errnum) ("(Error ocurred)")
+//extern int errno;
+#define errno (GetLastError ())
+
+FILE* _fopen(const char *filename, const char *flags);
+
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif

+ 5 - 0
SquiLu-ext/dynamic_library.cpp

@@ -7,8 +7,13 @@
 #ifdef WIN32
 #include <windows.h>
 #define CLOSE_LIB(lib) (FreeLibrary((HINSTANCE)lib) != 0)
+#ifdef _WIN32_WCE
+#define OPEN_LIB(lib) (void*)LoadLibraryA(lib)
+#define GET_SYM(lib, sn) GetProcAddressA((HINSTANCE)lib, sn)
+#else
 #define OPEN_LIB(lib) (void*)LoadLibrary(lib)
 #define GET_SYM(lib, sn) GetProcAddress((HINSTANCE)lib, sn)
+#endif
 typedef void* (WINAPI*cPtrFuncVarArg)(...);
 #else
 #include <dlfcn.h>

+ 8 - 1
SquiLu-ext/lua_socket.cpp

@@ -709,7 +709,14 @@ p_timeout lua_timeout_markstart(p_timeout tm) {
 double lua_timeout_gettime(void) {
     FILETIME ft;
     double t;
-    GetSystemTimeAsFileTime(&ft);
+#if defined(UNDER_CE)
+    // Windows CE does not define GetSystemTimeAsFileTime so we do it in two steps.
+    SYSTEMTIME st;
+    GetSystemTime( &st );
+    SystemTimeToFileTime( &st, &ft );
+  #else
+    GetSystemTimeAsFileTime( &ft );  // never fails
+  #endif
     /* Windows file time (time since January 1, 1601 (UTC)) */
     t  = ft.dwLowDateTime/1.0e7 + ft.dwHighDateTime*(4294967296.0/1.0e7);
     /* convert to Unix Epoch time (time since January 1, 1970 (UTC)) */

+ 27 - 4
SquiLu-ext/sq_fs.c

@@ -32,15 +32,21 @@
 
 #define _LARGEFILE64_SOURCE
 
+#ifndef _WIN32_WCE
 #include <errno.h>
+#endif
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <time.h>
 #include <sys/stat.h>
 
-#ifdef _WIN32
+#if defined(_WIN32) || defined(_WIN32_WCE)
+#ifdef _WIN32_WCE
+#include "celibc.h"
+#else
 #include <direct.h>
+#endif
 #include <windows.h>
 #include <io.h>
 #include <sys/locking.h>
@@ -102,9 +108,17 @@ typedef struct dir_data {
   #define STAT_STRUCT struct stati64
  #else
   #define lfs_setmode(L,file,m)   ((void)L, _setmode(_fileno(file), m))
-  #define STAT_STRUCT struct _stati64
+  #ifdef _WIN32_WCE
+   #define STAT_STRUCT struct stat
+  #else
+   #define STAT_STRUCT struct _stati64
+  #endif
  #endif
-#define STAT_FUNC _stati64
+#ifdef _WIN32_WCE
+ #define STAT_FUNC _stat
+#else
+ #define STAT_FUNC _stati64
+#endif
 #define LSTAT_FUNC STAT_FUNC
 #else
 #define _O_TEXT               0
@@ -117,6 +131,7 @@ typedef struct dir_data {
 
 static const SQChar currFileName_key[] = _SC("currFileName");
 
+#ifndef _WIN32_WCE
 /*
 ** This function changes the working (current) directory
 */
@@ -149,6 +164,8 @@ static SQRESULT sqfs_currentdir (HSQUIRRELVM v) {
     return 1;
   }
 }
+#endif
+
 #if 0
 /*
 ** Check if the given element on the stack is a file and returns it.
@@ -386,7 +403,9 @@ static SQRESULT sqfs_mkdir (HSQUIRRELVM v) {
     SQ_FUNC_VARS_NO_TOP(v);
     SQ_GET_STRING(v, 2, path);
 	int fail;
-#ifdef _WIN32
+#ifdef _WIN32_WCE
+	fail = mkdir (path);
+#elif defined(_WIN32)
 	int oldmask = umask (0);
 	fail = _mkdir (path);
 #else
@@ -397,7 +416,9 @@ static SQRESULT sqfs_mkdir (HSQUIRRELVM v) {
 	if (fail) {
         return sq_throwerror (v, "%s", strerror(errno));
 	}
+#ifndef _WIN32_WCE
 	umask (oldmask);
+#endif
 	sq_pushbool (v, SQTrue);
 	return 1;
 }
@@ -799,8 +820,10 @@ static void set_info (HSQUIRRELVM v) {
 static SQRegFunction sqfs_methods[] =
 {
 	_DECL_FUNC(attributes,  -2, _SC(".ss")),
+#ifndef _WIN32_WCE
 	_DECL_FUNC(chdir,  2, _SC(".s")),
 	_DECL_FUNC(currentdir,  1, _SC(".")),
+#endif
 /*
 	_DECL_FUNC(lock,  -3, _SC("xsii")),
 */

+ 6 - 2
SquiLu-ext/sq_mongoose.cpp

@@ -251,7 +251,8 @@ sq_http_request_get_conn_buf(HSQUIRRELVM v)
     sq_pushstring(v, buf, buf_size);
     return 1;
 }
-
+
+#ifndef _WIN32_WCE
 static SQRESULT
 sq_http_request_handle_cgi_request(HSQUIRRELVM v)
 {
@@ -262,7 +263,8 @@ sq_http_request_handle_cgi_request(HSQUIRRELVM v)
     mg_handle_cgi_request(conn, prog);
 
     return 0;
-}
+}
+#endif
 
 static SQRESULT
 sq_http_request_get_option(HSQUIRRELVM v)
@@ -557,7 +559,9 @@ static SQRegFunction mg_http_request_methods[] =
 	_DECL_FUNC(get_cookie,  2, _SC("xs")),
 	_DECL_FUNC(get_header,  2, _SC("xs")),
 	_DECL_FUNC(send_file,  2, _SC("xs")),
+#ifndef _WIN32_WCE
 	_DECL_FUNC(handle_cgi_request,  2, _SC("xs")),
+#endif
 	_DECL_FUNC(get_option,  2, _SC("xs")),
 	_DECL_FUNC(check_password,  2, _SC("xs")),
 	_DECL_FUNC(close_session,  1, _SC("x")),

+ 124 - 115
SquiLu-ext/sqlite3.c

@@ -676,7 +676,7 @@ extern "C" {
 */
 #define SQLITE_VERSION        "3.7.16"
 #define SQLITE_VERSION_NUMBER 3007016
-#define SQLITE_SOURCE_ID      "2013-03-05 16:54:45 4e6e07a60e543d5d1727cde27ab11e156202a1b8"
+#define SQLITE_SOURCE_ID      "2013-03-06 01:41:53 4f5f3aebe81c3cbe539db3e33ec38fa3de47e90b"
 
 /*
 ** CAPI3REF: Run-Time Library Version Numbers
@@ -23647,7 +23647,7 @@ static int robust_open(const char *z, int f, mode_t m){
       struct stat statbuf;
       if( osFstat(fd, &statbuf)==0 
        && statbuf.st_size==0
-       && statbuf.st_mode&0777!=m 
+       && (statbuf.st_mode&0777)!=m 
       ){
         osFchmod(fd, m);
       }
@@ -30625,7 +30625,7 @@ static int sqlite3_os_type = 0;
 #  define osAreFileApisANSI()       1
 #  define osLockFile                LockFile
 #  define osUnlockFile              UnlockFile
-#  define osUnlockFileEx            UnlockFileEx
+//#  define osUnlockFileEx            UnlockFileEx
 #  define osLockFileEx              LockFileEx
 #endif
 
@@ -31955,6 +31955,7 @@ static void logIoerr(int nRetry){
 ** create a substitute.
 */
 /* #include <time.h> */
+#ifndef __GNUC__
 struct tm *__cdecl localtime(const time_t *t)
 {
   static struct tm y;
@@ -31977,6 +31978,7 @@ struct tm *__cdecl localtime(const time_t *t)
   return &y;
 }
 #endif
+#endif
 
 #define HANDLE_TO_WINFILE(a) (winFile*)&((char*)a)[-(int)offsetof(winFile,h)]
 
@@ -140061,7 +140063,7 @@ int int_cmp(const void *a, const void *b);
 ** compares 2 doubles
 ** to use with map_make
 */
-int double_cmp(const void *a, const void *b);
+int sqlite_double_cmp(const void *a, const void *b);
 
 #endif /* _MAP_H_ */
 
@@ -140217,28 +140219,35 @@ static int sqlite3Utf8CharLen(const char *z, int nByte){
 */
 
 #ifdef _WIN32_WCE
+#ifdef NO_CLEAR_FP
+#define CLEAR_ERRNO(a)
+#define HAS_ERRNO(a)  (0 == (a))
+#else
 #define CLEAR_ERRNO(a) ( _clearfp())
 #define HAS_ERRNO(a)  (_statusfp() == (a))
+#endif
 #define strerror(x)  "Error ocurred"
 #define errno (GetLastError ())
 
-static double zero(void) { return 0.0; }
-static double one (void) { return 1.0; }
-static double inf (void) { return one() / zero(); }
+#ifndef isinf
+static sqlite_double zero(void) { return LITDBL(0.0); }
+static sqlite_double one (void) { return LITDBL(1.0); }
+static sqlite_double inf (void) { return one() / zero(); }
 
 int
-isinf(double n)
+isinf(sqlite_double n)
 {
-    static double pinf = 0.0;
-    static double ninf = 0.0;
+    static sqlite_double pinf = LITDBL(0.0);
+    static sqlite_double ninf = LITDBL(0.0);
 
-    if (pinf == 0.0) {
+    if (pinf == LITDBL(0.0)) {
 	pinf = inf();
 	ninf = -pinf;
     }
     return memcmp(&n, &pinf, sizeof n) == 0
 	|| memcmp(&n, &ninf, sizeof n) == 0;
 }
+#endif
 
 /* DBL_MANT_DIG must be less than 4 times of bits of int */
 #ifndef DBL_MANT_DIG
@@ -140257,8 +140266,8 @@ isinf(double n)
 #define SMALL_CRITERIA (1.0*(1<<DBL_MANT_DIG/4)*(1<<(DBL_MANT_DIG/3+1-DBL_MANT_DIG/4)))
 #endif
 
-double
-acosh(double x)
+sqlite_double
+acosh(sqlite_double x)
 {
     if (x < 1)
 	x = -1;			/* NaN */
@@ -140271,16 +140280,16 @@ acosh(double x)
     return log(x);
 }
 
-double
-asinh(double x)
+sqlite_double
+asinh(sqlite_double x)
 {
     int neg = x < 0;
-    double z = fabs(x);
+    sqlite_double z = fabs(x);
 
     if (z < SMALL_CRITERIA) return x;
-    if (z < (1.0/(1<<DBL_MANT_DIG/5))) {
-	double x2 = z * z;
-	z *= 1 + x2 * (-1.0/6.0 + x2 * 3.0/40.0);
+    if (z < (LITDBL(1.0)/(1<<DBL_MANT_DIG/5))) {
+	sqlite_double x2 = z * z;
+	z *= 1 + x2 * (LITDBL(-1.0)/LITDBL(6.0) + x2 * LITDBL(3.0)/LITDBL(40.0));
     }
     else if (z > BIG_CRITERIA) {
 	z = log(z + z);
@@ -140292,11 +140301,11 @@ asinh(double x)
     return z;
 }
 
-double
-atanh(double x)
+sqlite_double
+atanh(sqlite_double x)
 {
     int neg = x < 0;
-    double z = fabs(x);
+    sqlite_double z = fabs(x);
 
     if (z < SMALL_CRITERIA) return x;
     z = log(z > 1 ? -1 : (1 + z) / (1 - z)) / 2;
@@ -140320,7 +140329,7 @@ atanh(double x)
 /* LMH 2007-03-25 Changed to use errno and remove domain; no pre-checking for errors. */
 #define GEN_MATH_WRAP_DOUBLE_1(name, function) \
 static void name(sqlite3_context *context, int argc, sqlite3_value **argv){\
-  double rVal = 0.0, val;\
+  sqlite_double rVal = LITDBL(0.0), val;\
   assert( argc==1 );\
   switch( sqlite3_value_type(argv[0]) ){\
     case SQLITE_NULL: {\
@@ -140360,24 +140369,24 @@ GEN_MATH_WRAP_DOUBLE_1(atanFunc, atan)
 */
 
 #ifndef HAVE_ACOSH
-static double acosh(double x){
-  return log(x + sqrt(x*x - 1.0));
+static sqlite_double acosh(sqlite_double x){
+  return log(x + sqrt(x*x - LITDBL(1.0)));
 }
 #endif
 
 GEN_MATH_WRAP_DOUBLE_1(acoshFunc, acosh)
 
 #ifndef HAVE_ASINH
-static double asinh(double x){
-  return log(x + sqrt(x*x + 1.0));
+static sqlite_double asinh(sqlite_double x){
+  return log(x + sqrt(x*x + LITDBL(1.0)));
 }
 #endif
 
 GEN_MATH_WRAP_DOUBLE_1(asinhFunc, asinh)
 
 #ifndef HAVE_ATANH
-static double atanh(double x){
-  return (1.0/2.0)*log((1+x)/(1-x)) ;
+static sqlite_double atanh(sqlite_double x){
+  return (LITDBL(1.0)/LITDBL(2.0))*log((1+x)/(1-x)) ;
 }
 #endif
 
@@ -140386,8 +140395,8 @@ GEN_MATH_WRAP_DOUBLE_1(atanhFunc, atanh)
 /*
 ** math.h doesn't require cot (cotangent) so it's defined here
 */
-static double cot(double x){
-  return 1.0/tan(x);
+static sqlite_double cot(sqlite_double x){
+  return LITDBL(1.0)/tan(x);
 }
 
 GEN_MATH_WRAP_DOUBLE_1(sinFunc, sin)
@@ -140395,7 +140404,7 @@ GEN_MATH_WRAP_DOUBLE_1(cosFunc, cos)
 GEN_MATH_WRAP_DOUBLE_1(tanFunc, tan)
 GEN_MATH_WRAP_DOUBLE_1(cotFunc, cot)
 
-static double coth(double x){
+static sqlite_double coth(sqlite_double x){
   return 1.0/tanh(x);
 }
 
@@ -140404,23 +140413,23 @@ static double coth(double x){
 ** them on those systems directly from the definition in terms of exp
 */
 #ifndef HAVE_SINH
-static double sinh(double x){
-  return (exp(x)-exp(-x))/2.0;
+static sqlite_double sinh(sqlite_double x){
+  return (exp(x)-exp(-x))/LITDBL(2.0);
 }
 #endif
 
 GEN_MATH_WRAP_DOUBLE_1(sinhFunc, sinh)
 
 #ifndef HAVE_COSH
-static double cosh(double x){
-  return (exp(x)+exp(-x))/2.0;
+static sqlite_double cosh(sqlite_double x){
+  return (exp(x)+exp(-x))/LITDBL(2.0);
 }
 #endif
 
 GEN_MATH_WRAP_DOUBLE_1(coshFunc, cosh)
 
 #ifndef HAVE_TANH
-static double tanh(double x){
+static sqlite_double tanh(sqlite_double x){
   return sinh(x)/cosh(x);
 }
 #endif
@@ -140434,10 +140443,10 @@ GEN_MATH_WRAP_DOUBLE_1(cothFunc, coth)
 */
 
 #ifndef HAVE_LOG10
-static double log10(double x){
-  static double l10 = -1.0;
-  if( l10<0.0 ){
-    l10 = log(10.0);
+static sqlite_double log10(sqlite_double x){
+  static sqlite_double l10 = LITDBL(-1.0);
+  if( l10<LITDBL(0.0) ){
+    l10 = log(LITDBL(10.0));
   }
   return log(x)/l10;
 }
@@ -140453,20 +140462,20 @@ GEN_MATH_WRAP_DOUBLE_1(expFunc, exp)
 #undef M_PI
 #ifndef M_PI
 /*
-** static double PI = acos(-1.0);
+** static sqlite_double PI = acos(-1.0);
 ** #define M_PI (PI)
 */
-#define M_PI 3.14159265358979323846
+#define M_PI LITDBL(3.14159265358979323846)
 #endif
 
 /* Convert Degrees into Radians */
-static double deg2rad(double x){
-  return x*M_PI/180.0;
+static sqlite_double deg2rad(sqlite_double x){
+  return x*M_PI/LITDBL(180.0);
 }
 
 /* Convert Radians into Degrees */
-static double rad2deg(double x){
-  return 180.0*x/M_PI;
+static sqlite_double rad2deg(sqlite_double x){
+  return LITDBL(180.0)*x/M_PI;
 }
 
 GEN_MATH_WRAP_DOUBLE_1(rad2degFunc, rad2deg)
@@ -140484,7 +140493,7 @@ static void piFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
 */
 static void squareFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
   i64 iVal = 0;
-  double rVal = 0.0;
+  sqlite_double rVal = LITDBL(0.0);
   assert( argc==1 );
   switch( sqlite3_value_type(argv[0]) ){
     case SQLITE_INTEGER: {
@@ -140507,15 +140516,15 @@ static void squareFunc(sqlite3_context *context, int argc, sqlite3_value **argv)
 /*
 ** Wraps the pow math.h function
 ** When both the base and the exponent are integers the result should be integer
-** (see sqrt just before this). Here the result is always double
+** (see sqrt just before this). Here the result is always sqlite_double
 */
 /* LMH 2007-03-25 Changed to use errno; no pre-checking for errors.  Also removes
   but that was present in the pre-checking that called sqlite3_result_error on
   a non-positive first argument, which is not always an error. */
 static void powerFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
-  double r1 = 0.0;
-  double r2 = 0.0;
-  double val;
+  sqlite_double r1 = LITDBL(0.0);
+  sqlite_double r2 = LITDBL(0.0);
+  sqlite_double val;
 
   assert( argc==2 );
 
@@ -140538,8 +140547,8 @@ static void powerFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
 ** atan2 wrapper
 */
 static void atn2Func(sqlite3_context *context, int argc, sqlite3_value **argv){
-  double r1 = 0.0;
-  double r2 = 0.0;
+  sqlite_double r1 = LITDBL(0.0);
+  sqlite_double r2 = LITDBL(0.0);
 
   assert( argc==2 );
 
@@ -140559,7 +140568,7 @@ static void atn2Func(sqlite3_context *context, int argc, sqlite3_value **argv){
 ** When the argument is NULL the result is also NULL (completly conventional)
 */
 static void signFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
-  double rVal=0.0;
+  sqlite_double rVal=LITDBL(0.0);
   i64 iVal=0;
   assert( argc==1 );
   switch( sqlite3_value_type(argv[0]) ){
@@ -140589,7 +140598,7 @@ static void signFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
 ** smallest integer value not less than argument
 */
 static void ceilFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
-  double rVal=0.0;
+  sqlite_double rVal=LITDBL(0.0);
   //i64 iVal=0;
   assert( argc==1 );
   switch( sqlite3_value_type(argv[0]) ){
@@ -140614,7 +140623,7 @@ static void ceilFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
 ** largest integer value not greater than argument
 */
 static void floorFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
-  double rVal=0.0;
+  sqlite_double rVal=LITDBL(0.0);
   //i64 iVal=0;
   assert( argc==1 );
   switch( sqlite3_value_type(argv[0]) ){
@@ -140682,7 +140691,7 @@ static void replicateFunc(sqlite3_context *context, int argc, sqlite3_value **ar
 ** Some systems (win32 among others) don't have an isblank function, this will emulate it.
 ** This function is not UFT-8 safe since it only analyses a byte character.
 */
-#if (!defined(HAVE_ISBLANK)) || defined(_WIN32_WCE)
+#if (!defined(HAVE_ISBLANK)) || (defined(_WIN32_WCE) && !defined(__GNUC__))
 int isblank(char c){
   return( ' '==c || '\t'==c );
 }
@@ -141331,8 +141340,8 @@ static void reverseFunc(sqlite3_context *context, int argc, sqlite3_value **argv
 */
 typedef struct StdevCtx StdevCtx;
 struct StdevCtx {
-  double rM;
-  double rS;
+  sqlite_double rM;
+  sqlite_double rS;
   i64 cnt;          /* number of elements */
 };
 
@@ -141347,9 +141356,9 @@ struct StdevCtx {
 typedef struct ModeCtx ModeCtx;
 struct ModeCtx {
   i64 riM;            /* integer value found so far */
-  double rdM;         /* double value found so far */
+  sqlite_double rdM;         /* sqlite_double value found so far */
   i64 cnt;            /* number of elements so far */
-  double pcnt;        /* number of elements smaller than a percentile */
+  sqlite_double pcnt;        /* number of elements smaller than a percentile */
   i64 mcnt;           /* maximum number of occurrences (for mode) */
   i64 mn;             /* number of occurrences (for mode and percentiles) */
   i64 is_double;      /* whether the computation is being done for doubles (>0) or integers (=0) */
@@ -141363,8 +141372,8 @@ struct ModeCtx {
 static void varianceStep(sqlite3_context *context, int argc, sqlite3_value **argv){
   StdevCtx *p;
 
-  double delta;
-  double x;
+  sqlite_double delta;
+  sqlite_double x;
 
   assert( argc==1 );
   p = sqlite3_aggregate_context(context, sizeof(*p));
@@ -141384,9 +141393,9 @@ static void varianceStep(sqlite3_context *context, int argc, sqlite3_value **arg
 static void modeStep(sqlite3_context *context, int argc, sqlite3_value **argv){
   ModeCtx *p;
   i64 xi=0;
-  double xd=0.0;
+  sqlite_double xd=LITDBL(0.0);
   i64 *iptr;
-  double *dptr;
+  sqlite_double *dptr;
   int type;
 
   assert( argc==1 );
@@ -141406,7 +141415,7 @@ static void modeStep(sqlite3_context *context, int argc, sqlite3_value **argv){
     }else{
       p->is_double = 1;
       /* map will be used for doubles */
-      *(p->m) = map_make(double_cmp);
+      *(p->m) = map_make(sqlite_double_cmp);
     }
   }
 
@@ -141419,7 +141428,7 @@ static void modeStep(sqlite3_context *context, int argc, sqlite3_value **argv){
     map_insert(p->m, iptr);
   }else{
     xd = sqlite3_value_double(argv[0]);
-    dptr = (double*)calloc(1,sizeof(double));
+    dptr = (sqlite_double*)calloc(1,sizeof(sqlite_double));
     *dptr = xd;
     map_insert(p->m, dptr);
   }
@@ -141431,7 +141440,7 @@ static void modeStep(sqlite3_context *context, int argc, sqlite3_value **argv){
 */
 static void modeIterate(void* e, i64 c, void* pp){
   i64 ei;
-  double ed;
+  sqlite_double ed;
   ModeCtx *p = (ModeCtx*)pp;
 
   if( 0==p->is_double ){
@@ -141445,7 +141454,7 @@ static void modeIterate(void* e, i64 c, void* pp){
 	  p->mn=1;
     }
   }else{
-    ed = *(double*)(e);
+    ed = *(sqlite_double*)(e);
 
 	if( p->mcnt==c ){
       ++p->mn;
@@ -141464,9 +141473,9 @@ static void modeIterate(void* e, i64 c, void* pp){
 */
 static void medianIterate(void* e, i64 c, void* pp){
   i64 ei;
-  double ed;
-  double iL;
-  double iR;
+  sqlite_double ed;
+  sqlite_double iL;
+  sqlite_double iR;
   int il;
   int ir;
   ModeCtx *p = (ModeCtx*)pp;
@@ -141486,7 +141495,7 @@ static void medianIterate(void* e, i64 c, void* pp){
         ei = *(int*)(e);
         p->riM += ei;
       }else{
-        ed = *(double*)(e);
+        ed = *(sqlite_double*)(e);
         p->rdM += ed;
       }
     }else{
@@ -141692,8 +141701,8 @@ static void differenceFunc(sqlite3_context *context, int argc, sqlite3_value **a
 ** fmod wrapper
 */
 static void fmodFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
-  double r1 = 0.0;
-  double r2 = 0.0;
+  sqlite_double r1 = LITDBL(0.0);
+  sqlite_double r2 = LITDBL(0.0);
 
   assert( argc==2 );
 
@@ -141708,13 +141717,13 @@ static void fmodFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
 
 static void	sqlitex_distance(sqlite3_context * context, int argc, sqlite3_value **argv)
 {
-	// expect x1, y1, x2, y2 all as doubles
-	double	x1;
-	double	y1;
-	double	x2;
-	double	y2;
-	register double	xd;
-	register double	yd;
+	// expect x1, y1, x2, y2 all as sqlite_doubles
+	sqlite_double	x1;
+	sqlite_double	y1;
+	sqlite_double	x2;
+	sqlite_double	y2;
+	register sqlite_double	xd;
+	register sqlite_double	yd;
 	int		i;
 
 	if (argc < 4)
@@ -141742,14 +141751,14 @@ static void	sqlitex_distance(sqlite3_context * context, int argc, sqlite3_value
 
 static void	sqlitex_bearing(sqlite3_context * context, int argc, sqlite3_value **argv)
 {
-	// expect x1, y1, x2, y2 all as doubles
-	double	x1;
-	double	y1;
-	double	x2;
-	double	y2;
-	double	xd;
-	double	yd;
-	double bearing;
+	// expect x1, y1, x2, y2 all as sqlite_doubles
+	sqlite_double	x1;
+	sqlite_double	y1;
+	sqlite_double	x2;
+	sqlite_double	y2;
+	sqlite_double	xd;
+	sqlite_double	yd;
+	sqlite_double bearing;
 	int		i;
 
 	if (argc < 4)
@@ -141782,14 +141791,14 @@ static void	sqlitex_bearing(sqlite3_context * context, int argc, sqlite3_value *
 
 static void	sqlitex_is_inside_circle(sqlite3_context * context, int argc, sqlite3_value **argv)
 {
-	// expect x1, y1, x2, y2 all as doubles
-	double	x1;
-	double	y1;
-	double	r;
-	double	x2;
-	double	y2;
-	register double	xd;
-	register double	yd;
+	// expect x1, y1, x2, y2 all as sqlite_doubles
+	sqlite_double	x1;
+	sqlite_double	y1;
+	sqlite_double	r;
+	sqlite_double	x2;
+	sqlite_double	y2;
+	register sqlite_double	xd;
+	register sqlite_double	yd;
 	int		i, result = 0;
 
 	if (argc < 5)
@@ -141823,7 +141832,7 @@ static void	sqlitex_is_inside_circle(sqlite3_context * context, int argc, sqlite
 
 static void	geo_distance(sqlite3_context * context, int argc, sqlite3_value **argv)
 {
-  double theta, dist, lat1, lon1, lat2, lon2;
+  sqlite_double theta, dist, lat1, lon1, lat2, lon2;
   char *unit;
   int i;
 
@@ -141843,15 +141852,15 @@ static void	geo_distance(sqlite3_context * context, int argc, sqlite3_value **ar
 
   theta = deg2rad(lon1 - lon2);
   dist = sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(theta);
-  dist = rad2deg(acos(dist)) * 60 * 1.1515;
+  dist = rad2deg(acos(dist)) * 60 * LITDBL(1.1515);
   switch(unit[0]) {
     //case 'M':
     //  break;
     case 'K':
-      dist = dist * 1.609344;
+      dist = dist * LITDBL(1.609344);
       break;
     case 'N':
-      dist = dist * 0.8684;
+      dist = dist * LITDBL(0.8684);
       break;
   }
   sqlite3_result_double(context, dist);
@@ -141862,13 +141871,13 @@ static const char GEOHASHBITS[] = {16,8,4,2,1};
 
 enum geoDir {geoRight, geoLeft, geoTop, geoBottom};
 
-void decode_geohash_bbox(char *geohash, double *lat, double *lon) {
+void decode_geohash_bbox(char *geohash, sqlite_double *lat, sqlite_double *lon) {
 	int i, j, hashlen;
 	char c, cd, mask, is_even=1;
 
-	lat[0] = -90.0;  lat[1] = 90.0;
-	lon[0] = -180.0; lon[1] = 180.0;
-	//*lat_err = 90.0;  *lon_err = 180.0;
+	lat[0] = LITDBL(-90.0);  lat[1] = LITDBL(90.0);
+	lon[0] = LITDBL(-180.0); lon[1] = LITDBL(180.0);
+	//*lat_err = LITDBL(90.0);  *lon_err = LITDBL(180.0);
 	hashlen = strlen(geohash);
 
 	for (i=0; i<hashlen; i++) {
@@ -141888,8 +141897,8 @@ void decode_geohash_bbox(char *geohash, double *lat, double *lon) {
 	}
 }
 
-void decode_geohash(char *geohash, double *point) {
-	double lat[2], lon[2];
+void decode_geohash(char *geohash, sqlite_double *point) {
+	sqlite_double lat[2], lon[2];
 
 	decode_geohash_bbox(geohash, lat, lon);
 
@@ -141900,7 +141909,7 @@ void decode_geohash(char *geohash, double *point) {
 static void	encode_geohash(sqlite3_context * context, int argc, sqlite3_value **argv)
 {
 	int is_even=1, i=0;
-	double lat[2], lon[2], mid, latitude, longitude;
+	sqlite_double lat[2], lon[2], mid, latitude, longitude;
 	int bit=0, ch=0;
 	int precision;
 	char *geohash;
@@ -141912,8 +141921,8 @@ static void	encode_geohash(sqlite3_context * context, int argc, sqlite3_value **
     precision = sqlite3_value_int(argv[2]);
 	geohash=sqlite3_malloc(precision+1);
 
-	lat[0] = -90.0;  lat[1] = 90.0;
-	lon[0] = -180.0; lon[1] = 180.0;
+	lat[0] = LITDBL(-90.0);  lat[1] = LITDBL(90.0);
+	lon[0] = LITDBL(-180.0); lon[1] = LITDBL(180.0);
 
 	while (i < precision) {
 		if (is_even) {
@@ -142234,9 +142243,9 @@ int int_cmp(const void *a, const void *b){
     return 1;
 }
 
-int double_cmp(const void *a, const void *b){
-  double aa = *(double *)(a);
-  double bb = *(double *)(b);
+int sqlite_double_cmp(const void *a, const void *b){
+  sqlite_double aa = *(sqlite_double *)(a);
+  sqlite_double bb = *(sqlite_double *)(b);
   /* printf("cmp %d <=> %d\n",aa,bb); */
   if(aa==bb)
     return 0;

+ 1 - 1
SquiLu-ext/sqlite3.h

@@ -109,7 +109,7 @@ extern "C" {
 */
 #define SQLITE_VERSION        "3.7.16"
 #define SQLITE_VERSION_NUMBER 3007016
-#define SQLITE_SOURCE_ID      "2013-03-05 16:54:45 4e6e07a60e543d5d1727cde27ab11e156202a1b8"
+#define SQLITE_SOURCE_ID      "2013-03-06 01:41:53 4f5f3aebe81c3cbe539db3e33ec38fa3de47e90b"
 
 /*
 ** CAPI3REF: Run-Time Library Version Numbers

+ 3 - 3
SquiLu-ext/sqratimport.cpp

@@ -213,15 +213,15 @@ static SQRESULT sqrat_importbin(HSQUIRRELVM v, const SQChar* moduleName) {
 
 #if defined(_WIN32)
     HMODULE mod;
-    mod = GetModuleHandle(moduleName);
+    mod = GetModuleHandleA(moduleName);
     if(mod == NULL) {
-        mod = LoadLibrary(moduleName);
+        mod = LoadLibraryA(moduleName);
         if(mod == NULL) {
             return SQ_ERROR;
         }
     }
 
-    modLoad = (SQMODULELOAD)GetProcAddress(mod, "sqmodule_load");
+    modLoad = (SQMODULELOAD)GetProcAddressA(mod, "sqmodule_load");
     if(modLoad == NULL) {
         FreeLibrary(mod);
         return SQ_ERROR;

+ 1 - 3
SquiLu/include/squirrel.h

@@ -111,7 +111,7 @@ struct SQInstance;
 struct SQDelegable;
 struct SQOuter;
 
-#ifdef _UNICODE
+#if defined(_UNICODE) && !defined(ONLY_ASCII)
 #define SQUNICODE
 #endif
 
@@ -123,10 +123,8 @@ struct SQOuter;
 #endif
 
 #else
-#ifndef _WIN32_WCE
 typedef unsigned short wchar_t;
 #endif
-#endif
 
 typedef wchar_t SQChar;
 typedef wchar_t USQChar;

+ 4 - 1
SquiLu/sq/sq.c

@@ -531,6 +531,7 @@ SQRESULT sqext_register_Java(HSQUIRRELVM v);
 SQRESULT sqext_register_ThreadObjects(HSQUIRRELVM v);
 SQRESULT sqext_register_csv_parser (HSQUIRRELVM v);
 SQRESULT sqext_register_fltklib(HSQUIRRELVM v);
+SQRESULT sqext_register_dad_utils(HSQUIRRELVM v);
 
 int main(int argc, char* argv[])
 {
@@ -568,16 +569,18 @@ int main(int argc, char* argv[])
 	sqext_register_mongoose(v);
 	sqrat_register_importlib(v);
 	sqext_register_tinyxml2(v);
+#ifndef _WIN32_WCE
 	sqext_register_decimal(v);
 	sqext_register_markdown(v);
+#endif
 
 	sqext_register_sq_slave_vm(v);
 	//sqext_register_ThreadObjects(v);
+	sqext_register_dad_utils(v);
 
 #ifdef WITH_FULL_DAD_EXTRAS
 	sqext_register_csv_parser(v);
 	sqext_register_PostgreSQL(v);
-	//sqext_register_dad_utils(v);
 	sqext_register_sq_zmq3(v);
 	//sqext_register_Java(v);
 #endif

+ 15 - 12
SquiLu/sqstdlib/sqstdsystem.cpp

@@ -5,7 +5,9 @@
 #include <time.h>
 #include <stdlib.h>
 #include <stdio.h>
-#ifndef _WIN32_WCE
+#ifdef _WIN32_WCE
+#include "celibc.h"
+#else
 #include <signal.h>
 #endif
 #include <sqstdsystem.h>
@@ -33,7 +35,6 @@
 
 SQ_OPT_STRING_STRLEN();
 
-#ifndef _WIN32_WCE
 static SQRESULT _system_getenv(HSQUIRRELVM v)
 {
 	const SQChar *s;
@@ -60,7 +61,6 @@ static SQRESULT _system_clock(HSQUIRRELVM v)
 	sq_pushfloat(v,((SQFloat)clock())/(SQFloat)CLOCKS_PER_SEC);
 	return 1;
 }
-#endif
 
 /*
 static SQRESULT _system_time(HSQUIRRELVM v)
@@ -148,7 +148,6 @@ static SQRESULT _system_difftime (HSQUIRRELVM v) {
   return 1;
 }
 
-#ifndef _WIN32_WCE
 static SQRESULT _system_remove(HSQUIRRELVM v)
 {
 	const SQChar *s;
@@ -223,8 +222,7 @@ static SQRESULT _system_date(HSQUIRRELVM v)
         sq_pushstring(v, (const SQChar*)b.GetBuf(), b.Len());
     }
     return 1;
-}
-#endif
+}
 
 static SQRESULT _system_exit (HSQUIRRELVM v) {
   SQRESULT status = 0;
@@ -257,7 +255,6 @@ static SQRESULT _system_exit (HSQUIRRELVM v) {
 #define sq_tmpnam(b,e)		{ e = (tmpnam(b) == NULL); }
 #endif
 
-#ifndef _WIN32_WCE
 static SQRESULT _system_tmpname (HSQUIRRELVM v) {
   SQChar buff[SQ_TMPNAMBUFSIZE];
   int err;
@@ -268,8 +265,12 @@ static SQRESULT _system_tmpname (HSQUIRRELVM v) {
   return 1;
 }
 
+#ifndef _WIN32_WCE
 #include <locale.h>
+#endif
+
 static SQRESULT _system_setlocale (HSQUIRRELVM v) {
+#ifndef _WIN32_WCE
   static const int cat[] = {LC_ALL, LC_COLLATE, LC_CTYPE, LC_MONETARY,
                       LC_NUMERIC, LC_TIME};
   static const SQChar *const catnames[] = {_SC("all"), _SC("collate"), _SC("ctype"),
@@ -283,8 +284,10 @@ static SQRESULT _system_setlocale (HSQUIRRELVM v) {
         return 1;
     }
   return sq_throwerror(v, _SC("invalid option %s for param %d"), name, 3);
-}
+#else
+  return 0;
 #endif
+}
 
 /*-------------------------------------------------------------------------*\
 * Sleep for n seconds.
@@ -509,7 +512,6 @@ static int _system_raise(HSQUIRRELVM v)
 
 #define _DECL_FUNC(name,nparams,pmask) {_SC(#name),_system_##name,nparams,pmask}
 static SQRegFunction systemlib_funcs[]={
-#ifndef _WIN32_WCE
 	_DECL_FUNC(getenv,2,_SC(".s")),
 	_DECL_FUNC(system,2,_SC(".s")),
 	_DECL_FUNC(clock,0,NULL),
@@ -518,13 +520,14 @@ static SQRegFunction systemlib_funcs[]={
 	_DECL_FUNC(date,-1,_SC(".sn")),
 	_DECL_FUNC(tmpname,1,_SC(".")),
 	_DECL_FUNC(setlocale,-1,_SC(".ss")),
-	_DECL_FUNC(getmillicount,1,_SC(".")),
-	_DECL_FUNC(getmillispan,2,_SC(".i")),
-#endif
 	_DECL_FUNC(time,-1,_SC(".t")),
 	_DECL_FUNC(difftime,-2,_SC(".nn")),
 	_DECL_FUNC(exit, -1,_SC(". b|i b")),
 	_DECL_FUNC(sleep, 2,_SC(".n")),
+#ifndef _WIN32_WCE
+	_DECL_FUNC(getmillicount,1,_SC(".")),
+	_DECL_FUNC(getmillispan,2,_SC(".i")),
+#endif
 	{0,0}
 };
 #undef _DECL_FUNC

+ 95 - 9
SquiLu/squilu.cbp

@@ -14,6 +14,7 @@
 				<Option parameters="spectralnorm.nut" />
 				<Compiler>
 					<Add option="-g" />
+					<Add option="-DWITH_FULL_DAD_EXTRAS=1" />
 					<Add directory="../../zeromq-3.2.2/include" />
 				</Compiler>
 				<Linker>
@@ -35,6 +36,8 @@
 					<Add option="-Wall" />
 					<Add option="-fno-rtti" />
 					<Add option="-fno-strict-aliasing" />
+					<Add option="-DNDEBUG=1" />
+					<Add option="-DWITH_FULL_DAD_EXTRAS=1" />
 					<Add directory="../../zeromq-3.2.2/include" />
 				</Compiler>
 				<Linker>
@@ -58,6 +61,8 @@
 				<Option compiler="clang_compiler" />
 				<Compiler>
 					<Add option="-O2" />
+					<Add option="-DNDEBUG=1" />
+					<Add option="-DWITH_FULL_DAD_EXTRAS=1" />
 				</Compiler>
 				<Linker>
 					<Add option="-s" />
@@ -73,7 +78,7 @@
 				<Option output="bin/squilu.exe" prefix_auto="1" extension_auto="0" />
 				<Option object_output="obj/Release-win32/" />
 				<Option type="1" />
-				<Option compiler="gnu_gcc_compiler_static" />
+				<Option compiler="mingw32_compiler" />
 				<Compiler>
 					<Add option="-O3" />
 					<Add option="-Wall" />
@@ -81,6 +86,8 @@
 					<Add option="-fno-strict-aliasing" />
 					<Add option="-DAS_STATIC_LIB=1" />
 					<Add option="-DINET_ATON=1" />
+					<Add option="-DNDEBUG=1" />
+					<Add option="-DWITH_FULL_DAD_EXTRAS=1" />
 					<Add directory="../../zeromq-3.2.2/include" />
 					<Add directory="../../../../Program Files/PostgreSQL/9.1/include" />
 				</Compiler>
@@ -111,6 +118,8 @@
 					<Add option="-fno-rtti" />
 					<Add option="-fno-strict-aliasing" />
 					<Add option="-DWITH_FLTK=1" />
+					<Add option="-DNDEBUG=1" />
+					<Add option="-DWITH_FULL_DAD_EXTRAS=1" />
 					<Add directory="../../zeromq-3.2.2/include" />
 					<Add directory="../fltk" />
 					<Add directory="../libharu/include" />
@@ -155,6 +164,7 @@
 					<Add option="-fno-rtti" />
 					<Add option="-fno-strict-aliasing" />
 					<Add option="-DWITH_FLTK=1" />
+					<Add option="-DWITH_FULL_DAD_EXTRAS=1" />
 					<Add directory="../../zeromq-3.2.2/include" />
 					<Add directory="../fltk" />
 					<Add directory="../flu" />
@@ -188,7 +198,7 @@
 				<Option output="bin/squilu-fltk.exe" prefix_auto="1" extension_auto="0" />
 				<Option object_output="obj/Release-win32/" />
 				<Option type="1" />
-				<Option compiler="gnu_gcc_compiler_static" />
+				<Option compiler="mingw32_compiler" />
 				<Compiler>
 					<Add option="-O3" />
 					<Add option="-Wall" />
@@ -197,6 +207,8 @@
 					<Add option="-DAS_STATIC_LIB=1" />
 					<Add option="-DINET_ATON=1" />
 					<Add option="-DWITH_FLTK=1" />
+					<Add option="-DNDEBUG=1" />
+					<Add option="-DWITH_FULL_DAD_EXTRAS=1" />
 					<Add directory="../../zeromq-3.2.2/include" />
 					<Add directory="../../../../Program Files/PostgreSQL/9.1/include" />
 					<Add directory="../fltk" />
@@ -236,7 +248,7 @@
 				<Option output="bin/squilu-fltk-w.exe" prefix_auto="1" extension_auto="0" />
 				<Option object_output="obj/Release-win32/" />
 				<Option type="0" />
-				<Option compiler="gnu_gcc_compiler_static" />
+				<Option compiler="mingw32_compiler" />
 				<Compiler>
 					<Add option="-O3" />
 					<Add option="-Wall" />
@@ -245,6 +257,8 @@
 					<Add option="-DAS_STATIC_LIB=1" />
 					<Add option="-DINET_ATON=1" />
 					<Add option="-DWITH_FLTK=1" />
+					<Add option="-DNDEBUG=1" />
+					<Add option="-DWITH_FULL_DAD_EXTRAS=1" />
 					<Add directory="../../zeromq-3.2.2/include" />
 					<Add directory="../../../../Program Files/PostgreSQL/9.1/include" />
 					<Add directory="../fltk" />
@@ -292,6 +306,7 @@
 					<Add option="-fno-strict-aliasing" />
 					<Add option="-DNEED_SUBLATIN_C=1" />
 					<Add option="-DSQUILU_ALONE=1" />
+					<Add option="-DNDEBUG=1" />
 					<Add directory="../../zeromq-3.2.2/include" />
 				</Compiler>
 				<Linker>
@@ -312,7 +327,7 @@
 				<Option output="bin/squilu-alone-wince" prefix_auto="1" extension_auto="1" />
 				<Option object_output="obj/Release-alone-wince/" />
 				<Option type="1" />
-				<Option compiler="mingw32ce_compiler" />
+				<Option compiler="cegcc_compiler" />
 				<Compiler>
 					<Add option="-Os" />
 					<Add option="-Wall" />
@@ -321,18 +336,47 @@
 					<Add option="-DNEED_SUBLATIN_C=1" />
 					<Add option="-DSQUILU_ALONE=1" />
 					<Add option="-D_WIN32_WCE=1" />
+					<Add option="-DNDEBUG=1" />
 					<Add directory="../../zeromq-3.2.2/include" />
 				</Compiler>
 				<Linker>
 					<Add option="-s" />
 					<Add library="../../zeromq-3.2.2/libzmq3.a" />
-					<Add library="pthread" />
-					<Add library="rt" />
-					<Add library="dl" />
 					<Add library="axtls" />
 					<Add library="mpdecimal" />
 					<Add library="discount" />
-					<Add library="fltk_z" />
+					<Add library="coredll" />
+					<Add directory="../../zeromq-3.2.2" />
+					<Add directory="../fltk/lib" />
+				</Linker>
+			</Target>
+			<Target title="Release wince">
+				<Option output="bin/squilu-wince" prefix_auto="1" extension_auto="1" />
+				<Option object_output="obj/Release-wince/" />
+				<Option type="1" />
+				<Option compiler="cegcc_compiler" />
+				<Compiler>
+					<Add option="-O3" />
+					<Add option="-Wall" />
+					<Add option="-fno-rtti" />
+					<Add option="-fno-strict-aliasing" />
+					<Add option="-DINET_ATON=1" />
+					<Add option="-DNDEBUG=1" />
+					<Add option="-DSQLITE_OMIT_WAL=1" />
+					<Add option="-DSQLITE_OS_WIN=1" />
+					<Add option="-DSQLITE_OS_WINCE=1" />
+					<Add option="-D_WIN32_WCE=0x300" />
+					<Add option="-DHAVE_ISBLANK=1" />
+					<Add option="-DNO_CLEAR_FP=1" />
+					<Add directory="../../zeromq-3.2.2/include" />
+				</Compiler>
+				<Linker>
+					<Add option="-s" />
+					<Add library="axtls-wince" />
+					<Add library="discount-wince" />
+					<Add library="coredll" />
+					<Add library="ws2" />
+					<Add library="z" />
 					<Add directory="../../zeromq-3.2.2" />
 					<Add directory="../fltk/lib" />
 				</Linker>
@@ -341,11 +385,11 @@
 		<Compiler>
 			<Add option="-Wall" />
 			<Add option="-fno-strict-aliasing" />
+			<Add option="-DONLY_ASCII=1" />
 			<Add option="-DPROFILE_SQVM0=1" />
 			<Add option="-DSQ_JIT_LLVM44=1" />
 			<Add option="-D_DEBUG_DUMP33=1" />
 			<Add option="-DWITH_DAD_EXTRAS=1" />
-			<Add option="-DWITH_FULL_DAD_EXTRAS=1" />
 			<Add option="-DSQ_SUBLATIN=1" />
 			<Add option="-DNEED_SUBLATIN_C2=1" />
 			<Add option="-DSQUSEDOUBLE=1" />
@@ -353,6 +397,7 @@
 			<Add option="-DNO_EXCEPTION_KEY_NOT_FOUND0=1" />
 			<Add option="-D_SQ642=1" />
 			<Add option="-DNO_GARBAGE_COLLECTOR00=1" />
+			<Add option="-DTHREADSAFE=1" />
 			<Add option="-DSQLITE_DEFAULT_FILE_FORMAT=4" />
 			<Add option="-DSQLITE_DEFAULT_AUTOVACUUM=1" />
 			<Add option="-DSQLITE_DEFAULT_FOREIGN_KEYS=1" />
@@ -396,9 +441,19 @@
 		</Linker>
 		<Unit filename="../SquiLu-ext/HighResolutionTimer.cpp" />
 		<Unit filename="../SquiLu-ext/HighResolutionTimer.h" />
+		<Unit filename="../SquiLu-ext/celibc.c">
+			<Option compilerVar="CC" />
+			<Option target="Release alone wince" />
+			<Option target="Release wince" />
+		</Unit>
+		<Unit filename="../SquiLu-ext/celibc.h">
+			<Option target="Release alone wince" />
+			<Option target="Release wince" />
+		</Unit>
 		<Unit filename="../SquiLu-ext/code_mix_prep.c">
 			<Option compilerVar="CC" />
 		</Unit>
+		<Unit filename="../SquiLu-ext/dad_utils.cpp" />
 		<Unit filename="../SquiLu-ext/dynamic_library.cpp">
 			<Option target="Debug" />
 			<Option target="Release" />
@@ -408,6 +463,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/dynamic_library.h">
 			<Option target="Debug" />
@@ -418,6 +474,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/fpdf.cpp">
 			<Option target="Debug" />
@@ -428,6 +485,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/fpdf.h">
 			<Option target="Debug" />
@@ -438,6 +496,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/lua_socket.cpp">
 			<Option target="Debug" />
@@ -448,6 +507,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/lua_socket.h">
 			<Option target="Debug" />
@@ -458,6 +518,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/mongoose.c">
 			<Option compilerVar="CC" />
@@ -469,6 +530,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/mongoose.h">
 			<Option target="Debug" />
@@ -479,6 +541,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/pdf-font.cpp">
 			<Option target="Debug" />
@@ -489,6 +552,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/pdf-font.h">
 			<Option target="Debug" />
@@ -499,6 +563,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_axtls.c">
 			<Option compilerVar="CC" />
@@ -510,6 +575,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_base64.cpp">
 			<Option target="Debug" />
@@ -520,6 +586,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_decimal.cpp">
 			<Option target="Debug" />
@@ -540,6 +607,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_fpdf.cpp">
 			<Option target="Debug" />
@@ -550,6 +618,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_fs.c">
 			<Option compilerVar="CC" />
@@ -561,6 +630,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_markdown.cpp">
 			<Option target="Debug" />
@@ -571,6 +641,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_mix.cpp">
 			<Option target="Debug" />
@@ -581,6 +652,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_mongoose.cpp">
 			<Option target="Debug" />
@@ -591,6 +663,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_parsecsv.cpp">
 			<Option target="Debug" />
@@ -622,6 +695,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_slave_vm.cpp">
 			<Option target="Debug" />
@@ -632,6 +706,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_socket.cpp">
 			<Option target="Debug" />
@@ -642,6 +717,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_sqlite3.cpp">
 			<Option target="Debug" />
@@ -652,6 +728,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_tinyxml2.cpp">
 			<Option target="Debug" />
@@ -662,6 +739,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_zlib.cpp">
 			<Option target="Debug" />
@@ -672,6 +750,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sq_zmq3.cpp">
 			<Option target="Debug" />
@@ -693,6 +772,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sqlite3.h">
 			<Option target="Debug" />
@@ -703,6 +783,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sqmodule.h">
 			<Option target="Debug" />
@@ -713,6 +794,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sqratimport.cpp">
 			<Option target="Debug" />
@@ -723,6 +805,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/sqratimport.h">
 			<Option target="Debug" />
@@ -733,6 +816,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/tinyxml2.cpp">
 			<Option target="Debug" />
@@ -743,6 +827,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="../SquiLu-ext/tinyxml2.h">
 			<Option target="Debug" />
@@ -753,6 +838,7 @@
 			<Option target="Debug FLTK" />
 			<Option target="Release FLTK win32" />
 			<Option target="Release FLTK win32 no console" />
+			<Option target="Release wince" />
 		</Unit>
 		<Unit filename="dadbiz.rc">
 			<Option compilerVar="WINDRES" />

+ 17 - 3
discount/libdiscount.cbp

@@ -7,7 +7,7 @@
 		<Option compiler="gcc" />
 		<Build>
 			<Target title="Debug">
-				<Option output="libdiscount" prefix_auto="1" extension_auto="1" />
+				<Option output="discount" prefix_auto="1" extension_auto="1" />
 				<Option working_dir="" />
 				<Option object_output="obj/Debug/" />
 				<Option type="2" />
@@ -19,7 +19,7 @@
 				</Compiler>
 			</Target>
 			<Target title="Release">
-				<Option output="libdiscount" prefix_auto="1" extension_auto="1" />
+				<Option output="discount" prefix_auto="1" extension_auto="1" />
 				<Option working_dir="" />
 				<Option object_output="obj/Release/" />
 				<Option type="2" />
@@ -33,7 +33,7 @@
 				</Linker>
 			</Target>
 			<Target title="Release win32">
-				<Option output="libdiscount-win32" prefix_auto="1" extension_auto="1" />
+				<Option output="discount-win32" prefix_auto="1" extension_auto="1" />
 				<Option working_dir="" />
 				<Option object_output="obj/Release-win32/" />
 				<Option type="2" />
@@ -46,6 +46,20 @@
 					<Add option="-s" />
 				</Linker>
 			</Target>
+			<Target title="Release wince">
+				<Option output="discount-wince" prefix_auto="1" extension_auto="1" />
+				<Option working_dir="" />
+				<Option object_output="obj/Release-wince/" />
+				<Option type="2" />
+				<Option compiler="mingw32_compiler" />
+				<Compiler>
+					<Add option="-O2" />
+					<Add option="-Wall" />
+				</Compiler>
+				<Linker>
+					<Add option="-s" />
+				</Linker>
+			</Target>
 		</Build>
 		<Compiler>
 			<Add directory="G:/c/discount-2.1.2/" />

+ 21 - 7
myaxtls/axtls.cbp

@@ -7,7 +7,7 @@
 		<Option compiler="gcc" />
 		<Build>
 			<Target title="Debug">
-				<Option output="libaxtls" prefix_auto="1" extension_auto="1" />
+				<Option output="axtls" prefix_auto="1" extension_auto="1" />
 				<Option working_dir="" />
 				<Option object_output="obj/Debug/" />
 				<Option type="2" />
@@ -18,7 +18,7 @@
 				</Compiler>
 			</Target>
 			<Target title="Release">
-				<Option output="libaxtls" prefix_auto="1" extension_auto="1" />
+				<Option output="axtls" prefix_auto="1" extension_auto="1" />
 				<Option working_dir="" />
 				<Option object_output="obj/Release/" />
 				<Option type="2" />
@@ -33,7 +33,7 @@
 				</Linker>
 			</Target>
 			<Target title="Release-lua-jit">
-				<Option output="libaxtls-lua-jit" prefix_auto="1" extension_auto="1" />
+				<Option output="axtls-lua-jit" prefix_auto="1" extension_auto="1" />
 				<Option working_dir="" />
 				<Option object_output="obj/Release/" />
 				<Option type="2" />
@@ -49,7 +49,7 @@
 				</Linker>
 			</Target>
 			<Target title="Debug-lua-jit">
-				<Option output="libaxtls-lua-jit" prefix_auto="1" extension_auto="1" />
+				<Option output="axtls-lua-jit" prefix_auto="1" extension_auto="1" />
 				<Option working_dir="" />
 				<Option object_output="obj/Debug/" />
 				<Option type="2" />
@@ -62,7 +62,7 @@
 				</Compiler>
 			</Target>
 			<Target title="Release O3">
-				<Option output="libaxtls" prefix_auto="1" extension_auto="1" />
+				<Option output="axtls" prefix_auto="1" extension_auto="1" />
 				<Option working_dir="" />
 				<Option object_output="obj/Release/" />
 				<Option type="2" />
@@ -79,7 +79,7 @@
 				</Linker>
 			</Target>
 			<Target title="Release WIN32">
-				<Option output="libaxtls-win32" prefix_auto="1" extension_auto="1" />
+				<Option output="axtls-win32" prefix_auto="1" extension_auto="1" />
 				<Option working_dir="" />
 				<Option object_output="obj/Release-win32/" />
 				<Option type="2" />
@@ -93,9 +93,23 @@
 					<Add option="-s" />
 				</Linker>
 			</Target>
+			<Target title="Release WINCE">
+				<Option output="axtls-wince" prefix_auto="1" extension_auto="1" />
+				<Option working_dir="" />
+				<Option object_output="obj/Release-wince/" />
+				<Option type="2" />
+				<Option compiler="cegcc_compiler" />
+				<Option createDefFile="1" />
+				<Compiler>
+					<Add option="-O3" />
+					<Add option="-D_WIN32_WCE=1" />
+				</Compiler>
+				<Linker>
+					<Add option="-s" />
+				</Linker>
+			</Target>
 		</Build>
 		<Compiler>
-			<Add option="-march=i686" />
 			<Add option="-O2" />
 			<Add option="-DSSL_STATIC_LIBRARY=1" />
 			<Add option="-DAXTLS_LIBRARY=1" />

+ 1 - 1
myaxtls/os_port.c

@@ -87,7 +87,7 @@ EXP_FUNC int STDCALL getdomainname(char *buf, int buf_size)
                         0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS)
         return -1;
 
-    RegQueryValueEx(hKey, "Domain", NULL, &datatype, (LPBYTE)buf, &bufferlength);
+    RegQueryValueEx(hKey, TEXT("Domain"), NULL, &datatype, (LPBYTE)buf, &bufferlength);
     RegCloseKey(hKey);
     return 0;
 }