18 # define WIN32_LEAN_AND_MEAN 21 # define gmtime_r(x, y) gmtime_s(y, x) 22 # define localtime_r(x, y) localtime_s(y, x) 24 #ifdef HAVE_SYS_UTSNAME_H 25 # include <sys/utsname.h> 28 #include <cygwin/version.h> 38 int RecalcDateTime(
struct tm *st,
const int year,
const int month,
const int day,
const int hour,
const int minute,
const int second)
40 const int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
54 memset(st, 0,
sizeof(*st));
58 for (i = 0; i < month - 1; i++)
59 st->tm_yday += days[i];
62 p = (14 - month) / 12;
63 q = month + 12 * p - 2;
65 st->tm_wday = (day + (31 * q) / 12 + r + r / 4 - r / 100 + r / 400) % 7;
71 st->tm_year = year - 1900;
72 st->tm_mon = month - 1;
84 int RecalcDate(
struct tm *st,
const int year,
const int month,
const int day)
93 int GetDayOfYear(
unsigned int year,
unsigned int month,
unsigned int day)
111 return 1 + (day - st.tm_wday) / 7;
117 int GetDayOfWeek(
unsigned int year,
unsigned int month,
unsigned int day)
129 char *
DayOfWeek (
unsigned int year,
unsigned int month,
unsigned int day)
131 static char DayOfWeekChar[10];
133 strcpy(DayOfWeekChar,
"");
135 case 0: strcpy(DayOfWeekChar,
"Sun");
break;
136 case 1: strcpy(DayOfWeekChar,
"Mon");
break;
137 case 2: strcpy(DayOfWeekChar,
"Tue");
break;
138 case 3: strcpy(DayOfWeekChar,
"Wed");
break;
139 case 4: strcpy(DayOfWeekChar,
"Thu");
break;
140 case 5: strcpy(DayOfWeekChar,
"Fri");
break;
141 case 6: strcpy(DayOfWeekChar,
"Sat");
break;
143 return DayOfWeekChar;
148 time_t now = time(NULL);
150 localtime_r(&now, &tl);
152 return (
int)(mktime(&tl) - mktime(&tg));
159 sprintf(str,
"%ld", (
long)timet);
174 now = localtime(&timet);
175 Date->
Year = now->tm_year + 1900;
176 Date->
Month = now->tm_mon + 1;
177 Date->
Day = now->tm_mday;
178 Date->
Hour = now->tm_hour;
179 Date->
Minute = now->tm_min;
180 Date->
Second = now->tm_sec;
191 struct tm timestruct;
198 memset(×truct, 0,
sizeof(timestruct));
199 timestruct.tm_year = DT.
Year - 1900;
200 timestruct.tm_mon = DT.
Month - 1;
201 timestruct.tm_mday = DT.
Day;
202 timestruct.tm_hour = DT.
Hour;
203 timestruct.tm_min = DT.
Minute;
204 timestruct.tm_sec = DT.
Second;
210 timestruct.tm_isdst = now->tm_isdst;
212 timestruct.tm_isdst = -1;
214 #ifdef HAVE_STRUCT_TM_TM_ZONE 216 timestruct.tm_gmtoff = now->tm_gmtoff;
217 timestruct.tm_zone = now->tm_zone;
220 return mktime(×truct);
229 memset(&tm_time, 0,
sizeof(tm_time));
230 tm_time.tm_year = DT.
Year - 1900;
231 tm_time.tm_mon = DT.
Month - 1;
232 tm_time.tm_mday = DT.
Day;
233 tm_time.tm_hour = DT.
Hour;
234 tm_time.tm_min = DT.
Minute;
235 tm_time.tm_sec = DT.
Second;
236 tm_time.tm_isdst = -1;
240 t_time = mktime (&tm_time);
254 t_time += diff*multi;
256 t_time -= diff*multi;
260 dbgprintf(NULL,
"EndTime: %02i-%02i-%04i %02i:%02i:%02i\n",
267 static char retval[200],retval2[200];
276 setlocale(LC_ALL,
".OCP");
280 strftime(retval2, 200,
"%c", &timeptr);
282 snprintf(retval,
sizeof(retval) - 1,
" %+03i%02i",
284 strcat(retval2,retval);
287 strftime(retval, 200,
"%A", &timeptr);
288 if (strstr(retval2,retval)==NULL) {
290 strftime(retval, 200,
"%a", &timeptr);
291 if (strstr(retval2,retval)==NULL) {
292 strcat(retval2,
" (");
293 strcat(retval2,retval);
299 setlocale(LC_ALL,
".ACP");
308 static char retval[200],retval2[200];
311 setlocale(LC_ALL,
".OCP");
315 timeptr.tm_isdst = -1;
316 timeptr.tm_year = dt.
Year - 1900;
317 timeptr.tm_mon = dt.
Month - 1;
318 timeptr.tm_mday = dt.
Day;
319 timeptr.tm_hour = dt.
Hour;
320 timeptr.tm_min = dt.
Minute;
321 timeptr.tm_sec = dt.
Second;
323 #ifdef HAVE_STRUCT_TM_TM_ZONE 324 timeptr.tm_zone = NULL;
328 strftime(retval2, 200,
"%x", &timeptr);
331 strftime(retval, 200,
"%A", &timeptr);
332 if (strstr(retval2,retval)==NULL) {
334 strftime(retval, 200,
"%a", &timeptr);
335 if (strstr(retval2,retval)==NULL) {
336 strcat(retval2,
" (");
337 strcat(retval2,retval);
343 setlocale(LC_ALL,
".ACP");
351 const int days[]={31,28,31,30,31,30,31,31,30,31,30,31};
353 if (date->
Year != 0 &&
354 ((date->
Year % 4 == 0 && date->
Year % 100 != 0) || date->
Year % 400 == 0) &&
356 return (date->
Day <= 29);
358 return date->
Year != 0 &&
360 date->
Day >= 1 && date->
Day <= days[date->
Month-1];
365 return date->
Hour <= 23 &&
370 size_t GetLine(FILE *File,
char *Line,
int count)
374 if (fgets(Line, count, File) != NULL) {
375 num = strlen(Line) - 1;
377 if (Line[num] !=
'\n' && Line[num] !=
'\r')
break;
402 const char *whitespaces,
const size_t spaceslen,
403 const char *quotes,
const size_t quoteslen,
406 size_t i=0,number=0,j=0, lastquote = 0;
415 for (i = 0; i < messagesize; i++) {
423 for (j = lines->
allocated - 20; j < lines->allocated; j++) {
431 for (j = 0; j < quoteslen; j++) {
432 if (quotes[j] == message[i]) {
433 insidequotes = !(insidequotes);
446 for (j = 0; j < spaceslen; j++) {
447 if (whitespaces[j] == message[i]) {
471 if (number % 2 == 1 && insidequotes) {
472 insidequotes =
FALSE;
478 if (eot && !whitespace) {
479 lines->
numbers[number] = messagesize;
485 if (message == NULL) {
489 return message + lines->
numbers[start * 2 - 2];
504 lines->
retval = (
char *)realloc(lines->
retval, len + 1);
505 if (lines->
retval == NULL) {
510 memcpy(lines->
retval, pos, len);
512 lines->
retval[len] =
'\0';
533 memcpy(dest, pos, len);
543 # ifdef HAVE_SYS_UTSNAME_H 547 static char Buffer[100] = {0x00};
550 if (Buffer[0] != 0)
return Buffer;
553 memset(&Ver,0,
sizeof(OSVERSIONINFOEX));
554 Ver.dwOSVersionInfoSize =
sizeof(OSVERSIONINFOEX);
556 if (!GetVersionEx((OSVERSIONINFO *)&Ver)) {
558 Ver.dwOSVersionInfoSize =
sizeof(OSVERSIONINFO);
559 if (!GetVersionEx((OSVERSIONINFO *)&Ver)) {
560 snprintf(Buffer,
sizeof(Buffer) - 1,
"Windows");
568 if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 0 && Ver.dwBuildNumber == 950) {
569 snprintf(Buffer,
sizeof(Buffer) - 1,
"Windows 95");
570 }
else if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 0 && Ver.dwBuildNumber == 1111) {
571 snprintf(Buffer,
sizeof(Buffer) - 1,
"Windows 95 OSR2.x");
574 }
else if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 10 && Ver.dwBuildNumber == 1998) {
575 snprintf(Buffer,
sizeof(Buffer) - 1,
"Windows 98");
576 }
else if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 10 && Ver.dwBuildNumber == 2222) {
577 snprintf(Buffer,
sizeof(Buffer) - 1,
"Windows 98 SE");
579 }
else if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 90 && Ver.dwBuildNumber == 3000) {
580 snprintf(Buffer,
sizeof(Buffer) - 1,
"Windows ME");
584 }
else if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 0 && Ver.dwBuildNumber == 1381) {
585 snprintf(Buffer,
sizeof(Buffer) - 1,
"Windows NT 4.0");
587 }
else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 0 && Ver.dwBuildNumber == 2195) {
588 snprintf(Buffer,
sizeof(Buffer) - 1,
"Windows 2000");
590 }
else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 1 && Ver.dwBuildNumber == 2600) {
591 snprintf(Buffer,
sizeof(Buffer) - 1,
"Windows XP");
594 if (Ver.wSuiteMask & VER_SUITE_PERSONAL) {
595 snprintf(Buffer+strlen(Buffer),
sizeof(Buffer) - 1 - strlen(Buffer),
" Home");
597 snprintf(Buffer+strlen(Buffer),
sizeof(Buffer) - 1 - strlen(Buffer),
" Pro");
602 }
else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 2) {
603 snprintf(Buffer,
sizeof(Buffer) - 1,
"Windows 2003");
605 }
else if (Ver.dwMajorVersion == 6 && Ver.dwMinorVersion == 0) {
606 snprintf(Buffer,
sizeof(Buffer) - 1,
"Windows Vista");
608 }
else if (Ver.dwMajorVersion == 6 && Ver.dwMinorVersion > 0) {
609 snprintf(Buffer,
sizeof(Buffer) - 1,
"Windows Server 2007");
612 snprintf(Buffer,
sizeof(Buffer) - 1,
"Windows %i.%i.%i",(
int)Ver.dwMajorVersion,(
int)Ver.dwMinorVersion,(
int)Ver.dwBuildNumber);
615 if (Extended && Ver.wServicePackMajor != 0) {
616 snprintf(Buffer+strlen(Buffer),
sizeof(Buffer) - 1 - strlen(Buffer),
" SP%i",Ver.wServicePackMajor);
618 #elif defined(HAVE_SYS_UTSNAME_H) 620 snprintf(Buffer,
sizeof(Buffer) - 1,
"%s, kernel %s (%s)", Ver.sysname, Ver.release, Ver.version);
621 #elif defined(__FreeBSD__) 622 snprintf(Buffer,
sizeof(Buffer) - 1,
"FreeBSD");
623 #elif defined(__NetBSD__) 624 snprintf(Buffer,
sizeof(Buffer) - 1,
"NetBSD");
625 #elif defined(__OpenBSD__) 626 snprintf(Buffer,
sizeof(Buffer) - 1,
"OpenBSD");
627 #elif defined(__GNU__) 628 snprintf(Buffer,
sizeof(Buffer) - 1,
"GNU/Hurd");
629 #elif defined(sun) || defined(__sun) || defined(__sun__) 631 snprintf(Buffer,
sizeof(Buffer) - 1,
"Sun Solaris");
633 snprintf(Buffer,
sizeof(Buffer) - 1,
"SunOS");
635 #elif defined(hpux) || defined(__hpux) || defined(__hpux__) 636 snprintf(Buffer,
sizeof(Buffer) - 1,
"HP-UX");
637 #elif defined(ultrix) || defined(__ultrix) || defined(__ultrix__) 638 snprintf(Buffer,
sizeof(Buffer) - 1,
"DEC Ultrix");
639 #elif defined(sgi) || defined(__sgi) 640 snprintf(Buffer,
sizeof(Buffer) - 1,
"SGI Irix");
641 #elif defined(__osf__) 642 snprintf(Buffer,
sizeof(Buffer) - 1,
"OSF Unix");
643 #elif defined(bsdi) || defined(__bsdi__) 644 snprintf(Buffer,
sizeof(Buffer) - 1,
"BSDI Unix");
646 snprintf(Buffer,
sizeof(Buffer) - 1,
"AIX Unix");
647 #elif defined(_UNIXWARE) 648 snprintf(Buffer,
sizeof(Buffer) - 1,
"SCO Unixware");
650 snprintf(Buffer,
sizeof(Buffer) - 1,
"DG Unix");
651 #elif defined(__QNX__) 652 snprintf(Buffer,
sizeof(Buffer) - 1,
"QNX");
654 snprintf(Buffer,
sizeof(Buffer) - 1,
"unknown OS");
661 static char Buffer[100] = {0x00};
664 if (Buffer[0] != 0)
return Buffer;
667 if (_MSC_VER == 1200) {
668 snprintf(Buffer,
sizeof(Buffer) - 1,
"MS VC 6.0");
669 }
else if (_MSC_VER == 1300) {
670 snprintf(Buffer,
sizeof(Buffer) - 1,
"MS VC .NET 2002");
671 }
else if (_MSC_VER == 1310) {
672 snprintf(Buffer,
sizeof(Buffer) - 1,
"MS VC .NET 2003");
673 }
else if (_MSC_VER == 1400) {
674 snprintf(Buffer,
sizeof(Buffer) - 1,
"MS VC .NET 2005");
676 snprintf(Buffer,
sizeof(Buffer) - 1,
"MS VC %i",_MSC_VER);
678 #elif defined(__BORLANDC__) 679 snprintf(Buffer,
sizeof(Buffer) - 1,
"Borland C++ %i",__BORLANDC__);
680 #elif defined(__MINGW32__) 681 snprintf(Buffer,
sizeof(Buffer) - 1,
"GCC %i.%i, MinGW %i.%i", __GNUC__, __GNUC_MINOR__, __MINGW32_MAJOR_VERSION, __MINGW32_MINOR_VERSION);
682 #elif defined(__CYGWIN__) 683 snprintf(Buffer,
sizeof(Buffer) - 1,
"GCC %i.%i, Cygwin %i.%i", __GNUC__, __GNUC_MINOR__, CYGWIN_VERSION_DLL_MAJOR, CYGWIN_VERSION_DLL_MINOR);
684 #elif defined(__GNUC__) 685 snprintf(Buffer,
sizeof(Buffer) - 1,
"GCC %i.%i", __GNUC__, __GNUC_MINOR__);
687 snprintf(Buffer,
sizeof(Buffer) - 1,
"djgpp %d.%d", __DJGPP, __DJGPP_MINOR);
688 #elif defined(__SUNPRO_CC) 689 snprintf(Buffer,
sizeof(Buffer) - 1,
"Sun C++ %x", __SUNPRO_CC);
690 #elif defined(__INTEL_COMPILER) 691 snprintf(Buffer,
sizeof(Buffer) - 1,
"Intel Compiler %ld", __INTEL_COMPILER);
693 snprintf(Buffer,
sizeof(Buffer) - 1,
"unknown compiler");
702 size_t len = strlen(latest_version);
704 for (i = 0; i < len ; i++) {
705 if (latest_version[i] > current_version[i]) {
717 while(isspace(buff[i])) {
721 memmove(buff, buff + i, strlen(buff + i));
723 i = strlen(buff) - 1;
724 while(isspace(buff[i]) && i >= 0) {
char * OSDate(GSM_DateTime dt)
void FreeLines(GSM_CutLines *lines)
int GetWeekOfMonth(unsigned int year, unsigned int month, unsigned int day)
void GetTimeDifference(unsigned long diff, GSM_DateTime *DT, gboolean Plus, int multi)
void CopyLineString(char *dest, const char *src, const GSM_CutLines *lines, int start)
int GetDayOfYear(unsigned int year, unsigned int month, unsigned int day)
const char * GetLineString(const char *message, GSM_CutLines *lines, int start)
int GetDayOfWeek(unsigned int year, unsigned int month, unsigned int day)
int RecalcDateTime(struct tm *st, const int year, const int month, const int day, const int hour, const int minute, const int second)
char * DayOfWeek(unsigned int year, unsigned int month, unsigned int day)
size_t GetLine(FILE *File, char *Line, int count)
int RecalcDate(struct tm *st, const int year, const int month, const int day)
int GSM_GetLocalTimezoneOffset()
void StripSpaces(char *buff)
void Fill_GSM_DateTime(GSM_DateTime *Date, time_t timet)
void InitLines(GSM_CutLines *lines)
gboolean GSM_IsNewerVersion(const char *latest_version, const char *current_version)
int GetLineLength(const char *message UNUSED, const GSM_CutLines *lines, int start)
gboolean CheckTime(GSM_DateTime *date)
char * OSDateTime(GSM_DateTime dt, gboolean TimeZone)
const char * GetLineStringPos(const char *message, const GSM_CutLines *lines, int start)
void GSM_GetCurrentDateTime(GSM_DateTime *Date)
time_t Fill_Time_T(GSM_DateTime DT)
GSM_DateTime GSM_AddTime(GSM_DateTime DT, GSM_DeltaTime delta)
void GSM_DateTimeToTimestamp(GSM_DateTime *Date, char *str)
void GSM_DateTimeFromTimestamp(GSM_DateTime *Date, const char *str)
void SplitLines(const char *message, const size_t messagesize, GSM_CutLines *lines, const char *whitespaces, const size_t spaceslen, const char *quotes, const size_t quoteslen, const gboolean eot)
gboolean CheckDate(GSM_DateTime *date)
const char * GetCompiler(void)