This patch might work, but no guarantees. I am not able to compile the
current master, thus I tested this only with a Subsurface version from
January. And naturally the patch did not apply cleanly, so I had to
manually merge it to master => not tested, not compiled...
(compilation fails on linking, so this should be syntactically
correct)

miika
From 3e427fea003a5b79da54f3f5cf9c9daf00f22abf Mon Sep 17 00:00:00 2001
From: Miika Turkia <[email protected]>
Date: Fri, 24 Apr 2015 08:39:20 -0400
Subject: [PATCH] Add suit field for CSV import

Fixes #853

Signed-off-by: Miika Turkia <[email protected]>
---
 dive.h                        |  2 +-
 file.c                        | 12 ++++++++----
 qt-ui/divelogimportdialog.cpp |  3 ++-
 xslt/manualcsv2xml.xslt       | 10 ++++++++++
 4 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/dive.h b/dive.h
index af4eb0d..9fad667 100644
--- a/dive.h
+++ b/dive.h
@@ -653,7 +653,7 @@ extern int parse_file(const char *filename);
 extern int parse_csv_file(const char *filename, int time, int depth, int temp, int po2f, int cnsf, int ndlf, int ttsf, int stopdepthf, int pressuref, int sepidx, const char *csvtemplate, int units);
 extern int parse_seabear_csv_file(const char *filename, int time, int depth, int temp, int po2f, int cnsf, int ndlf, int ttsf, int stopdepthf, int pressuref, int sepidx, const char *csvtemplate, int units, const char *delta);
 extern int parse_txt_file(const char *filename, const char *csv);
-extern int parse_manual_file(const char *filename, int separator_index, int units, int dateformat, int durationformat, int number, int date, int time, int duration, int location, int gps, int maxdepth, int meandepth, int divemaster, int buddy, int notes, int weight, int tags, int cylsizef, int startpresf, int endpresf, int o2f, int hef, int airtempf, int watertempf);
+extern int parse_manual_file(const char *filename, int separator_index, int units, int dateformat, int durationformat, int number, int date, int time, int duration, int location, int gps, int maxdepth, int meandepth, int divemaster, int buddy, int suit, int notes, int weight, int tags, int cylsizef, int startpresf, int endpresf, int o2f, int hef, int airtempf, int watertempf);
 
 extern int save_dives(const char *filename);
 extern int save_dives_logic(const char *filename, bool select_only);
diff --git a/file.c b/file.c
index c95c469..5646f3e 100644
--- a/file.c
+++ b/file.c
@@ -1016,18 +1016,18 @@ int parse_seabear_csv_file(const char *filename, int timef, int depthf, int temp
 
 int parse_manual_file(const char *filename, int sepidx, int units, int dateformat, int durationformat,
 		      int numberf, int datef, int timef, int durationf, int locationf, int gpsf, int maxdepthf, int meandepthf,
-		      int divemasterf, int buddyf, int notesf, int weightf, int tagsf, int cylsizef, int startpresf, int endpresf,
+		      int divemasterf, int buddyf, int suitf, int notesf, int weightf, int tagsf, int cylsizef, int startpresf, int endpresf,
 		      int o2f, int hef, int airtempf, int watertempf)
 {
 	if (verbose > 4) {
 		fprintf(stderr, "filename %s, sepidx %d, units %d, dateformat %d, durationformat %d\n", filename, sepidx, units, dateformat, durationformat);
 		fprintf(stderr, "numberf %d, datef %d, timef %d, durationf %d, locationf %d, gpsf %d, maxdepthf %d, meandepthf %d\n", numberf, datef, timef, durationf, locationf, gpsf, maxdepthf, meandepthf);
-		fprintf(stderr, "divemasterf %d, buddyf %d, notesf %d, weightf %d, tagsf %d, cylsizef %d, startpresf %d, endpresf %d\n", divemasterf, buddyf, notesf, weightf, tagsf, cylsizef, startpresf, endpresf);
+		fprintf(stderr, "divemasterf %d, buddyf %d, suitf %d, notesf %d, weightf %d, tagsf %d, cylsizef %d, startpresf %d, endpresf %d\n", divemasterf, buddyf, suitf, notesf, weightf, tagsf, cylsizef, startpresf, endpresf);
 		fprintf(stderr, "o2f %d, hef %d, airtempf %d, watertempf %d\n", o2f, hef, airtempf, watertempf);
 	}
 	struct memblock mem;
 	int pnr = 0;
-	char *params[53];
+	char *params[55];
 	char numberbuf[MAXCOLDIGITS];
 	char datebuf[MAXCOLDIGITS];
 	char timebuf[MAXCOLDIGITS];
@@ -1038,6 +1038,7 @@ int parse_manual_file(const char *filename, int sepidx, int units, int dateforma
 	char meandepthbuf[MAXCOLDIGITS];
 	char divemasterbuf[MAXCOLDIGITS];
 	char buddybuf[MAXCOLDIGITS];
+	char suitbuf[MAXCOLDIGITS];
 	char notesbuf[MAXCOLDIGITS];
 	char weightbuf[MAXCOLDIGITS];
 	char tagsbuf[MAXCOLDIGITS];
@@ -1058,7 +1059,7 @@ int parse_manual_file(const char *filename, int sepidx, int units, int dateforma
 	char curtime[6];
 	int ret;
 
-	if (numberf >= MAXCOLS || datef >= MAXCOLS || timef >= MAXCOLS || durationf >= MAXCOLS || locationf >= MAXCOLS || gpsf >= MAXCOLS || maxdepthf >= MAXCOLS || meandepthf >= MAXCOLS || buddyf >= MAXCOLS || notesf >= MAXCOLS || weightf >= MAXCOLS || tagsf >= MAXCOLS || cylsizef >= MAXCOLS || startpresf >= MAXCOLS || endpresf >= MAXCOLS || o2f >= MAXCOLS || hef >= MAXCOLS || airtempf >= MAXCOLS || watertempf >= MAXCOLS)
+	if (numberf >= MAXCOLS || datef >= MAXCOLS || timef >= MAXCOLS || durationf >= MAXCOLS || locationf >= MAXCOLS || gpsf >= MAXCOLS || maxdepthf >= MAXCOLS || meandepthf >= MAXCOLS || buddyf >= MAXCOLS || suitf >= MAXCOLS || notesf >= MAXCOLS || weightf >= MAXCOLS || tagsf >= MAXCOLS || cylsizef >= MAXCOLS || startpresf >= MAXCOLS || endpresf >= MAXCOLS || o2f >= MAXCOLS || hef >= MAXCOLS || airtempf >= MAXCOLS || watertempf >= MAXCOLS)
 		return report_error(translate("gettextFromC", "Maximum number of supported columns on CSV import is %d"), MAXCOLS);
 
 	snprintf(numberbuf, MAXCOLDIGITS, "%d", numberf);
@@ -1071,6 +1072,7 @@ int parse_manual_file(const char *filename, int sepidx, int units, int dateforma
 	snprintf(meandepthbuf, MAXCOLDIGITS, "%d", meandepthf);
 	snprintf(divemasterbuf, MAXCOLDIGITS, "%d", divemasterf);
 	snprintf(buddybuf, MAXCOLDIGITS, "%d", buddyf);
+	snprintf(suitbuf, MAXCOLDIGITS, "%d", suitf);
 	snprintf(notesbuf, MAXCOLDIGITS, "%d", notesf);
 	snprintf(weightbuf, MAXCOLDIGITS, "%d", weightf);
 	snprintf(tagsbuf, MAXCOLDIGITS, "%d", tagsf);
@@ -1113,6 +1115,8 @@ int parse_manual_file(const char *filename, int sepidx, int units, int dateforma
 	params[pnr++] = divemasterbuf;
 	params[pnr++] = "buddyField";
 	params[pnr++] = buddybuf;
+	params[pnr++] = "suitField";
+	params[pnr++] = suitbuf;
 	params[pnr++] = "notesField";
 	params[pnr++] = notesbuf;
 	params[pnr++] = "weightField";
diff --git a/qt-ui/divelogimportdialog.cpp b/qt-ui/divelogimportdialog.cpp
index 763476d..4090648 100644
--- a/qt-ui/divelogimportdialog.cpp
+++ b/qt-ui/divelogimportdialog.cpp
@@ -24,7 +24,7 @@ const DiveLogImportDialog::CSVAppConfig DiveLogImportDialog::CSVApps[CSVAPPS] =
 ColumnNameProvider::ColumnNameProvider(QObject *parent) : QAbstractListModel(parent)
 {
 	columnNames << tr("Dive #") << tr("Date") << tr("Time") << tr("Duration") << tr("Location") << tr("GPS") << tr("Weight") << tr("Cyl. size") << tr("Start pressure") <<
-		       tr("End pressure") << tr("Max. depth") << tr("Avg. depth") << tr("Divemaster") << tr("Buddy") << tr("Notes") << tr("Tags") << tr("Air temp.") << tr("Water temp.") <<
+		       tr("End pressure") << tr("Max. depth") << tr("Avg. depth") << tr("Divemaster") << tr("Buddy") << tr("Suit") << tr("Notes") << tr("Tags") << tr("Air temp.") << tr("Water temp.") <<
 		       tr("O₂") << tr("He") << tr("Sample time") << tr("Sample depth") << tr("Sample temperature") << tr("Sample pO₂") << tr("Sample CNS") << tr("Sample NDL") <<
 		       tr("Sample TTS") << tr("Sample stopdepth") << tr("Sample pressure");
 }
@@ -639,6 +639,7 @@ void DiveLogImportDialog::on_buttonBox_accepted()
 						r.indexOf(tr("Avg. depth")),
 						r.indexOf(tr("Divemaster")),
 						r.indexOf(tr("Buddy")),
+						r.indexOf(tr("Suit")),
 						r.indexOf(tr("Notes")),
 						r.indexOf(tr("Weight")),
 						r.indexOf(tr("Tags")),
diff --git a/xslt/manualcsv2xml.xslt b/xslt/manualcsv2xml.xslt
index 15eb8f0..83c5435 100644
--- a/xslt/manualcsv2xml.xslt
+++ b/xslt/manualcsv2xml.xslt
@@ -17,6 +17,7 @@
   <xsl:param name="meanDepthField" select="meanDepthField"/>
   <xsl:param name="divemasterField" select="divemasterField"/>
   <xsl:param name="buddyField" select="buddyField"/>
+  <xsl:param name="suitField" select="suitField"/>
   <xsl:param name="notesField" select="notesField"/>
   <xsl:param name="weightField" select="weightField"/>
   <xsl:param name="dateformat" select="dateformat"/>
@@ -343,6 +344,15 @@
         </buddy>
       </xsl:if>
 
+      <xsl:if test="$suitField >= 0">
+        <suit>
+          <xsl:call-template name="getFieldByIndex">
+            <xsl:with-param name="index" select="$suitField"/>
+            <xsl:with-param name="line" select="$line"/>
+          </xsl:call-template>
+        </suit>
+      </xsl:if>
+
       <xsl:if test="$notesField >= 0">
         <notes>
           <xsl:call-template name="getFieldByIndex">
-- 
2.1.0

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to