> Remember, I wrote, that WinCE might not support UNC pathnames?
> Just tested this. It *doesn't*!
Gross.
What if we instead do something like the attached patch? Then instead of
sprinkling this horror elsewhere around the code, we at least have one
central place to mess with it and the ability (currently unused) to have
one place that tests "does this string look like a serial port name" ala
isatty().
This also gives you one place - already inside a windows specific block
- to do whatever you have to do for wince even if it's just 'return
comname';
If we agree this is a reasonable approach, I'll remove the excessively
commented out code and commit it today.
RJL
Index: gbser.h
===================================================================
RCS file: /cvsroot/gpsbabel/gpsbabel/gbser.h,v
retrieving revision 1.1
diff -p -u -r1.1 gbser.h
--- gbser.h 22 May 2006 16:10:54 -0000 1.1
+++ gbser.h 20 Jun 2006 17:35:36 -0000
@@ -23,3 +23,7 @@ void *gbser_init(const char *name);
void gbser_deinit (void *);
int gbser_read(void *handle, char *ibuf, int sz);
int gbser_setspeed(void *handle, unsigned speed);
+
+#if __WIN32__
+char * fix_win_serial_name(const char *comname);
+#endif
Index: gbser_win.c
===================================================================
RCS file: /cvsroot/gpsbabel/gpsbabel/gbser_win.c,v
retrieving revision 1.2
diff -p -u -r1.2 gbser_win.c
--- gbser_win.c 21 May 2006 21:04:41 -0000 1.2
+++ gbser_win.c 20 Jun 2006 17:35:36 -0000
@@ -36,16 +36,17 @@ gbser_init(const char *portname)
// DCB tio;
COMMTIMEOUTS timeout;
HANDLE comport;
- char *xname= xstrdup("\\\\.\\\\");
+// char *xname= xstrdup("\\\\.\\\\");
+ char *xname = fix_win_serial_name(portname);
gbser_win_handle* handle = xcalloc(1, sizeof(*handle));;
- /* Amazingly, windows will fail the open below unless we
- * prepend \\.\ to the name. It also then fails the open
- * unless we strip the colon from the name. Aaaaargh!
- */
- xname = xstrappend(xname, portname);
- if (xname[strlen(xname)-1] == ':')
- xname[strlen(xname)-1] = 0;
+// /* Amazingly, windows will fail the open below unless we
+// * prepend \\.\ to the name. It also then fails the open
+// * unless we strip the colon from the name. Aaaaargh!
+// */
+// xname = xstrappend(xname, portname);
+// if (xname[strlen(xname)-1] == ':')
+// xname[strlen(xname)-1] = 0;
// xCloseHandle(comport);
comport = CreateFile(xname, GENERIC_READ|GENERIC_WRITE,
@@ -176,3 +177,36 @@ gbser_deinit(void *handle)
gbser_win_handle *h = (gbser_win_handle *) handle;
xfree(h);
}
+
+
+
+
+/*
+ * This isn't part of the above abstraction; it's just a helper for
+ * the other serial modules in the tree.
+ *
+ * Windows does a weird thing with serial ports.
+ * COM ports 1 - 9 are "COM1:" through "COM9:"
+ * The one after that is \\.\\com10 - this function tries to plaster over
+ * that.
+ * It returns a pointer to a staticly allocated buffer and is therefore not
+ * thread safe. The buffer pointed to remains valid only until the next
+ * call to this function.
+ */
+static char gb_com_buffer[100];
+
+char *
+fix_win_serial_name(const char *comname)
+{
+ /* If in the form 'COMx:', use it in place */
+ if ((strlen(comname) == 5) && (comname[4] == ':')) {
+ strcpy(gb_com_buffer, comname);
+ } else {
+ snprintf(gb_com_buffer, sizeof(gb_com_buffer),
+ "\\\\.\\\\%s", comname);
+ if (gb_com_buffer[strlen(gb_com_buffer) - 1 ] == ':') {
+ gb_com_buffer[strlen(gb_com_buffer) - 1] = 0;
+ }
+ }
+ return gb_com_buffer;
+}
Index: magproto.c
===================================================================
RCS file: /cvsroot/gpsbabel/gpsbabel/magproto.c,v
retrieving revision 1.125
diff -p -u -r1.125 magproto.c
--- magproto.c 19 Jun 2006 21:15:29 -0000 1.125
+++ magproto.c 20 Jun 2006 17:35:36 -0000
@@ -525,14 +525,15 @@ int
terminit(const char *portname, int create_ok)
{
DCB tio;
- char *xname = xstrdup("\\\\.\\\\");
+// char *xname = xstrdup("\\\\.\\\\");
+ char *xname = fix_win_serial_name(portname);
COMMTIMEOUTS timeout;
is_file = 0;
- xname = xstrappend(xname, portname);
- if (xname[strlen(xname)-1] == ':')
- xname[strlen(xname)-1] = 0;
+// xname = xstrappend(xname, portname);
+// if (xname[strlen(xname)-1] == ':')
+// xname[strlen(xname)-1] = 0;
xCloseHandle(comport);
Index: util.c
===================================================================
RCS file: /cvsroot/gpsbabel/gpsbabel/util.c,v
retrieving revision 1.94
diff -p -u -r1.94 util.c
--- util.c 19 Jun 2006 20:47:05 -0000 1.94
+++ util.c 20 Jun 2006 17:35:36 -0000
@@ -1423,3 +1423,4 @@ char *xml_attribute( xml_tag *tag, char
}
return result;
}
+
Index: jeeps/gpsserial.c
===================================================================
RCS file: /cvsroot/gpsbabel/gpsbabel/jeeps/gpsserial.c,v
retrieving revision 1.32
diff -p -u -r1.32 gpsserial.c
--- jeeps/gpsserial.c 20 Apr 2006 23:19:27 -0000 1.32
+++ jeeps/gpsserial.c 20 Jun 2006 17:35:36 -0000
@@ -88,14 +88,15 @@ int32 GPS_Serial_On(const char *port, gp
DCB tio;
COMMTIMEOUTS timeout;
HANDLE comport;
+ char *xname = fix_win_serial_name(port);
win_serial_data *wsd = xcalloc(sizeof (win_serial_data), 1);
*dh = (gpsdevh*) wsd;
- comport = CreateFile(port, GENERIC_READ|GENERIC_WRITE, 0, NULL,
+ comport = CreateFile(xname, GENERIC_READ|GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, 0, NULL);
if (comport == INVALID_HANDLE_VALUE) {
- GPS_Serial_Error("CreateFile on '%s' failed", port);
+ GPS_Serial_Error("CreateFile on '%s' failed", xname);
gps_errno = SERIAL_ERROR;
return 0;
}
|