author | zautrix <zautrix> | 2004-10-05 11:13:51 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-05 11:13:51 (UTC) |
commit | 50ab40e1e02ad7c65c17a78d08116a808b1257aa (patch) (side-by-side diff) | |
tree | 0d1939e2297fa7bbd8e1f2030f154463854164c6 /gammu/emb/common/misc/misc.c | |
parent | cf8616f64f20e5448d4ff644f7cc15750cf3f85f (diff) | |
download | kdepimpi-50ab40e1e02ad7c65c17a78d08116a808b1257aa.zip kdepimpi-50ab40e1e02ad7c65c17a78d08116a808b1257aa.tar.gz kdepimpi-50ab40e1e02ad7c65c17a78d08116a808b1257aa.tar.bz2 |
updated to latest gammu version
-rw-r--r-- | gammu/emb/common/misc/misc.c | 15 |
1 files changed, 12 insertions, 3 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 @@ -1,37 +1,40 @@ /* (c) 2002-2004 by Marcin Wiacek and Michal Cihar */ /* Checking used compiler (c) 2002 by Michal Cihar */ #include <string.h> #include <ctype.h> #include <time.h> #include <stdarg.h> #include <stdio.h> #include <locale.h> #include <sys/timeb.h> #ifdef WIN32 # include "windows.h" #endif +#if defined(linux) || defined(__linux) || defined(__linux__) +# include <sys/utsname.h> +#endif #include "../gsmstate.h" #include "misc.h" /* Based on article in Polish PC-Kurier 8/1998 page 104 * Archive on http://www.pckurier.pl */ char *DayOfWeek (int year, int month, int day) { int p,q,r,w; static char DayOfWeekChar[10]; p=(14-month) / 12; q=month+12*p-2; r=year-p; w=(day+(31*q) / 12 + r + r / 4 - r / 100 + r / 400) % 7; strcpy(DayOfWeekChar,""); switch (w) { case 0: strcpy(DayOfWeekChar,"Sun"); break; case 1: strcpy(DayOfWeekChar,"Mon"); break; case 2: strcpy(DayOfWeekChar,"Tue"); break; case 3: strcpy(DayOfWeekChar,"Wed"); break; case 4: strcpy(DayOfWeekChar,"Thu"); break; case 5: strcpy(DayOfWeekChar,"Fri"); break; @@ -210,52 +213,54 @@ char *OSDate (GSM_DateTime dt) #else strftime(retval2, 200, "%x", &timeptr); #endif /* If don't have weekday name, include it */ strftime(retval, 200, "%A", &timeptr); if (strstr(retval2,retval)==NULL) { /* Check also for short name */ strftime(retval, 200, "%a", &timeptr); if (strstr(retval2,retval)==NULL) { strcat(retval2," ("); strcat(retval2,retval); strcat(retval2,")"); } } #ifdef WIN32 setlocale(LC_ALL, ".ACP"); #endif return retval2; } bool CheckDate(GSM_DateTime *date) { - /* FIXME: This could also check if day is correct for selected month */ + const unsigned int days[]={31,29,31,30,31,30,31,31,30,31,30,31}; + + /* FIXME: This could also check for leap years */ return date->Year != 0 && date->Month >= 1 && date->Month <= 12 && - date->Day >= 1 && date->Day <= 31; + date->Day >= 1 && date->Day <= days[date->Month]; } bool CheckTime(GSM_DateTime *date) { return date->Hour <= 23 && date->Hour >= 0 && date->Minute <= 59 && date->Minute >= 0 && date->Second <= 59 && date->Second >= 0; } int GetLine(FILE *File, char *Line, int count) { int num; if (fgets(Line, count, File) != NULL) { num = strlen(Line) - 1; while(1) { if (Line[num] != '\n' && Line[num] != '\r') break; if (num == 0) break; Line[num--] = 0; } return strlen(Line); } return -1; } @@ -430,48 +435,51 @@ void DumpMessage(FILE *df, Debug_Level dl, const unsigned char *message, int mes if (j != len-1) buffer[j*4+2] = message[i]; buffer[(len-1)*4+j+3] = message[i]; } else { buffer[(len-1)*4+j+3] = '.'; } if (j != len-1 && i != messagesize-1) buffer[j*4+3] = '|'; if (j == len-1) { smfprintf(df, dl, "%s\n", buffer); memset(buffer,0x20,sizeof(buffer)); buffer[len*5-1]=0; j = 0; } else { j++; } } if (j != 0) smfprintf(df, dl, "%s\n", buffer); } char *GetOS(void) { #ifdef WIN32 OSVERSIONINFOEX Ver; bool Extended = true; #endif +#if defined(linux) || defined(__linux) || defined(__linux__) + struct utsname Ver; +#endif static char Buffer[100] = {0x00}; #ifdef WIN32 memset(&Ver,sizeof(OSVERSIONINFOEX),0); Ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); if (!GetVersionEx((OSVERSIONINFO *)&Ver)) { Extended = false; Ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); if (!GetVersionEx((OSVERSIONINFO *)&Ver)) { //#ifdef _MSC_VER
// Ver.dwMajorVersion = _winmajor; // Ver.dwMinorVersion = _winminor; // Ver.dwBuildNumber = _osver; //#else sprintf(Buffer, "Windows"); return Buffer; //#endif } } /* ----------------- 9x family ------------------ */ /* no info about Win95 SP1, Win95 OSR2.1, Win95 OSR2.5.... */ @@ -499,49 +507,50 @@ char *GetOS(void) } else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 1 && Ver.dwBuildNumber == 2600) { sprintf(Buffer,"Win XP"); #if _MSC_VER > 1200 //6.0 has it undeclared
if (Extended) { if (Ver.wSuiteMask & VER_SUITE_PERSONAL) { sprintf(Buffer+strlen(Buffer)," Home"); } else { sprintf(Buffer+strlen(Buffer)," Pro"); } }
#endif } else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 2) { sprintf(Buffer,"Win 2003"); } else { sprintf(Buffer, "Windows %i.%i.%i",Ver.dwMajorVersion,Ver.dwMinorVersion,Ver.dwBuildNumber); } if (Extended && Ver.wServicePackMajor != 0) { sprintf(Buffer+strlen(Buffer)," SP%i",Ver.wServicePackMajor); } #elif defined(linux) || defined(__linux) || defined(__linux__) - sprintf(Buffer, "Linux"); + uname(&Ver); + sprintf(Buffer, "Linux, kernel %s",Ver.release); #elif defined(__FreeBSD__) sprintf(Buffer, "FreeBSD"); #elif defined(__NetBSD__) sprintf(Buffer, "NetBSD"); #elif defined(__OpenBSD__) sprintf(Buffer, "OpenBSD"); #elif defined(__GNU__) sprintf(Buffer, "GNU/Hurd"); #elif defined(sun) || defined(__sun) || defined(__sun__) # ifdef __SVR4 sprintf(Buffer, "Sun Solaris"); # else sprintf(Buffer, "SunOS"); # endif #elif defined(hpux) || defined(__hpux) || defined(__hpux__) sprintf(Buffer, "HP-UX"); #elif defined(ultrix) || defined(__ultrix) || defined(__ultrix__) sprintf(Buffer, "DEC Ultrix"); #elif defined(sgi) || defined(__sgi) sprintf(Buffer, "SGI Irix"); #elif defined(__osf__) sprintf(Buffer, "OSF Unix"); #elif defined(bsdi) || defined(__bsdi__) sprintf(Buffer, "BSDI Unix"); |