summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2009-02-19 12:00:05 +0000
committerEric S. Raymond <esr@thyrsus.com>2009-02-19 12:00:05 +0000
commit50038e3acc531301ebf9372778939100fbbaae71 (patch)
tree01e75bd3cdc936e3a4e20f9db229b7ae96c1a5a8
parent2141d5ae096cdc4572a687a3590ff32d7b380a39 (diff)
downloadgpsd-50038e3acc531301ebf9372778939100fbbaae71.tar.gz
Make command parsing a bit more forgiving.
-rw-r--r--gpsmon.c50
1 files changed, 37 insertions, 13 deletions
diff --git a/gpsmon.c b/gpsmon.c
index 3fe1792d..0e30f549 100644
--- a/gpsmon.c
+++ b/gpsmon.c
@@ -501,12 +501,13 @@ int main (int argc, char **argv)
continue;
/*@ +usedef +compdef @*/
- p = line;
-
- while (*p != '\0' && !isspace(*p))
- p++;
- while (*p != '\0' && isspace(*p))
- p++;
+ arg = line;
+ if (isspace(line[1])) {
+ for (arg = line+2; *arg != '\0' && isspace(*arg); arg++)
+ arg++;
+ arg++;
+ } else
+ arg = line + 1;
if (active != NULL && (*active)->command != NULL) {
status = (*active)->command(line);
@@ -521,15 +522,15 @@ int main (int argc, char **argv)
case 'c': /* send control packet */
len = 0;
/*@ -compdef @*/
- while (*p != '\0')
+ while (*arg != '\0')
{
- (void)sscanf(p,"%x",&v);
+ (void)sscanf(arg,"%x",&v);
putbyte(buf, len, v);
len++;
- while (*p != '\0' && !isspace(*p))
- p++;
- while (*p != '\0' && isspace(*p))
- p++;
+ while (*arg != '\0' && !isspace(*arg))
+ arg++;
+ while (*arg != '\0' && isspace(*arg))
+ arg++;
}
if (active == NULL)
monitor_complain("No device defined yet");
@@ -606,7 +607,7 @@ int main (int argc, char **argv)
if (active == NULL)
monitor_complain("No device defined yet");
else if (serial) {
- v = (unsigned)atoi(line+1);
+ v = (unsigned)atoi(arg);
/* Ugh...should have a controlfd slot
* in the session structure, really
*/
@@ -638,6 +639,29 @@ int main (int argc, char **argv)
}
break;
+#if 0
+ case 't': /* force device type */
+ if (strlen(arg) > 0) {
+ int matchcount = 0;
+ const struct gps_type_t **dp, *forcetype = NULL;
+ for (dp = gpsd_drivers; *dp; dp++) {
+ if (strstr((*dp)->type_name, line) != NULL) {
+ forcetype = *dp;
+ matchcount++;
+ }
+ }
+ if (matchcount == 0) {
+ monitor_complain("No type name matches.");
+ } else if (matchcount == 1) {
+ assert(forcetype != NULL);
+ gpsd_switch_driver(&session, forcetype->type_name);
+ } else {
+ monitor_complain("Multiple driver type names match.");
+ }
+ }
+ break;
+#endif
+
default:
monitor_complain("Unknown command");
break;