Gammu internals  1.38.0
misc.c File Reference
#include <gammu-config.h>
#include <gammu-misc.h>
#include "misc.h"
#include "coding/coding.h"
#include "../debug.h"
#include <string.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
Include dependency graph for misc.c:

Go to the source code of this file.

Functions

int RecalcDateTime (struct tm *st, const int year, const int month, const int day, const int hour, const int minute, const int second)
 
int RecalcDate (struct tm *st, const int year, const int month, const int day)
 
int GetDayOfYear (unsigned int year, unsigned int month, unsigned int day)
 
int GetWeekOfMonth (unsigned int year, unsigned int month, unsigned int day)
 
int GetDayOfWeek (unsigned int year, unsigned int month, unsigned int day)
 
char * DayOfWeek (unsigned int year, unsigned int month, unsigned int day)
 
int GSM_GetLocalTimezoneOffset ()
 
void GSM_DateTimeToTimestamp (GSM_DateTime *Date, char *str)
 
void GSM_DateTimeFromTimestamp (GSM_DateTime *Date, const char *str)
 
void Fill_GSM_DateTime (GSM_DateTime *Date, time_t timet)
 
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 GetTimeDifference (unsigned long diff, GSM_DateTime *DT, gboolean Plus, int multi)
 
char * OSDateTime (GSM_DateTime dt, gboolean TimeZone)
 
char * OSDate (GSM_DateTime dt)
 
gboolean CheckDate (GSM_DateTime *date)
 
gboolean CheckTime (GSM_DateTime *date)
 
size_t GetLine (FILE *File, char *Line, int count)
 
void InitLines (GSM_CutLines *lines)
 
void FreeLines (GSM_CutLines *lines)
 
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)
 
const char * GetLineStringPos (const char *message, const GSM_CutLines *lines, int start)
 
const char * GetLineString (const char *message, GSM_CutLines *lines, int start)
 
int GetLineLength (const char *message UNUSED, const GSM_CutLines *lines, int start)
 
void CopyLineString (char *dest, const char *src, const GSM_CutLines *lines, int start)
 
const char * GetOS (void)
 
const char * GetCompiler (void)
 
gboolean GSM_IsNewerVersion (const char *latest_version, const char *current_version)
 
void StripSpaces (char *buff)
 

Function Documentation

§ CopyLineString()

void CopyLineString ( char *  dest,
const char *  src,
const GSM_CutLines lines,
int  start 
)

Copies line to variable.

Definition at line 522 of file misc.c.

References GetLineLength(), and GetLineStringPos().

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 }
int GetLineLength(const char *message UNUSED, const GSM_CutLines *lines, int start)
Definition: misc.c:517
const char * GetLineStringPos(const char *message, const GSM_CutLines *lines, int start)
Definition: misc.c:483

§ FreeLines()

void FreeLines ( GSM_CutLines lines)

Frees line cut structure.

Definition at line 392 of file misc.c.

References GSM_CutLines::allocated, GSM_CutLines::numbers, and GSM_CutLines::retval.

Referenced by NOKIA_EncodeDateTime().

393 {
394  free(lines->numbers);
395  lines->numbers = NULL;
396  lines->allocated = 0;
397  free(lines->retval);
398  lines->retval = NULL;
399 }
size_t * numbers
Definition: misc.h:38
size_t allocated
Definition: misc.h:42
char * retval
Definition: misc.h:46

§ GetCompiler()

const char* GetCompiler ( void  )

Gets compiler which was used to compile Gammu library.

Definition at line 659 of file misc.c.

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 }

§ GetLine()

size_t GetLine ( FILE *  File,
char *  Line,
int  count 
)

Reads single line from file.

Parameters
FileFile descriptor to read from.
LineBuffer where t ostore result.
countMaximal length of text which can be stored in buffer.
Returns
Length of read line, -1 on error.

Definition at line 370 of file misc.c.

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 }

§ GetLineLength()

int GetLineLength ( const char *message  UNUSED,
const GSM_CutLines lines,
int  start 
)

Definition at line 517 of file misc.c.

References GSM_CutLines::numbers.

Referenced by CopyLineString(), and GetLineString().

518 {
519  return lines->numbers[start*2-2+1] - lines->numbers[start*2-2];
520 }
size_t * numbers
Definition: misc.h:38

§ GetLineString()

const char* GetLineString ( const char *  message,
GSM_CutLines lines,
int  start 
)

Returns pointer to static buffer containing line.

Parameters
messageParsed message.
linesParsed lines information.
startWhich line we want.

Definition at line 492 of file misc.c.

References dbgprintf, GetLineLength(), GetLineStringPos(), and GSM_CutLines::retval.

Referenced by NOKIA_EncodeDateTime().

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 }
int GetLineLength(const char *message UNUSED, const GSM_CutLines *lines, int start)
Definition: misc.c:517
const char * GetLineStringPos(const char *message, const GSM_CutLines *lines, int start)
Definition: misc.c:483
#define dbgprintf
Definition: debug.h:72
char * retval
Definition: misc.h:46

§ GetLineStringPos()

const char* GetLineStringPos ( const char *  message,
const GSM_CutLines lines,
int  start 
)

Definition at line 483 of file misc.c.

References GSM_CutLines::numbers.

Referenced by CopyLineString(), and GetLineString().

484 {
485  if (message == NULL) {
486  return NULL;
487  }
488 
489  return message + lines->numbers[start * 2 - 2];
490 }
size_t * numbers
Definition: misc.h:38

§ GetOS()

const char* GetOS ( void  )

Gets host OS.

Definition at line 537 of file misc.c.

References FALSE, and TRUE.

Referenced by GSM_InitConnection_Log().

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 }
int gboolean
Definition: gammu-types.h:23
#define FALSE
Definition: gammu-types.h:25
#define TRUE
Definition: gammu-types.h:28

§ GetTimeDifference()

void GetTimeDifference ( unsigned long  diff,
GSM_DateTime DT,
gboolean  Plus,
int  multi 
)

Definition at line 247 of file misc.c.

References GSM_DateTime::Day, dbgprintf, Fill_GSM_DateTime(), Fill_Time_T(), GSM_DateTime::Hour, GSM_DateTime::Minute, GSM_DateTime::Month, GSM_DateTime::Second, and GSM_DateTime::Year.

Referenced by GSM_GetCalendarRecurranceRepeat(), and NOKIA_EncodeDateTime().

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 }
void Fill_GSM_DateTime(GSM_DateTime *Date, time_t timet)
Definition: misc.c:170
#define dbgprintf
Definition: debug.h:72
time_t Fill_Time_T(GSM_DateTime DT)
Definition: misc.c:189

§ GSM_AddTime()

GSM_DateTime GSM_AddTime ( GSM_DateTime  DT,
GSM_DeltaTime  delta 
)

Definition at line 223 of file misc.c.

References GSM_DateTime::Day, GSM_DeltaTime::Day, Fill_GSM_DateTime(), GSM_DateTime::Hour, GSM_DeltaTime::Hour, GSM_DateTime::Minute, GSM_DeltaTime::Minute, GSM_DateTime::Month, GSM_DateTime::Second, GSM_DeltaTime::Second, and GSM_DateTime::Year.

Referenced by GSM_Calendar_AdjustDate(), GSM_DecodeVCALENDAR_VTODO(), and GSM_ToDo_AdjustDate().

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 }
void Fill_GSM_DateTime(GSM_DateTime *Date, time_t timet)
Definition: misc.c:170

§ GSM_IsNewerVersion()

gboolean GSM_IsNewerVersion ( const char *  latest_version,
const char *  current_version 
)

Returns TRUE if firmware version is newer.

Parameters
latest_versionString containing version (eg. latest available).
current_versionString containing version (eg. current one).
Returns
True if latest_version > current_version.

Definition at line 699 of file misc.c.

References FALSE, and TRUE.

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 }
#define FALSE
Definition: gammu-types.h:25
#define TRUE
Definition: gammu-types.h:28

§ InitLines()

void InitLines ( GSM_CutLines lines)

Initializes line cut structure.

Definition at line 385 of file misc.c.

References GSM_CutLines::allocated, GSM_CutLines::numbers, and GSM_CutLines::retval.

Referenced by NOKIA_EncodeDateTime().

386 {
387  lines->numbers = NULL;
388  lines->allocated = 0;
389  lines->retval = NULL;
390 }
size_t * numbers
Definition: misc.h:38
size_t allocated
Definition: misc.h:42
char * retval
Definition: misc.h:46

§ RecalcDate()

int RecalcDate ( struct tm *  st,
const int  year,
const int  month,
const int  day 
)

Recalculates struct tm content.

Definition at line 84 of file misc.c.

References RecalcDateTime().

Referenced by GetDayOfWeek(), GetDayOfYear(), and GetWeekOfMonth().

85 {
86  return RecalcDateTime(st, year, month, day, 0, 0, 0);
87 }
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

§ RecalcDateTime()

int RecalcDateTime ( struct tm *  st,
const int  year,
const int  month,
const int  day,
const int  hour,
const int  minute,
const int  second 
)

Recalculates struct tm content. We can not use mktime directly, as it works only for dates > 1970. Day of week calculation is nased on article in Polish PC-Kurier 8/1998 page 104.

See also
http://www.pckurier.pl

Definition at line 38 of file misc.c.

References CheckDate(), CheckTime(), GSM_DateTime::Day, GSM_DateTime::Hour, GSM_DateTime::Minute, GSM_DateTime::Month, GSM_DateTime::Second, GSM_DateTime::Timezone, and GSM_DateTime::Year.

Referenced by OSDateTime(), and RecalcDate().

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 }
gboolean CheckTime(GSM_DateTime *date)
Definition: misc.c:363
gboolean CheckDate(GSM_DateTime *date)
Definition: misc.c:349

§ SplitLines()

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 
)

Calculates string cut points to split it to lines.

Definition at line 401 of file misc.c.

References GSM_CutLines::allocated, FALSE, GSM_CutLines::numbers, and TRUE.

Referenced by NOKIA_EncodeDateTime().

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 }
size_t * numbers
Definition: misc.h:38
size_t allocated
Definition: misc.h:42
int gboolean
Definition: gammu-types.h:23
#define FALSE
Definition: gammu-types.h:25
#define TRUE
Definition: gammu-types.h:28

§ StripSpaces()

void StripSpaces ( char *  buff)

Strips spaces from string.

Parameters
[in,out]buffString where to strip buffers.

Definition at line 713 of file misc.c.

Referenced by GSM_InitConnection_Log().

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 }