summaryrefslogtreecommitdiff
path: root/libgps.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2009-02-25 10:48:40 +0000
committerEric S. Raymond <esr@thyrsus.com>2009-02-25 10:48:40 +0000
commitf5fbcdfd3ccea470bd498522b80ac5c80212d112 (patch)
treea90da5465339c5ea6504810a92f070d06cf9fb97 /libgps.c
parentfc92942f6445f023f2fda73e75019478ddeab104 (diff)
downloadgpsd-f5fbcdfd3ccea470bd498522b80ac5c80212d112.tar.gz
Standardized parsing of server:port:device client arguments.
Diffstat (limited to 'libgps.c')
-rw-r--r--libgps.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/libgps.c b/libgps.c
index c1508ebe..ba41b1f2 100644
--- a/libgps.c
+++ b/libgps.c
@@ -618,6 +618,38 @@ int gps_del_callback(struct gps_data_t *gpsdata, pthread_t *handler)
}
#endif /* HAVE_LIBPTHREAD */
+
+void gpsd_source_spec(const char *arg, struct fixsource_t *source)
+/* standard parsing of a GPS data source spec */
+{
+ source->server = "127.0.0.1";
+ source->port = DEFAULT_GPSD_PORT;
+ source->device = NULL;
+
+ if (arg != NULL) {
+ char *colon1;
+ source->spec = strdup(arg);
+ colon1 = strchr(source->spec, ':');
+
+ if (colon1 != NULL) {
+ char *colon2;
+ *colon1 = '\0';
+ if (colon1 != source->spec)
+ source->server = source->spec;
+ source->port = colon1 + 1;
+ colon2 = strchr(source->port, ':');
+ if (colon2 != NULL) {
+ *colon2 = '\0';
+ source->device = colon2 + 1;
+ }
+ } else if (strchr(source->spec, '/') != NULL) {
+ source->device = source->spec;
+ } else {
+ source->server = source->spec;
+ }
+ }
+}
+
#ifdef TESTMAIN
/*
* A simple command-line exerciser for the library.