summaryrefslogtreecommitdiffstats
path: root/core/file.c
AgeCommit message (Collapse)Author
2019-04-12Cleanup: move parse-function declarations out of "dive.h"Gravatar Berthold Stoeger
Move the declaration of these functions to "file.h" and "parse.h" according to the translation unit they are defined in. Thus, not all users of "dive.h" have to suck in "sqlite3.h". Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Parser: parse into custom dive site tableGravatar Berthold Stoeger
To extend the undo system to dive sites, the importers and downloaders must not parse directly into the global dive site table. Instead, pass a dive_site_table argument to parse into. For now, always pass the global dive_site_table so that this commit should not cause any functional change. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-09Parser: add trip_table parameter to parsing functionsGravatar Berthold Stoeger
To allow parsing into arbitrary trip_tables, add the corresponding parameter to the parsing functions and the parser state. Currently, all callers pass the global trip_table so there should be no change in functionality. These arguments will be replaced in subsequent commits. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-12-29Initial support for Shearwater CloudGravatar Miika Turkia
This works to some extent to part of a sample log I received. However, still quite a bit more work is needed. Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2018-09-28Parser: parse text-based files into arbitrary tableGravatar Berthold Stoeger
In d815e0c9476ef62e6b84fb28ce48ab7cddefe77e a dive_table pointer was added to the parsing functions to allow parsing into tables other than the global dive table. This will be necessary for undo of import and implementation a cleaner interface. A few cases, notably CSV and proprietary formats were forgotten. Implement parsing into arbitrary tables also for these cases. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-23Parse: pass dive_table argument to parse_file()Gravatar Berthold Stoeger
To enable undo of divelog-importing it is crucial that parse_file() can parse into arbitrary dive tables. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-23Cleanup: fix memory leak on failed DLF importGravatar Berthold Stoeger
In the case of a failed dlf import, the memory of the read-in file was not freed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-23Cleanup: fix memory leak in OSTC importGravatar Berthold Stoeger
The OSTC branch forgot to release the memory of the file. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-05-24core: replace (void) with UNUSED(x) and include ssrf.hGravatar jan Iversen
Unused parameters in C are "silenced" by adding UNUSED(x) Signed-off-by: Jan Iversen <jani@apache.org>
2018-05-14Core: introduce new subsurface-string headerGravatar Dirk Hohndel
First small step to shrinking dive.h. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-02-26Cleanup: Unify qthelper.h and qthelperfromc.hGravatar Berthold Stoeger
Since all qt-helpers are defined in qthelper.cpp, there seems to be no reason to have two include files. By unifying the two files, duplication and inconsistencies are removed. The C++-only part is simply compiled away with #ifdefs. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-11Introduce helper function empty_string()Gravatar Berthold Stoeger
There are ca. 50 constructs of the kind same_string(s, "") to test for empty or null strings. Replace them by the new helper function empty_string(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-08Make a few functions of static linkageGravatar Berthold Stoeger
Make functions in core/file.c, core/parse.c and core/import-csv.c that were not used outside their translation unit of static linkage. parse_date is moved from core/file.c to core/import-csv.c, since it is used only there. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-08Refactor CSV importGravatar Miika Turkia
Move CSV import related functions into import-csv.c. Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-12-27Cleanup: avoid dereferencing NULL pointerGravatar Dirk Hohndel
Coverity CID 208330 Coverity CID 208301 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-14Remove function isCloudUrl()Gravatar Berthold Stoeger
The function isCloudUrl() was only called in one place, parse_file(). But, isCloudUrl() could only return true if the filename was of the git-repository kind (url[branch]). In such a case, control flow would never reach the point where isCloudUrl() is called, since is_git_repository() returns non-NULL and the function returns early. Therefore, remove this function. Moreover, adapt the affected if-statement by replacing "str && !strcmp(str, ...)" with the more concise "same_string(str, ...)". Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-09-11Inform user if there was no dive profile in DL7/ZXU fileGravatar Miika Turkia
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-09-11Import dive number from DL7 logGravatar Miika Turkia
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-08-03Fix Poseidon MkVI txt file import sensor pressuresGravatar Linus Torvalds
When I unified the sample pressures in commit 11a0c0cc7018 ("Unify sample pressure and o2pressure as pressure[2] array") I did all the obvious conversions, including the conversion of the Poseidon txt file import: case POSEIDON_PRESSURE: - sample->cylinderpressure.mbar = lrint(val * 1000); + sample->pressure[0].mbar = lrint(val * 1000); break; case POSEIDON_O2CYLINDER: - sample->o2cylinderpressure.mbar = lrint(val * 1000); + sample->pressure[1].mbar = lrint(val * 1000); break; which was ObviouslyCorrect(tm). But as so often is the case, obvious doesn't actually exist. The old "o2cylinderpressure[]" model had an implicit sensor associated with it, and that implicit sensor mapping wasn't obvious, and didn't get fixed. It turns out that the way the Poseidon sensor mapping works, the O2 cylinder is cylinder 0, and the diluent cylinder is cylinder 1, so just use the add_sample_pressure() helper to set both sensor index and pressure value. And since we now do all the sensor indexing right, we can also get rid of some manual cylinder sample pressure code, because the generic dive fixup will just DTRT. It used to screw up because the diluent sensor number was wrong before, and the import code tried to work around that by hand. Reported-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-20Unify sample pressure and o2pressure as pressure[2] arrayGravatar Linus Torvalds
We currently carry two pressures around for all the samples and plot info, but the second pressure is reserved for CCR dives as the O2 cylinder pressure. That's kind of annoying when we *could* use it for regular sidemount dives as the secondary pressure. So start prepping for that instead: don't make it "pressure" and "o2pressure", make it just be an array of two pressure values. NOTE! This is purely mindless prepwork. It literally just does a search-and-replace, keeping the exact same semantics, so "pressure[1]" is still just O2 pressure. But at some future date, we can now start using it for a second sensor value for sidemount instead. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-05-07Merge branch 'seabear-refactor'Gravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-05-07Datatrak import rework: changes of file.c and file.hGravatar Salvador Cuñat
Datatrak import is called from parse_file() in file.c. This function reads the full file to be imported into a memblock structure. It's easier and more secure, to parse this buffer instead of the file itself. These are the necessary changes in function datatrak_import() declaration and call. Signed-off-by: Salvador Cuñat <salvador.cunat@gmail.com>
2017-05-07Fix NDL and TTS for Seabear importGravatar Miika Turkia
Apparently the refactoring changed these values to be returned directly in seconds. Not sure why, but luckily we have test cases that discovered the change. Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-05-07Refactor Seabear importGravatar Miika Turkia
Moving the GUI independent Seabear import functionality to Subsurface core. This will allow Robert to call it directly from download from DC. Tested with H3 against released and daily versions of Subsurface. The result differs somewhat, but it is actually fixing 2 bugs: - Temperature was mis-interpreted previously - Sample interval for a dive with 1 second interval was parsed incorrectly Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2017-04-29Add SPDX header to core C filesGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-03-09Fix potential double/float to int rounding errorsGravatar Jeremie Guichard
Not using lrint(f) when converting double/float to int creates rounding errors. This error was detected by TestParse::testParseDM4 failure on Windows. It was creating rounding inconsistencies on Linux too, see change in TestDiveDM4.xml. Enable -Wfloat-conversion for gcc version greater than 4.9.0 Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2016-11-09Clean up some warnings in file.cGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-11-09Parse multiple dives from single DL7 log fileGravatar Miika Turkia
Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-06-11Remove unused variableGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-05-05NULL terminate the parameters arrayGravatar Miika Turkia
Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-05-05Allow parsing of .txt files on importGravatar Miika Turkia
Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-05-03Parse date and time from on APD importGravatar Miika Turkia
This will parse the date and time information on CSV import if the file name matches the one used by APD log viewer (date and time are available in the file name). Hard coding the year to 20?? is a bit unfortunate, but as there is only 2 digits in the year, we have to invent something. And it would be quite optimistic to assume this will bite us back any time soon :D Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-05-02Print xsltproc command line on verbose modeGravatar Miika Turkia
Printed command line can be used to manually test the import function, allowing faster testing of XSLT changes, and showing debug prints that are discarded by Subsurface. Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-30Fix typoGravatar Dirk Hohndel
Otherwise this code makes no sense (and has no effect). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-30Merge branch 'offlineDefault'Gravatar Dirk Hohndel
2016-04-30Don't pretend that opening git repo succeededGravatar Dirk Hohndel
Not sure why we claimed that this was successful when clearly it wasn't. There's a risk that this could break something on the desktop, but it makes no sense to me why that would be the right thing to do. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-25Parse date and time in DL7 importGravatar Miika Turkia
Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-25Grab the payload of DL7 fileGravatar Miika Turkia
This allows us to parse the DL7 profile data (skipping the header and footer) Signed-off-by: Miika Turkia <miika.turkia@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-05QML UI: don't fetch the remote twice when loadingGravatar Dirk Hohndel
We first check the sha to see if we want to load at all. But at that point we already have the repository and the branch and we have synced with the remote. So when we decide that we need to reload from storage, we don't need to repeat those steps, instead we can go directly to the git load. For that to work we need to pass the repository pointer and the branch name back to the caller so that we can directly call git_load_dives(). Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-05git storage: compare with correct SHA when checking if cache is currentGravatar Dirk Hohndel
Otherwise by the time we make the comparison the saved_git_id has already been updated. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-04Move subsurface-core to core and qt-mobile to mobile-widgetsGravatar Dirk Hohndel
Having subsurface-core as a directory name really messes with autocomplete and is obviously redundant. Simmilarly, qt-mobile caused an autocomplete conflict and also was inconsistent with the desktop-widget name for the directory containing the "other" UI. And while cleaning up the resulting change in the path name for include files, I decided to clean up those even more to make them consistent overall. This could have been handled in more commits, but since this requires a make clean before the build, it seemed more sensible to do it all in one. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>