Re: [PATCH] Use git pull with rebase in build script

2015-07-12 Thread Linus Torvalds
On Sun, Jul 12, 2015 at 11:07 AM, Dirk Hohndel d...@hohndel.org wrote:

 It's just that I don't know how else to do it and keep the branches
 reasonably useful.

So I guess the current model *works*, it just causes nasty problems
occasionally.

The best model is likely one where you have two separate branches:

 - you have the ugly working branch that is never ever rebased, and
that people who want to track libdivecomputer as a _user_ would be (so
this is what the build.sh script would pull).

   Because it's never rebased, git pull works fine, with or without
rebase (and with --rebase might be better, because *if* somebody has
their own work going on, they most definitely wouldn't want to have
that work ever get mixed into that branch.

 - you have the cleanup branch, which ends up occasionally rebasing
on top of upstream libdivecomputer, and has a clean history that you
can hope that Jef will eventually take more and more of.

  This cleanup branch you don't necessarily work on very actively,
it's more of a update when libdivecomputer has done something we
really want or care about.

Now, that all sounds easy (just have two branches), but the magic is
that you want to keep them in sync. And *that* is fairly simple, but
it's simple only if you follow a few basic rules.

 (a) they start out with the exact same contents (you're a
mathematician, this is going to be an inductive proof, and this is the
starting point - and the trivial case is by having the exact same tree
with the same history).

 (b) You need to remember this place in the ugly working tree.  The
*contents* are the same, but the history may not be, remember, so you
might tag that location with sync-point or something like that.

 (c) when *you* do libdivecomputer development, you probably want to
work in the ugly working tree, and you just keep adding commits to it.
Ignore the cleanup tree, it's not what people really *use*, it's more
of a nice marker of what used to be clean development ready for
merging back upstream. So work work work in this tree normally, and
the two trees diverge both in history and in content. But the clean
tree stays the same.

 (d) you decide that you want to synchronize the two trees after
having done *your* work, you can now do a complex rebase

git rebase -i --onto cleanup sync-point

  which should rebase all your work you did in (c) since your last
sync-point onto the cleanup branch.

 NOTE! It's important that cleanup and sync-point have the
exact same tree: that guarantees that the rebase will be trivial.
You're applying the same patches onto the same tree state - it's just
a different history. You're now moving your ugly tree work to be on
top of the cleaned-up history.

 (e) you may choose to clean up history further now (it maybe you
weren't so careful when you were working in your ugly tree, but now
you want things to be tip-top, so you do some cleanup and further
testing in this state, wanting to make it be something that you could
send upstream to Jef.

 (f) in fact, it's now so nice and clean that you update the cleanup
branch with the new state:

git branch -f cleanup HEAD

 because you now have a new cleanup state.

 (g) but now you've rebased your ugly tree, and it might not even
match the old state of your working tree because of the cleanups you
did in (e), so we've really screwed up! The whole point was to make
the ugly tree always be a fast-forward! And the whole point was to
keep the two in sync (see step (a))! What kind of idiotic working
model is this!

 (h) to the rescue. At this point, you just do git pull --strategy
ours publicrepo to say pull in all the stuff I've pushed out, but
use the merge strategy of picking the exact current state.

 This is what makes your tree the ugly tree: you just created a
nice clean branch (to use as your cleaned-up version), and then you
use the state of that branch (to make sure it matches the cleanup -
see point (a)), but you merged in all the ugly history, including all
the old ugly merges, so that your branch is always a fast-forward.

 (i) Now remember this state as the new sync-point:

git tag -f sync-point

 (or I guess you could keep sync-point as just a branch instead
of a tag, that way you'll have the branch history in the reflog)

And now we're back to (a).

What I didn't describe above is what you should do when you actually
want to update from Jef's upstream. When you do that, make sure that
you synchronize like the above first, so that your clean branch and
your ugly branch have the same contents. Then you just check out your
clean branch, and rebase it on top of its upstream (ie Jef's branch).
The clean branch you rebase, after all, and it has simple clean
history so rebasing it on top of Jef's should be fairly simple too,
and keeps the history clean:

git checkout cleanup
gti pull --rebase

And after you've rebased the clean branch, you go back to your ugly
branch, and since the clean 

Re: OSTCTools import support

2015-07-12 Thread Salvador Cuñat
Hi Anton,

2015-07-10 0:48 GMT+02:00, Anton Lundin gla...@acc.umu.se:


 Looks like the first byte is a version(?) marker to. 0x64 in the old
 files in dives/ and 0x65 in the ones posted on the forum.


Yes it's correct, but this byte doesn't seem to be related to the
software tool but to the data type downloaded from the dc.  This way,
it happens to be 0x64 for OSTC 2N and 0x65 for OSTC3 (I've dowloaded
recent dives with latest release and the files are still marked 0x64
and seem to be just the same structure than older files).

I still haven't found in the OSTC3 files how the model number is
stored, so, although I have shamelessly copied the way libdc
stablishes it, this means that for OSTC3 family every DC will default
to OSTC3 except SPORT model.

BTW,  I'll take a look in depth at the HW forum searching for more
.dive file samples.  There will probably be more there.

Regards.

Salva.
___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


[GSoC] Week 7 (Native Bluetooth support)

2015-07-12 Thread Claudiu Olteanu
Hello,

Here is a resume about the things I did this week:
- successfully downloaded the dives from 3 different environments
(ArchLinux, Fedora 22, OpenSuse 13.2)
- compiled and tested our custom BT serial implementation with the new Qt
5.5.0
- compiled and tested our custom  BT serial implementation for Android
platform
- fixed the connectivity issues for Android platform (I will send you a
patch tomorrow)
- started the documentation for Windows support and started working on a
prototype

For the next week I want to finish documentation
and the prototype to see what functionalities I can cover
with Microsoft Bluetooth stack.

Have a nice week,
Claudiu
___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


Re: [PATCH] Use git pull with rebase in build script

2015-07-12 Thread Dirk Hohndel
On Sun, Jul 12, 2015 at 03:51:39PM +0200, Henrik Brautaset Aronsen wrote:
 
  On 12 Jul 2015, at 15:45, Dirk Hohndel d...@hohndel.org wrote:
  
  Why would you need -rebase for the libgit2 repository, unless you have
  local changes (and I just realize that I need to patch the build script to
  use a later commit there, anyway, as that one still doesn't work with
  proxies).
 
 OK, maybe the rebase in libgit is a bit too eager.

OK

  And since I frequently force push into the Subsurface-testing
  branches of libdc and marble, I'm not sure what benefit -rebase gives you
  there. You usually need to remove those directories and check out fresh
  copies for things to be in a consistent state.
 
 Rebase can actually cope with a force push automatically.  It’s pretty
 awesome, as some would say.  On several occations when the build fails,
 it’s in the middle of a merge in either libdc or (recently) marble.
 Then I just go to the project in question,  abort the merge, and do a
 git pull —rebase.  Voila, build.sh can continue.  By adding this to the
 script I don’t have to intervene manually.

Thanks for the explanation, Henrik. I read a bit through the git-rebase
manpage and that has not necessarily completely enlightened me on the
wisdom of this changes.

Linus, this sounds nice... you obviously understand the inner workings
here much better. Is this a reasonable thing to do? Or will it cause
pregnant kittens?

I like adding things that make it easier for our developers to stay
current.

/D
___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


[PATCH] Use git pull with rebase in build script

2015-07-12 Thread subsurface
From: Henrik Brautaset Aronsen subsurf...@henrik.synth.no

Without rebase, the build script would stop because it
couldn't complete a merge.
---
 scripts/build.sh | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/scripts/build.sh b/scripts/build.sh
index 7b54bea..cb9b4ad 100755
--- a/scripts/build.sh
+++ b/scripts/build.sh
@@ -77,7 +77,7 @@ if [ ! -d libgit2 ] ; then
 fi
 cd libgit2
 # let's build with a recent enough version of master for the latest features
-git pull origin master
+git pull --rebase origin master
 if ! git checkout c11daac9de2 ; then
echo Can't find the right commit in libgit2 - giving up
exit 1
@@ -110,7 +110,7 @@ if [ ! -d libdivecomputer ] ; then
fi
 fi
 cd libdivecomputer
-git pull
+git pull --rebase
 if ! git checkout Subsurface-testing ; then
echo can't check out the Subsurface-testing branch of libdivecomputer 
-- giving up
exit 1
@@ -134,7 +134,7 @@ if [ ! -d marble-source ] ; then
fi
 fi
 cd marble-source
-git pull
+git pull --rebase
 if ! git checkout Subsurface-testing ; then
echo can't check out the Subsurface-testing branch of marble -- giving 
up
exit 1
-- 
2.4.1

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


Another Subsurface crash

2015-07-12 Thread Rick Walsh
I've finally been catching up on assigning locations to my last 150 odd
dives in Subsurface.  Wow that's a huge effort, but I've got there.

I've been working with the latest master (commit
d8ca04626589221c5f7c178e882cfaa4c095ce2a, Author: Dirk Hohndel 
d...@hohndel.org, Date:   Fri Jul 10 13:28:28 2015 -0700), and built
everything in a clean directory with build.sh a few hours ago.

Most things are working great, including really useful features I have
barely tested before, such as the filtering (awesome), editing multiple
dives at once, and location management.

I have a couple of annoyances with the Marble behaviour.
Firstly, it keeps zooming out when I right-click to edit the location of a
site that doesn't yet have coordinates.

Secondly, I repeatedly try to use Marble to set coordinates for a dive that
doesn't have a location set.  It allows me to right-click and select 'edit
location', but then it won't let me double click to choose a new location.
I worked out that it's because I haven't yet named the site, which makes
some sense, but it would be good if there were a message in Marble
prompting me to name the site first.  Especially because once I work out my
mistake, it inevitably zooms out to somewhere over Africa, so I have to
zoom and pan to find my way back to whatever little site I'd carefully
zoomed to previously in Australia/Asia/New Zealand.

But the real problem is I'm getting crashes as seemingly random intervals.
It seems to happen when I'm either selecting a different site from the
list, merging dives, or editing multiple dives.  Most of the time it
doesn't crash, so it's hard to repeat.  Backtrace (copied below in full)
and memory map (first few lines copied) are helpfully printed to the
command terminal.  It doesn't mean much to me, but it hopefully it does to
someone.

Running Fedora 22 with Qt 5.4.2 (from Fedora repositories).

[rick@localhost build]$ ./subsurface
Map theme file does not exist: 
QInotifyFileSystemWatcherEngine::addPaths: inotify_add_watch failed: No
such file or directory
*** Error in `./subsurface': free(): invalid size: 0x034d3e30 ***
=== Backtrace: =
/lib64/libc.so.6(+0x77e9d)[0x7fec7ba06e9d]
/lib64/libc.so.6(+0x7f53c)[0x7fec7ba0e53c]
/lib64/libc.so.6(cfree+0x4c)[0x7fec7ba12e9c]
./subsurface(free_taxonomy+0x45)[0x6ca9df]
./subsurface(copy_dive_site+0xd7)[0x67f009]
./subsurface(_ZN7MainTab14updateDiveInfoEb+0x959)[0x5e3e29]
./subsurface(_ZN10MainWindow20current_dive_changedEi+0x56)[0x4fafd0]
./subsurface[0x5a1532]
/lib64/libQt5Core.so.5(_ZN11QMetaObject8activateEP7QObjectiiPPv+0x7ba)[0x7fec7c59807a]
./subsurface(_ZN12DiveListView18currentDiveChangedEi+0x46)[0x59e098]
./subsurface(_ZN12DiveListView16selectionChangedERK14QItemSelectionS2_+0x74d)[0x5b934f]
/lib64/libQt5Widgets.so.5(+0x3abf01)[0x7fec7d72df01]
/lib64/libQt5Core.so.5(_ZN11QMetaObject8activateEP7QObjectiiPPv+0x7ba)[0x7fec7c59807a]
/lib64/libQt5Core.so.5(_ZN19QItemSelectionModel16selectionChangedERK14QItemSelectionS2_+0x37)[0x7fec7c5189b7]
/lib64/libQt5Core.so.5(_ZN19QItemSelectionModel20emitSelectionChangedERK14QItemSelectionS2_+0x22c)[0x7fec7c51cddc]
/lib64/libQt5Core.so.5(_ZN19QItemSelectionModel6selectERK14QItemSelection6QFlagsINS_13SelectionFlagEE+0x1d6)[0x7fec7c51f256]
/lib64/libQt5Core.so.5(_ZN19QItemSelectionModel6selectERK11QModelIndex6QFlagsINS_13SelectionFlagEE+0x3c)[0x7fec7c51a84c]
/lib64/libQt5Core.so.5(_ZN19QItemSelectionModel15setCurrentIndexERK11QModelIndex6QFlagsINS_13SelectionFlagEE+0x1a4)[0x7fec7c518d94]
/lib64/libQt5Widgets.so.5(_ZN17QAbstractItemView13keyPressEventEP9QKeyEvent+0x9b7)[0x7fec7d72c627]
/lib64/libQt5Widgets.so.5(_ZN9QTreeView13keyPressEventEP9QKeyEvent+0x6b)[0x7fec7d773b5b]
/lib64/libQt5Widgets.so.5(_ZN7QWidget5eventEP6QEvent+0x997)[0x7fec7d517347]
/lib64/libQt5Widgets.so.5(_ZN6QFrame5eventEP6QEvent+0x1e)[0x7fec7d6115de]
/lib64/libQt5Widgets.so.5(_ZN19QAbstractScrollArea5eventEP6QEvent+0x373)[0x7fec7d694483]
/lib64/libQt5Widgets.so.5(_ZN17QAbstractItemView5eventEP6QEvent+0x8b)[0x7fec7d73451b]
/lib64/libQt5Widgets.so.5(_ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent+0x8c)[0x7fec7d4d47ec]
/lib64/libQt5Widgets.so.5(_ZN12QApplication6notifyEP7QObjectP6QEvent+0x939)[0x7fec7d4da429]
/lib64/libQt5Core.so.5(_ZN16QCoreApplication14notifyInternalEP7QObjectP6QEvent+0xdb)[0x7fec7c56767b]
/lib64/libQt5Widgets.so.5(+0x1ae5f3)[0x7fec7d5305f3]
/lib64/libQt5Widgets.so.5(_ZN19QApplicationPrivate13notify_helperEP7QObjectP6QEvent+0x8c)[0x7fec7d4d47ec]
/lib64/libQt5Widgets.so.5(_ZN12QApplication6notifyEP7QObjectP6QEvent+0x3a0)[0x7fec7d4d9e90]
/lib64/libQt5Core.so.5(_ZN16QCoreApplication14notifyInternalEP7QObjectP6QEvent+0xdb)[0x7fec7c56767b]
/lib64/libQt5Gui.so.5(_ZN22QGuiApplicationPrivate15processKeyEventEPN29QWindowSystemInterfacePrivate8KeyEventE+0xd7)[0x7fec7cd2e9d7]
/lib64/libQt5Gui.so.5(_ZN22QGuiApplicationPrivate24processWindowSystemEventEPN29QWindowSystemInterfacePrivate17WindowSystemEventE+0x115)[0x7fec7cd33975]

Re: Another Subsurface crash

2015-07-12 Thread Dirk Hohndel
On Sun, Jul 12, 2015 at 07:19:53PM +1000, Rick Walsh wrote:
 I've finally been catching up on assigning locations to my last 150 odd
 dives in Subsurface.  Wow that's a huge effort, but I've got there.

That is huge - especially as location management right now is not where it
should be. It sort of almost works, but not really.

 I've been working with the latest master (commit
 d8ca04626589221c5f7c178e882cfaa4c095ce2a, Author: Dirk Hohndel 
 d...@hohndel.org, Date:   Fri Jul 10 13:28:28 2015 -0700), and built
 everything in a clean directory with build.sh a few hours ago.
 
 Most things are working great, including really useful features I have
 barely tested before, such as the filtering (awesome), editing multiple
 dives at once, and location management.

I'm glad you are finding things you enjoy. Subsurface is quite feature
rich already, and more things are under way.

 I have a couple of annoyances with the Marble behaviour.
 Firstly, it keeps zooming out when I right-click to edit the location of a
 site that doesn't yet have coordinates.

Yes, picking a GPS location with the globe is currently not really
supported. That's supposed to be done on a different screen that isn't
implemented, yet.

 Secondly, I repeatedly try to use Marble to set coordinates for a dive that
 doesn't have a location set.  It allows me to right-click and select 'edit
 location', but then it won't let me double click to choose a new location.
 I worked out that it's because I haven't yet named the site, which makes
 some sense, but it would be good if there were a message in Marble
 prompting me to name the site first.  Especially because once I work out my
 mistake, it inevitably zooms out to somewhere over Africa, so I have to
 zoom and pan to find my way back to whatever little site I'd carefully
 zoomed to previously in Australia/Asia/New Zealand.

As I said, this isn't supposed to work right now. I should have removed
the right click menu with the edit button...

 But the real problem is I'm getting crashes as seemingly random intervals.

Indeed, that is a real problem. And we are having a hell of a time
tracking some of them down.

 It seems to happen when I'm either selecting a different site from the
 list, merging dives, or editing multiple dives.  Most of the time it
 doesn't crash, so it's hard to repeat.  Backtrace (copied below in full)
 and memory map (first few lines copied) are helpfully printed to the
 command terminal.  It doesn't mean much to me, but it hopefully it does to
 someone.

The crashes are caused by memory corruptions (somewhere we are writing to
the wrong locations) that are painfully hard to track down. Your stack
trace shows that you are running a release build of Subsurface, which
makes things even harder to debug as it doesn't give line numners in the
stack trace...

 [rick@localhost build]$ ./subsurface
 Map theme file does not exist: 
 QInotifyFileSystemWatcherEngine::addPaths: inotify_add_watch failed: No
 such file or directory
 *** Error in `./subsurface': free(): invalid size: 0x034d3e30 ***

Definitely once again a memory corruption

 === Backtrace: =
 /lib64/libc.so.6(+0x77e9d)[0x7fec7ba06e9d]
 /lib64/libc.so.6(+0x7f53c)[0x7fec7ba0e53c]
 /lib64/libc.so.6(cfree+0x4c)[0x7fec7ba12e9c]
 ./subsurface(free_taxonomy+0x45)[0x6ca9df]

So while this is where the bug was triggered, that's not where it
happened. Where it happened is some time earlier when we wrote all over
the wrong part of memory - it just doesn't trigger until we try to free
memory or try to allocate more memory and glibc finally runs into the
corrupted data and crashes.

/D
___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


Re: [PATCH] Use git pull with rebase in build script

2015-07-12 Thread Henrik Brautaset Aronsen

 On 12 Jul 2015, at 15:45, Dirk Hohndel d...@hohndel.org wrote:
 
 Why would you need -rebase for the libgit2 repository, unless you have
 local changes (and I just realize that I need to patch the build script to
 use a later commit there, anyway, as that one still doesn't work with
 proxies).

OK, maybe the rebase in libgit is a bit too eager.

 And since I frequently force push into the Subsurface-testing
 branches of libdc and marble, I'm not sure what benefit -rebase gives you
 there. You usually need to remove those directories and check out fresh
 copies for things to be in a consistent state.

Rebase can actually cope with a force push automatically.  It’s pretty awesome, 
as some would say.  On several occations when the build fails, it’s in the 
middle of a merge in either libdc or (recently) marble.  Then I just go to the 
project in question,  abort the merge, and do a git pull —rebase.  Voila, 
build.sh can continue.  By adding this to the script I don’t have to intervene 
manually.

Henrik



___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


Re: [PATCH] Use git pull with rebase in build script

2015-07-12 Thread Dirk Hohndel
Henrik,

I'll admit that I think of the build script more as a get started, have
all the pieces in place kinda thing. And then assume that people will
simply update the different packages as needed (which in most cases means
not very often).

Why would you need -rebase for the libgit2 repository, unless you have
local changes (and I just realize that I need to patch the build script to
use a later commit there, anyway, as that one still doesn't work with
proxies). And since I frequently force push into the Subsurface-testing
branches of libdc and marble, I'm not sure what benefit -rebase gives you
there. You usually need to remove those directories and check out fresh
copies for things to be in a consistent state.

So can you explain a bit more why you suggest this change?

/D

On Sun, Jul 12, 2015 at 02:42:18PM +0200, subsurf...@henrik.synth.no wrote:
 From: Henrik Brautaset Aronsen subsurf...@henrik.synth.no
 
 Without rebase, the build script would stop because it
 couldn't complete a merge.
 ---
  scripts/build.sh | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
 
 diff --git a/scripts/build.sh b/scripts/build.sh
 index 7b54bea..cb9b4ad 100755
 --- a/scripts/build.sh
 +++ b/scripts/build.sh
 @@ -77,7 +77,7 @@ if [ ! -d libgit2 ] ; then
  fi
  cd libgit2
  # let's build with a recent enough version of master for the latest features
 -git pull origin master
 +git pull --rebase origin master
  if ! git checkout c11daac9de2 ; then
   echo Can't find the right commit in libgit2 - giving up
   exit 1
 @@ -110,7 +110,7 @@ if [ ! -d libdivecomputer ] ; then
   fi
  fi
  cd libdivecomputer
 -git pull
 +git pull --rebase
  if ! git checkout Subsurface-testing ; then
   echo can't check out the Subsurface-testing branch of libdivecomputer 
 -- giving up
   exit 1
 @@ -134,7 +134,7 @@ if [ ! -d marble-source ] ; then
   fi
  fi
  cd marble-source
 -git pull
 +git pull --rebase
  if ! git checkout Subsurface-testing ; then
   echo can't check out the Subsurface-testing branch of marble -- giving 
 up
   exit 1
 -- 
 2.4.1
 
 ___
 subsurface mailing list
 subsurface@subsurface-divelog.org
 http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


[PATCH 05/17] Import a bit more data from Divinglog

2015-07-12 Thread Miika Turkia
Signed-off-by: Miika Turkia miika.tur...@gmail.com
---
 parse-xml.c | 32 +---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/parse-xml.c b/parse-xml.c
index 62eceaa..9d6cb3a 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -2869,14 +2869,40 @@ extern int divinglog_dive(void *param, int columns, 
char **data, char **column)
if (data[6])
cur_dive-dc.duration.seconds = atoi(data[6]) * 60;
 
+   if (data[7])
+   utf8_string(data[7], cur_dive-divemaster);
+
+   if (data[8])
+   cur_dive-airtemp.mkelvin = C_to_mkelvin(atol(data[8]));
+
+   if (data[9])
+   cur_dive-watertemp.mkelvin = C_to_mkelvin(atol(data[9]));
+
+   if (data[10]) {
+   cur_dive-weightsystem[0].weight.grams = atol(data[10]) * 1000;
+   cur_dive-weightsystem[0].description = 
strdup(translate(gettextFromC, unknown));
+   }
+
+   if (data[11])
+   cur_dive-suit = strdup(data[11]);
+
settings_start();
dc_settings_start();
-   cur_settings.dc.model = strdup(Divinglog import);
+
+   if (data[12]) {
+   cur_dive-dc.model = strdup(data[12]);
+   } else {
+   cur_settings.dc.model = strdup(Divinglog import);
+   }
 
dc_settings_end();
settings_end();
 
-   cur_dive-dc.model = strdup(Divinglog import);
+   if (data[12]) {
+   cur_dive-dc.model = strdup(data[12]);
+   } else {
+   cur_dive-dc.model = strdup(Divinglog import);
+   }
dive_end();
 
return SQLITE_OK;
@@ -2890,7 +2916,7 @@ int parse_divinglog_buffer(sqlite3 *handle, const char 
*url, const char *buffer,
char *err = NULL;
target_table = table;
 
-   char get_dives[] = select Number,strftime('%s',Divedate || ' ' || 
ifnull(Entrytime,'00:00')),Country || ' - ' || City || ' - ' || 
Place,Buddy,Comments,Depth,Divetime from Logbook where UUID not in (select UUID 
from DeletedRecords);
+   char get_dives[] = select Number,strftime('%s',Divedate || ' ' || 
ifnull(Entrytime,'00:00')),Country || ' - ' || City || ' - ' || 
Place,Buddy,Comments,Depth,Divetime,Divemaster,Airtemp,Watertemp,Weight,Divesuit,Computer
 from Logbook where UUID not in (select UUID from DeletedRecords);
 
retval = sqlite3_exec(handle, get_dives, divinglog_dive, handle, err);
 
-- 
2.1.4

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


[PATCH 08/17] Divinglog import: RBT warning event added

2015-07-12 Thread Miika Turkia
Signed-off-by: Miika Turkia miika.tur...@gmail.com
---
 parse-xml.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/parse-xml.c b/parse-xml.c
index d651fa2..2750b3f 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -2885,6 +2885,17 @@ extern int divinglog_profile(void *handle, int columns, 
char **data, char **colu
sample_end();
}
 
+   for (i = 0, ptr = data[1]; i * 12  len; ++i) {
+   /* Remaining bottom time warning */
+   if (ptr[6] - '0') {
+   event_start();
+   cur_event.time.seconds = sinterval * i;
+   strcpy(cur_event.name, rbt);
+   event_end();
+   }
+   ptr += 12;
+   }
+
return 0;
 }
 
-- 
2.1.4

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


[PATCH 06/17] Parse depth from Divinglog database

2015-07-12 Thread Miika Turkia
Signed-off-by: Miika Turkia miika.tur...@gmail.com
---
 parse-xml.c | 61 +
 1 file changed, 61 insertions(+)

diff --git a/parse-xml.c b/parse-xml.c
index 9d6cb3a..4e2ead7 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -2843,11 +2843,58 @@ int parse_cobalt_buffer(sqlite3 *handle, const char 
*url, const char *buffer, in
return 0;
 }
 
+extern int divinglog_profile(void *handle, int columns, char **data, char 
**column)
+{
+   int sinterval = 0;
+   unsigned long i, len;
+   char *ptr;
+
+   /* We do not have samples */
+   if (!data[1])
+   return 0;
+
+   if (data[0])
+   sinterval = atoi(data[0]);
+
+   /*
+* Profile
+*
+* DCRASWEE
+* D: Depth (in meter with two decimals)
+* C: Deco (1 = yes, 0 = no)
+* R: RBT (Remaining Bottom Time warning)
+* A: Ascent warning
+* S: Decostop ignored
+* W: Work warning
+* E: Extra info (different for every computer)
+*
+* Example: 00450001
+* 4.5 m, no deco, no RBT warning, ascanding too fast, no decostop 
ignored, no work, no extra info
+*/
+
+   len = strlen(data[1]);
+   for (i = 0, ptr = data[1]; i * 12  len; ++i) {
+   sample_start();
+
+   cur_sample-time.seconds = sinterval * i;
+   ptr[5] = 0;
+   cur_sample-depth.mm = atoi(ptr) * 10;
+
+   ptr += 12;
+   sample_end();
+   }
+
+   return 0;
+}
+
+
 extern int divinglog_dive(void *param, int columns, char **data, char **column)
 {
int retval = 0;
sqlite3 *handle = (sqlite3 *)param;
char *err = NULL;
+   char get_profile_template[] = select ProfileInt,Profile from Logbook 
where Number = %d;
+   char get_buffer[1024];
 
dive_start();
cur_dive-number = atoi(data[0]);
@@ -2903,6 +2950,20 @@ extern int divinglog_dive(void *param, int columns, char 
**data, char **column)
} else {
cur_dive-dc.model = strdup(Divinglog import);
}
+
+   /*
+* Parse Profile - depth and warnings
+* I am assuming that dive number is unique, but if not, then we
+* will have to use ID instead.
+*/
+
+   snprintf(get_buffer, sizeof(get_buffer) - 1, get_profile_template, 
cur_dive-number);
+   retval = sqlite3_exec(handle, get_buffer, divinglog_profile, 0, err);
+   if (retval != SQLITE_OK) {
+   fprintf(stderr, %s, Database query divinglog_profile 
failed.\n);
+   return 1;
+   }
+
dive_end();
 
return SQLITE_OK;
-- 
2.1.4

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


[PATCH 10/17] Divinglog import: Deco stop ignored event added

2015-07-12 Thread Miika Turkia
Signed-off-by: Miika Turkia miika.tur...@gmail.com
---
Do we have a better text for this one than violation?
---
 parse-xml.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/parse-xml.c b/parse-xml.c
index 1aaf8ea..c110481 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -2901,6 +2901,14 @@ extern int divinglog_profile(void *handle, int columns, 
char **data, char **colu
strcpy(cur_event.name, ascent);
event_end();
}
+
+   /* Deco stop ignored */
+   if (ptr[8] - '0') {
+   event_start();
+   cur_event.time.seconds = sinterval * i;
+   strcpy(cur_event.name, violation);
+   event_end();
+   }
ptr += 12;
}
 
-- 
2.1.4

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


[PATCH 01/17] Add .sql extension for import

2015-07-12 Thread Miika Turkia
Generic divelog might come with the .sql extension, thus adding that to
the file filter.

Signed-off-by: Miika Turkia miika.tur...@gmail.com
---
 qt-ui/mainwindow.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp
index 305ddf6..4861ad6 100644
--- a/qt-ui/mainwindow.cpp
+++ b/qt-ui/mainwindow.cpp
@@ -948,6 +948,7 @@ QString MainWindow::filter()
f += Dive log files ( *.ssrf ;
f += *.can *.CAN ;
f += *.db *.DB  ;
+   f += *.sql *.SQL  ;
f += *.dld *.DLD ;
f += *.jlb *.JLB ;
f += *.lvd *.LVD ;
@@ -1532,8 +1533,8 @@ void MainWindow::loadFiles(const QStringList fileNames)
 void MainWindow::on_actionImportDiveLog_triggered()
 {
QStringList fileNames = QFileDialog::getOpenFileNames(this, tr(Open 
dive log file), lastUsedDir(),
-   tr(Dive log files (*.ssrf *.can *.csv *.db *.dld *.jlb *.lvd 
*.sde *.udcf *.uddf *.xml *.txt *.dlf *.apd
-   *.SSRF *.CAN *.CSV *.DB *.DLD *.JLB *.LVD *.SDE *.UDCF 
*.UDDF *.xml *.TXT *.DLF *.APD);;
+   tr(Dive log files (*.ssrf *.can *.csv *.db *.sql *.dld *.jlb 
*.lvd *.sde *.udcf *.uddf *.xml *.txt *.dlf *.apd
+   *.SSRF *.CAN *.CSV *.DB *.SQL *.DLD *.JLB *.LVD *.SDE 
*.UDCF *.UDDF *.xml *.TXT *.DLF *.APD);;
Cochran files (*.can *.CAN);;
CSV files (*.csv *.CSV);;
DiveLog.de files (*.dld *.DLD);;
-- 
2.1.4

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


Re: [PATCH] Use git pull with rebase in build script

2015-07-12 Thread Linus Torvalds
On Sun, Jul 12, 2015 at 7:05 AM, Dirk Hohndel d...@hohndel.org wrote:

 Thanks for the explanation, Henrik. I read a bit through the git-rebase
 manpage and that has not necessarily completely enlightened me on the
 wisdom of this changes.

I suspect it ends up working better in practice, although I do think
it has the chance of being really really horribly broken when you do a
non-fast-forward.

I dunno. The current situation isn't good either. The whole base
things on a branch that does non-fast-forwards model really is
entirely broken.

 Linus
___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


[PATCH 07/17] Divinglog import: in deco?

2015-07-12 Thread Miika Turkia
Signed-off-by: Miika Turkia miika.tur...@gmail.com
---
 parse-xml.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/parse-xml.c b/parse-xml.c
index 4e2ead7..d651fa2 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -2877,6 +2877,7 @@ extern int divinglog_profile(void *handle, int columns, 
char **data, char **colu
sample_start();
 
cur_sample-time.seconds = sinterval * i;
+   cur_sample-in_deco = ptr[5] - '0' ? true : false;
ptr[5] = 0;
cur_sample-depth.mm = atoi(ptr) * 10;
 
-- 
2.1.4

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


[PATCH 03/17] Basic dive info for Divinglog DB import

2015-07-12 Thread Miika Turkia
This parses the basic metadata of a dive when importing Divinglog
database. (Discarding deleted dives is my best guess as I do not have
that in my sample dive.)

Signed-off-by: Miika Turkia miika.tur...@gmail.com
---
 dive.h  |  1 +
 file.c  |  9 +
 parse-xml.c | 59 +++
 3 files changed, 69 insertions(+)

diff --git a/dive.h b/dive.h
index fcc01a8..f53d46f 100644
--- a/dive.h
+++ b/dive.h
@@ -663,6 +663,7 @@ extern int parse_dm4_buffer(sqlite3 *handle, const char 
*url, const char *buf, i
 extern int parse_dm5_buffer(sqlite3 *handle, const char *url, const char *buf, 
int size, struct dive_table *table);
 extern int parse_shearwater_buffer(sqlite3 *handle, const char *url, const 
char *buf, int size, struct dive_table *table);
 extern int parse_cobalt_buffer(sqlite3 *handle, const char *url, const char 
*buf, int size, struct dive_table *table);
+extern int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char 
*buf, int size, struct dive_table *table);
 extern int parse_dlf_buffer(unsigned char *buffer, size_t size);
 
 extern int parse_file(const char *filename);
diff --git a/file.c b/file.c
index 085c333..3bbcace 100644
--- a/file.c
+++ b/file.c
@@ -171,6 +171,7 @@ static int try_to_open_db(const char *filename, struct 
memblock *mem)
char dm5_test[] = select count(*) from sqlite_master where 
type='table' and name='Dive' and sql like '%SampleBlob%';
char shearwater_test[] = select count(*) from sqlite_master where 
type='table' and name='system' and sql like '%dbVersion%';
char cobalt_test[] = select count(*) from sqlite_master where 
type='table' and name='TrackPoints' and sql like '%DepthPressure%';
+   char divinglog_test[] = select count(*) from sqlite_master where 
type='table' and name='DBInfo' and sql like '%PrgName%';
int retval;
 
retval = sqlite3_open(filename, handle);
@@ -212,6 +213,14 @@ static int try_to_open_db(const char *filename, struct 
memblock *mem)
return retval;
}
 
+   /* Testing if DB schema resembles Divinglog database format */
+   retval = sqlite3_exec(handle, divinglog_test, db_test_func, 0, NULL);
+   if (!retval) {
+   retval = parse_divinglog_buffer(handle, filename, mem-buffer, 
mem-size, dive_table);
+   sqlite3_close(handle);
+   return retval;
+   }
+
sqlite3_close(handle);
 
return retval;
diff --git a/parse-xml.c b/parse-xml.c
index 54a9b94..7f00294 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -2843,6 +2843,65 @@ int parse_cobalt_buffer(sqlite3 *handle, const char 
*url, const char *buffer, in
return 0;
 }
 
+extern int divinglog_dive(void *param, int columns, char **data, char **column)
+{
+   int retval = 0;
+   sqlite3 *handle = (sqlite3 *)param;
+   char *err = NULL;
+
+   dive_start();
+   cur_dive-number = atoi(data[0]);
+
+   cur_dive-when = (time_t)(atol(data[1]));
+
+   if (data[2])
+   cur_dive-dive_site_uuid = create_dive_site(data[2]);
+
+   if (data[3])
+   utf8_string(data[3], cur_dive-buddy);
+
+   if (data[4])
+   utf8_string(data[4], cur_dive-notes);
+
+   if (data[5])
+   cur_dive-dc.maxdepth.mm = atoi(data[5]) * 1000;
+
+   if (data[6])
+   cur_dive-dc.duration.seconds = atoi(data[6]) * 60;
+
+   settings_start();
+   dc_settings_start();
+   cur_settings.dc.model = strdup(Divinglog import);
+
+   dc_settings_end();
+   settings_end();
+
+   cur_dive-dc.model = strdup(Divinglog import);
+   dive_end();
+
+   return SQLITE_OK;
+}
+
+
+int parse_divinglog_buffer(sqlite3 *handle, const char *url, const char 
*buffer, int size,
+   struct dive_table *table)
+{
+   int retval;
+   char *err = NULL;
+   target_table = table;
+
+   char get_dives[] = select Number,strftime('%s',Divedate || ' ' || 
Entrytime),Country || ' - ' || City || ' - ' || 
Place,Buddy,Comments,Depth,Divetime from Logbook where UUID not in (select UUID 
from DeletedRecords);
+
+   retval = sqlite3_exec(handle, get_dives, divinglog_dive, handle, err);
+
+   if (retval != SQLITE_OK) {
+   fprintf(stderr, Database query failed '%s'.\n, url);
+   return 1;
+   }
+
+   return 0;
+}
+
 int parse_dlf_buffer(unsigned char *buffer, size_t size)
 {
unsigned char *ptr = buffer;
-- 
2.1.4

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


[PATCH 09/17] Divinglog import: Ascent warning added

2015-07-12 Thread Miika Turkia
Signed-off-by: Miika Turkia miika.tur...@gmail.com
---
 parse-xml.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/parse-xml.c b/parse-xml.c
index 2750b3f..1aaf8ea 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -2893,6 +2893,14 @@ extern int divinglog_profile(void *handle, int columns, 
char **data, char **colu
strcpy(cur_event.name, rbt);
event_end();
}
+
+   /* Ascent warning */
+   if (ptr[7] - '0') {
+   event_start();
+   cur_event.time.seconds = sinterval * i;
+   strcpy(cur_event.name, ascent);
+   event_end();
+   }
ptr += 12;
}
 
-- 
2.1.4

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


[PATCH 14/17] Divinglog import: use dive ID as identifier

2015-07-12 Thread Miika Turkia
Since mapping cylinders requires use of dive ID, we might as well use
the ID to map the profile also.

Signed-off-by: Miika Turkia miika.tur...@gmail.com
---
 parse-xml.c | 10 ++
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/parse-xml.c b/parse-xml.c
index 97e3785..bca7345 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -2985,7 +2985,7 @@ extern int divinglog_dive(void *param, int columns, char 
**data, char **column)
int retval = 0, diveid;
sqlite3 *handle = (sqlite3 *)param;
char *err = NULL;
-   char get_profile_template[] = select ProfileInt,Profile,Profile2 from 
Logbook where Number = %d;
+   char get_profile_template[] = select ProfileInt,Profile,Profile2 from 
Logbook where ID = %d;
char get_cylinder_template[] = select 
TankID,TankSize,PresS,PresE,PresW,O2,He,DblTank from Tank where LogID = %d 
order by TankID;
char get_buffer[1024];
 
@@ -3053,13 +3053,7 @@ extern int divinglog_dive(void *param, int columns, char 
**data, char **column)
cur_dive-dc.model = strdup(Divinglog import);
}
 
-   /*
-* Parse Profile - depth and warnings
-* I am assuming that dive number is unique, but if not, then we
-* will have to use ID instead.
-*/
-
-   snprintf(get_buffer, sizeof(get_buffer) - 1, get_profile_template, 
cur_dive-number);
+   snprintf(get_buffer, sizeof(get_buffer) - 1, get_profile_template, 
diveid);
retval = sqlite3_exec(handle, get_buffer, divinglog_profile, 0, err);
if (retval != SQLITE_OK) {
fprintf(stderr, %s, Database query divinglog_profile 
failed.\n);
-- 
2.1.4

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


[PATCH 12/17] Divinglog import: import temperature graph

2015-07-12 Thread Miika Turkia
Signed-off-by: Miika Turkia miika.tur...@gmail.com
---
 parse-xml.c | 28 +---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/parse-xml.c b/parse-xml.c
index 37f08cc..7d1f312 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -2846,8 +2846,8 @@ int parse_cobalt_buffer(sqlite3 *handle, const char *url, 
const char *buffer, in
 extern int divinglog_profile(void *handle, int columns, char **data, char 
**column)
 {
int sinterval = 0;
-   unsigned long i, len;
-   char *ptr;
+   unsigned long i, len, lenprofile2 = 0;
+   char *ptr, temp[4];
 
/* We do not have samples */
if (!data[1])
@@ -2870,9 +2870,26 @@ extern int divinglog_profile(void *handle, int columns, 
char **data, char **colu
 *
 * Example: 00450001
 * 4.5 m, no deco, no RBT warning, ascanding too fast, no decostop 
ignored, no work, no extra info
+*
+*
+* Profile2
+*
+* TTTIRRR
+*
+* T: Temperature (in °C with one decimal)
+* F: Tank pressure 1 (in bar with one decimal)
+* I: Tank ID (0, 1, 2 ... 9)
+* R: RBT (in min)
+*
+* Example: 25518051099
+* 25.5 °C, 180.5 bar, Tank 1, 99 min RBT
 */
 
len = strlen(data[1]);
+
+   if (data[2])
+   lenprofile2 = strlen(data[2]);
+
for (i = 0, ptr = data[1]; i * 12  len; ++i) {
sample_start();
 
@@ -2881,6 +2898,11 @@ extern int divinglog_profile(void *handle, int columns, 
char **data, char **colu
ptr[5] = 0;
cur_sample-depth.mm = atoi(ptr) * 10;
 
+   if (i * 11  lenprofile2) {
+   memcpy(temp, data[2][i * 11], 3);
+   cur_sample-temperature.mkelvin = 
C_to_mkelvin(atoi(temp) / 10);
+   }
+
ptr += 12;
sample_end();
}
@@ -2929,7 +2951,7 @@ extern int divinglog_dive(void *param, int columns, char 
**data, char **column)
int retval = 0;
sqlite3 *handle = (sqlite3 *)param;
char *err = NULL;
-   char get_profile_template[] = select ProfileInt,Profile from Logbook 
where Number = %d;
+   char get_profile_template[] = select ProfileInt,Profile,Profile2 from 
Logbook where Number = %d;
char get_buffer[1024];
 
dive_start();
-- 
2.1.4

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


[PATCH 13/17] Divinglog import: get cylinder information

2015-07-12 Thread Miika Turkia
Signed-off-by: Miika Turkia miika.tur...@gmail.com
---
 parse-xml.c | 48 ++--
 1 file changed, 46 insertions(+), 2 deletions(-)

diff --git a/parse-xml.c b/parse-xml.c
index 7d1f312..97e3785 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -2843,6 +2843,40 @@ int parse_cobalt_buffer(sqlite3 *handle, const char 
*url, const char *buffer, in
return 0;
 }
 
+extern int divinglog_cylinder(void *handle, int columns, char **data, char 
**column)
+{
+   short dbl = 1;
+   //char get_cylinder_template[] = select 
TankID,TankSize,PresS,PresE,PresW,O2,He,DblTank from Tank where LogID = %d;
+
+   if (data[7]  atoi(data[7])  0)
+   dbl = 2;
+
+   cylinder_start();
+
+   /*
+* Assuming that we have to double the cylinder size, if double
+* is set
+*/
+
+   if (data[1]  atoi(data[1])  0)
+   cur_dive-cylinder[cur_cylinder_index].type.size.mliter = 
atol(data[1]) * 1000 * dbl;
+
+   if (data[2]  atoi(data[2])  0)
+   cur_dive-cylinder[cur_cylinder_index].start.mbar = 
atol(data[2]) * 1000;
+   if (data[3]  atoi(data[3])  0)
+   cur_dive-cylinder[cur_cylinder_index].end.mbar = atol(data[3]) 
* 1000;
+   if (data[4]  atoi(data[4])  0)
+   
cur_dive-cylinder[cur_cylinder_index].type.workingpressure.mbar = 
atol(data[4]) * 1000;
+   if (data[5]  atoi(data[5])  0)
+   cur_dive-cylinder[cur_cylinder_index].gasmix.o2.permille = 
atol(data[5]) * 10;
+   if (data[6]  atoi(data[6])  0)
+   cur_dive-cylinder[cur_cylinder_index].gasmix.he.permille = 
atol(data[6]) * 10;
+
+   cylinder_end();
+
+   return 0;
+}
+
 extern int divinglog_profile(void *handle, int columns, char **data, char 
**column)
 {
int sinterval = 0;
@@ -2948,13 +2982,15 @@ extern int divinglog_profile(void *handle, int columns, 
char **data, char **colu
 
 extern int divinglog_dive(void *param, int columns, char **data, char **column)
 {
-   int retval = 0;
+   int retval = 0, diveid;
sqlite3 *handle = (sqlite3 *)param;
char *err = NULL;
char get_profile_template[] = select ProfileInt,Profile,Profile2 from 
Logbook where Number = %d;
+   char get_cylinder_template[] = select 
TankID,TankSize,PresS,PresE,PresW,O2,He,DblTank from Tank where LogID = %d 
order by TankID;
char get_buffer[1024];
 
dive_start();
+   diveid = atoi(data[13]);
cur_dive-number = atoi(data[0]);
 
cur_dive-when = (time_t)(atol(data[1]));
@@ -3000,6 +3036,14 @@ extern int divinglog_dive(void *param, int columns, char 
**data, char **column)
cur_settings.dc.model = strdup(Divinglog import);
}
 
+   snprintf(get_buffer, sizeof(get_buffer) - 1, get_cylinder_template, 
diveid);
+   retval = sqlite3_exec(handle, get_buffer, divinglog_cylinder, 0, err);
+   if (retval != SQLITE_OK) {
+   fprintf(stderr, %s, Database query divinglog_cylinder 
failed.\n);
+   return 1;
+   }
+
+
dc_settings_end();
settings_end();
 
@@ -3035,7 +3079,7 @@ int parse_divinglog_buffer(sqlite3 *handle, const char 
*url, const char *buffer,
char *err = NULL;
target_table = table;
 
-   char get_dives[] = select Number,strftime('%s',Divedate || ' ' || 
ifnull(Entrytime,'00:00')),Country || ' - ' || City || ' - ' || 
Place,Buddy,Comments,Depth,Divetime,Divemaster,Airtemp,Watertemp,Weight,Divesuit,Computer
 from Logbook where UUID not in (select UUID from DeletedRecords);
+   char get_dives[] = select Number,strftime('%s',Divedate || ' ' || 
ifnull(Entrytime,'00:00')),Country || ' - ' || City || ' - ' || 
Place,Buddy,Comments,Depth,Divetime,Divemaster,Airtemp,Watertemp,Weight,Divesuit,Computer,ID
 from Logbook where UUID not in (select UUID from DeletedRecords);
 
retval = sqlite3_exec(handle, get_dives, divinglog_dive, handle, err);
 
-- 
2.1.4

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


[PATCH 04/17] Support empty time on Divinglog import

2015-07-12 Thread Miika Turkia
Signed-off-by: Miika Turkia miika.tur...@gmail.com
---
 parse-xml.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/parse-xml.c b/parse-xml.c
index 7f00294..62eceaa 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -2890,7 +2890,7 @@ int parse_divinglog_buffer(sqlite3 *handle, const char 
*url, const char *buffer,
char *err = NULL;
target_table = table;
 
-   char get_dives[] = select Number,strftime('%s',Divedate || ' ' || 
Entrytime),Country || ' - ' || City || ' - ' || 
Place,Buddy,Comments,Depth,Divetime from Logbook where UUID not in (select UUID 
from DeletedRecords);
+   char get_dives[] = select Number,strftime('%s',Divedate || ' ' || 
ifnull(Entrytime,'00:00')),Country || ' - ' || City || ' - ' || 
Place,Buddy,Comments,Depth,Divetime from Logbook where UUID not in (select UUID 
from DeletedRecords);
 
retval = sqlite3_exec(handle, get_dives, divinglog_dive, handle, err);
 
-- 
2.1.4

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


[PATCH 16/17] Divinglog import: adding pressure samples

2015-07-12 Thread Miika Turkia
Signed-off-by: Miika Turkia miika.tur...@gmail.com
---
 parse-xml.c | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/parse-xml.c b/parse-xml.c
index 974906e..991b1e9 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -2882,7 +2882,7 @@ extern int divinglog_profile(void *handle, int columns, 
char **data, char **colu
 {
int sinterval = 0;
unsigned long i, len, lenprofile2 = 0;
-   char *ptr, temp[4];
+   char *ptr, temp[4], pres[5];
 
/* We do not have samples */
if (!data[1])
@@ -2938,6 +2938,11 @@ extern int divinglog_profile(void *handle, int columns, 
char **data, char **colu
cur_sample-temperature.mkelvin = 
C_to_mkelvin(atoi(temp) / 10);
}
 
+   if (data[2]) {
+   memcpy(pres, data[2][i * 11 + 3], 4);
+   cur_sample-cylinderpressure.mbar = atoi(pres) * 100;
+   }
+
ptr += 12;
sample_end();
}
-- 
2.1.4

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


[PATCH 17/17] Divinglog import: generate gaschange events

2015-07-12 Thread Miika Turkia
Signed-off-by: Miika Turkia miika.tur...@gmail.com
---
 parse-xml.c | 21 +
 1 file changed, 21 insertions(+)

diff --git a/parse-xml.c b/parse-xml.c
index 991b1e9..fb01d4d 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -2883,6 +2883,7 @@ extern int divinglog_profile(void *handle, int columns, 
char **data, char **colu
int sinterval = 0;
unsigned long i, len, lenprofile2 = 0;
char *ptr, temp[4], pres[5];
+   short oldcyl = -1;
 
/* We do not have samples */
if (!data[1])
@@ -2982,6 +2983,26 @@ extern int divinglog_profile(void *handle, int columns, 
char **data, char **colu
ptr += 12;
}
 
+   for (i = 0; i * 11  lenprofile2; ++i) {
+   short tank = data[2][i * 11 + 7] - '0';
+   if (oldcyl != tank) {
+   struct gasmix *mix = cur_dive-cylinder[tank].gasmix;
+   int o2 = get_o2(mix);
+   int he = get_he(mix);
+
+   event_start();
+   cur_event.time.seconds = sinterval * i;
+   strcpy(cur_event.name, gaschange);
+
+   o2 = (o2 + 5) / 10;
+   he = (he + 5) / 10;
+   cur_event.value = o2 + (he  16);
+
+   event_end();
+   oldcyl = tank;
+   }
+   }
+
return 0;
 }
 
-- 
2.1.4

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


[PATCH 15/17] Divinglog import: grab information for cylinder 0

2015-07-12 Thread Miika Turkia
Cylinder 0 is stored on the Logbook table along with other dive metadata
(not in Tank table).

Signed-off-by: Miika Turkia miika.tur...@gmail.com
---
 parse-xml.c | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/parse-xml.c b/parse-xml.c
index bca7345..974906e 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -23,6 +23,7 @@
 int verbose, quit;
 int metric = 1;
 int last_xml_version = -1;
+int diveid = -1;
 
 static xmlDoc *test_xslt_transforms(xmlDoc *doc, const char **params);
 
@@ -2982,10 +2983,11 @@ extern int divinglog_profile(void *handle, int columns, 
char **data, char **colu
 
 extern int divinglog_dive(void *param, int columns, char **data, char **column)
 {
-   int retval = 0, diveid;
+   int retval = 0;
sqlite3 *handle = (sqlite3 *)param;
char *err = NULL;
char get_profile_template[] = select ProfileInt,Profile,Profile2 from 
Logbook where ID = %d;
+   char get_cylinder0_template[] = select 
0,TankSize,PresS,PresE,PresW,O2,He,DblTank from Logbook where ID = %d;
char get_cylinder_template[] = select 
TankID,TankSize,PresS,PresE,PresW,O2,He,DblTank from Tank where LogID = %d 
order by TankID;
char get_buffer[1024];
 
@@ -3036,6 +3038,13 @@ extern int divinglog_dive(void *param, int columns, char 
**data, char **column)
cur_settings.dc.model = strdup(Divinglog import);
}
 
+   snprintf(get_buffer, sizeof(get_buffer) - 1, get_cylinder0_template, 
diveid);
+   retval = sqlite3_exec(handle, get_buffer, divinglog_cylinder, 0, err);
+   if (retval != SQLITE_OK) {
+   fprintf(stderr, %s, Database query divinglog_cylinder0 
failed.\n);
+   return 1;
+   }
+
snprintf(get_buffer, sizeof(get_buffer) - 1, get_cylinder_template, 
diveid);
retval = sqlite3_exec(handle, get_buffer, divinglog_cylinder, 0, err);
if (retval != SQLITE_OK) {
-- 
2.1.4

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


[PATCH 02/17] Hook up processing of .sql files

2015-07-12 Thread Miika Turkia
---
 file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/file.c b/file.c
index e6b0a3f..085c333 100644
--- a/file.c
+++ b/file.c
@@ -448,7 +448,7 @@ int parse_file(const char *filename)
}
 
fmt = strrchr(filename, '.');
-   if (fmt  (!strcasecmp(fmt + 1, DB) || !strcasecmp(fmt + 1, BAK))) 
{
+   if (fmt  (!strcasecmp(fmt + 1, DB) || !strcasecmp(fmt + 1, BAK) 
|| !strcasecmp(fmt + 1, SQL))) {
if (!try_to_open_db(filename, mem)) {
free(mem.buffer);
return 0;
-- 
2.1.4

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


[PATCH 11/17] Divinglog import: add workload warning

2015-07-12 Thread Miika Turkia
Signed-off-by: Miika Turkia miika.tur...@gmail.com
---
 parse-xml.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/parse-xml.c b/parse-xml.c
index c110481..37f08cc 100644
--- a/parse-xml.c
+++ b/parse-xml.c
@@ -2909,6 +2909,14 @@ extern int divinglog_profile(void *handle, int columns, 
char **data, char **colu
strcpy(cur_event.name, violation);
event_end();
}
+
+   /* Workload warning */
+   if (ptr[9] - '0') {
+   event_start();
+   cur_event.time.seconds = sinterval * i;
+   strcpy(cur_event.name, workload);
+   event_end();
+   }
ptr += 12;
}
 
-- 
2.1.4

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


[PATCH 1/2] OSTCTools - Improve error management

2015-07-12 Thread Salvador Cuñat
- Introduce an exit point to cowardly run away from the file if
something goes wrong (undefined dc family, inconsistent family/model
pair, etc), without crashing subsurface.
- Simplifies (user point of view) and makes translatables the error
messages shown in the status bar.
- Modifies ostc_prepare_data() to emit a return code to manage posible
failures.

Signed-off-by: Salvador Cuñat salvador.cu...@gmail.com
---
 ostctools.c | 31 ++-
 1 file changed, 18 insertions(+), 13 deletions(-)

diff --git a/ostctools.c b/ostctools.c
index 45a21e9..0bb00ee 100644
--- a/ostctools.c
+++ b/ostctools.c
@@ -38,7 +38,7 @@ static dc_descriptor_t *ostc_get_data_descriptor(int 
data_model, dc_family_t dat
 /*
  * Fills a device_data_t structure with known dc data and a descriptor.
  */
-static void ostc_prepare_data(int data_model, dc_family_t dc_fam, 
device_data_t *dev_data)
+static int ostc_prepare_data(int data_model, dc_family_t dc_fam, device_data_t 
*dev_data)
 {
device_data_t *ldc_dat = calloc(1, sizeof(device_data_t));
dc_descriptor_t *data_descriptor;
@@ -53,8 +53,10 @@ static void ostc_prepare_data(int data_model, dc_family_t 
dc_fam, device_data_t
ldc_dat-vendor = copy_string(data_descriptor-vendor);
ldc_dat-model = copy_string(data_descriptor-product);
*dev_data = *ldc_dat;
-   }
+   } else
+   return 0;
free(ldc_dat);
+   return 1;
 }
 
 /*
@@ -71,17 +73,15 @@ void ostctools_import(const char *file, struct dive_table 
*divetable)
char *tmp;
struct dive *ostcdive = alloc_dive();
dc_status_t rc = 0;
-   int model = 0, i = 0;
+   int model, ret, i = 0;
unsigned int serial;
struct extra_data *ptr;
 
// Open the archive
if ((archive = subsurface_fopen(file, rb)) == NULL) {
-   report_error(translate(gettextFromC, Error: couldn't open 
the file));
-   free(devdata);
-   free(buffer);
+   report_error(translate(gettextFromC, Failed to read '%s'), 
file);
free(ostcdive);
-   return;
+   goto out;
}
 
// Read dive number from the log
@@ -124,9 +124,14 @@ void ostctools_import(const char *file, struct dive_table 
*divetable)
dc_fam = DC_FAMILY_NULL;
}
 
-   // Prepare data to pass to libdivecomputer. OSTC protocol doesn't 
include
-   // a model number so will use 0.
-   ostc_prepare_data(model, dc_fam, devdata);
+   // Prepare data to pass to libdivecomputer.
+   ret = ostc_prepare_data(model, dc_fam, devdata);
+   if (ret == 0){
+   report_error(translate(gettextFromC, Unknown DC in dive 
%d), ostcdive-number);
+   free(ostcdive);
+   fclose(archive);
+   goto out;
+   }
tmp = calloc(strlen(devdata-vendor)+strlen(devdata-model)+28,1);
sprintf(tmp, %s %s (Imported from OSTCTools), devdata-vendor, 
devdata-model);
ostcdive-dc.model =  copy_string(tmp);
@@ -135,7 +140,7 @@ void ostctools_import(const char *file, struct dive_table 
*divetable)
// Parse the dive data
rc = libdc_buffer_parser(ostcdive, devdata, buffer, i+1);
if (rc != DC_STATUS_SUCCESS)
-   report_error(Libdc returned error -%s- for dive %d, 
errmsg(rc), ostcdive-number);
+   report_error(translate(gettextFromC,Error - %s - parsing 
dive %d), errmsg(rc), ostcdive-number);
 
// Serial number is not part of the header nor the profile, so libdc 
won't
// catch it. If Serial is part of the extra_data, and set to zero, 
remove
@@ -153,10 +158,10 @@ void ostctools_import(const char *file, struct dive_table 
*divetable)
*ptr = *(ptr)-next;
}
 
-   free(devdata);
-   free(buffer);
record_dive_to_table(ostcdive, divetable);
mark_divelist_changed(true);
sort_table(divetable);
fclose(archive);
+out:   free(devdata);
+   free(buffer);
 }
-- 
2.1.4

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface


[PATCH 2/2] OSTCTools - change management of model and dc family

2015-07-12 Thread Salvador Cuñat
HW introduced some changes in dc's data structures with FROG and OSTC3
families (types 0x22 and 0x23 in HW's terms) that I didn't take into
account as we lacked of .dive files to test.

BTW I previously set the model to 0 as it was not stored in the file
but wasn't relevant for the data parsing in MK2, OSTC and OSTC2N/2C
models.

Thanks to Anton's advice we have got some OSTC3 dives to test, so this
patch takes into account the different data structures for different
families, and try to stablish a model number based on device's serial
number, as libdc does.

Signed-off-by: Salvador Cuñat salvador.cu...@gmail.com
---
 ostctools.c | 50 +-
 1 file changed, 37 insertions(+), 13 deletions(-)

diff --git a/ostctools.c b/ostctools.c
index 0bb00ee..fa7cb65 100644
--- a/ostctools.c
+++ b/ostctools.c
@@ -108,20 +108,44 @@ void ostctools_import(const char *file, struct dive_table 
*divetable)
}
 
// Try to determine the dc family based on the header type
-   switch (buffer[2]) {
-   case 0x20:
-   case 0x21:
+   if (buffer[2] == 0x20 || buffer[2] == 0x21)
dc_fam = DC_FAMILY_HW_OSTC;
-   break;
-   case 0x22:
-   dc_fam = DC_FAMILY_HW_FROG;
-   break;
-   case 0x23:
-   dc_fam = DC_FAMILY_HW_OSTC3;
-   break;
-   default:
-   fprintf(stderr, got unknown dc family %x\n, buffer[2]);
-   dc_fam = DC_FAMILY_NULL;
+   else {
+   switch (buffer[8]) {
+   case 0x22:
+   dc_fam = DC_FAMILY_HW_FROG;
+   break;
+   case 0x23:
+   dc_fam = DC_FAMILY_HW_OSTC3;
+   break;
+   default:
+   report_error(translate(gettextFromC, Unknown 
DC in dive %d), ostcdive-number);
+   free(ostcdive);
+   fclose(archive);
+   goto out;
+   }
+   }
+
+   // Try to determine the model based on serial number
+   switch (dc_fam) {
+   case DC_FAMILY_HW_OSTC:
+   if (serial  7000)
+   model = 3; //2C
+   else if (serial  2048)
+   model = 2; //2N
+   else if (serial  300)
+   model = 1; //MK2
+   else
+   model = 0; //OSTC
+   break;
+   case DC_FAMILY_HW_FROG:
+   model = 0;
+   break;
+   default:
+   if (serial  1)
+   model = 0x12; //Sport
+   else
+   model = 0x0A; //OSTC3
}
 
// Prepare data to pass to libdivecomputer.
-- 
2.1.4

___
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface