summaryrefslogtreecommitdiff
path: root/xgpsspeed.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2005-01-03 16:23:24 +0000
committerEric S. Raymond <esr@thyrsus.com>2005-01-03 16:23:24 +0000
commit693df1b6a6c838074eef2c94f2552ab7de018419 (patch)
tree89c5ddef17e655d87a33e59d485c39b2f78d24f8 /xgpsspeed.c
parent05fcee1c373954095a7be95756bd92c7d7105255 (diff)
downloadgpsd-693df1b6a6c838074eef2c94f2552ab7de018419.tar.gz
James Cameron's --unit patch.
Diffstat (limited to 'xgpsspeed.c')
-rw-r--r--xgpsspeed.c35
1 files changed, 30 insertions, 5 deletions
diff --git a/xgpsspeed.c b/xgpsspeed.c
index 2031d68b..532748ed 100644
--- a/xgpsspeed.c
+++ b/xgpsspeed.c
@@ -9,6 +9,7 @@
#include <X11/Shell.h>
#include <X11/Xaw/Label.h>
#include <X11/Xaw/Paned.h>
+#include <Xm/XmStrDefs.h>
#include <Tachometer.h>
#include "xgpsspeed.icon"
@@ -19,12 +20,14 @@ static XrmOptionDescRec options[] = {
{"-rv", "*reverseVideo", XrmoptionNoArg, "TRUE"},
{"-nc", "*needleColor", XrmoptionSepArg, NULL},
{"-needlecolor","*needleColor", XrmoptionSepArg, NULL},
+{"--units", "*units", XrmoptionSepArg, NULL},
};
String fallback_resources[] = {NULL};
static struct gps_data_t *gpsdata;
static Widget tacho;
-static double speedfactor = KNOTS_TO_MPH;
+static double speedfactor;
+static Widget toplevel;
static void update_display(char *buf UNUSED)
{
@@ -37,27 +40,49 @@ static void handle_input(XtPointer client_data UNUSED,
gps_poll(gpsdata);
}
+static char *get_resource(char *name, char *default_value)
+{
+ XtResource xtr;
+ char *value = NULL;
+
+ xtr.resource_name = name;
+ xtr.resource_class = "AnyClass";
+ xtr.resource_type = XmRString;
+ xtr.resource_size = sizeof(String);
+ xtr.resource_offset = 0;
+ xtr.default_type = XmRImmediate;
+ xtr.default_addr = default_value;
+ XtGetApplicationResources(toplevel, &value, &xtr, 1, NULL, 0);
+ if (value) return value;
+ return default_value;
+}
+
int main(int argc, char **argv)
{
Arg args[10];
XtAppContext app;
int option;
- char *colon, *server = NULL, *port = DEFAULT_GPSD_PORT;
- Widget toplevel, base;
+ char *colon, *server = NULL, *port = DEFAULT_GPSD_PORT, *units;
+ Widget base;
toplevel = XtVaAppInitialize(&app, "xpsspeed.ad",
options, XtNumber(options),
&argc, argv, fallback_resources, NULL);
+
+ speedfactor = KNOTS_TO_MPH;
+ units = get_resource("units", "mph");
+ if (!strcmp(units, "kph")) speedfactor = KNOTS_TO_KPH;
+
while ((option = getopt(argc, argv, "?hkv")) != -1) {
switch (option) {
case 'k':
- speedfactor = KNOTS_TO_KMPH;
+ speedfactor = KNOTS_TO_KPH;
break;
case 'v':
printf("xgpsspeed %s\n", VERSION);
exit(0);
case 'h': case '?': default:
- fputs("usage: gps [-?] [-h] [-v] [-rv] [-nc] [-needlecolor] [server[:port]]\n", stderr);
+ fputs("usage: gps [-?] [-h] [-v] [-rv] [-nc] [-needlecolor] [--units {kph,mph}] [server[:port]]\n", stderr);
exit(1);
}
}