Commit graph

139 commits

Author SHA1 Message Date
Robert C. Helling
0d7c192e6e For CCR dives, the diluent cylinder is the current cylinder
Change the meaning that _the_ cylinder (as we treat it in OC dives) is the
diluent cylinder (rather than the O2 cylinder). This eliminates special
cases. Now, for CCR, we have to handle the O2 cylinder in addition
(rather than the diluent in addition).

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-17 11:45:06 +00:00
Dirk Hohndel
23304f69c0 Load and save the dc type for CCR dives
Oddly we already had code to load this from XML, but nothing else.
This makes the load from XML work like the rest of our code and adds the
save to XML plus the load and save for the git format.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-16 23:20:39 +00:00
Dirk Hohndel
202c5cbfeb Save CCR cylinder use in XML and git
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-16 22:13:12 +00:00
Dirk Hohndel
d84f76ae14 Revert "Save cylinder pressure from samples"
This reverts commit 763dfef315.

I didn't pay enough attention when accepting this - it saves redundant
data.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-15 09:40:53 -08:00
Miika Turkia
744e14b450 Save the diluent pressures to XML
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-15 06:04:58 -08:00
Miika Turkia
763dfef315 Save cylinder pressure from samples
If start and end cylinder pressure is not explicitly set for secondary
cylinders, we must store the start and end pressures from the
sample_{start,end} attribute. Faulty behavior is obvious at least when
importing Poseidon logs.

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-15 06:04:40 -08:00
Dirk Hohndel
d6b4109409 Load and save extra data in Subsurface XML format
Includes test dive to test missing attributes and the overall syntax.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-11-07 12:59:15 -08:00
Robert C. Helling
5f44fdd9cf Make planner work again for CCR dives
The latest CCR patches had rendered the planner not usable for CCR dives.
This patch corrects this (and reenables the CCR set point column for
segments). The problem was that a new member setpoint of struct divepoint
had been introduced, but there was already po2 which had the same meaning.
This patch merges the two and renames them setpoint to prevent future
confusion.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-19 07:07:07 -07:00
Linus Torvalds
df4e26c875 Start sanitizing gaschange event information
Decode the gasmix data into a sane format when creating the event, and
add the (currently unused) ability to specify a gas change to a
particular cylinder rather than (or in addition to) the gasmix.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-10-12 07:45:37 -04:00
Sergey Starosek
b87a602265 Suppress XML preamble in CSV export
To obey <xsl:output omit-xml-declaration="yes"/> element
one should rely on libxslt to do its job instead of writing
document himself.

Discussion on this subject can be found at
http://comments.gmane.org/gmane.comp.gnome.lib.xslt/3839

Signed-off-by: Sergey Starosek <sergey.starosek@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-16 09:14:27 -07:00
Anton Lundin
6b4dd8d597 Don't trust isspace() unless isascii() approves
We have seen isspace(0xC3) return true on windows so we need to do
something about this.

As a wise man said:
Using "isspace()" and friends on anything but the 0-127 range is just
fraught with danger, regardless of platform.

We remedy this by checking that isascii() says that its a 7-bit ascii
character, something isspace() knows how to handle

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-10 12:44:51 -07:00
Anton Lundin
848a5352c7 Add support divecomputer based TTS
Since earlier have we had support for our own calculated TTS. This adds
support for holding TTS values reported by a dive computer.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-09 13:22:00 -07:00
Dirk Hohndel
f297d9f91e Fix picture loading
Signed vs unsigned comparisons are such a pain. Since we want offsets to
be +/- 30 minutes around the dive we need to allow negative offsets - but
duration_t was defined as uint32_t.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-07-08 12:29:06 -07:00
Dirk Hohndel
a26719c541 Picture handling: switch to stronger typed offset
Also change the on file XML to be even easier to read by making it a
duration as well (which gets us '32:34 min' instead of un-typed seconds).
This is backwards compatible, it will happily read what was written with
the previous commit).

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-09 09:38:50 -07:00
Dirk Hohndel
1604299a5b Picture handling: change data structure to store offset instead timestamp
It makes no sense to store a 64bit time stamp with every picture. Even the
32bit offset (in seconds) from the dive start is WAY overkill. But
switching to that makes the code much more simple in a number of spots.
And makes what is saved to the XML file easier to read, too.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-08 17:17:49 -07:00
Tomaz Canabrava
0b5e1f700d Save the timestamp of the dive.
Save the timestamp of the dive if it exists in the data provided
by the exif library.

[Dirk Hohndel: fixed whitespace and format specifier]

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-08 12:42:22 -07:00
Gehad elrobey
464a611d8d HTML: Better quoting to the export strings
Move the quote function to membuffer.c and adding wrappers that call
it from both xml and html exporters to get rid of redundancy.

Quote the location, buddy, suit, tags and notes This
prevents js code from crashing.

[Miika Turkia: minor whitespace and code fix]

Signed-off-by: Gehad elrobey <gehadelrobey@gmail.com>
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-06 10:08:09 -07:00
Willem Ferguson
eaf6d56487 CCR code: Change to sample structure
1) All the variables in the sample structures are strongly typed
2) Two additional types were declared in units.h:
     o2pressure_t
     bearing_t
3) The following variables were added:
     diluentpressure
     o2setpoint
     o2sensor[3]
4) Changes to a number of files were made to chanf
     sample->po2 to sample->po2.mbar
     bearing to bearring.degrees

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-03 17:05:25 -07:00
Tomaz Canabrava
58f2613dae Add photo saving for the XML backend.
This code correctly saves the added pictures on the xml backend.
next: git backend.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-06-03 16:38:36 -07:00
Anton Lundin
05d9cc409c Migrate code to for_each_dive and for_each_dc
[Dirk Hohndel: this overlapped with my commit 09e7c61fee ("Consistently
	       use for_each_dive (and use it correctly)") so I took the
	       pieces that I had missed]

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-20 11:51:40 +09:00
Anton Lundin
84414baece Rewrite show_location to use membuffer primitives
This simplifies the logic and doesn't rely on show_utf8 to print empty
blocks.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-08 12:25:32 -07:00
Dirk Hohndel
a0a25554a7 Manually implement strndup
Mac and Windows don't appear to have that function, so just implement the
poor man's version by hand.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-07 09:28:26 -07:00
Anton Lundin
ba31a57857 Remove trailing spaces from the produced output
The code found the trailing spaces and just didn't care about it.

This also removes the FIXME quoting, because quoting is managed.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-07 09:21:51 -07:00
Anton Lundin
868827f5ec Qt turns edited locations into null-strings
They aren't null pointers after you touched them, so we can't rely on
that to choose if we should use put_string or show_utf8.
show_utf8 would not print the tag if it only contains a \0 as body.

Fixes #440

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-06 15:35:39 -07:00
Anton Lundin
7c3b68e3ae Terminate the string before relying on strlen
Its a c-string we put, so it must be null-terminated.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-06 15:35:22 -07:00
Anton Lundin
7b0b5d9643 Revert "Save latitude and longitude on XML even if location not set"
This fixes the bug in #440 by accident, and introduces lots of empty
attributes and tags in the xml.

This reverts commit 6378bfd91e.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-05-06 15:35:08 -07:00
Miika Turkia
f6be4ccf22 Add GUI support for exporting in CSV format
This patch adds an item to File menu to export all dives in CSV format.
Naturally this includes also the code to perform the export.

Fixes #434

Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-26 17:20:32 -07:00
Tomaz Canabrava
6378bfd91e Save latitude and longitude on XML even if location not set
This bug don't exists when saving to git storage, only when saving XML.
The latitude and longitude were being discarded if the location name was
not set and this breaks some users workflow. Not nice.

This should fix the final missing part for bug #440

Fixes #440

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-25 07:19:18 -07:00
Tomaz Canabrava
9598462830 Removed the globals 'userid' and 'save_userid_local' variables
This is a preferences setting, it should belong to the preferences
structure.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-17 08:37:31 -07:00
Venkatesh Shukla
3abcde9a2a Add option to save userid in data files
The userid of Subsurface Webservice can be included in locally saved xml
files and git repository.
For xml files, it is stored in userid tag. For git repo, it is stored
in 00-Subsurface file present in the repo.
Preference dialog and webservice dialog modified to include option
for saving userid locally.

In case of difference in default userid and userid in local file,
some semantics are followed. These can be referred to here:
http://lists.hohndel.org/pipermail/subsurface/2014-April/011422.html

Fixes #473

Signed-off-by: Venkatesh Shukla <venkatesh.shukla.eee11@iitbhu.ac.in>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-04-14 09:40:30 -07:00
Dirk Hohndel
781b2e35d4 Revert "If saving to a git repository fails, don't create oddly named XML file"
This reverts commit e70bbb637e

Linus' solution in commit 27c36ec4cf ("Improved handling of git syntax
names with no git repository") is much better and makes my hack
unnecessary.
2014-03-14 21:01:13 -07:00
Dirk Hohndel
e70bbb637e If saving to a git repository fails, don't create oddly named XML file
Before this change when the user gave a git style filename, say
/tmp/mydives[myname], if Subsurface couldn't create a repository with that
branch, it instead saved an XML file to this exact name, with '[' and ']'.
That clearly is not the desired behavior, so report an error instead.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-14 16:01:52 -07:00
Linus Torvalds
76d4e3d916 error handling: return errors for save functions
Note! This just returns the error (and uses "report_error()" to generate
a string that is currently printed to stderr).  Nothing actually *uses*
that error return yet, and we don't show the error string in the GUI.

Baby steps.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-14 10:49:07 -07:00
Linus Torvalds
3fe0019bc2 git object format: make sure parenthood isn't lost when saving
This makes subsurface remember the git source commit of the dive data.

If you save to an existing branch, subsurface will now complain and
refuse to save if you try to save if the existing branch is not related
to the original source.  That would destroy the history of the dive
data, which in turn would make it impossible to do sane merging of the
data.

If you save to a new branch, it will see if the previous parent commit
is known in the repository you are saving to, and will save parenthood
information if so.  Otherwise it will save it as a new parentless commit
("root commit" in git parlance).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-13 20:48:31 -07:00
Linus Torvalds
7902af246c Stop using the "git descriptor file" model
Instead, just encode the git repository information in the filename.

We want to make it much harder to make it match a real filename, but to
still allow easy browsing with the file manager interface.  So the git
repository "filename" format is the path to the git repository
directory, with the branch name encoded as "[branch]" at the end rather
than the "path:branch" format that we used in the descriptor file.

[ For example, on Windows, a filename like "c:\my.xml" could be
  interpreted as the branchame "\my.xml" in the repository in the
  directory "c" ]

In particular, with this model, no filename that ends with ".xml" could
possibly ever be considered a git repository name, since the last
character of a git pathname is always ']'.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-12 19:41:19 -07:00
Linus Torvalds
eb47b2a8d8 Get rid of crazy empty tag_list element at the start
So this is totally unrelated to the git repository format, except for
the fact that I noticed it while writing the git saving code.

The subsurface divetag list handling is being stupid, and has a
initial dummy entry at the head of the list for no good reason.

I say "no good reason", because there *is* a reason for it: it allows
code to avoid the special case of empty list and adding entries to
before the first entry etc etc.  But that reason is a really *bad*
reason, because it's valid only because people don't understand basic
list manipulation and pointers to pointers.

So get rid of the dummy element, and do things right instead - by
passing a *pointer* to the list, instead of the list. And then when
traversing the list and looking for a place to insert things, don't go
to the next entry - just update the "pointer to pointer" to point to
the address of the next entry. Each entry in a C linked list is no
different than the list itself, so you can use the pointer to the
pointer to the next entry as a pointer to the list.

This is a pet peeve of mine. The real beauty of pointers can never be
understood unless you understand the indirection they allow. People
who grew up with Pascal and were corrupted by that mindset are
mentally stunted. Niklaus Wirth has a lot to answer for!

But never fear. You too can overcome that mental limitation, it just
needs some brain exercise. Reading this patch may help. In particular,
contemplate the new "taglist_add_divetag()".

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-10 11:36:17 -07:00
Linus Torvalds
689fe36030 Initial implementation of git save format
This saves the dive data into a git object repository instead of a
single XML file.

We create a git object tree with each dive as a separate file,
hierarchically by trip and date.

NOTE 1: This largely duplicates the XML saving code, because trying to
share it seemed just too painful: the logic is very similar, but the
details of the actual strings end up differing sufficiently that there
are tons of trivial differences.

The git save format is line-based with minimal quoting, while XML quotes
everything with either "<..\>" or using single quotes around attributes.

NOTE 2: You currently need a dummy "file" to save to, which points to
the real save location: the git repository and branch to be used.  We
should make this a config thing, but for testing, do something like
this:

	echo git /home/torvalds/scuba:linus > git-test

to create that git information file, and when you use "Save To" and
specify "git-test" as the file to save to, subsurface will use the new
git save logic to save to the branch "linus" in the repository found at
"/home/torvalds/scuba".

NOTE 3: The git save format uses just the git object directory, it does
*not* check out the result in any git working tree or index.  So after
you do a save, you can do

     git log -p linus

to see what actually happened in that branch, but it will not affect any
actual checked-out state in the repository.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-06 14:52:03 -08:00
Dirk Hohndel
c365103029 Mark ignored error return as intentional
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-05 18:55:42 -08:00
Dirk Hohndel
e80a6822d5 Whitespace cleanup for parse-xml.c and save-xml.c
This is looking really good. Done using our whitespace tool.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-16 15:58:13 -08:00
Dirk Hohndel
6424b162f0 Allow backups for .ssrf files as well
In commit 102bf768944b ("Rename old 'xml' file as 'bak' file when saving")
Linus forgot about our other standard filename extension...

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-16 15:58:13 -08:00
Linus Torvalds
90dddeb4cc Rename old 'xml' file as 'bak' file when saving
If you use the standard naming convention and end your subsurface
filename in ".xml", we will now save away any previous xml file as a
"bak" file before writing a new one.

This can be useful for:

- recovering from mistakes that deleted old dives

- seeing what changed (ie you can do things like "diff -u xyz.bak
  xyz.xml") after doing some operation and saving the result.

However, this does only a single level of backups - if you save twice,
you will obviously have lost the original. I'd strongly encourage some
external backup system in addition to this very simplistic backup.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-16 15:58:02 -08:00
Linus Torvalds
77da20196f Clean up membuffer internal structure names, add strip function
The "size" member was confusing - it's the size of the allocation, not
the size of the current string.  The size of the current string is the
member called "used".

This naming makes perfect sense for the internal implementation, but
it's confusing to users who actually do want to get the size of the
resulting string at the end.

So rename the fields to "alloc" and "len" - which is pretty clear.

This also adds a helper function to strip whitespace from the end:
"strip_mb()".

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-10 07:03:25 -08:00
Linus Torvalds
22f66501ac Add support for heartrate and bearing information in samples
libdivecomputer already supports this, but we didn't save it.

Tested-by: Oscar Isoz <jan.oscar.isoz@gmail.com>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-10 07:03:24 -08:00
Linus Torvalds
96a4fd1bb2 Save XML files into a memory buffer rather than directly into a file
This introduces a "struct membuffer" abstraction that you can write
things into, and makes the XML saving code write to the memory buffer
rather than a file.

The UDDF export already really wanted this: it used to write to a file,
only to then read that file back into memory, delete the file, and then
*rewrite* the file after doing the magic xslt transform.

But the longer-term reason for this is that I want to try to write other
formats, and I want to try to share most helpers.  And those other
formats will need this memory buffer model.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-16 12:51:23 +07:00
Anton Lundin
33391a77e9 Convert the C code to using stdbool and true/false
Earlier we converted the C++ code to using true/false, and this converts
the C code to using the same style.

We already depended on stdbool.h in subsurfacestartup.[ch], and we build
with -std=gnu99 so nobody could build subsurface without a c99 compiler.

[Dirk Hohndel: small change suggested by Thiago Macieira: don't include
               stdbool.h for C++]

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-16 09:34:50 +07:00
Lubomir I. Ivanov
fbff6127ac Files: use the new open() wrappers
Adds use of everything from the new wrappers(), but the
opendir() one.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-19 07:28:21 -08:00
Dirk Hohndel
379fa5f652 Really save airtemp and watertemp in the dive
I thought I had this fixed, but a silly thinko broke my fix.
Only abort the saving if both air AND water temperature are already
covered by the divecomputer(s) in a dive. If at least one of them is
different, then create a divetemperature tag and fill in that value at the
dive level.

Fixes #313

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-06 20:13:12 -08:00
Dirk Hohndel
ff5fa70a88 Editing air or water temperature should modify dive computer, not dive
The dive fields are summary fields, the actual data needs to be in the
divecomputer specific fields.

Fixes #307
2013-11-29 12:05:21 -08:00
Anton Lundin
57fb878b41 Show/save weights up to and including last valid
Previous show and save code would have aborted at the first invalid
weight system. This makes sure we save and show all weight systems up
until and including the last valid.

If we had:
integrated: 1kg
belt: 2kg
ankle: 3kg

And changed belt to 0 kg, we would have only saved integrated 1kg, and
nothing about the belt or the ankle weights. This will save all of them,
and show all of them.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-27 14:13:47 -08:00
Maximilian Güntner
80532a685a Escape all problematic characters when saving a tag
Signed-off-by: Maximilian Güntner <maximilian.guentner@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-15 13:14:23 +09:00