Gammu internals  1.38.0
misc.c
Go to the documentation of this file.
1 /* (c) 2002-2005 by Marcin Wiacek and Michal Cihar */
2 /* Checking used compiler (c) 2002 by Michal Cihar */
3 
4 #include <gammu-config.h>
5 #include <gammu-misc.h>
6 
7 #include "misc.h"
8 
9 #include "coding/coding.h"
10 #include "../debug.h"
11 
12 #include <string.h>
13 #include <time.h>
14 #include <stdio.h>
15 #include <stdlib.h>
16 #include <ctype.h>
17 #ifdef WIN32
18 # define WIN32_LEAN_AND_MEAN
19 # include <windows.h>
20 # include <locale.h>
21 # define gmtime_r(x, y) gmtime_s(y, x)
22 # define localtime_r(x, y) localtime_s(y, x)
23 #endif
24 #ifdef HAVE_SYS_UTSNAME_H
25 # include <sys/utsname.h>
26 #endif
27 #ifdef __CYGWIN__
28 #include <cygwin/version.h>
29 #endif
30 
38 int RecalcDateTime(struct tm *st, const int year, const int month, const int day, const int hour, const int minute, const int second)
39 {
40  const int days[] = {31,28,31,30,31,30,31,31,30,31,30,31};
41  int i, p, q, r;
42  GSM_DateTime Date;
43 
44  Date.Year = year;
45  Date.Month = month;
46  Date.Day = day;
47  Date.Hour = hour;
48  Date.Minute = minute;
49  Date.Second = second;
50  Date.Timezone = 0;
51 
52  if (!CheckDate(&Date) || !CheckTime(&Date)) return 0;
53 
54  memset(st, 0, sizeof(*st));
55 
56  /* Calculate day of year */
57  st->tm_yday = day;
58  for (i = 0; i < month - 1; i++)
59  st->tm_yday += days[i];
60 
61  /* Calculate day of week */
62  p = (14 - month) / 12;
63  q = month + 12 * p - 2;
64  r = year - p;
65  st->tm_wday = (day + (31 * q) / 12 + r + r / 4 - r / 100 + r / 400) % 7;
66 
67 
68  st->tm_hour = hour;
69  st->tm_min = minute;
70  st->tm_sec = second;
71  st->tm_year = year - 1900;
72  st->tm_mon = month - 1;
73  st->tm_mday = day;
74 
75  st->tm_isdst = -1; /* FIXME */
76 
77  return 1;
78 }
79 
80 
84 int RecalcDate(struct tm *st, const int year, const int month, const int day)
85 {
86  return RecalcDateTime(st, year, month, day, 0, 0, 0);
87 }
88 
89 
93 int GetDayOfYear(unsigned int year, unsigned int month, unsigned int day)
94 {
95  struct tm st;
96 
97  RecalcDate(&st, year, month, day);
98 
99  return st.tm_yday;
100 }
101 
105 int GetWeekOfMonth(unsigned int year, unsigned int month, unsigned int day)
106 {
107  struct tm st;
108 
109  RecalcDate(&st, year, month, day);
110 
111  return 1 + (day - st.tm_wday) / 7;
112 }
113 
117 int GetDayOfWeek(unsigned int year, unsigned int month, unsigned int day)
118 {
119  struct tm st;
120 
121  RecalcDate(&st, year, month, day);
122 
123  return st.tm_wday;
124 }
125 
129 char *DayOfWeek (unsigned int year, unsigned int month, unsigned int day)
130 {
131  static char DayOfWeekChar[10];
132 
133  strcpy(DayOfWeekChar,"");
134  switch (GetDayOfWeek(year, month, day)) {
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;
142  }
143  return DayOfWeekChar;
144 }
145 
147  struct tm tg, tl;
148  time_t now = time(NULL);
149  gmtime_r(&now, &tg);
150  localtime_r(&now, &tl);
151  // Returns offset including daylight saving (found as boolean in tl.tm_isdst).
152  return (int)(mktime(&tl) - mktime(&tg));
153 }
154 
155 void GSM_DateTimeToTimestamp(GSM_DateTime *Date, char *str)
156 {
157  time_t timet;
158  timet = Fill_Time_T(*Date);
159  sprintf(str, "%ld", (long)timet);
160 }
161 
162 void GSM_DateTimeFromTimestamp(GSM_DateTime *Date, const char *str)
163 {
164  time_t timet;
165 
166  timet = atof(str);
167  Fill_GSM_DateTime(Date, timet);
168 }
169 
170 void Fill_GSM_DateTime(GSM_DateTime *Date, time_t timet)
171 {
172  struct tm *now;
173 
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;
182 }
183 
185 {
186  Fill_GSM_DateTime(Date, time(NULL));
187 }
188 
190 {
191  struct tm timestruct;
192  struct tm *now;
193  time_t t;
194 
195 
196  dbgprintf(NULL, "StartTime: %s\n", OSDate(DT));
197 
198  memset(&timestruct, 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;
205 
206  time(&t);
207  now = localtime(&t);
208 
209 #ifdef HAVE_DAYLIGHT
210  timestruct.tm_isdst = now->tm_isdst;
211 #else
212  timestruct.tm_isdst = -1;
213 #endif
214 #ifdef HAVE_STRUCT_TM_TM_ZONE
215  /* No time zone information */
216  timestruct.tm_gmtoff = now->tm_gmtoff;
217  timestruct.tm_zone = now->tm_zone;
218 #endif
219 
220  return mktime(&timestruct);
221 }
222 
224 {
225  struct tm tm_time;
226  time_t t_time;
227  GSM_DateTime Date;
228 
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;
237 
238  /* TODO: This works only for dates after 1970. But birthday dates may be before, so a more general
239  method than mktime /localtime should be used. */
240  t_time = mktime (&tm_time);
241  t_time = t_time + delta.Second + 60* (delta.Minute + 60* (delta.Hour + 24*delta.Day));
242 
243  Fill_GSM_DateTime ( &Date, t_time);
244  return Date;
245 }
246 
247 void GetTimeDifference(unsigned long diff, GSM_DateTime *DT, gboolean Plus, int multi)
248 {
249  time_t t_time;
250 
251  t_time = Fill_Time_T(*DT);
252 
253  if (Plus) {
254  t_time += diff*multi;
255  } else {
256  t_time -= diff*multi;
257  }
258 
259  Fill_GSM_DateTime(DT, t_time);
260  dbgprintf(NULL, "EndTime: %02i-%02i-%04i %02i:%02i:%02i\n",
261  DT->Day,DT->Month,DT->Year,DT->Hour,DT->Minute,DT->Second);
262 }
263 
264 char *OSDateTime (GSM_DateTime dt, gboolean TimeZone)
265 {
266  struct tm timeptr;
267  static char retval[200],retval2[200];
268 
269  if (!RecalcDateTime(&timeptr, dt.Year, dt.Month, dt.Day,
270  dt.Hour, dt.Minute, dt.Second)) {
271  retval2[0] = '\0';
272  return retval2;
273  }
274 
275 #ifdef WIN32
276  setlocale(LC_ALL, ".OCP");
277 #endif
278 
279  /* This is not Y2K safe */
280  strftime(retval2, 200, "%c", &timeptr);
281  if (TimeZone) {
282  snprintf(retval, sizeof(retval) - 1, " %+03i%02i",
283  dt.Timezone / 3600, abs((dt.Timezone % 3600) / 60));
284  strcat(retval2,retval);
285  }
286  /* If don't have weekday name, include it */
287  strftime(retval, 200, "%A", &timeptr);
288  if (strstr(retval2,retval)==NULL) {
289  /* Check for abbreviated weekday */
290  strftime(retval, 200, "%a", &timeptr);
291  if (strstr(retval2,retval)==NULL) {
292  strcat(retval2," (");
293  strcat(retval2,retval);
294  strcat(retval2,")");
295  }
296  }
297 
298 #ifdef WIN32
299  setlocale(LC_ALL, ".ACP");
300 #endif
301 
302  return retval2;
303 }
304 
306 {
307  struct tm timeptr;
308  static char retval[200],retval2[200];
309 
310 #ifdef WIN32
311  setlocale(LC_ALL, ".OCP");
312 #endif
313 
314  timeptr.tm_yday = 0; /* FIXME */
315  timeptr.tm_isdst = -1; /* FIXME */
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;
322  timeptr.tm_wday = GetDayOfWeek(dt.Year, dt.Month, dt.Day);
323 #ifdef HAVE_STRUCT_TM_TM_ZONE
324  timeptr.tm_zone = NULL;
325 #endif
326 
327  /* This is not Y2K safe */
328  strftime(retval2, 200, "%x", &timeptr);
329 
330  /* If don't have weekday name, include it */
331  strftime(retval, 200, "%A", &timeptr);
332  if (strstr(retval2,retval)==NULL) {
333  /* Check also for short name */
334  strftime(retval, 200, "%a", &timeptr);
335  if (strstr(retval2,retval)==NULL) {
336  strcat(retval2," (");
337  strcat(retval2,retval);
338  strcat(retval2,")");
339  }
340  }
341 
342 #ifdef WIN32
343  setlocale(LC_ALL, ".ACP");
344 #endif
345 
346  return retval2;
347 }
348 
350 {
351  const int days[]={31,28,31,30,31,30,31,31,30,31,30,31};
352 
353  if (date->Year != 0 &&
354  ((date->Year % 4 == 0 && date->Year % 100 != 0) || date->Year % 400 == 0) &&
355  date->Month == 2) {
356  return (date->Day <= 29);
357  }
358  return date->Year != 0 &&
359  date->Month >= 1 && date->Month <= 12 &&
360  date->Day >= 1 && date->Day <= days[date->Month-1];
361 }
362 
364 {
365  return date->Hour <= 23 &&
366  date->Minute <= 59 &&
367  date->Second <= 59;
368 }
369 
370 size_t GetLine(FILE *File, char *Line, int count)
371 {
372  int num;
373 
374  if (fgets(Line, count, File) != NULL) {
375  num = strlen(Line) - 1;
376  while (num > 0) {
377  if (Line[num] != '\n' && Line[num] != '\r') break;
378  Line[num--] = '\0';
379  }
380  return strlen(Line);
381  }
382  return -1;
383 }
384 
386 {
387  lines->numbers = NULL;
388  lines->allocated = 0;
389  lines->retval = NULL;
390 }
391 
393 {
394  free(lines->numbers);
395  lines->numbers = NULL;
396  lines->allocated = 0;
397  free(lines->retval);
398  lines->retval = NULL;
399 }
400 
401 void SplitLines(const char *message, const size_t messagesize, GSM_CutLines *lines,
402  const char *whitespaces, const size_t spaceslen,
403  const char *quotes, const size_t quoteslen,
404  const gboolean eot)
405 {
406  size_t i=0,number=0,j=0, lastquote = 0;
407  gboolean whitespace = TRUE, nowwhite = FALSE, insidequotes = FALSE;
408 
409  /* Clean current lines */
410  for (i = 0; i < lines->allocated; i++) {
411  lines->numbers[i] = 0;
412  }
413 
414  /* Go through message */
415  for (i = 0; i < messagesize; i++) {
416  /* Reallocate buffer if needed */
417  if (number + 2 >= lines->allocated) {
418  lines->allocated += 20;
419  lines->numbers = (size_t *)realloc(lines->numbers, lines->allocated * sizeof(size_t));
420  if (lines->numbers == NULL) {
421  return;
422  }
423  for (j = lines->allocated - 20; j < lines->allocated; j++) {
424  lines->numbers[j] = 0;
425  }
426  }
427 
428  nowwhite = FALSE;
429 
430  /* Check for quotes */
431  for (j = 0; j < quoteslen; j++) {
432  if (quotes[j] == message[i]) {
433  insidequotes = !(insidequotes);
434  lastquote = i;
435  break;
436  }
437  }
438 
439  /* Find matching quote */
440  if (insidequotes) {
441  continue;
442  }
443 
444 rollback_quote:
445  /* Check for whitespace */
446  for (j = 0; j < spaceslen; j++) {
447  if (whitespaces[j] == message[i]) {
448  nowwhite = TRUE;
449  break;
450  }
451  }
452 
453  /* Split line if there is change from whitespace to non whitespace */
454  if (whitespace) {
455  if (!nowwhite) {
456  lines->numbers[number] = i;
457  number++;
458  whitespace = FALSE;
459  }
460  } else {
461  if (nowwhite) {
462  lines->numbers[number] = i;
463  number++;
464  whitespace = TRUE;
465  }
466 
467  }
468  }
469 
470  /* Check for unterminated quotes and roll back to ignore them */
471  if (number % 2 == 1 && insidequotes) {
472  insidequotes = FALSE;
473  i = lastquote;
474  goto rollback_quote;
475  }
476 
477  /* Store possible end if there was not just whitespace */
478  if (eot && !whitespace) {
479  lines->numbers[number] = messagesize;
480  }
481 }
482 
483 const char *GetLineStringPos(const char *message, const GSM_CutLines *lines, int start)
484 {
485  if (message == NULL) {
486  return NULL;
487  }
488 
489  return message + lines->numbers[start * 2 - 2];
490 }
491 
492 const char *GetLineString(const char *message, GSM_CutLines *lines, int start)
493 {
494  int len=0;
495  const char *pos;
496 
497  pos = GetLineStringPos(message, lines, start);
498  if (pos == NULL) {
499  return NULL;
500  }
501 
502  len = GetLineLength(message, lines, start);
503 
504  lines->retval = (char *)realloc(lines->retval, len + 1);
505  if (lines->retval == NULL) {
506  dbgprintf(NULL, "Allocation failed!\n");
507  return NULL;
508  }
509 
510  memcpy(lines->retval, pos, len);
511 
512  lines->retval[len] = '\0';
513 
514  return lines->retval;
515 }
516 
517 int GetLineLength(const char *message UNUSED, const GSM_CutLines *lines, int start)
518 {
519  return lines->numbers[start*2-2+1] - lines->numbers[start*2-2];
520 }
521 
522 void CopyLineString(char *dest, const char *src, const GSM_CutLines *lines, int start)
523 {
524  int len;
525  const char *pos;
526 
527  len = GetLineLength(src, lines, start);
528  pos = GetLineStringPos(src, lines, start);
529  if (pos == NULL) {
530  dest[0] = '\0';
531  return;
532  }
533  memcpy(dest, pos, len);
534  dest[len] = '\0';
535 }
536 
537 const char *GetOS(void)
538 {
539 #ifdef WIN32
540  OSVERSIONINFOEX Ver;
541  gboolean Extended = TRUE;
542 #else
543 # ifdef HAVE_SYS_UTSNAME_H
544  struct utsname Ver;
545 # endif
546 #endif
547  static char Buffer[100] = {0x00};
548 
549  /* Value was already calculated */
550  if (Buffer[0] != 0) return Buffer;
551 
552 #ifdef WIN32
553  memset(&Ver,0,sizeof(OSVERSIONINFOEX));
554  Ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
555 
556  if (!GetVersionEx((OSVERSIONINFO *)&Ver)) {
557  Extended = FALSE;
558  Ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
559  if (!GetVersionEx((OSVERSIONINFO *)&Ver)) {
560  snprintf(Buffer, sizeof(Buffer) - 1, "Windows");
561  return Buffer;
562  }
563  }
564 
565  /* ----------------- 9x family ------------------ */
566 
567  /* no info about Win95 SP1, Win95 OSR2.1, Win95 OSR2.5.... */
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");
572 
573  /* no info about Win98 SP1.... */
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");
578 
579  } else if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 90 && Ver.dwBuildNumber == 3000) {
580  snprintf(Buffer, sizeof(Buffer) - 1, "Windows ME");
581 
582  /* ---------------- NT family ------------------- */
583 
584  } else if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 0 && Ver.dwBuildNumber == 1381) {
585  snprintf(Buffer, sizeof(Buffer) - 1, "Windows NT 4.0");
586 
587  } else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 0 && Ver.dwBuildNumber == 2195) {
588  snprintf(Buffer, sizeof(Buffer) - 1, "Windows 2000");
589 
590  } else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 1 && Ver.dwBuildNumber == 2600) {
591  snprintf(Buffer, sizeof(Buffer) - 1, "Windows XP");
592 #if _MSC_VER > 1200 /* 6.0 has it undeclared */
593  if (Extended) {
594  if (Ver.wSuiteMask & VER_SUITE_PERSONAL) {
595  snprintf(Buffer+strlen(Buffer), sizeof(Buffer) - 1 - strlen(Buffer)," Home");
596  } else {
597  snprintf(Buffer+strlen(Buffer), sizeof(Buffer) - 1 - strlen(Buffer)," Pro");
598  }
599  }
600 #endif
601 
602  } else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 2) {
603  snprintf(Buffer, sizeof(Buffer) - 1, "Windows 2003");
604 
605  } else if (Ver.dwMajorVersion == 6 && Ver.dwMinorVersion == 0) {
606  snprintf(Buffer, sizeof(Buffer) - 1, "Windows Vista");
607 
608  } else if (Ver.dwMajorVersion == 6 && Ver.dwMinorVersion > 0) {
609  snprintf(Buffer, sizeof(Buffer) - 1, "Windows Server 2007");
610 
611  } else {
612  snprintf(Buffer, sizeof(Buffer) - 1, "Windows %i.%i.%i",(int)Ver.dwMajorVersion,(int)Ver.dwMinorVersion,(int)Ver.dwBuildNumber);
613  }
614 
615  if (Extended && Ver.wServicePackMajor != 0) {
616  snprintf(Buffer+strlen(Buffer), sizeof(Buffer) - 1 - strlen(Buffer)," SP%i",Ver.wServicePackMajor);
617  }
618 #elif defined(HAVE_SYS_UTSNAME_H)
619  uname(&Ver);
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__)
630 # ifdef __SVR4
631  snprintf(Buffer, sizeof(Buffer) - 1, "Sun Solaris");
632 # else
633  snprintf(Buffer, sizeof(Buffer) - 1, "SunOS");
634 # endif
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");
645 #elif defined(_AIX)
646  snprintf(Buffer, sizeof(Buffer) - 1, "AIX Unix");
647 #elif defined(_UNIXWARE)
648  snprintf(Buffer, sizeof(Buffer) - 1, "SCO Unixware");
649 #elif defined(DGUX)
650  snprintf(Buffer, sizeof(Buffer) - 1, "DG Unix");
651 #elif defined(__QNX__)
652  snprintf(Buffer, sizeof(Buffer) - 1, "QNX");
653 #else
654  snprintf(Buffer, sizeof(Buffer) - 1, "unknown OS");
655 #endif
656  return Buffer;
657 }
658 
659 const char *GetCompiler(void)
660 {
661  static char Buffer[100] = {0x00};
662 
663  /* Value was already calculated */
664  if (Buffer[0] != 0) return Buffer;
665 
666 #ifdef _MSC_VER
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");
675  } else {
676  snprintf(Buffer, sizeof(Buffer) - 1, "MS VC %i",_MSC_VER);
677  }
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__);
686 #elif defined(DJGPP)
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);
692 #else
693  snprintf(Buffer, sizeof(Buffer) - 1, "unknown compiler");
694 #endif
695 
696  return Buffer;
697 }
698 
699 gboolean GSM_IsNewerVersion(const char *latest_version, const char *current_version)
700 {
701  size_t i;
702  size_t len = strlen(latest_version);
703 
704  for (i = 0; i < len ; i++) {
705  if (latest_version[i] > current_version[i]) {
706  return TRUE;
707  }
708  }
709 
710  return FALSE;
711 }
712 
713 void StripSpaces(char *buff)
714 {
715  ssize_t i = 0;
716 
717  while(isspace(buff[i])) {
718  i++;
719  }
720  if (i > 0) {
721  memmove(buff, buff + i, strlen(buff + i));
722  }
723  i = strlen(buff) - 1;
724  while(isspace(buff[i]) && i >= 0) {
725  buff[i] = 0;
726  i--;
727  }
728 
729 }
730 
731 /* How should editor hadle tabs in this file? Add editor commands here.
732  * vim: noexpandtab sw=8 ts=8 sts=8:
733  */
const char * GetOS(void)
Definition: misc.c:537
char * OSDate(GSM_DateTime dt)
Definition: misc.c:305
void FreeLines(GSM_CutLines *lines)
Definition: misc.c:392
int GetWeekOfMonth(unsigned int year, unsigned int month, unsigned int day)
Definition: misc.c:105
void GetTimeDifference(unsigned long diff, GSM_DateTime *DT, gboolean Plus, int multi)
Definition: misc.c:247
void CopyLineString(char *dest, const char *src, const GSM_CutLines *lines, int start)
Definition: misc.c:522
int GetDayOfYear(unsigned int year, unsigned int month, unsigned int day)
Definition: misc.c:93
const char * GetLineString(const char *message, GSM_CutLines *lines, int start)
Definition: misc.c:492
int GetDayOfWeek(unsigned int year, unsigned int month, unsigned int day)
Definition: misc.c:117
int RecalcDateTime(struct tm *st, const int year, const int month, const int day, const int hour, const int minute, const int second)
Definition: misc.c:38
size_t * numbers
Definition: misc.h:38
char * DayOfWeek(unsigned int year, unsigned int month, unsigned int day)
Definition: misc.c:129
size_t GetLine(FILE *File, char *Line, int count)
Definition: misc.c:370
int RecalcDate(struct tm *st, const int year, const int month, const int day)
Definition: misc.c:84
int GSM_GetLocalTimezoneOffset()
Definition: misc.c:146
void StripSpaces(char *buff)
Definition: misc.c:713
size_t allocated
Definition: misc.h:42
void Fill_GSM_DateTime(GSM_DateTime *Date, time_t timet)
Definition: misc.c:170
int gboolean
Definition: gammu-types.h:23
void InitLines(GSM_CutLines *lines)
Definition: misc.c:385
#define FALSE
Definition: gammu-types.h:25
gboolean GSM_IsNewerVersion(const char *latest_version, const char *current_version)
Definition: misc.c:699
int GetLineLength(const char *message UNUSED, const GSM_CutLines *lines, int start)
Definition: misc.c:517
gboolean CheckTime(GSM_DateTime *date)
Definition: misc.c:363
char * OSDateTime(GSM_DateTime dt, gboolean TimeZone)
Definition: misc.c:264
const char * GetLineStringPos(const char *message, const GSM_CutLines *lines, int start)
Definition: misc.c:483
#define dbgprintf
Definition: debug.h:72
void GSM_GetCurrentDateTime(GSM_DateTime *Date)
Definition: misc.c:184
time_t Fill_Time_T(GSM_DateTime DT)
Definition: misc.c:189
GSM_DateTime GSM_AddTime(GSM_DateTime DT, GSM_DeltaTime delta)
Definition: misc.c:223
void GSM_DateTimeToTimestamp(GSM_DateTime *Date, char *str)
Definition: misc.c:155
#define TRUE
Definition: gammu-types.h:28
void GSM_DateTimeFromTimestamp(GSM_DateTime *Date, const char *str)
Definition: misc.c:162
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)
Definition: misc.c:401
#define UNUSED
Definition: gammu-misc.h:105
char * retval
Definition: misc.h:46
gboolean CheckDate(GSM_DateTime *date)
Definition: misc.c:349
const char * GetCompiler(void)
Definition: misc.c:659