2 * Navit, a modular navigation system.
3 * Copyright (C) 2005-2008 Navit Team
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * version 2 as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the
16 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
28 strtoupper(char *dest, const char *src)
31 *dest++=toupper(*src++);
36 strtolower(char *dest, const char *src)
39 *dest++=tolower(*src++);
45 hash_callback(gpointer key, gpointer value, gpointer user_data)
48 *l=g_list_prepend(*l, value);
52 g_hash_to_list(GHashTable *h)
55 g_hash_table_foreach(h, hash_callback, &ret);
61 hash_callback_key(gpointer key, gpointer value, gpointer user_data)
64 *l=g_list_prepend(*l, key);
68 g_hash_to_list_keys(GHashTable *h)
71 g_hash_table_foreach(h, hash_callback_key, &ret);
77 g_strconcat_printf(gchar *buffer, gchar *fmt, ...)
83 str=g_strdup_vprintf(fmt, ap);
87 ret=g_strconcat(buffer, str, NULL);
94 int g_utf8_strlen_force_link(gchar *buffer, int max);
96 g_utf8_strlen_force_link(gchar *buffer, int max)
98 return g_utf8_strlen(buffer, max);
102 #if defined(_WIN32) || defined(__CEGCC__)
106 #if defined(_WIN32) || defined(__CEGCC__) || defined (__APPLE__)
108 char *stristr(const char *String, const char *Pattern)
110 char *pptr, *sptr, *start;
112 for (start = (char *)String; *start != (int)NULL; start++)
114 /* find start of pattern in string */
115 for ( ; ((*start!=(int)NULL) && (toupper(*start) != toupper(*Pattern))); start++)
117 if ((int)NULL == *start)
120 pptr = (char *)Pattern;
121 sptr = (char *)start;
123 while (toupper(*sptr) == toupper(*pptr))
128 /* if end of pattern then pattern was found */
130 if ((int)NULL == *pptr)
138 # define SIZE_MAX ((size_t) -1)
141 # define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
145 # define flockfile(x) ((void) 0)
147 #if !HAVE_FUNLOCKFILE
149 # define funlockfile(x) ((void) 0)
152 /* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */
154 # define EOVERFLOW E2BIG
157 /* Read up to (and including) a DELIMITER from FP into *LINEPTR (and
158 NUL-terminate it). *LINEPTR is a pointer returned from malloc (or
159 NULL), pointing to *N characters of space. It is realloc'ed as
160 necessary. Returns the number of characters read (not including
161 the null terminator), or -1 on error or EOF. */
164 getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
169 if (lineptr == NULL || n == NULL || fp == NULL)
176 if (*lineptr == NULL || *n == 0)
179 *lineptr = (char *) realloc (*lineptr, *n);
180 if (*lineptr == NULL)
198 /* Make enough space for len+1 (for final NUL) bytes. */
199 if (cur_len + 1 >= *n)
202 SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;
203 size_t needed = 2 * *n + 1; /* Be generous. */
206 if (needed_max < needed)
208 if (cur_len + 1 >= needed)
214 new_lineptr = (char *) realloc (*lineptr, needed);
215 if (new_lineptr == NULL)
221 *lineptr = new_lineptr;
225 (*lineptr)[cur_len] = i;
231 (*lineptr)[cur_len] = '\0';
232 result = cur_len ? cur_len : result;
235 funlockfile (fp); /* doesn't set errno */
241 getline (char **lineptr, size_t *n, FILE *stream)
243 return getdelim (lineptr, n, '\n', stream);
246 #if defined(_UNICODE)
247 wchar_t* newSysString(const char *toconvert)
249 int newstrlen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, toconvert, -1, 0, 0);
250 wchar_t *newstring = g_new(wchar_t,newstrlen);
251 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, toconvert, -1, newstring, newstrlen) ;
255 char * newSysString(const char *toconvert)
257 return g_strdup(toconvert);
263 iso8601_to_secs(char *iso8601)
265 int a,b,d,val[6],i=0;
266 char *start=iso8601,*pos=iso8601;
267 while (*pos && i < 6) {
268 if (*pos < '0' || *pos > '9') {
269 val[i++]=atoi(start);
284 d=1461*(val[0]+4716)/4+306001*(val[1]+1)/10000+val[2]+b-2442112;
286 return ((d*24+val[3])*60+val[4])*60+val[5];
290 current_to_iso8601(void)
296 g_get_current_time(&time);
297 timep = g_time_val_to_iso8601(&time);
299 #ifdef HAVE_API_WIN32_BASE
302 timep=g_strdup_printf("%d-%02d-%02dT%02d:%02d:%02dZ",ST.wYear,ST.wMonth,ST.wDay,ST.wHour,ST.wMinute,ST.wSecond);
309 strftime(buffer, sizeof(buffer), "%Y-%m-%dT%TZ", tm);
310 timep=g_strdup(buffer);