Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix synthetic shortname option handling #978

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -875,10 +875,10 @@ void mkshort_del_handle(short_handle* h);
void setshort_length(short_handle, int n);
void setshort_badchars(short_handle, const char*);
void setshort_goodchars(short_handle, const char*);
void setshort_mustupper(short_handle, int n);
void setshort_mustuniq(short_handle, int n);
void setshort_whitespace_ok(short_handle, int n);
void setshort_repeating_whitespace_ok(short_handle, int n);
void setshort_mustupper(short_handle, bool b);
void setshort_mustuniq(short_handle, bool b);
void setshort_whitespace_ok(short_handle, bool b);
void setshort_repeating_whitespace_ok(short_handle, bool b);
void setshort_defname(short_handle, const char* s);

#define ARGTYPE_UNKNOWN 0x00000000U
Expand Down
14 changes: 7 additions & 7 deletions garmin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static char* categorybitsopt = nullptr;
static char* baudopt = nullptr;
static int baud = 0;
static int categorybits;
static int receiver_must_upper = 1;
static bool receiver_must_upper = true;
static QTextCodec* codec{nullptr};

static Format* gpx_vec;
Expand Down Expand Up @@ -140,7 +140,7 @@ static QString str_to_unicode(const QByteArray& cstr) {return codec->toUnicode(c
static void
rw_init(const QString& fname)
{
receiver_must_upper = 1;
receiver_must_upper = true;
const char* receiver_charset = "US-ASCII";

if (!mkshort_handle) {
Expand Down Expand Up @@ -256,7 +256,7 @@ rw_init(const QString& fname)
break;
case 382: /* C320 */
receiver_short_length = 30;
receiver_must_upper = 0;
receiver_must_upper = false;
break;
case 292: /* (60|76)C[S]x series */
case 421: /* Vista|Legend Cx */
Expand All @@ -266,7 +266,7 @@ rw_init(const QString& fname)
case 957: /* Legend HC */
receiver_short_length = 14;
snwhiteopt = xstrdup("1");
receiver_must_upper = 0;
receiver_must_upper = false;
/* This might be 8859-1 */
receiver_charset = "windows-1252";
break;
Expand All @@ -278,16 +278,16 @@ rw_init(const QString& fname)
break;
case 231: /* Quest */
case 463: /* Quest 2 */
receiver_must_upper = 0;
receiver_must_upper = false;
receiver_short_length = 30;
receiver_charset = "windows-1252";
break;
case 577: // Rino 530HCx Version 2.50
receiver_must_upper = 0;
receiver_must_upper = false;
receiver_short_length = 14;
break;
case 429: // Streetpilot i3
receiver_must_upper = 0;
receiver_must_upper = false;
receiver_charset = "windows-1252";
receiver_short_length = 30;
break;
Expand Down
8 changes: 4 additions & 4 deletions garmin_gpi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1262,10 +1262,10 @@ GarminGPIFormat::wr_init(const QString& fname)

setshort_length(short_h, 1024);
setshort_badchars(short_h, "\r\n");
setshort_mustupper(short_h, 0);
setshort_mustuniq(short_h, 1);
setshort_whitespace_ok(short_h, 1);
setshort_repeating_whitespace_ok(short_h, 0);
setshort_mustupper(short_h, false);
setshort_mustuniq(short_h, true);
setshort_whitespace_ok(short_h, true);
setshort_repeating_whitespace_ok(short_h, false);
setshort_defname(short_h, "POI");

codepage = 0;
Expand Down
8 changes: 4 additions & 4 deletions gdb.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1119,10 +1119,10 @@ GdbFormat::reset_short_handle(const char* defname)

setshort_length(short_h, GDB_NAME_BUFFERLEN);
setshort_badchars(short_h, "\r\n\t");
setshort_mustupper(short_h, 0);
setshort_mustuniq(short_h, 1);
setshort_whitespace_ok(short_h, 1);
setshort_repeating_whitespace_ok(short_h, 1);
setshort_mustupper(short_h, false);
setshort_mustuniq(short_h, true);
setshort_whitespace_ok(short_h, true);
setshort_repeating_whitespace_ok(short_h, true);
setshort_defname(short_h, defname);
}

Expand Down
2 changes: 1 addition & 1 deletion gpx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ GpxFormat::gpx_reset_short_handle()
mkshort_handle = mkshort_new_handle();

if (suppresswhite) {
setshort_whitespace_ok(mkshort_handle, 0);
setshort_whitespace_ok(mkshort_handle, false);
}

setshort_length(mkshort_handle, xstrtoi(snlen, nullptr, 10));
Expand Down
2 changes: 1 addition & 1 deletion holux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ static const char* mknshort(const char* stIn,unsigned int sLen)
}

setshort_length(mkshort_handle, sLen);
setshort_mustuniq(mkshort_handle, 0);
setshort_mustuniq(mkshort_handle, false);
setshort_defname(mkshort_handle, "");

char* shortstr = mkshort(mkshort_handle, stIn, false);
Expand Down
24 changes: 12 additions & 12 deletions humminbird.cc
Original file line number Diff line number Diff line change
Expand Up @@ -586,28 +586,28 @@ HumminbirdBase::humminbird_wr_init(const QString& fname)

setshort_length(wptname_sh, WPT_NAME_LEN - 1);
setshort_badchars(wptname_sh, BAD_CHARS);
setshort_mustupper(wptname_sh, 0);
setshort_mustuniq(wptname_sh, 0);
setshort_whitespace_ok(wptname_sh, 1);
setshort_repeating_whitespace_ok(wptname_sh, 1);
setshort_mustupper(wptname_sh, false);
setshort_mustuniq(wptname_sh, false);
setshort_whitespace_ok(wptname_sh, true);
setshort_repeating_whitespace_ok(wptname_sh, true);
setshort_defname(wptname_sh, "WPT");

rtename_sh = mkshort_new_handle();
setshort_length(rtename_sh, RTE_NAME_LEN - 1);
setshort_badchars(rtename_sh, BAD_CHARS);
setshort_mustupper(rtename_sh, 0);
setshort_mustuniq(rtename_sh, 0);
setshort_whitespace_ok(rtename_sh, 1);
setshort_repeating_whitespace_ok(rtename_sh, 1);
setshort_mustupper(rtename_sh, false);
setshort_mustuniq(rtename_sh, false);
setshort_whitespace_ok(rtename_sh, true);
setshort_repeating_whitespace_ok(rtename_sh, true);
setshort_defname(rtename_sh, "Route");

trkname_sh = mkshort_new_handle();
setshort_length(trkname_sh, RTE_NAME_LEN - 1);
setshort_badchars(trkname_sh, BAD_CHARS);
setshort_mustupper(trkname_sh, 0);
setshort_mustuniq(trkname_sh, 0);
setshort_whitespace_ok(trkname_sh, 1);
setshort_repeating_whitespace_ok(trkname_sh, 1);
setshort_mustupper(trkname_sh, false);
setshort_mustuniq(trkname_sh, false);
setshort_whitespace_ok(trkname_sh, true);
setshort_repeating_whitespace_ok(trkname_sh, true);
setshort_defname(trkname_sh, "Track");

waypoint_num = 0;
Expand Down
16 changes: 8 additions & 8 deletions mkshort.cc
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ setshort_length(short_handle h, int l)
*/

void
setshort_whitespace_ok(short_handle h, int l)
setshort_whitespace_ok(short_handle h, bool b)
{
auto* hdl = (mkshort_handle_imp*) h;
hdl->whitespaceok = l;
hdl->whitespaceok = b;
}

/*
Expand All @@ -280,10 +280,10 @@ setshort_whitespace_ok(short_handle h, int l)
*/

void
setshort_repeating_whitespace_ok(short_handle h, int l)
setshort_repeating_whitespace_ok(short_handle h, bool b)
{
auto* hdl = (mkshort_handle_imp*) h;
hdl->repeating_whitespaceok = l;
hdl->repeating_whitespaceok = b;
}

/*
Expand Down Expand Up @@ -342,10 +342,10 @@ setshort_goodchars(short_handle h, const char* s)
* Call with i non-zero if generated names must be uppercase only.
*/
void
setshort_mustupper(short_handle h, int i)
setshort_mustupper(short_handle h, bool b)
{
auto* hdl = (mkshort_handle_imp*) h;
hdl->mustupper = i;
hdl->mustupper = b;
}


Expand All @@ -354,10 +354,10 @@ setshort_mustupper(short_handle h, int i)
* (By default, they are.)
*/
void
setshort_mustuniq(short_handle h, int i)
setshort_mustuniq(short_handle h, bool b)
{
auto* hdl = (mkshort_handle_imp*) h;
hdl->must_uniq = i;
hdl->must_uniq = b;
}

char*
Expand Down
12 changes: 3 additions & 9 deletions ozi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -467,17 +467,11 @@ wr_init(const QString& fname)

setshort_length(mkshort_handle, xstrtoi(snlenopt, nullptr, 10));

if (snwhiteopt) {
setshort_whitespace_ok(mkshort_handle, xstrtoi(snwhiteopt, nullptr, 10));
}
setshort_whitespace_ok(mkshort_handle, snwhiteopt != nullptr);

if (snupperopt) {
setshort_mustupper(mkshort_handle, xstrtoi(snupperopt, nullptr, 10));
}
setshort_mustupper(mkshort_handle, snupperopt != nullptr);

if (snuniqueopt) {
setshort_mustuniq(mkshort_handle, xstrtoi(snuniqueopt, nullptr, 10));
}
setshort_mustuniq(mkshort_handle, snuniqueopt != nullptr);

setshort_badchars(mkshort_handle, "\",");
}
Expand Down
2 changes: 2 additions & 0 deletions reference/mkshort.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
35.000000,-90.000000,n n,d d
35.000001,-90.000001,n n,d d
6 changes: 6 additions & 0 deletions reference/mkshort.style
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FIELD_DELIMITER COMMA
RECORD_DELIMITER NEWLINE
IFIELD LAT_DECIMAL, "", "%f"
IFIELD LON_DECIMAL, "", "%f"
IFIELD SHORTNAME, "", "%s"
IFIELD DESCRIPTION,"","%s"
6 changes: 6 additions & 0 deletions reference/ozi000.wpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
OziExplorer Waypoint File Version 1.1
WGS 84
Reserved 2
Reserved 3
1,dd,35.000000,-90.000000,,0,1,3,0,65535,d d,0,0,0,-777,6,0,17
2,dd,35.000001,-90.000001,,0,1,3,0,65535,d d,0,0,0,-777,6,0,17
6 changes: 6 additions & 0 deletions reference/ozi001.wpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
OziExplorer Waypoint File Version 1.1
WGS 84
Reserved 2
Reserved 3
1,d d,35.000000,-90.000000,,0,1,3,0,65535,d d,0,0,0,-777,6,0,17
2,d d,35.000001,-90.000001,,0,1,3,0,65535,d d,0,0,0,-777,6,0,17
6 changes: 6 additions & 0 deletions reference/ozi010.wpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
OziExplorer Waypoint File Version 1.1
WGS 84
Reserved 2
Reserved 3
1,DD,35.000000,-90.000000,,0,1,3,0,65535,d d,0,0,0,-777,6,0,17
2,DD,35.000001,-90.000001,,0,1,3,0,65535,d d,0,0,0,-777,6,0,17
6 changes: 6 additions & 0 deletions reference/ozi100.wpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
OziExplorer Waypoint File Version 1.1
WGS 84
Reserved 2
Reserved 3
1,dd,35.000000,-90.000000,,0,1,3,0,65535,d d,0,0,0,-777,6,0,17
2,dd.1,35.000001,-90.000001,,0,1,3,0,65535,d d,0,0,0,-777,6,0,17
2 changes: 2 additions & 0 deletions reference/xcsv000.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
35.000000,-90.000000,dd,d d
35.000001,-90.000001,dd,d d
2 changes: 2 additions & 0 deletions reference/xcsv001.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
35.000000,-90.000000,d d,d d
35.000001,-90.000001,d d,d d
2 changes: 2 additions & 0 deletions reference/xcsv010.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
35.000000,-90.000000,DD,d d
35.000001,-90.000001,DD,d d
2 changes: 2 additions & 0 deletions reference/xcsv100.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
35.000000,-90.000000,dd,d d
35.000001,-90.000001,dd.1,d d
10 changes: 10 additions & 0 deletions testo.d/ozi.test
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ compare ${REFERENCE}/track/ozitracks~gpx-2.plt ${TMPDIR}/ozitracks~gpx-2.plt

# test ozi with no output making sure we don't throw an error or segmentation fault.
gpsbabel -i gpx -f ${REFERENCE}/track/ozitracks.gpx -x nuketypes,waypoints,tracks,routes -o ozi -F ${TMPDIR}/empty.plt

# test sn options
gpsbabel -s -i xcsv,style=${REFERENCE}/mkshort.style -f reference/mkshort.csv -o ozi,snunique=0,snupper=0,snwhite=0 -F ${TMPDIR}/ozi000.wpt
compare ${REFERENCE}/ozi000.wpt ${TMPDIR}/ozi000.wpt
gpsbabel -s -i xcsv,style=${REFERENCE}/mkshort.style -f reference/mkshort.csv -o ozi,snunique=1,snupper=0,snwhite=0 -F ${TMPDIR}/ozi100.wpt
compare ${REFERENCE}/ozi100.wpt ${TMPDIR}/ozi100.wpt
gpsbabel -s -i xcsv,style=${REFERENCE}/mkshort.style -f reference/mkshort.csv -o ozi,snunique=0,snupper=1,snwhite=0 -F ${TMPDIR}/ozi010.wpt
compare ${REFERENCE}/ozi010.wpt ${TMPDIR}/ozi010.wpt
gpsbabel -s -i xcsv,style=${REFERENCE}/mkshort.style -f reference/mkshort.csv -o ozi,snunique=0,snupper=0,snwhite=1 -F ${TMPDIR}/ozi001.wpt
compare ${REFERENCE}/ozi001.wpt ${TMPDIR}/ozi001.wpt
10 changes: 10 additions & 0 deletions testo.d/xcsv.test
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,13 @@ gpsbabel -i unicsv -f ${REFERENCE}/gmsd.unicsv -o xcsv,style=${TMPDIR}/gmsd.styl
compare ${REFERENCE}/gmsd.xcsv ${TMPDIR}/gmsd.xcsv
gpsbabel -i xcsv,style=${TMPDIR}/gmsd.style -f ${REFERENCE}/gmsd.xcsv -o unicsv -F ${TMPDIR}/gmsd.unicsv
compare ${REFERENCE}/gmsd.unicsv ${TMPDIR}/gmsd.unicsv

# test sn options
gpsbabel -s -i xcsv,style=${REFERENCE}/mkshort.style -f reference/mkshort.csv -o xcsv,style=${REFERENCE}/mkshort.style,snunique=0,snupper=0,snwhite=0 -F ${TMPDIR}/xcsv000.csv
compare ${REFERENCE}/xcsv000.csv ${TMPDIR}/xcsv000.csv
gpsbabel -s -i xcsv,style=${REFERENCE}/mkshort.style -f reference/mkshort.csv -o xcsv,style=${REFERENCE}/mkshort.style,snunique=1,snupper=0,snwhite=0 -F ${TMPDIR}/xcsv100.csv
compare ${REFERENCE}/xcsv100.csv ${TMPDIR}/xcsv100.csv
gpsbabel -s -i xcsv,style=${REFERENCE}/mkshort.style -f reference/mkshort.csv -o xcsv,style=${REFERENCE}/mkshort.style,snunique=0,snupper=1,snwhite=0 -F ${TMPDIR}/xcsv010.csv
compare ${REFERENCE}/xcsv010.csv ${TMPDIR}/xcsv010.csv
gpsbabel -s -i xcsv,style=${REFERENCE}/mkshort.style -f reference/mkshort.csv -o xcsv,style=${REFERENCE}/mkshort.style,snunique=0,snupper=0,snwhite=1 -F ${TMPDIR}/xcsv001.csv
compare ${REFERENCE}/xcsv001.csv ${TMPDIR}/xcsv001.csv
4 changes: 2 additions & 2 deletions tpg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ tpg_write()

if (global_opts.synthesize_shortnames) {
setshort_length(mkshort_handle, 32);
setshort_whitespace_ok(mkshort_handle, 1);
setshort_mustupper(mkshort_handle, 1);
setshort_whitespace_ok(mkshort_handle, true);
setshort_mustupper(mkshort_handle, true);
}

if (s > MAXTPGOUTPUTPINS) {
Expand Down
12 changes: 3 additions & 9 deletions xcsv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1936,17 +1936,11 @@ XcsvFormat::wr_init(const QString& fname)
setshort_length(xcsv_file->mkshort_handle, xstrtoi(snlenopt, nullptr, 10));
}

if (snwhiteopt) {
setshort_whitespace_ok(xcsv_file->mkshort_handle, xstrtoi(snwhiteopt, nullptr, 10));
}
setshort_whitespace_ok(xcsv_file->mkshort_handle, snwhiteopt != nullptr);

if (snupperopt) {
setshort_mustupper(xcsv_file->mkshort_handle, xstrtoi(snupperopt, nullptr, 10));
}
setshort_mustupper(xcsv_file->mkshort_handle, snupperopt != nullptr);

if (snuniqueopt) {
setshort_mustuniq(xcsv_file->mkshort_handle, xstrtoi(snuniqueopt, nullptr, 10));
}
setshort_mustuniq(xcsv_file->mkshort_handle, snuniqueopt != nullptr);

setshort_badchars(xcsv_file->mkshort_handle, CSTR(xcsv_style->badchars));

Expand Down
2 changes: 1 addition & 1 deletion xcsv.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ class XcsvStyle
std::optional<int> shortlen;

/* SHORTWHITE from style file */
std::optional<int> whitespace_ok;
std::optional<bool> whitespace_ok;

private:
/* Types */
Expand Down