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.
26 strtoupper(char *dest, const char *src)
29 *dest++=toupper(*src++);
34 strtolower(char *dest, const char *src)
37 *dest++=tolower(*src++);
43 hash_callback(gpointer key, gpointer value, gpointer user_data)
46 *l=g_list_prepend(*l, value);
50 g_hash_to_list(GHashTable *h)
53 g_hash_table_foreach(h, hash_callback, &ret);
59 g_strconcat_printf(gchar *buffer, gchar *fmt, ...)
65 str=g_strdup_vprintf(fmt, ap);
69 ret=g_strconcat(buffer, str, NULL);
76 int g_utf8_strlen_force_link(gchar *buffer, int max);
78 g_utf8_strlen_force_link(gchar *buffer, int max)
80 return g_utf8_strlen(buffer, max);
84 #if defined(_WIN32) || defined(__CEGCC__)
87 char *stristr(const char *String, const char *Pattern)
89 char *pptr, *sptr, *start;
91 for (start = (char *)String; *start != (int)NULL; start++)
93 /* find start of pattern in string */
94 for ( ; ((*start!=(int)NULL) && (toupper(*start) != toupper(*Pattern))); start++)
96 if ((int)NULL == *start)
99 pptr = (char *)Pattern;
100 sptr = (char *)start;
102 while (toupper(*sptr) == toupper(*pptr))
107 /* if end of pattern then pattern was found */
109 if ((int)NULL == *pptr)
117 # define SIZE_MAX ((size_t) -1)
120 # define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
124 # define flockfile(x) ((void) 0)
126 #if !HAVE_FUNLOCKFILE
128 # define funlockfile(x) ((void) 0)
131 /* Some systems, like OSF/1 4.0 and Woe32, don't have EOVERFLOW. */
133 # define EOVERFLOW E2BIG
136 /* Read up to (and including) a DELIMITER from FP into *LINEPTR (and
137 NUL-terminate it). *LINEPTR is a pointer returned from malloc (or
138 NULL), pointing to *N characters of space. It is realloc'ed as
139 necessary. Returns the number of characters read (not including
140 the null terminator), or -1 on error or EOF. */
143 getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
148 if (lineptr == NULL || n == NULL || fp == NULL)
155 if (*lineptr == NULL || *n == 0)
158 *lineptr = (char *) realloc (*lineptr, *n);
159 if (*lineptr == NULL)
177 /* Make enough space for len+1 (for final NUL) bytes. */
178 if (cur_len + 1 >= *n)
181 SSIZE_MAX < SIZE_MAX ? (size_t) SSIZE_MAX + 1 : SIZE_MAX;
182 size_t needed = 2 * *n + 1; /* Be generous. */
185 if (needed_max < needed)
187 if (cur_len + 1 >= needed)
193 new_lineptr = (char *) realloc (*lineptr, needed);
194 if (new_lineptr == NULL)
200 *lineptr = new_lineptr;
204 (*lineptr)[cur_len] = i;
210 (*lineptr)[cur_len] = '\0';
211 result = cur_len ? cur_len : result;
214 funlockfile (fp); /* doesn't set errno */
220 getline (char **lineptr, size_t *n, FILE *stream)
222 return getdelim (lineptr, n, '\n', stream);
225 #if defined(_UNICODE)
226 wchar_t* newSysString(const char *toconvert)
228 int newstrlen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, toconvert, -1, 0, 0);
229 wchar_t *newstring = g_new(wchar_t,newstrlen);
230 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, toconvert, -1, newstring, newstrlen) ;
234 char * newSysString(const char *toconvert)
236 return g_strdup(toconvert);