aboutsummaryrefslogtreecommitdiffstats
path: root/parse-xml.c
AgeCommit message (Collapse)Author
2014-04-17Removed the globals 'userid' and 'save_userid_local' variablesGravatar Tomaz Canabrava
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-14Add option to save userid in data filesGravatar Venkatesh Shukla
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-03-14Convert other users of showError() to the new world orderGravatar Linus Torvalds
The "report_error()" interface is a lot simpler, although some of the C++ code uses QStrings which make them a bit annoying, especially for the varargs model. Still, even with the explicit conversion to UTF8 and "char *", the report_error() model is much nicer. This also just makes refreshDisplay() do the error reporting in the UI automatically, so a number of error paths don't even have to worry. And the multi-line model of error reporting means that it all automatically does the right thing, and reports errors for each file rather than just for the last file that failed to open. So this removes closer to a hundred lines of cruft, while being a simpler interface and doing better error reporting. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-10Get rid of crazy empty tag_list element at the startGravatar Linus Torvalds
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-09Parse basic trip and dive data from the git blobsGravatar Linus Torvalds
Some things are still missing: samples and events, and cylinder and weightsystem information. But most of the basics are there (although the lack of sample data makes a big visual impact) Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-03-05Another small tweak to whitespace toolGravatar Dirk Hohndel
clang-format doesn't appear to reindent multi line #define statements correctly - so this hopefully will clean those up. The included whitespace corrections to the code should stay in place when using the updated tool. This includes cleaning up some multi-line comments that were messed up the last time around as well as a few other minor changes. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-16Whitespace cleanup for parse-xml.c and save-xml.cGravatar Dirk Hohndel
This is looking really good. Done using our whitespace tool. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-15Remove some unused variablesGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-14Import gas info for Shearwater DesktopGravatar Miika Turkia
Used gas mixes and gas changes are imported. Also po2, ndl, cns and ceiling are added to profile samples. As far as I can tell, the Searwater Desktop shows ceiling in 3 meter (or feet equivalent) steps, but stores in feet (or probably meters). I just use the value reported, no conversion to 3 meter steps. Fixes #432 Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-14Import Shearwater Desktop divelog databaseGravatar Miika Turkia
Sqlite database from Shearwater Desktop log software is imported. Just the basic information like location, buddy, notes and dive profile (depth and temperature). This is tested with a DB in Imperial units, thus metric input might contain errors. Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-14Refactoring sqlite import supportGravatar Miika Turkia
Move the opening of DB connection to occur before DC dependent code. This way we can try to detect log software before calling the DC dependent import function. This prepares for adding support for Shearwater sqlite database. Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-12Use "rint()" instead of rounding manually with "+ 0.5"Gravatar Linus Torvalds
rint() is "round to nearest integer", and does a better job than +0.5 (followed by the implicit truncation inherent in integer casting). We already used 'rint()' for values that could be negative (where +0.5 is actively wrong), let's just make it consistent. Of course, as is usual for the messy C math functions, it depends on the current rounding mode. But the default round-to-nearest is what we want and use, and the functions that explicitly always round to nearest aren't standard enough to worry about. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-10Fix calloc parameter order.Gravatar Boris Barbulovski
* Set correct calloc parameters order(num, size) Signed-off-by: Boris Barbulovski <bbarbulovski@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-10Add support for heartrate and bearing information in samplesGravatar Linus Torvalds
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-09parse-xml.c: Fix a warning about missing bracesGravatar Lubomir I. Ivanov
warning: suggest explicit braces to avoid ambiguous 'else' Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-02-08Check XML attribute to detect correct XSLTGravatar Miika Turkia
Very few dive log files can be identified by the name of the root element in the XML log. As same element names are used between different software, we need to use attributes as well to identify correct XSLT to convert the log to Subsurface format. I would not be surprised if at some point we'll just have to present a dialog to the user and ask which software is in use...but this is enough for now. This also adds the shearwater.xslt to the list. Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-25Hook up XSLT and include it in resourcesGravatar Miika Turkia
XSLT to import manually kept CSV logs is hooked up and included in resources. Fixes #427 Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-21Don't compare floats for equalityGravatar Robert C. Helling
Now that we have a macro to replace float equality testing, we should use it in places where floating point jitter might bite use otherwise. Signed-off-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-17Add Sensus XSLT as a resource and enable itGravatar Miika Turkia
Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-16Whitespace and coding style updatesGravatar Dirk Hohndel
Another futile attempt to cleanup the code and make coding style and whitespace consistent. I tried to add a file that describes the key points of our coding style. I have no illusions that this will help the least bit... This commit should ONLY change whitespace Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-16Convert the C code to using stdbool and true/falseGravatar Anton Lundin
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-10Add a few more Suunto eventsGravatar Miika Turkia
Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-10Import tags from Suunto database fileGravatar Miika Turkia
Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-10Do not plot temperatures on DM4 import if no infoGravatar Miika Turkia
If we do not have temperature readings, we do not want to plot the temperature samples either. See #415 Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-08const'ify our strtod() helper functionsGravatar Linus Torvalds
The C library doesn't use const char pointers for legacy reasons (and because you *can* modify the string the end pointer points to), but let's do it in our internal implementation just because it's a nice guarantee to have. We actually used to have a non-const end pointer and replace a decimal comma with a decimal dot, but that was because we didn't have the fancy "allow commas" flags. So by using our own strtod_flags() function, we can now keep all the strings we parse read-only rather than modify them as we parse them. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2014-01-02Make our 'ascii_strtod()' helper more genericGravatar Linus Torvalds
We'll want to do sane parsing of strings, but the C library makes it hard to handle user input sanely and the Qt toDouble() function interface was designed by a retarded chipmunk. So just extend our existing hacky "ascii_strtod()" to allow a more generic interface. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-20Silence a few warningsGravatar Dirk Hohndel
None of these are actual bugs. But none of the fixes are harmful, either. And much as I hate adding the 'default' clauses, I'd rather not have the build output cluttered by invalid warnings. The exception is the fix in divelistview.cpp - while I don't think it is possible for this function to be called with no dive selected, initializing pd to NULL is cheap insurance in case that does happen for some weird reason. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-19Fix a small coding style issueGravatar Lubomir I. Ivanov
Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-16Remove the xslt_path now that all XSLT files are kept in a resourceGravatar Thiago Macieira
Signed-off-by: Thiago Macieira <thiago@macieira.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-16Move the XSLT files into a Qt resourceGravatar Thiago Macieira
This means we no longer need to keep them on disk and worry about installing / uninstalling them. They will always be kept in-memory (compressed). Signed-off-by: Thiago Macieira <thiago@macieira.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-12Correctly parse multiple tags in the divelogGravatar Dirk Hohndel
The old parsing code overwrote the first comma with a '\0' and then checked the index against the length of the buffer - which was changed by replacing the ',' with the '\0'. This means that since commit 78acf20848c0 ("Don't crash on loading tags longer than 127 chars") Subsurface has potentially damaged / lost data in dive files! Added a test dive that shows the issue if opened by a Subsurface version after the commit mentioned above but before this commit. Reported-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-11Fix some whitespace damageGravatar Anton Lundin
Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-11Don't crash on loading tags longer than 127 charsGravatar Anton Lundin
We didn't enforce a limit on tag length, but we would crash on a tag longer than 127 chars. This uses the xml buffer as scratch space. Don't really know if this is fair, but it looks like it works. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-12-11Plug memory leak in duration()Gravatar Anton Lundin
Strdup should be followed by a free()... Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-28Quiet down valgrind warningsGravatar Linus Torvalds
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-27Remove some constants and use helpers insteadGravatar Anton Lundin
We have allot of helpers, use them instead of local variants. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-22Don't parse 32bit hex values with strtolGravatar Dirk Hohndel
On a 32bit machine this will truncate values with MSB set to 0x7fffffff Fixes #164 (thanks to Linus for pointing me in the right direction) Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-20Use the get_o2/get_he helpersGravatar Anton Lundin
We have helpers that take care of O2_IN_AIR and so on. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-02Speed up XML loadingGravatar Linus Torvalds
This tries to speed up XML loading for large XML files (and thus subsurface startup times) by trimming the fat off our own matching code. The actual libxml overhead (particularly string allocation) tends to be the dominant part, so this only speeds up a big load by about 12% for me, but hey, it can be noticeable. Dirk's example nasty 175MB xml file with ~5200 dives takes "only' 7.7 seconds to load, when it used to take 8.8s. And that's on a fast machine. For smaller xml files, the dynamic loading costs etc startup costs tend to be big enough that the xml parsing costs aren't as noticeable. Aside from switching the node names around to "little endian" (ie least significant name first) format to avoid some unnecessary strlen() calls, this makes the nodename generation use a non-locale 'tolower()', and only decodes up to two levels of names (since that's the maximum we ever match against anyway). It also introduces a "-q" argument to make startup timing easier. Passing in "-q" just makes subsurface quit imediately after doing all necessary startup code. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-11-02Replaced the tag implementationGravatar Maximilian Güntner
The new implementation supports custom tags which are provided by the user as well as default tags which are provided by subsurface. Default tags can be translated and will be written to XML in their non-localized form. Signed-off-by: Maximilian Güntner <maximilian.guentner@gmail.com>
2013-10-20Get rid of compiler warning on format stringsGravatar Miika Turkia
This gets rid of compiler warnings "format not a string literal and no format arguments [-Wformat-security]". E.g. when building distribution packages these warnings are often treated as errors preventing the build (with good reason). Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2013-10-16GUI for CSV importGravatar Miika Turkia
This patch implements GUI for importing CSV log files. One is able to configure what columns contain time, depth and temperature fields. Pre-configured log applications currently included are ADP log viewer and XP5. (Both of these use actually tab as separator, so the field separator currently hard-coded.) [Dirk Hohndel: minor fixes] Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-09Next step towards working translationsGravatar Dirk Hohndel
This may seem like a really odd change - but with this change the Qt tools can correctly parse the C files (and qt-gui.cpp) and get the context for the translatable strings right. It's not super-pretty (I'll admit that _("string literal") is much easier on the eye than translate("gettextFromC", "string literal") ) but I think this will be the price of success. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-07Allow passing NULL as second argument to ascii_strtodGravatar Dirk Hohndel
We do this in our own sources... Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-07ascii_strtod that actually does what we needGravatar Linus Torvalds
Dirk's ascii_strtod was blindly copied from other GPL code and didn't do what was the main purpose (i.e. ignore the locale and still accept the numbers we have in our data files). This implementation does *not* care about INF/NaN, and it does *not* try to handle some strange conditions (overflow/underflow), and I do *not* guarantee that it doesn't have rounding issues. That said, for our native format, we never print odd FP numbers anyway (since we use fixed-point integer arithmetic), and while we *do* care about exponents for some of the odder import formats (I remember seeing them in jdivelog output), we don't care about the crazy cases. So rather than worry about getting the edge cases right for the max double exponents (around +-308), it just says "screw you" and gives you something close enough. So what it *does* try to do is handle the actual parsing right, and get the right answer for all the reasonable cases. Works-For-Me(tm). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-06Trying to switch to Qt translationGravatar Dirk Hohndel
This compiles and looks about right, but it doesn't appear to work, yet. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-06First steps towards removing glib dependenciesGravatar Dirk Hohndel
- remove the build flags and libraries from the Makefile / Configure.mk - remove the glib types (gboolean, gchar, gint64, gint) - comment out / hack around gettext - replace the glib file helper functions - replace g_ascii_strtod - replace g_build_filename - use environment variables instead of g_get_home_dir() & g_get_user_name() - comment out GPS string parsing (uses glib utf8 macros) This needs massive cleanup, but it's a snapshot of what I have right now, in case people want to look at it. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-04Use helper function to find xslt folderGravatar Dirk Hohndel
This seems much better than the different hard coded and semi-hard coded paths we had before. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-10-02Initial code to import CSV log filesGravatar Miika Turkia
This patch implements basic functionality to import CSV formatted log profiles to Subsurface. The import includes time, depth and temperature from AP Logviewer based on one sample log file I have received. It is assumed that dive time is the first parameter and depth second. Temperature is given as a parameter from C source (hard coded currently to field 15) but we should have a GUI implemented for selecting the wanted fields. The two different sample logs of CSV dive log export I have received use tabulator as field separator. I assume the possible GUI should have option for the FS as well to be given as parameter to the XSLT. [Dirk Hohndel: small fix to the error string malloc] Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2013-09-19Identify below floor event type properly.Gravatar Michael Andreen
This event is on when accumulating deco time. Once you reach the floor deco time will start decreasing and the event will stop. Going below the floor again will re-activate the event. Also identify event type 13 in DM4 imports as airtime. Signed-off-by: Michael Andreen <harv@ruin.nu> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>