static void parse_rte_info(const char *buff, route_head *route) /* "R" */ { char *c; int col = -1; c = csv_lineparse(buff, ",", "", col++); while (c != NULL) { c = lrtrim(c); if (*c != '\0') { #if 0 printf(MYNAME "_read_rte_info: col(%d)=%s\n", col, c); #endif switch(col) { case 0: break; /* unknown field (colour?) */ case 1: route->rte_name = xstrdup(c); break; case 2: break; /* unknown field */ } } c = csv_lineparse(NULL, ",", "", col++); } }
static void garmin_txt_read(void) { char *buff; current_line = 0; while ((buff = gbfgetstr(fin))) { char *cin; if ((current_line++ == 0) && fin->unicode) cet_convert_init(CET_CHARSET_UTF8, 1); cin = lrtrim(buff); if (*cin == '\0') continue; cin = csv_lineparse(cin, "\t", "", 0); if (cin == NULL) continue; if (case_ignore_strcmp(cin, "Header") == 0) parse_header(); else if (case_ignore_strcmp(cin, "Grid") == 0) parse_grid(); else if (case_ignore_strcmp(cin, "Datum") == 0) parse_datum(); else if (case_ignore_strcmp(cin, "Waypoint") == 0) parse_waypoint(); else if (case_ignore_strcmp(cin, "Route Waypoint") == 0) parse_route_waypoint(); else if (case_ignore_strcmp(cin, "Trackpoint") == 0) parse_track_waypoint(); else if (case_ignore_strcmp(cin, "Route") == 0) parse_route_header(); else if (case_ignore_strcmp(cin, "Track") == 0) parse_track_header(); else if (case_ignore_strcmp(cin, "Map") == 0) /* do nothing */ ; else fatal(MYNAME ": Unknwon identifier (%s) at line %d!\n", cin, current_line); /* flush pending data */ while (csv_lineparse(NULL, "\t", "", 0)); } }
static waypoint * parse_trkpt(char *buff) { int col = -1; char *c; struct tm tm; waypoint *wpt = waypt_new(); c = strstr(buff, "A "); if (c == buff) col++; memset(&tm, 0, sizeof(tm)); c = csv_lineparse(buff, " ", "", col++); while (c != NULL) { c = lrtrim(c); if (*c != '\0') { #if 0 printf(MYNAME "_read_trkpt: col(%d)=%s\n", col, c); #endif switch(col) { case 2: human_to_dec(c, &wpt->latitude, NULL, 1); break; case 3: human_to_dec(c, NULL, &wpt->longitude, 2); break; case 4: compegps_parse_date(c, &tm); break; case 5: compegps_parse_time(c, &tm); wpt->creation_time = mkgmtime(&tm); break; case 7: wpt->altitude = atof(c); break; } } c = csv_lineparse(NULL, " ", "", col++); } fix_datum(&wpt->latitude, &wpt->longitude); return wpt; }
static void parse_datum(void) { char *str = csv_lineparse(NULL, "\t", "", 1); if (str != NULL) datum_index = gt_lookup_datum_index(str, MYNAME); else fatal(MYNAME ": Missing GPS datum headline!\n"); }
static void parse_wpt_info(const char *buff, waypoint *wpt) /* "w" */ { char *c; int col = -1; double fx; c = csv_lineparse(buff, ",", "", col++); while (c != NULL) { c = lrtrim(c); if (*c != '\0') { #if 0 printf(MYNAME "_read_wpt_info: col(%d)=%s\n", col, c); #endif switch(col) { case 0: wpt->icon_descr = xstrdup(c); wpt->wpt_flags.icon_descr_is_dynamic = 1; break; case 1: break; /* Text postion */ case 2: break; /* Lens zoom level */ case 3: break; /* Text colour */ case 4: break; /* Background colour */ case 5: break; /* Transparent text (0=transparent, 1=no transparent) */ case 6: break; /* ??? */ case 7: break; /* ??? */ case 8: /* radius */ fx = atof(c); if (fx > 0) WAYPT_SET(wpt, proximity, fx); break; } } c = csv_lineparse(NULL, ",", "", col++); } }
static void parse_grid(void) { char *str = csv_lineparse(NULL, "\t", "", 1); if (str != NULL) { if (strstr(str, "dd.ddddd") != 0) grid_index = grid_lat_lon_ddd; else if (strstr(str, "mm.mmm") != 0) grid_index = grid_lat_lon_dmm; else if (strstr(str, "mm'ss.s") != 0) grid_index = grid_lat_lon_dms; else grid_index = gt_lookup_grid_type(str, MYNAME); } else fatal(MYNAME ": Missing grid headline!\n"); }
static void parse_header(void) { char *str; int column = -1; free_header(unknown_header); while ((str = csv_lineparse(NULL, "\t", "", column++))) { header_lines[unknown_header][column] = strupper(xstrdup(str)); header_ct[unknown_header]++; if (header_ct[unknown_header] >= MAX_HEADER_FIELDS) break; } }
static void parse_track_waypoint(void) { char *str; int column = -1; waypoint *wpt; bind_fields(trkpt_header); wpt = waypt_new(); while ((str = csv_lineparse(NULL, "\t", "", column++))) { int field_no; double x; if (! *str) continue; field_no = header_fields[trkpt_header][column]; switch(field_no) { case 1: parse_coordinates(str, datum_index, grid_index, &wpt->latitude, &wpt->longitude, MYNAME); break; case 2: parse_date_and_time(str, &wpt->creation_time); break; case 3: if (parse_distance(str, &x, 1, MYNAME)) wpt->altitude = x; break; case 4: if (parse_distance(str, &x, 1, MYNAME)) WAYPT_SET(wpt, depth, x); break; case 5: if (parse_temperature(str, &x)) WAYPT_SET(wpt, temperature, x); break; case 8: if (parse_speed(str, &x, 1, MYNAME)) WAYPT_SET(wpt, speed, x); break; case 9: WAYPT_SET(wpt, course, atoi(str)); break; } } track_add_wpt(current_trk, wpt); }
static void parse_track_header(void) { char *str; int column = -1; route_head *trk; bind_fields(track_header); trk = route_head_alloc(); while ((str = csv_lineparse(NULL, "\t", "", column++))) { int field_no = header_fields[track_header][column]; switch(field_no) { case 1: trk->rte_name = DUPSTR(str); break; case 6: trk->rte_url = DUPSTR(str); break; } } track_add_head(trk); current_trk = trk; }
static void parse_route_waypoint(void) { char *str; int column = -1; waypoint *wpt = NULL; bind_fields(rtept_header); while ((str = csv_lineparse(NULL, "\t", "", column++))) { int field_no = header_fields[rtept_header][column]; switch(field_no) { case 1: is_fatal((*str == '\0'), MYNAME ": Route waypoint without name at line %d!\n", current_line); wpt = find_waypt_by_name(str); is_fatal((wpt == NULL), MYNAME ": Route waypoint \"%s\" not in waypoint list (line %d)!\n", str, current_line); wpt = waypt_dupe(wpt); break; } } if (wpt != NULL) route_add_wpt(current_rte, wpt); }
static void parse_route_header(void) { char *str; int column = -1; route_head *rte; rte = route_head_alloc(); bind_fields(route_header); while ((str = csv_lineparse(NULL, "\t", "", column++))) { int field_no = header_fields[route_header][column]; switch(field_no) { case 1: rte->rte_name = DUPSTR(str); break; case 5: rte->rte_url = DUPSTR(str); break; } } route_add_head(rte); current_rte = rte; }
static void gopal_read(void) { char *buff; char *str, *c; int column; long line; double hmsd,speed; int fix, hms; route_head *route; waypoint *wpt, *lastwpt=NULL; double long_old,lat_old; char tbuffer[64]; long_old=0;lat_old=0; strftime(routename,sizeof(routename),"Tracklog %c",localtime(&tx)); route = route_head_alloc(); route->rte_name=xstrdup(routename); route_add_head(route); line=0; while ((buff = gbfgetstr(fin))) { if ((line == 0) && fin->unicode) cet_convert_init(CET_CHARSET_UTF8, 1); str = buff = lrtrim(buff); if (*buff == '\0') continue; if (gopal_check_line(buff)!=8)continue; wpt = waypt_new(); column = -1; // the format of gopal is quite simple. Unfortunately the developers forgot the date as the first element... //TICK; TIME; LONG; LAT; HEIGHT; SPEED; Fix; HDOP; SAT //3801444, 080558, 2.944362, 43.262117, 295.28, 0.12964, 2, 2.900000, 3 c = csv_lineparse(str, ",", "", column++); while (c != NULL) { switch(column) { case 0: /* "-" */ /* unknown fields for the moment */ //sscanf(c, "%llu", &wpt->microseconds); break; case 1: /* Time UTC */ sscanf(c,"%lf",&hmsd); hms = (int) hmsd; tm.tm_sec = hms % 100; hms = hms / 100; tm.tm_min = hms % 100; hms = hms / 100; tm.tm_hour = hms % 100; tm.tm_year=trackdate.tm_year; tm.tm_mon=trackdate.tm_mon; tm.tm_mday=trackdate.tm_mday; wpt->creation_time = tx+((((time_t)tm.tm_hour * 60) + tm.tm_min) * 60) + tm.tm_sec; if (global_opts.debug_level > 1){ strftime(tbuffer, sizeof(tbuffer), "%c", gmtime(&wpt->creation_time)); printf("parsed timestamp: %s\n",tbuffer); } break; case 2: /* longitude */ sscanf(c, "%lf", &wpt->longitude); break; case 3: /* latitude */ sscanf(c, "%lf", &wpt->latitude); break; case 4: /* altitude */ sscanf(c, "%lf", &wpt->altitude); break; case 5: /* speed */ //sscanf(c, "%lf", &wpt->speed); wpt->speed=atof(c); if (global_opts.debug_level > 1){ printf("parsed speed: %8.5f\n",wpt->speed); } break; case 6: /* type of fix */ sscanf(c, "%d", &fix); //my device shows only 0 or 2 //should i guess from no of sats if 2d or 3d? switch (fix) { case 0: wpt->fix = fix_none;break; case 2: wpt->fix = fix_2d;break; //case 3: wpt->fix = fix_3d;break; //case 4: wpt->fix = fix_dgps;break; /* 2D_diff */ //case 5: wpt->fix = fix_dgps;break; /* 3D_diff */ default: wpt->fix = fix_unknown; break; } break; case 7: /* hdop */ wpt->hdop = atof(c); //sscanf(c, "%lf", &wpt->hdop); does not work ??? //wpt->vdop=0;wpt->hdop=0; break; case 8: /* number of sats */ sscanf(c, "%d", &wpt->sat); break; } c = csv_lineparse(NULL, ",", "", column++); } line++; if ((wpt->fix != fix_none)&&(lat_old==0)){ //first-time init lat_old=wpt->latitude; long_old=wpt->longitude; //route_add_wpt(route, wpt); lastwpt=wpt; } //calculate the speed to reach this waypoint from the last. This way I try to sort out invalid waypoints speed=0; if (lastwpt !=NULL) { speed=3.6*radtometers(gcdist(RAD(lastwpt->latitude), RAD(lastwpt->longitude), RAD(wpt->latitude), RAD(wpt->longitude))) / abs(wpt->creation_time - lastwpt->creation_time); //printf("speed line %d %lf \n",line,speed); } /* Error handling: in the tracklog of my device sometimes "jump" waypoints ;-) */ if ((optclean) && (((wpt->longitude==0.0)|| (wpt->latitude==0.0)||(abs(wpt->latitude)>90)||(abs(wpt->longitude)>180))|| ((speed>maxspeed)||(speed<minspeed))) ) { if (global_opts.debug_level > 1) fprintf(stderr,"Problem in or around line %5lu: \"%s\" %lf km/h\n",line,buff,speed); } else { if (global_opts.debug_level > 1) fprintf(stderr,"valid line %5lu: \"%s\" %lf km/h\n",line,buff,speed); lastwpt=wpt; long_old=wpt->longitude; lat_old=wpt->latitude; route_add_wpt(route,wpt); waypt_add(waypt_dupe( wpt)); } } }
static waypoint* parse_wpt(char *buff) { int col = -1; char *c, *cx; waypoint *wpt = waypt_new(); struct tm tm; memset(&tm, 0, sizeof(tm)); int has_time = 0; c = strstr(buff, "A "); if (c == buff) col++; c = csv_lineparse(buff, " ", "", col++); while (c != NULL) { c = lrtrim(c); if (*c != '\0') { #if 0 printf(MYNAME "_read_wpt: col(%d)=%s\n", col, c); #endif switch(col) { case 0: cx = c + strlen(c) - 1; /* trim trailing underscores */ while ((cx >= c) && (*cx == '_')) *cx-- = '\0'; if (*c != '\0') wpt->shortname = xstrdup(c); break; case 2: human_to_dec(c, &wpt->latitude, NULL, 1); break; case 3: human_to_dec(c, NULL, &wpt->longitude, 2); break; // Older compegps used a dumb constant. // Report are that 2010-era writes a sensible // value here. /* always "27-MAR-62 00:00:00" */ case 4: if (strcmp(c, "27-MAR-62")) { has_time = 1; compegps_parse_date(c, &tm); } break; case 5: if (has_time) { compegps_parse_time(c, &tm); wpt->creation_time = mkgmtime(&tm); } case 6: wpt->altitude = atof(c); break; case 7: wpt->description = xstrdup(c); break; default: if (col > 7) { wpt->description = xstrappend(wpt->description, " "); wpt->description = xstrappend(wpt->description, c); } } } c = csv_lineparse(NULL, " ", "", col++); } fix_datum(&wpt->latitude, &wpt->longitude); return wpt; }
static int ppdb_read_wpt(route_head *head, int isRoute) { char *data, *str; double altfeet; struct tm tm; while (pdb_read_rec(file_in, NULL, NULL, NULL, (void *)&data) >= 0) { waypoint *wpt_tmp = waypt_new(); int line = 0; char *tmp = data; /* Print the whole input record. All input records are printed before processing. */ if (global_opts.debug_level >= 5) { DBG(("\n\ --- BEGIN Input data record -----------------------------------------------\n\ %s\n\ --- END Input data record -------------------------------------------------\n",data)); } while ((str = csv_lineparse(tmp, ",", "\"", line++))) { tmp = NULL; switch(line) { case 1: /* latitude */ wpt_tmp->latitude = ppdb_decode_coord(str); break; case 2: /* longitude */ wpt_tmp->longitude = ppdb_decode_coord(str); break; case 3: /* altitude */ if (*str != '\0') { CHECK_INP(1, sscanf(str, "%lf", &altfeet), "altitude", str); if (altfeet != -9999) wpt_tmp->altitude = FEET_TO_METERS(altfeet); } break; case 4: /* time and date (optional) */ memset(&tm, 0, sizeof(tm)); if (ppdb_decode_tm(str, &tm)) { tm.tm_year -= 1900; tm.tm_mon--; wpt_tmp->creation_time = mkgmtime(&tm); } break; case 5: /* name */ if (*str != '\0') wpt_tmp->shortname = xstrdup(str); break; case 6: /* icon */ if (*str != '\0') wpt_tmp->icon_descr = xstrdup(str); wpt_tmp->wpt_flags.icon_descr_is_dynamic = 1; break; case 7: /* notes */ if (*str != '\0') wpt_tmp->notes = xstrdup(str); break; } } /* Print the whole input record, should a warning be triggered. * Use warning() here instead of DBG() to print the data record * right after the warning is issued. */ if (warn_ && (global_opts.debug_level > 1) && (global_opts.debug_level < 5)) { warning("Faulty input data record : %s\n",data); warn_ = 0; } if (head && isRoute ) route_add_wpt(head, wpt_tmp); else if (head) track_add_wpt(head, wpt_tmp); else waypt_add(wpt_tmp); }
static void data_read(void) { char *buff; char *s; char *holder; waypoint *wpt_tmp; int i; int linecount = 0; while ((buff = gbfgetstr(file_in))) { if ((linecount++ == 0) && file_in->unicode) cet_convert_init(CET_CHARSET_UTF8, 1); /* skip the line if it contains "sHyperLink" as it is a header (I hope :) */ if ((strlen(buff)) && (strstr(buff, "sHyperLink") == NULL)) { wpt_tmp = waypt_new(); /* data delimited by tabs, not enclosed in quotes. */ s = buff; s = csv_lineparse(s, "\t", "", linecount); i = 0; while (s) { switch (i) { /* Group sID sDescription fLat fLong fEasting fNorthing fAlt iColour iSymbol sHyperLink */ /* 0 1 2 3 4 5 6 7 8 9 10 */ case 0: /* ignore: group */ break; case 1: wpt_tmp->shortname = csv_stringtrim(s, "", 0); break; case 2: /* Description is not a TopoMapPro format requirement. If we assign "" then .loc/.gpx will generate empty XML tags :( */ holder = csv_stringtrim(s, "", 0); if (strlen(holder)) wpt_tmp->description = holder; else xfree(holder); break; case 3: wpt_tmp->latitude = atof(s); break; case 4: wpt_tmp->longitude = atof(s); break; case 5: /* ignore: NZMapGrid Easting */ break; case 6: /* ignore: NZMapGrid Northing */ break; case 7: wpt_tmp->altitude = atof(s); break; case 8: /* ignore: color */ break; case 9: /* ignore: symbol (non standard) */ break; case 10: /* URL is not a TopoMapPro format requirement. You can store file links etc, we will discard anything that is not http (as URLs in TMPro must start "http:") as other GPS formats probably can't use the TopoMapLinks links. (plus discards length 0 strings (so no empty XML tags)) */ holder = csv_stringtrim(s, "", 0); if (strstr(holder, "http:") != NULL) wpt_tmp->url = holder; else xfree(holder); break; default: /* whoa! nelly */ warning(MYNAME ": Warning: data fields on line %d exceed specification.\n", linecount); break; } i++; s = csv_lineparse(NULL, "\t", "\"", linecount); } if (i != 11) { xfree(wpt_tmp); warning(MYNAME ": WARNING - extracted %d fields from line %d. \nData on line ignored.\n", i, linecount); } else { waypt_add(wpt_tmp); } } else { /* empty line */ } } }
static void parse_waypoint(void) { char *str; int column = -1; waypoint *wpt; garmin_fs_p gmsd = NULL; bind_fields(waypt_header); wpt = waypt_new(); gmsd = garmin_fs_alloc(-1); fs_chain_add(&wpt->fs, (format_specific_data *) gmsd); while ((str = csv_lineparse(NULL, "\t", "", column++))) { int i, dynamic; double d; int field_no = header_fields[waypt_header][column]; switch(field_no) { case 1: wpt->shortname = DUPSTR(str); break; case 2: wpt->notes = DUPSTR(str); break; case 3: for (i = 0; i <= gt_waypt_class_map_line; i++) { if (case_ignore_strcmp(str, gt_waypt_class_names[i]) == 0) { GMSD_SET(wpt_class, i); break; } } break; case 4: parse_coordinates(str, datum_index, grid_index, &wpt->latitude, &wpt->longitude, MYNAME); break; case 5: if (parse_distance(str, &d, 1, MYNAME)) wpt->altitude = d; break; case 6: if (parse_distance(str, &d, 1, MYNAME)) WAYPT_SET(wpt, depth, d); break; case 7: if (parse_distance(str, &d, 1, MYNAME)) WAYPT_SET(wpt, proximity, d); break; case 8: if (parse_temperature(str, &d)) WAYPT_SET(wpt, temperature, d); break; case 9: if (parse_display(str, &i)) GMSD_SET(display, i); break; case 10: break; /* skip color */ case 11: i = gt_find_icon_number_from_desc(str, GDB); GMSD_SET(icon, i); wpt->icon_descr = gt_find_desc_from_icon_number(i, GDB, &dynamic); wpt->wpt_flags.icon_descr_is_dynamic = dynamic; break; case 12: GMSD_SETSTR(facility, str); break; case 13: GMSD_SETSTR(city, str); break; case 14: GMSD_SETSTR(state, str); break; case 15: GMSD_SETSTR(country, str); GMSD_SETSTR(cc, gt_get_icao_cc(str, wpt->shortname)); break; case 16: parse_date_and_time(str, &wpt->creation_time); break; case 17: wpt->url = DUPSTR(str); break; case 18: GMSD_SET(category, parse_categories(str)); break; default: break; } } waypt_add(wpt); }
static void unicsv_parse_one_line(char *ibuf) { char *s; waypoint *wpt = NULL; int column; int utm_zone = -9999; double utm_easting = 0; double utm_northing = 0; char utm_zc = 'N'; char bng_zone[3] = ""; double bng_easting = 0; double bng_northing = 0; double swiss_easting = unicsv_unknown; double swiss_northing = unicsv_unknown; int checked = 0; time_t date = -1, time = -1; int msec = -1; char is_localtime = 0; garmin_fs_t *gmsd; double d; struct tm ymd; int src_datum = unicsv_datum_idx; int ns = 1; int ew = 1; #ifdef UNICSV_GC_READY geocache_data *gc_data = NULL; #endif wpt = waypt_new(); wpt->latitude = unicsv_unknown; wpt->longitude = unicsv_unknown; memset(&ymd, 0, sizeof(ymd)); column = -1; while ((s = csv_lineparse(ibuf, unicsv_fieldsep, "\"", 0))) { if (column > unicsv_fields_tab_ct) break; /* ignore extra fields on line */ ibuf = NULL; column++; checked++; s = lrtrim(s); if (! *s) continue; /* skip empty columns */ switch(unicsv_fields_tab[column]) { case fld_time: case fld_date: case fld_datetime: /* switch column type if it looks like an iso time string */ if (strchr(s, 'T')) unicsv_fields_tab[column] = fld_iso_time; break; default: ; } switch(unicsv_fields_tab[column]) { case fld_latitude: human_to_dec( s, &wpt->latitude, &wpt->longitude, 1 ); wpt->latitude = wpt->latitude * ns; break; case fld_longitude: human_to_dec( s, &wpt->latitude, &wpt->longitude, 2 ); wpt->longitude = wpt->longitude * ew; break; case fld_shortname: wpt->shortname = xstrdup(s); break; case fld_description: wpt->description = xstrdup(s); break; case fld_notes: wpt->notes = xstrdup(s); break; case fld_url: wpt->url = xstrdup(s); break; case fld_altitude: if (parse_distance(s, &d, unicsv_altscale, MYNAME)) { if (fabs(d) < fabs(unknown_alt)) wpt->altitude = d; } break; case fld_utm_zone: utm_zone = atoi(s); break; case fld_utm_easting: utm_easting = atof(s); break; case fld_utm_northing: utm_northing = atof(s); break; case fld_utm_zone_char: utm_zc = toupper(s[0]); break; case fld_utm: parse_coordinates(s, unicsv_datum_idx, grid_utm, &wpt->latitude, &wpt->longitude, MYNAME); /* coordinates from parse_coordinates are in WGS84 don't convert a second time */ src_datum = DATUM_WGS84; break; case fld_bng: parse_coordinates(s, DATUM_OSGB36, grid_bng, &wpt->latitude, &wpt->longitude, MYNAME); /* coordinates from parse_coordinates are in WGS84 don't convert a second time */ src_datum = DATUM_WGS84; break; case fld_bng_zone: strncpy(bng_zone, s, sizeof(bng_zone)); strupper(bng_zone); break; case fld_bng_northing: bng_northing = atof(s); break; case fld_bng_easting: bng_easting = atof(s); break; case fld_swiss: parse_coordinates(s, DATUM_WGS84, grid_swiss, &wpt->latitude, &wpt->longitude, MYNAME); /* coordinates from parse_coordinates are in WGS84 don't convert a second time */ src_datum = DATUM_WGS84; break; case fld_swiss_easting: swiss_easting = atof(s); break; case fld_swiss_northing: swiss_northing = atof(s); break; case fld_hdop: wpt->hdop = atof(s); if (unicsv_detect) unicsv_data_type = trkdata; break; case fld_pdop: wpt->pdop = atof(s); if (unicsv_detect) unicsv_data_type = trkdata; break; case fld_vdop: wpt->vdop = atof(s); if (unicsv_detect) unicsv_data_type = trkdata; break; case fld_sat: wpt->sat = atoi(s); if (unicsv_detect) unicsv_data_type = trkdata; break; case fld_fix: if (unicsv_detect) unicsv_data_type = trkdata; if (case_ignore_strcmp(s, "none") == 0) wpt->fix = fix_none; else if (case_ignore_strcmp(s, "2d") == 0) wpt->fix = fix_2d; else if (case_ignore_strcmp(s, "3d") == 0) wpt->fix = fix_3d; else if (case_ignore_strcmp(s, "dgps") == 0) wpt->fix = fix_dgps; else if (case_ignore_strcmp(s, "pps") == 0) wpt->fix = fix_pps; else wpt->fix = fix_unknown; break; case fld_utc_date: if ((is_localtime < 2) && (date < 0)) { date = unicsv_parse_date(s, NULL); is_localtime = 0; } break; case fld_utc_time: if ((is_localtime < 2) && (time < 0)) { time = unicsv_parse_time(s, &msec, &date); is_localtime = 0; } break; case fld_speed: if (parse_speed(s, &d, 1.0, MYNAME)) { WAYPT_SET(wpt, speed, d); if (unicsv_detect) unicsv_data_type = trkdata; } break; case fld_course: WAYPT_SET(wpt, course, atof(s)); if (unicsv_detect) unicsv_data_type = trkdata; break; case fld_temperature: d = atof(s); if (fabs(d) < 999999) WAYPT_SET(wpt, temperature, d); break; case fld_temperature_f: d = atof(s); if (fabs(d) < 999999) WAYPT_SET(wpt, temperature, FAHRENHEIT_TO_CELSIUS(d)); break; case fld_heartrate: wpt->heartrate = atoi(s); if (unicsv_detect) unicsv_data_type = trkdata; break; case fld_cadence: wpt->cadence = atoi(s); if (unicsv_detect) unicsv_data_type = trkdata; break; case fld_proximity: if (parse_distance(s, &d, unicsv_proximityscale, MYNAME)) WAYPT_SET(wpt, proximity, d); break; case fld_depth: if (parse_distance(s, &d, unicsv_depthscale, MYNAME)) WAYPT_SET(wpt, depth, d); break; case fld_symbol: wpt->icon_descr = xstrdup(s); wpt->wpt_flags.icon_descr_is_dynamic = 1; break; case fld_iso_time: is_localtime = 2; /* fix result */ wpt->creation_time = xml_parse_time(s, &wpt->microseconds); break; case fld_time: if ((is_localtime < 2) && (time < 0)) { time = unicsv_parse_time(s, &msec, &date); is_localtime = 1; } break; case fld_date: if ((is_localtime < 2) && (date < 0)) { date = unicsv_parse_date(s, NULL); is_localtime = 1; } break; case fld_year: ymd.tm_year = atoi(s); break; case fld_month: ymd.tm_mon = atoi(s); break; case fld_day: ymd.tm_mday = atoi(s); break; case fld_hour: ymd.tm_hour = atoi(s); break; case fld_min: ymd.tm_min = atoi(s); break; case fld_sec: ymd.tm_sec = atoi(s); break; case fld_datetime: if ((is_localtime < 2) && (date < 0) && (time < 0)) { time = unicsv_parse_time(s, &msec, &date); is_localtime = 1; } break; case fld_ns: ns = tolower(s[0]) == 'n' ? 1 : -1; wpt->latitude *= ns; break; case fld_ew: ew = tolower(s[0]) == 'e' ? 1 : -1; wpt->longitude *= ew; break; case fld_garmin_city: case fld_garmin_postal_code: case fld_garmin_state: case fld_garmin_country: case fld_garmin_addr: case fld_garmin_phone_nr: case fld_garmin_phone_nr2: case fld_garmin_fax_nr: case fld_garmin_email: case fld_garmin_facility: gmsd = GMSD_FIND(wpt); if (! gmsd) { gmsd = garmin_fs_alloc(-1); fs_chain_add(&wpt->fs, (format_specific_data *) gmsd); } switch(unicsv_fields_tab[column]) { case fld_garmin_city: GMSD_SETSTR(city, s); break; case fld_garmin_postal_code: GMSD_SETSTR(postal_code, s); break; case fld_garmin_state: GMSD_SETSTR(state, s); break; case fld_garmin_country: GMSD_SETSTR(country, s); break; case fld_garmin_addr: GMSD_SETSTR(addr, s); break; case fld_garmin_phone_nr: GMSD_SETSTR(phone_nr, s); break; case fld_garmin_phone_nr2: GMSD_SETSTR(phone_nr2, s); break; case fld_garmin_fax_nr: GMSD_SETSTR(fax_nr, s); break; case fld_garmin_email: GMSD_SETSTR(email, s); break; case fld_garmin_facility: GMSD_SETSTR(facility, s); break; default: break; } break; #ifdef UNICSV_GC_READY case fld_gc_id: case fld_gc_type: case fld_gc_container: case fld_gc_terr: case fld_gc_diff: case fld_gc_is_archived: case fld_gc_is_available: case fld_gc_exported: case fld_gc_last_found: case fld_gc_placer: case fld_gc_placer_id: case fld_gc_hint: gc_data = waypt_alloc_gc_data(wpt); switch(unicsv_fields_tab[column]) { case fld_gc_id: gc_data->id = atoi(s); if (gc_data->id == 0) gc_data->id = unicsv_parse_gc_id(s); break; case fld_gc_type: gc_data->type = gs_mktype(s); break; case fld_gc_container: gc_data->container = gs_mkcont(s); break; case fld_gc_terr: gc_data->terr = atof(s) * 10; break; case fld_gc_diff: gc_data->diff = atof(s) * 10; break; case fld_gc_is_archived: gc_data->is_archived = unicsv_parse_status(s); break; case fld_gc_is_available: gc_data->is_available = unicsv_parse_status(s); break; case fld_gc_exported: { time_t time, date; int msec; time = unicsv_parse_time(s, &msec, &date); if (date || time) gc_data->exported = unicsv_adjust_time(time, &date); } break; case fld_gc_last_found: { time_t time, date; int msec; time = unicsv_parse_time(s, &msec, &date); if (date || time) gc_data->last_found = unicsv_adjust_time(time, &date); } break; case fld_gc_placer: gc_data->placer = xstrdup(s); break; case fld_gc_placer_id: gc_data->placer_id = atoi(s); break; case fld_gc_hint: gc_data->hint = xstrdup(s); break; default: break; } break; #endif case fld_terminator: /* dummy */ checked--; break; } } if (checked == 0) { waypt_free(wpt); return; } if (is_localtime < 2) { /* not fixed */ if ((time >= 0) && (date >= 0)) { time_t t = date + time; if (is_localtime) { struct tm tm; tm = *gmtime(&t); if (opt_utc) wpt->creation_time = mkgmtime(&tm); else wpt->creation_time = mklocaltime(&tm); } else wpt->creation_time = t; } else if (time >= 0) wpt->creation_time = time; else if (date >= 0) wpt->creation_time = date; else if (ymd.tm_year || ymd.tm_mon || ymd.tm_mday) { if (ymd.tm_year < 100) { if (ymd.tm_year <= 70) ymd.tm_year += 2000; else ymd.tm_year += 1900; } ymd.tm_year -= 1900; if (ymd.tm_mon == 0) ymd.tm_mon = 1; if (ymd.tm_mday == 0) ymd.tm_mday = 1; ymd.tm_mon--; if (opt_utc) wpt->creation_time = mkgmtime(&ymd); else wpt->creation_time = mklocaltime(&ymd); } else if (ymd.tm_hour || ymd.tm_min || ymd.tm_sec) { if (opt_utc) wpt->creation_time = mkgmtime(&ymd); else wpt->creation_time = mklocaltime(&ymd); } if (msec >= 0) wpt->microseconds = msec; if (opt_utc) wpt->creation_time += atoi(opt_utc) * SECONDS_PER_HOUR; } /* utm/bng/swiss can be optional */ if ((wpt->latitude == unicsv_unknown) && (wpt->longitude == unicsv_unknown)) { if (utm_zone != -9999) { GPS_Math_UTM_EN_To_Known_Datum(&wpt->latitude, &wpt->longitude, utm_easting, utm_northing, utm_zone, utm_zc, unicsv_datum_idx); } else if (bng_zone[0]) { if (! GPS_Math_UKOSMap_To_WGS84_M( bng_zone, bng_easting, bng_northing, &wpt->latitude, &wpt->longitude)) fatal(MYNAME ": Unable to convert BNG coordinates (%s %.f %.f)!\n", bng_zone, bng_easting, bng_northing); src_datum = DATUM_WGS84; /* don't convert afterwards */ } else if ((swiss_easting != unicsv_unknown) && (swiss_northing != unicsv_unknown)) { GPS_Math_Swiss_EN_To_WGS84(swiss_easting, swiss_northing, &wpt->latitude, &wpt->longitude); src_datum = DATUM_WGS84; /* don't convert afterwards */ } } if ((src_datum != DATUM_WGS84) && (wpt->latitude != unicsv_unknown) && (wpt->longitude != unicsv_unknown)) { double alt; GPS_Math_Known_Datum_To_WGS84_M(wpt->latitude, wpt->longitude, (double) 0.0, &wpt->latitude, &wpt->longitude, &alt, src_datum); } switch(unicsv_data_type) { case rtedata: if (! unicsv_route) { unicsv_route = route_head_alloc(); route_add_head(unicsv_route); } route_add_wpt(unicsv_route, wpt); break; case trkdata: if (! unicsv_track) { unicsv_track = route_head_alloc(); track_add_head(unicsv_track); } track_add_wpt(unicsv_track, wpt); break; default: waypt_add(wpt); } }
static void nmn4_read_data(void) { char *buff; char *str, *c; int column; int line = 0; char *zip1, *zip2, *city, *street, *number; route_head *route; waypoint *wpt; route = route_head_alloc(); route_add_head(route); while ((buff = gbfgetstr(fin))) { if ((line++ == 0) && fin->unicode) cet_convert_init(CET_CHARSET_UTF8, 1); str = buff = lrtrim(buff); if (*buff == '\0') continue; nmn4_check_line(buff); /* for a quiet compiler */ zip1 = zip2 = city = street = number = NULL; wpt = waypt_new(); column = -1; c = csv_lineparse(str, "|", "", column++); while (c != NULL) { switch(column) { case 0: /* "-" */ /* unknown fields for the moment */ case 1: /* "-" */ case 2: /* "-" */ case 3: /* "-" */ case 9: /* "-" */ case 10: /* "-" */ case 13: /* "-" */ case 14: /* "-" */ case 15: /* "" */ break; case 4: /* ZIP Code */ if (*c != '-') zip1 = xstrdup(c); else zip1 = xstrdup(""); break; case 5: /* City */ if (*c != '-') city = xstrdup(c); else city = xstrdup(""); break; case 6: /* ZIP Code -2- */ if (*c != '-') zip2 = xstrdup(c); else zip2 = xstrdup(""); break; case 7: /* Street */ if (*c != '-') street = xstrdup(c); else street = xstrdup(""); break; case 8: /* Number */ if (*c != '-') number = xstrdup(c); else number = xstrdup(""); /* This is our final index All stuff for generating names or comments is hold locally. We don't have fields for street, city or zip-code. Instead we construct a description from that. */ if (strcmp(zip1, zip2) == 0) *zip2 = '\0'; if (*city != '\0') { /* if any field following city has a value, add a comma to city */ if ((*street != '\0') || (*number != '\0') || (*zip2 != '\0')) city = xstrappend(city, ","); } /* concats all fields to one string and release */ wpt->description = nmn4_concat(zip1, city, street, number, zip2, NULL); break; case 11: /* longitude */ sscanf(c, "%lf", &wpt->longitude); break; case 12: /* latitude */ sscanf(c, "%lf", &wpt->latitude); break; } c = csv_lineparse(NULL, "|", "", column++); } route_add_wpt(route, wpt); } }
static void unicsv_fondle_header(char *ibuf) { char *s; char *buf = NULL; int i, column; const cet_cs_vec_t *ascii = &cet_cs_vec_ansi_x3_4_1968; /* us-ascii */ /* Convert the entire header to lower case for convenience. * If we see a tab in that header, we decree it to be tabsep. */ unicsv_fieldsep = ","; for (s = ibuf; *s; s++) { if (*s == '\t') { unicsv_fieldsep = "\t"; } else if (*s == ';') { unicsv_fieldsep = ";"; } else if (*s == '|') { unicsv_fieldsep = "|"; } else { continue; } break; } for (s = ibuf; *s; s++) { *s = tolower(*s); } /* convert the header line into native ascii */ if (global_opts.charset != ascii) { buf = cet_str_any_to_any(ibuf, global_opts.charset, ascii); ibuf = buf; } column = -1; while ((s = csv_lineparse(ibuf, unicsv_fieldsep, "\"", 0))) { field_t *f = &fields_def[0]; ibuf = NULL; column++; unicsv_fields_tab_ct++; s = lrtrim(s); if (column % 4 == 0) { int sz = (column + 4) * sizeof(*unicsv_fields_tab); if (column == 0) unicsv_fields_tab = (field_e*) xmalloc(sz); else unicsv_fields_tab = (field_e*) xrealloc(unicsv_fields_tab, sz); for (i = 0; i < 4; i++) unicsv_fields_tab[column + i] = fld_terminator; } while (f->name) { if (unicsv_compare_fields(s, f)) { unicsv_fields_tab[column] = f->type; break; } f++; } if ((! f->name) && global_opts.debug_level) warning(MYNAME ": Unhandled column \"%s\".\n", s); /* handle some special items */ if (f->type == fld_altitude) { if (UNICSV_CONTAINS("ft") || UNICSV_CONTAINS("feet")) { unicsv_altscale = FEET_TO_METERS(1); } } if (f->type == fld_depth) { if (UNICSV_CONTAINS("ft") || UNICSV_CONTAINS("feet")) { unicsv_depthscale = FEET_TO_METERS(1); } } if (f->type == fld_proximity) { if (UNICSV_CONTAINS("ft") || UNICSV_CONTAINS("feet")) { unicsv_proximityscale = FEET_TO_METERS(1); } } if ((f->type == fld_time) || (f->type == fld_date)) { if (UNICSV_CONTAINS("iso")) f->type = fld_iso_time; } } if (buf) xfree(buf); }