From: Linus Torvalds Date: Wed, 2 May 2012 16:36:55 +0000 (-0700) Subject: Make subsurface compile with current libdivecomputer git tree X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=2d1a316d848441a7d1137cb51b1ee0b8222aaa74;p=ext%2Fsubsurface.git Make subsurface compile with current libdivecomputer git tree libdivecomputer has the absolute worst interfaces to any library *ever*, and randomly changes those crappy interfaces when it adds support for new dive computers. It would have been much better if the interface was just a "open this device" with a device descriptor structure pointer, so that when Jef adds support for new devices, the old descriptors still stay around and work the same way - there's just a new descriptor structure that you *can* use if you want. Along with a data structure to name the devices and their descriptors, this would actually mean that users could just support pretty much any random device that LD supports. But no, that's not how libdivecomputer works. It has random enums and crazy different ad-hoc interfaces for different dive computers. Or, like in this case, crazy different ad-hoc interfaces for the *same*old* dive computer. Right now, for example, the support for the new Heinrichs Weikamp "Frog" computer added a flag to the interface for the old OSTC_2 support. Breaking any libdivecomputer users even if you didn't need Frog support. And is there a version number in the header files to check for? Yes, there's a version number. But no, it's not useful, since it doesn't actually change with the interface changes. This time, Jef actually did change the version number (from 0.1.0 to 0.2.0) as part of new development version, but there's no reason to believe that it will change in the future as the interfaces change - it never has before. So it's actually safer - and easier to understand - to check for the existence of the new header file inclusion mechanism. A new version of libdivecomputer that supports the HW Frog computer will include the "ostc_frog.h" header file when you include the libdivecomputer device.h file, and that will result in HW_FROG_H being defined. So we can check whether libdivecomputer has the new interface and supports the Frog by doing an "#ifdef HW_FROG_H" hack. Ugh. Signed-off-by: Linus Torvalds --- diff --git a/libdivecomputer.c b/libdivecomputer.c index bf912f0..14f794e 100644 --- a/libdivecomputer.c +++ b/libdivecomputer.c @@ -10,6 +10,14 @@ #include "libdivecomputer.h" +/* Christ. Libdivecomputer has the worst configuration system ever. */ +#ifdef HW_FROG_H + #define NOT_FROG , 0 + #define LIBDIVECOMPUTER_SUPPORTS_FROG +#else + #define NOT_FROG +#endif + static void error(const char *fmt, ...) { va_list args; @@ -78,7 +86,12 @@ static parser_status_t create_parser(device_data_t *devdata, parser_t **parser) return mares_iconhd_parser_create(parser, devdata->devinfo.model); case DEVICE_TYPE_HW_OSTC: - return hw_ostc_parser_create(parser); + return hw_ostc_parser_create(parser NOT_FROG); + +#ifdef LIBDIVECOMPUTER_SUPPORTS_FROG + case DEVICE_TYPE_HW_FROG: + return hw_ostc_parser_create(parser, 1); +#endif case DEVICE_TYPE_CRESSI_EDY: case DEVICE_TYPE_ZEAGLE_N2ITION3: @@ -544,6 +557,9 @@ struct device_list device_list[] = { { "Mares Puck, Nemo Air, Nemo Wide", DEVICE_TYPE_MARES_PUCK }, { "Mares Icon HD", DEVICE_TYPE_MARES_ICONHD }, { "OSTC", DEVICE_TYPE_HW_OSTC }, +#ifdef LIBDIVECOMPUTER_SUPPORTS_FROG + { "OSTC Frog", DEVICE_TYPE_HW_FROG }, +#endif { "Cressi Edy", DEVICE_TYPE_CRESSI_EDY }, { "Zeagle N2iTiON 3", DEVICE_TYPE_ZEAGLE_N2ITION3 }, { "Atomics Cobalt", DEVICE_TYPE_ATOMICS_COBALT },