aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Miika Turkia <miika.turkia@gmail.com>2018-01-07 15:33:04 +0200
committerGravatar mturkia <miika.turkia@gmail.com>2018-01-08 06:06:12 +0200
commit5e9e6625d0a9723c0add2ce1a1b6a4386d6f9811 (patch)
tree1052baf60d829b15689877df6df40e35579b913e /core
parentf2beeb40787b9aa1ad6d1b9cdc30a709137e306a (diff)
downloadsubsurface-5e9e6625d0a9723c0add2ce1a1b6a4386d6f9811.tar.gz
Function to look for new line on DL7 import
Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
Diffstat (limited to 'core')
-rw-r--r--core/import-csv.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/core/import-csv.c b/core/import-csv.c
index 7a72ae718..d866fc254 100644
--- a/core/import-csv.c
+++ b/core/import-csv.c
@@ -50,6 +50,23 @@ void add_sample_data(struct sample *sample, enum csv_format type, double val)
}
}
+char *parse_dan_new_line(char *buf, const char *NL)
+{
+ char *iter = buf;
+
+ if (!iter)
+ return NULL;
+
+ iter = strstr(iter, NL);
+ if (iter) {
+ iter += strlen(NL);
+ } else {
+ fprintf(stderr, "DEBUG: No new line found\n");
+ return NULL;
+ }
+ return iter;
+}
+
int parse_dan_format(const char *filename, char **params, int pnr)
{
int ret = 0, i;
@@ -144,10 +161,8 @@ int parse_dan_format(const char *filename, char **params, int pnr)
/* Search for the next line */
if (iter)
- iter = strstr(iter, NL);
- if (iter) {
- iter += strlen(NL);
- } else {
+ iter = parse_dan_new_line(iter, NL);
+ if (!iter) {
fprintf(stderr, "DEBUG: No new line found");
return -1;
}
@@ -169,11 +184,10 @@ int parse_dan_format(const char *filename, char **params, int pnr)
end_ptr += ptr - (char *)mem_csv.buffer;
return report_error(translate("gettextFromC", "No dive profile found from '%s'"), filename);
}
+
if (ptr)
- ptr = strstr(ptr, NL);
- if (ptr) {
- ptr += strlen(NL);
- } else {
+ ptr = parse_dan_new_line(ptr, NL);
+ if (!ptr) {
fprintf(stderr, "DEBUG: Data corrupt");
return -1;
}