Skip to content

Commit

Permalink
remove remaining shadows of cet (GPSBabel#971)
Browse files Browse the repository at this point in the history
* wean garmin_gpi from global_opts.codec and cet.

* wean garmin from global_opts.codec and cet.

* remove cet

* don't include deprecated includes, no global codec.

* fix garmin includes

* fix up comment indicating garmin encoding issues.

* fiddle with encoding functions.

* change get_codec signature.

* trailling white space
  • Loading branch information
tsteven4 authored Jan 6, 2023
1 parent 7b321cd commit 2be4547
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 156 deletions.
2 changes: 0 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ set(JEEPS

# SUPPORT
set(SUPPORT
cet_util.cc
csv_util.cc
fatal.cc
filter_vecs.cc
Expand Down Expand Up @@ -203,7 +202,6 @@ endif()

# HEADERS
set(HEADERS
cet_util.h
csv_util.h
defs.h
dg-100.h
Expand Down
4 changes: 1 addition & 3 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@

#define CSTR(qstr) ((qstr).toUtf8().constData())
#define CSTRc(qstr) ((qstr).toLatin1().constData())
#define STRFROMUNICODE(qstr) (global_opts.codec->fromUnicode(qstr).constData())
#define STRTOUNICODE(cstr) (global_opts.codec->toUnicode(cstr))

/*
* Amazingly, this constant is not specified in the standard...
Expand Down Expand Up @@ -182,7 +180,6 @@ struct global_options {
int smart_icons;
int smart_names;
inifile_t* inifile;
QTextCodec* codec;
};

extern global_options global_opts;
Expand Down Expand Up @@ -1064,6 +1061,7 @@ void gb_setbit(void* buf, uint32_t nr);
void* gb_int2ptr(int i);
int gb_ptr2int(const void* p);

QTextCodec* get_codec(const QByteArray& cs_name);
void list_codecs();
void list_timezones();
QString grapheme_truncate(const QString& input, unsigned int count);
Expand Down
File renamed without changes.
File renamed without changes.
88 changes: 78 additions & 10 deletions garmin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@
#include <QByteArray> // for QByteArray
#include <QChar> // for QChar
#include <QString> // for QString
#include <QTextCodec> // for QTextCodec
#include <QVector> // for QVector
#include <Qt> // for CaseInsensitive
#include <QtGlobal> // for qPrintable, foreach

#include "defs.h"
#include "cet_util.h" // for cet_convert_init, cet_cs_vec_utf8
#include "format.h" // for Format
#include "formspec.h" // for FormatSpecificDataList
#include "garmin_device_xml.h" // for gdx_get_info, gdx_info, gdx_file, gdx_jmp_buf
#include "garmin_fs.h" // for garmin_fs_garmin_after_read, garmin_fs_garmin_before_write
#include "garmin_tables.h" // for gt_find_icon_number_from_desc, PCX, gt_find_desc_from_icon_number
Expand Down Expand Up @@ -78,6 +79,7 @@ static char* baudopt = nullptr;
static int baud = 0;
static int categorybits;
static int receiver_must_upper = 1;
static QTextCodec* codec{nullptr};

static Format* gpx_vec;

Expand Down Expand Up @@ -129,13 +131,17 @@ QVector<arglist_t> garmin_args = {

static const char* d103_symbol_from_icon_number(unsigned int n);
static int d103_icon_number_from_symbol(const QString& s);
static void garmin_fs_garmin_after_read(GPS_PWay way, Waypoint* wpt, int protoid);
static void garmin_fs_garmin_before_write(const Waypoint* wpt, GPS_PWay way, int protoid);

static QByteArray str_from_unicode(const QString& qstr) {return codec->fromUnicode(qstr);}
static QString str_to_unicode(const QByteArray& cstr) {return codec->toUnicode(cstr);}

static void
rw_init(const QString& fname)
{
receiver_must_upper = 1;
const char* receiver_charset = nullptr;
const char* receiver_charset = CET_CHARSET_ASCII;

if (!mkshort_handle) {
mkshort_handle = mkshort_new_handle();
Expand Down Expand Up @@ -335,15 +341,13 @@ rw_init(const QString& fname)

/*
* This used to mean something when we used cet, but these days this
* format either use implicit QString conversions (utf8) which is
* likely a bug, or we have hard coded QString::fromLatin1 or CSTRc.
* So all the above detection of receiver_charset is for naught.
* But perhaps we will use an appropriate codec based on receiver_charset
* someday.
* format either uses implicit QString conversions (utf8),
* or we have hard coded QString::fromLatin1, CSTRc, or CSTR. These
* are likely bugs.
* However, this is still used for garmin_fs_garmin_after_read,
* garmin_fs_garmin_before_write.
*/
if (receiver_charset) {
cet_convert_init(receiver_charset, 1);
}
codec = get_codec(receiver_charset);
}

static void
Expand Down Expand Up @@ -1210,3 +1214,67 @@ d103_icon_number_from_symbol(const QString& s)
}
return 0;
}

static void
garmin_fs_garmin_after_read(const GPS_PWay way, Waypoint* wpt, const int protoid)
{
garmin_fs_t* gmsd = garmin_fs_alloc(protoid);
wpt->fs.FsChainAdd(gmsd);

/* nothing happens until gmsd is allocated some lines above */

/* !!! class needs protocol specific conversion !!! (ToDo)
garmin_fs_t::set_wpt_class(gmsd, way[i]->wpt_class);
*/
/* flagged data fields */
garmin_fs_t::set_display(gmsd, gt_switch_display_mode_value(way->dspl, gps_waypt_type, 1));
if (way->category != 0) {
garmin_fs_t::set_category(gmsd, way->category);
}
if (way->dst < 1.0e25f) {
WAYPT_SET(wpt, proximity, way->dst);
}
if (way->temperature_populated) {
WAYPT_SET(wpt, temperature, way->temperature);
}
if (way->dpth < 1.0e25f) {
WAYPT_SET(wpt, depth, way->dpth);
}
/* will copy until a null character or the end of the fixed length way field is reached, whichever comes first. */
garmin_fs_t::set_cc(gmsd, str_to_unicode(QByteArray(way->cc, qstrnlen(way->cc, sizeof(way->cc)))));
garmin_fs_t::set_city(gmsd, str_to_unicode(QByteArray(way->city, qstrnlen(way->city, sizeof(way->city)))));
garmin_fs_t::set_state(gmsd, str_to_unicode(QByteArray(way->state, qstrnlen(way->state, sizeof(way->state)))));
garmin_fs_t::set_facility(gmsd, str_to_unicode(QByteArray(way->facility, qstrnlen(way->facility, sizeof(way->facility)))));
garmin_fs_t::set_cross_road(gmsd, str_to_unicode(QByteArray(way->cross_road, qstrnlen(way->cross_road, sizeof(way->cross_road)))));
garmin_fs_t::set_addr(gmsd, str_to_unicode(QByteArray(way->addr, qstrnlen(way->addr, sizeof(way->addr)))));
}

static void
garmin_fs_garmin_before_write(const Waypoint* wpt, GPS_PWay way, const int protoid)
{
garmin_fs_t* gmsd = garmin_fs_t::find(wpt);

(void)protoid; // unused for now.

if (gmsd == nullptr) {
return;
}

/* ToDo: protocol specific conversion of class
way[i]->wpt_class = garmin_fs_t::get_wpt_class(gmsd, way[i]->wpt_class);
*/
way->dspl = gt_switch_display_mode_value(
garmin_fs_t::get_display(gmsd, way->dspl), gps_waypt_type, 0);
way->category = garmin_fs_t::get_category(gmsd, way->category);
way->dpth = WAYPT_GET(wpt, depth, way->dpth);
way->dst = WAYPT_GET(wpt, proximity, way->dpth);
way->temperature = WAYPT_GET(wpt, temperature, way->temperature);

/* destination may not be null terminated, but we will fill with nulls if necessary */
strncpy(way->cc, str_from_unicode(garmin_fs_t::get_cc(gmsd, nullptr)).constData(), sizeof(way->cc));
strncpy(way->city, str_from_unicode(garmin_fs_t::get_city(gmsd, nullptr)).constData(), sizeof(way->city));
strncpy(way->state, str_from_unicode(garmin_fs_t::get_state(gmsd, nullptr)).constData(), sizeof(way->state));
strncpy(way->facility, str_from_unicode(garmin_fs_t::get_facility(gmsd, nullptr)).constData(), sizeof(way->facility));
strncpy(way->cross_road, str_from_unicode(garmin_fs_t::get_cross_road(gmsd, nullptr)).constData(), sizeof(way->cross_road));
strncpy(way->addr, str_from_unicode(garmin_fs_t::get_addr(gmsd, nullptr)).constData(), sizeof(way->addr));
}
68 changes: 0 additions & 68 deletions garmin_fs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@
*/

#include <cassert> // for assert
#include <cstdio> // for snprintf, sscanf
#include <cstdlib> // for strtod
#include <cstring> // for strncpy

#include <QByteArray> // for QByteArray
#include <QString> // for QString, QStringLiteral
#include <QXmlStreamWriter> // for QXmlStreamWriter
#include <Qt> // for CaseInsensitive
Expand All @@ -34,7 +31,6 @@
#include "garmin_fs.h"
#include "garmin_tables.h" // for gt_switch_display_mode_value, gt_display_mode_symbol, gt_display_mode_symbol_and_comment, gt_display_mode_symbol_and_name
#include "inifile.h" // for inifile_readstr
#include "jeeps/gps.h" // for gps_waypt_type


#define MYNAME "garmin_fs"
Expand Down Expand Up @@ -320,67 +316,3 @@ garmin_fs_merge_category(const char* category_name, Waypoint* waypt)
garmin_fs_t::set_category(gmsd, cat);
return 1;
}

void
garmin_fs_garmin_after_read(const GPS_PWay way, Waypoint* wpt, const int protoid)
{
garmin_fs_t* gmsd = garmin_fs_alloc(protoid);
wpt->fs.FsChainAdd(gmsd);

/* nothing happens until gmsd is allocated some lines above */

/* !!! class needs protocol specific conversion !!! (ToDo)
garmin_fs_t::set_wpt_class(gmsd, way[i]->wpt_class);
*/
/* flagged data fields */
garmin_fs_t::set_display(gmsd, gt_switch_display_mode_value(way->dspl, gps_waypt_type, 1));
if (way->category != 0) {
garmin_fs_t::set_category(gmsd, way->category);
}
if (way->dst < 1.0e25f) {
WAYPT_SET(wpt, proximity, way->dst);
}
if (way->temperature_populated) {
WAYPT_SET(wpt, temperature, way->temperature);
}
if (way->dpth < 1.0e25f) {
WAYPT_SET(wpt, depth, way->dpth);
}
// These use STRTOUNICODE which uses gobal_opts.codec.
garmin_fs_t::set_cc(gmsd, STRTOUNICODE(QByteArray(way->cc, sizeof(way->cc)).constData()));
garmin_fs_t::set_city(gmsd, STRTOUNICODE(QByteArray(way->city, sizeof(way->city)).constData()));
garmin_fs_t::set_state(gmsd, STRTOUNICODE(QByteArray(way->state, sizeof(way->state)).constData()));
garmin_fs_t::set_facility(gmsd, STRTOUNICODE(QByteArray(way->facility, sizeof(way->facility)).constData()));
garmin_fs_t::set_cross_road(gmsd, STRTOUNICODE(QByteArray(way->cross_road, sizeof(way->cross_road)).constData()));
garmin_fs_t::set_addr(gmsd, STRTOUNICODE(QByteArray(way->addr, sizeof(way->addr)).constData()));
}

void
garmin_fs_garmin_before_write(const Waypoint* wpt, GPS_PWay way, const int protoid)
{
garmin_fs_t* gmsd = garmin_fs_t::find(wpt);

(void)protoid; // unused for now.

if (gmsd == nullptr) {
return;
}

/* ToDo: protocol specific conversion of class
way[i]->wpt_class = garmin_fs_t::get_wpt_class(gmsd, way[i]->wpt_class);
*/
way->dspl = gt_switch_display_mode_value(
garmin_fs_t::get_display(gmsd, way->dspl), gps_waypt_type, 0);
way->category = garmin_fs_t::get_category(gmsd, way->category);
way->dpth = WAYPT_GET(wpt, depth, way->dpth);
way->dst = WAYPT_GET(wpt, proximity, way->dpth);
way->temperature = WAYPT_GET(wpt, temperature, way->temperature);

// These use STRFROMUNICODE which uses gobal_opts.codec.
strncpy(way->cc, STRFROMUNICODE(garmin_fs_t::get_cc(gmsd, nullptr)), sizeof(way->cc));
strncpy(way->city, STRFROMUNICODE(garmin_fs_t::get_city(gmsd, nullptr)), sizeof(way->city));
strncpy(way->state, STRFROMUNICODE(garmin_fs_t::get_state(gmsd, nullptr)), sizeof(way->state));
strncpy(way->facility, STRFROMUNICODE(garmin_fs_t::get_facility(gmsd, nullptr)), sizeof(way->facility));
strncpy(way->cross_road, STRFROMUNICODE(garmin_fs_t::get_cross_road(gmsd, nullptr)), sizeof(way->cross_road));
strncpy(way->addr, STRFROMUNICODE(garmin_fs_t::get_addr(gmsd, nullptr)), sizeof(way->addr));
}
4 changes: 0 additions & 4 deletions garmin_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

#include "defs.h"
#include "formspec.h" // for FsChainFind, kFsGmsd, FormatSpecificData
#include "jeeps/gps.h"


/* this order is used by most devices */
Expand Down Expand Up @@ -236,7 +235,4 @@ unsigned char garmin_fs_merge_category(const char* category_name, Waypoint* wayp

#define GMSD_SECTION_CATEGORIES "Garmin Categories"

void garmin_fs_garmin_after_read(GPS_PWay way, Waypoint* wpt, int protoid);
void garmin_fs_garmin_before_write(const Waypoint* wpt, GPS_PWay way, int protoid);

#endif
Loading

0 comments on commit 2be4547

Please sign in to comment.