diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2009-02-25 10:48:40 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2009-02-25 10:48:40 +0000 |
commit | f5fbcdfd3ccea470bd498522b80ac5c80212d112 (patch) | |
tree | a90da5465339c5ea6504810a92f070d06cf9fb97 /libgps.c | |
parent | fc92942f6445f023f2fda73e75019478ddeab104 (diff) | |
download | gpsd-f5fbcdfd3ccea470bd498522b80ac5c80212d112.tar.gz |
Standardized parsing of server:port:device client arguments.
Diffstat (limited to 'libgps.c')
-rw-r--r-- | libgps.c | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -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. |