summaryrefslogtreecommitdiffstats
path: root/parse-xml.c
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2013-10-05 00:29:09 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-10-06 10:41:44 -0700
commit4b12f28ca453b038fdeca8e6ada106e0c157296b (patch)
treeae6c72da921baf80870ea57a5ec4ea9126fe201c /parse-xml.c
parent3e0ecb5ff6a95e1be8f22359048e4dfa85d165bc (diff)
downloadsubsurface-4b12f28ca453b038fdeca8e6ada106e0c157296b.tar.gz
First steps towards removing glib dependencies
- remove the build flags and libraries from the Makefile / Configure.mk - remove the glib types (gboolean, gchar, gint64, gint) - comment out / hack around gettext - replace the glib file helper functions - replace g_ascii_strtod - replace g_build_filename - use environment variables instead of g_get_home_dir() & g_get_user_name() - comment out GPS string parsing (uses glib utf8 macros) This needs massive cleanup, but it's a snapshot of what I have right now, in case people want to look at it. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'parse-xml.c')
-rw-r--r--parse-xml.c119
1 files changed, 108 insertions, 11 deletions
diff --git a/parse-xml.c b/parse-xml.c
index 66246570f..0ed3d11bd 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -11,7 +11,12 @@
#include <libxml/parserInternals.h>
#include <libxml/tree.h>
#include <libxslt/transform.h>
+#if 0
#include <glib/gi18n.h>
+#else /* stupid */
+#define _(arg) arg
+#define N_(arg) arg
+#endif
#include<sqlite3.h>
#include "dive.h"
@@ -129,7 +134,7 @@ struct {
const char *nickname, *serial_nr, *firmware;
} dc;
} cur_settings;
-static gboolean in_settings = FALSE;
+static bool in_settings = FALSE;
static struct tm cur_tm;
static int cur_cylinder_index, cur_ws_index;
static int lastndl, laststoptime, laststopdepth, lastcns, lastpo2, lastindeco;
@@ -235,13 +240,101 @@ enum number_type {
FLOAT
};
+double ascii_strtod(char *str, char **ptr)
+{
+ char *p;
+
+ if (ptr == (char **)0)
+ return atof (str);
+
+ p = str;
+
+ while (isspace (*p))
+ ++p;
+
+ if (*p == '+' || *p == '-')
+ ++p;
+
+ /* INF or INFINITY. */
+ if ((p[0] == 'i' || p[0] == 'I')
+ && (p[1] == 'n' || p[1] == 'N')
+ && (p[2] == 'f' || p[2] == 'F'))
+ {
+ if ((p[3] == 'i' || p[3] == 'I')
+ && (p[4] == 'n' || p[4] == 'N')
+ && (p[5] == 'i' || p[5] == 'I')
+ && (p[6] == 't' || p[6] == 'T')
+ && (p[7] == 'y' || p[7] == 'Y'))
+ {
+ *ptr = p + 7;
+ return atof (str);
+ }
+ else
+ {
+ *ptr = p + 3;
+ return atof (str);
+ }
+ }
+
+ /* NAN or NAN(foo). */
+ if ((p[0] == 'n' || p[0] == 'N')
+ && (p[1] == 'a' || p[1] == 'A')
+ && (p[2] == 'n' || p[2] == 'N'))
+ {
+ p += 3;
+ if (*p == '(')
+ {
+ ++p;
+ while (*p != '\0' && *p != ')')
+ ++p;
+ if (*p == ')')
+ ++p;
+ }
+ *ptr = p;
+ return atof (str);
+ }
+
+ /* digits, with 0 or 1 periods in it. */
+ if (isdigit (*p) || *p == '.')
+ {
+ int got_dot = 0;
+ while (isdigit (*p) || (!got_dot && *p == '.'))
+ {
+ if (*p == '.')
+ got_dot = 1;
+ ++p;
+ }
+
+ /* Exponent. */
+ if (*p == 'e' || *p == 'E')
+ {
+ int i;
+ i = 1;
+ if (p[i] == '+' || p[i] == '-')
+ ++i;
+ if (isdigit (p[i]))
+ {
+ while (isdigit (p[i]))
+ ++i;
+ *ptr = p + i;
+ return atof (str);
+ }
+ }
+ *ptr = p;
+ return atof (str);
+ }
+ /* Didn't find any digits. Doesn't look like a number. */
+ *ptr = str;
+ return 0.0;
+}
+
static enum number_type parse_float(char *buffer, double *res, char **endp)
{
double val;
- static gboolean first_time = TRUE;
+ static bool first_time = TRUE;
errno = 0;
- val = g_ascii_strtod(buffer, endp);
+ val = ascii_strtod(buffer, endp);
if (errno || *endp == buffer)
return NEITHER;
if (**endp == ',') {
@@ -255,7 +348,7 @@ static enum number_type parse_float(char *buffer, double *res, char **endp)
}
/* Try again */
**endp = '.';
- val = g_ascii_strtod(buffer, endp);
+ val = ascii_strtod(buffer, endp);
}
}
@@ -436,7 +529,7 @@ static void percent(char *buffer, void *_fraction)
case FLOAT:
/* Turn fractions into percent unless explicit.. */
if (val <= 1.0) {
- while (g_ascii_isspace(*end))
+ while (isspace(*end))
end++;
if (*end != '%')
val *= 100;
@@ -487,10 +580,10 @@ static void utf8_string(char *buffer, void *_res)
{
int size;
char *res;
- while (g_ascii_isspace(*buffer))
+ while (isspace(*buffer))
buffer++;
size = strlen(buffer);
- while (size && g_ascii_isspace(buffer[size-1]))
+ while (size && isspace(buffer[size-1]))
size--;
if (!size)
return;
@@ -521,7 +614,7 @@ static void get_rating(char *buffer, void *_i)
static void double_to_permil(char *buffer, void *_i)
{
int *i = _i;
- *i = g_ascii_strtod(buffer, NULL) * 1000.0 + 0.5;
+ *i = ascii_strtod(buffer, NULL) * 1000.0 + 0.5;
}
static void hex_value(char *buffer, void *_i)
@@ -976,7 +1069,7 @@ static degrees_t parse_degrees(char *buf, char **end)
int sign = 1, decimals = 6, value = 0;
degrees_t ret;
- while (g_ascii_isspace(*buf))
+ while (isspace(*buf))
buf++;
switch (*buf) {
case '-':
@@ -1181,7 +1274,7 @@ static void try_to_fill_trip(dive_trip_t **dive_trip_p, const char *name, char *
* to make a dive valid, but if it has no location, no date and no
* samples I'm pretty sure it's useless.
*/
-static gboolean is_dive(void)
+static bool is_dive(void)
{
return (cur_dive &&
(cur_dive->location || cur_dive->when || cur_dive->dc.samples));
@@ -1863,7 +1956,11 @@ static xsltStylesheetPtr try_get_stylesheet(const char *path, int len, const cha
return NULL;
memcpy(filename, path, len);
- filename[len] = G_DIR_SEPARATOR;
+#ifdef WIN32
+ filename[len] = '\\';
+#else
+ filename[len] = '/';
+#endif
memcpy(filename + len + 1, name, namelen+1);
ret = NULL;