Wow, that just looks too awful.
Something like this should work I think and limit the changes to the essential :
at the top:
static struct gps_data_t* gdata = NULL;
#if GPSD_API_MAJOR_VERSION >= 5
static struct gps_data_t _gdata;
#endif
and for the init :
#if GPSD_API_MAJOR_VERSION >= 5
gdata = gps_open(g.gpsd_host, g.gpsd_port);
#else
if (gps_open(g.gpsd_host, g.gpsd_port, &_gdata) == -1)
gdata = NULL
else
gdata = &_gdata;
#endif;
I don't have any setup to test here tough.
Cheers,
Sylvain