summaryrefslogtreecommitdiffabout
path: root/gammu/emb/common/misc/misc.c
Unidiff
Diffstat (limited to 'gammu/emb/common/misc/misc.c') (more/less context) (ignore whitespace changes)
-rw-r--r--gammu/emb/common/misc/misc.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/gammu/emb/common/misc/misc.c b/gammu/emb/common/misc/misc.c
index c2f09e4..7227e7b 100644
--- a/gammu/emb/common/misc/misc.c
+++ b/gammu/emb/common/misc/misc.c
@@ -2,24 +2,27 @@
2/* Checking used compiler (c) 2002 by Michal Cihar */ 2/* Checking used compiler (c) 2002 by Michal Cihar */
3 3
4#include <string.h> 4#include <string.h>
5#include <ctype.h> 5#include <ctype.h>
6#include <time.h> 6#include <time.h>
7#include <stdarg.h> 7#include <stdarg.h>
8#include <stdio.h> 8#include <stdio.h>
9#include <locale.h> 9#include <locale.h>
10#include <sys/timeb.h> 10#include <sys/timeb.h>
11#ifdef WIN32 11#ifdef WIN32
12# include "windows.h" 12# include "windows.h"
13#endif 13#endif
14#if defined(linux) || defined(__linux) || defined(__linux__)
15# include <sys/utsname.h>
16#endif
14 17
15#include "../gsmstate.h" 18#include "../gsmstate.h"
16#include "misc.h" 19#include "misc.h"
17 20
18/* Based on article in Polish PC-Kurier 8/1998 page 104 21/* Based on article in Polish PC-Kurier 8/1998 page 104
19 * Archive on http://www.pckurier.pl 22 * Archive on http://www.pckurier.pl
20 */ 23 */
21char *DayOfWeek (int year, int month, int day) 24char *DayOfWeek (int year, int month, int day)
22{ 25{
23 int p,q,r,w; 26 int p,q,r,w;
24 static char DayOfWeekChar[10]; 27 static char DayOfWeekChar[10];
25 28
@@ -221,29 +224,31 @@ char *OSDate (GSM_DateTime dt)
221 strcat(retval2,")"); 224 strcat(retval2,")");
222 } 225 }
223 } 226 }
224 227
225#ifdef WIN32 228#ifdef WIN32
226 setlocale(LC_ALL, ".ACP"); 229 setlocale(LC_ALL, ".ACP");
227#endif 230#endif
228 231
229 return retval2; 232 return retval2;
230} 233}
231 234
232bool CheckDate(GSM_DateTime *date) 235bool CheckDate(GSM_DateTime *date)
233{ 236 {
234 /* FIXME: This could also check if day is correct for selected month */ 237 const unsigned int days[]={31,29,31,30,31,30,31,31,30,31,30,31};
238
239 /* FIXME: This could also check for leap years */
235 return date->Year != 0 && 240 return date->Year != 0 &&
236 date->Month >= 1 && date->Month <= 12 && 241 date->Month >= 1 && date->Month <= 12 &&
237 date->Day >= 1 && date->Day <= 31; 242 date->Day >= 1 && date->Day <= days[date->Month];
238} 243}
239 244
240bool CheckTime(GSM_DateTime *date) 245bool CheckTime(GSM_DateTime *date)
241{ 246{
242 return date->Hour <= 23 && date->Hour >= 0 && 247 return date->Hour <= 23 && date->Hour >= 0 &&
243 date->Minute <= 59 && date->Minute >= 0 && 248 date->Minute <= 59 && date->Minute >= 0 &&
244 date->Second <= 59 && date->Second >= 0; 249 date->Second <= 59 && date->Second >= 0;
245} 250}
246 251
247int GetLine(FILE *File, char *Line, int count) 252int GetLine(FILE *File, char *Line, int count)
248{ 253{
249 int num; 254 int num;
@@ -442,24 +447,27 @@ void DumpMessage(FILE *df, Debug_Level dl, const unsigned char *message, int mes
442 j++; 447 j++;
443 } 448 }
444 } 449 }
445 if (j != 0) smfprintf(df, dl, "%s\n", buffer); 450 if (j != 0) smfprintf(df, dl, "%s\n", buffer);
446} 451}
447 452
448char *GetOS(void) 453char *GetOS(void)
449{ 454{
450#ifdef WIN32 455#ifdef WIN32
451 OSVERSIONINFOEX Ver; 456 OSVERSIONINFOEX Ver;
452 bool Extended = true; 457 bool Extended = true;
453#endif 458#endif
459#if defined(linux) || defined(__linux) || defined(__linux__)
460 struct utsnameVer;
461#endif
454 static char Buffer[100] = {0x00}; 462 static char Buffer[100] = {0x00};
455 463
456#ifdef WIN32 464#ifdef WIN32
457 memset(&Ver,sizeof(OSVERSIONINFOEX),0); 465 memset(&Ver,sizeof(OSVERSIONINFOEX),0);
458 Ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); 466 Ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
459 467
460 if (!GetVersionEx((OSVERSIONINFO *)&Ver)) { 468 if (!GetVersionEx((OSVERSIONINFO *)&Ver)) {
461 Extended = false; 469 Extended = false;
462 Ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); 470 Ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
463 if (!GetVersionEx((OSVERSIONINFO *)&Ver)) { 471 if (!GetVersionEx((OSVERSIONINFO *)&Ver)) {
464//#ifdef _MSC_VER 472//#ifdef _MSC_VER
465 // Ver.dwMajorVersion = _winmajor; 473 // Ver.dwMajorVersion = _winmajor;
@@ -511,25 +519,26 @@ char *GetOS(void)
511 519
512 } else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 2) { 520 } else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 2) {
513 sprintf(Buffer,"Win 2003"); 521 sprintf(Buffer,"Win 2003");
514 522
515 } else { 523 } else {
516 sprintf(Buffer, "Windows %i.%i.%i",Ver.dwMajorVersion,Ver.dwMinorVersion,Ver.dwBuildNumber); 524 sprintf(Buffer, "Windows %i.%i.%i",Ver.dwMajorVersion,Ver.dwMinorVersion,Ver.dwBuildNumber);
517 } 525 }
518 526
519 if (Extended && Ver.wServicePackMajor != 0) { 527 if (Extended && Ver.wServicePackMajor != 0) {
520 sprintf(Buffer+strlen(Buffer)," SP%i",Ver.wServicePackMajor); 528 sprintf(Buffer+strlen(Buffer)," SP%i",Ver.wServicePackMajor);
521 } 529 }
522#elif defined(linux) || defined(__linux) || defined(__linux__) 530#elif defined(linux) || defined(__linux) || defined(__linux__)
523 sprintf(Buffer, "Linux"); 531 uname(&Ver);
532 sprintf(Buffer, "Linux, kernel %s",Ver.release);
524#elif defined(__FreeBSD__) 533#elif defined(__FreeBSD__)
525 sprintf(Buffer, "FreeBSD"); 534 sprintf(Buffer, "FreeBSD");
526#elif defined(__NetBSD__) 535#elif defined(__NetBSD__)
527 sprintf(Buffer, "NetBSD"); 536 sprintf(Buffer, "NetBSD");
528#elif defined(__OpenBSD__) 537#elif defined(__OpenBSD__)
529 sprintf(Buffer, "OpenBSD"); 538 sprintf(Buffer, "OpenBSD");
530#elif defined(__GNU__) 539#elif defined(__GNU__)
531 sprintf(Buffer, "GNU/Hurd"); 540 sprintf(Buffer, "GNU/Hurd");
532#elif defined(sun) || defined(__sun) || defined(__sun__) 541#elif defined(sun) || defined(__sun) || defined(__sun__)
533# ifdef __SVR4 542# ifdef __SVR4
534 sprintf(Buffer, "Sun Solaris"); 543 sprintf(Buffer, "Sun Solaris");
535# else 544# else