static gbuint16 parse_categories(const char *str) { char buff[256]; gbuint16 val; gbuint16 res = 0; char *cin, *cx; if (*str == '\0') return 0; strncpy(buff, str, sizeof(buff)); cin = lrtrim(buff); if (*cin == '\0') return 0; strcat(cin, ","); while ((cx = strchr(cin, ','))) { *cx++ = '\0'; cin = lrtrim(cin); if (*cin != '\0') { if (!garmin_fs_convert_category(cin, &val)) warning(MYNAME ": Unable to convert category \"%s\" at line %d!\n", cin, current_line); else res = res | val; } cin = cx; } return res; }
static void unicsv_print_str(const char *str) { if (str && *str) { char *cout, *cx; cout = strenquote(str, UNICSV_QUOT_CHAR); while ((cx = strstr(cout, "\r\n"))) { memmove(cx, cx + 1, strlen(cx)); *cx++ = ','; lrtrim(cx); } while ((cx = strchr(cout, '\r'))) { *cx++ = ','; lrtrim(cx); } while ((cx = strchr(cout, '\n'))) { *cx++ = ','; lrtrim(cx); } gbfprintf(fout, "%s%s", unicsv_fieldsep, cout); xfree(cout); } else gbfputs(unicsv_fieldsep, fout); }
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- // cfg_segment() // fail return e_failure -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ hPOS cfg_segment( MXCCFG *ch, char *grpKey, char *label ) { char *ptr; if ( !(ch->hCFG) ) return e_failure; fseek( ch->hCFG, ch->cfgHeadSize, SEEK_SET ); // get the seg info _nextLine: if( fgets( cache, cacheSize, ch->hCFG ) == NULL ) return e_failure; if( lrtrim(cache)[0] == '[' ) { if( !(ptr = strchr( cache, ']') ) ) { // error of config format return e_failure; } *ptr = '\0'; // clear the bolck mark if( stricmp(&cache[1], grpKey) == 0 ) { // **** if( label != NULL ) goto _nextLine2; ch->seg = ftell( ch->hCFG ); cfg_segEnd( ch ); return ch->seg; } } if( !feof( ch->hCFG ) ) goto _nextLine; if( label != NULL ) return e_failure; // get the label info _nextLine2: if( fgets( cache, cacheSize, ch->hCFG ) == NULL ) return e_failure; if( lrtrim(cache)[0] == '#' ) { lrtrim( &cache[1] ); if( stricmp(&cache[1], label) == 0 ) { // **** ch->seg = ftell( ch->hCFG ); cfg_segEnd( ch ); return ch->seg; } } if( cache[0] == '[' ) goto _cfg_segment_ret; if( !feof( ch->hCFG ) ) goto _nextLine2; _cfg_segment_ret: cfg_segEnd( ch ); return e_failure; } // end of cfg_segment()
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)); } }
int inchi_fgetsLfTab( char *szLine, int len, FILE *f ) { int length; char *p; char szSkip[256]; int bTooLongLine = 0; do { p = inchi_fgetsTab( szLine, len-1, f ); if ( !p ) { return -1; /* end of file or cannot read */ } szLine[len-1] = '\0'; /* bTooLongLine = !strchr( szLine, '\n' ); */ bTooLongLine = ( !p && ((int)strlen(szLine)) == len-2 ); lrtrim( szLine, &length ); } while ( !length ); if ( bTooLongLine ) { while ( p = inchi_fgetsTab( szSkip, sizeof(szSkip)-1, f ) ) { szSkip[sizeof(szSkip)-1] = '\0'; if ( strchr( szSkip, '\n' ) ) break; } } return length; }
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 char * nmn4_concat(char *arg0, ...) { va_list args; char *src, *res; res = NULL; va_start(args, arg0); src = (char *)arg0; while (src != NULL) { char *c = lrtrim(src); if (*c != '\0') { if (res == NULL) res = xstrdup(c); else { res = xstrappend(res, " "); res = xstrappend(res, c); } } xfree(src); src = va_arg(args, char *); } va_end(args); return res; }
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- // cfg_findItem() // fail return e_failure -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ hPOS cfg_findItem( MXCCFG *ch, char *cfgKey ) { int len; hPOS pos; len = strlen( lrtrim(cfgKey) ); fseek( ch->hCFG, ch->seg, SEEK_SET ); // locate the segment head _nextItem: pos = ftell( ch->hCFG ); if( fgets( cache, cacheSize, ch->hCFG ) == NULL) return e_failure; if( cache[0] == '[' || strlen(cache) == 0 ) // overlay boundary { return( e_failure ); } if( strchr(cache, '=') != NULL ) { if( strnicmp(cache, cfgKey, len) == 0 ) return pos; } if (!feof(ch->hCFG) ) goto _nextItem; else return e_failure; }
static char * trimmed_strdup(const char *str) { char *c1, *c2, *res; c1 = xstrdup(str); c2 = lrtrim(c1); if (*c2) res = xstrdup(c2); else res = NULL; xfree(c1); return res; }
const char *CLoadcf::CF_GetConfigString(const char *pGroup,const char *pCommandString,const char *notice) { char pGroupName[200]; sprintf(pGroupName,"[%s]",pGroup); L_RELOAD: CF_LocateGroupName(pGroupName); while ( CF_GetStrLine() ==0 ) { if (CF_InString(pReadBuffer,(char*)"[") ) goto L_CNT; if (CF_InString(pReadBuffer,pCommandString)) { char *pContent = pReadBuffer+strlen(pCommandString); lrtrim(pContent); return lrtrim(pContent+1); } } L_CNT: CF_LocateGroupName(pGroupName); sprintf(strText,"%s=%s\r\n",pCommandString,notice); curPos = CF_GetCurPos(); fclose(hConfig); if(bCreateFlag == false) { CF_ShowError(pReadBuffer,pCommandString); return notice; } CF_AddConfig(fConfig,strText,curPos); hConfig=fopen(fConfig,"rb"); if(hConfig==NULL) { CF_ShowError(pReadBuffer,pCommandString); return notice; } goto L_RELOAD; }
void wpt_desc(const char *args, const char **unused) { if (args) { char *tmp, *c; tmp = xstrdup((char *)args); c = lrtrim(tmp); if (*c) { wpt_tmp->description = xstrappend(wpt_tmp->description, c); } xfree(tmp); } }
/*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- // return: fail, NULL; success, not 0 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*/ char *cfg_read( MXCCFG *ch, char *cfgKey, char *buf ) { char *ptr; if( ch == NULL || buf == NULL || cfgKey == NULL ) return NULL; if( cfg_findItem( ch, cfgKey ) == e_failure ) return NULL; ptr = strchr(cache, '='); strcpy(buf, (char *)ptr + 1); return lrtrim( buf ); } // end of cfg_read()
static void unicsv_rd(void) { char *buff; if (unicsv_fieldsep == NULL) return; while ((buff = gbfgetstr(fin))) { buff = lrtrim(buff); if ((*buff == '\0') || (*buff == '#')) continue; unicsv_parse_one_line(buff); } }
int inchi_ios_getsTab1( char *szLine, int len, INCHI_IOSTREAM *f, int *bTooLongLine ) { int length; char *p; p = inchi_ios_str_getsTab( szLine, len-1, f ); if ( !p ) { *bTooLongLine = 0; return -1; /* end of file or cannot read */ } szLine[len-1] = '\0'; p = strchr( szLine, '\n' ); *bTooLongLine = ( !p && ((int)strlen(szLine)) == len-2 ); lrtrim( szLine, &length ); return length; }
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; }
int CLoadcf::CF_GetStrLine() { char *pReadPointer; do { pReadPointer=fgets(pReadBuffer,2549,hConfig); LineCount ++; if((pReadPointer==NULL)||(strlen(pReadBuffer)>=2200)) return -1; /*strupr(pReadBuffer);*/ //CF_FilterChar(pReadBuffer,pReadBuffer,' '); update zbz lrtrim(pReadBuffer); CF_FilterChar(pReadBuffer,pReadBuffer,'\t'); CF_FilterChar(pReadBuffer,pReadBuffer,'\n'); CF_FilterChar(pReadBuffer,pReadBuffer,'\r'); //CF_FilterChar(pReadBuffer,pReadBuffer,'='); update zbz } while (pReadBuffer[0] ==';'|| pReadBuffer[0] == 0); return 0; }
static int parse_date_and_time(char *str, time_t *value) { struct tm tm; char *cerr, *cin; memset(&tm, 0, sizeof(tm)); cin = lrtrim(str); if (*cin == '\0') return 0; cerr = strptime(cin, date_time_format, &tm); if (cerr == NULL) { cerr = strptime(cin, "%m/%d/%Y %I:%M:%S %p", &tm); is_fatal(cerr == NULL, MYNAME ": Invalid date or/and time \"%s\" at line %d!", cin, current_line); } // printf(MYNAME "_parse_date_and_time: %02d.%02d.%04d, %02d:%02d:%02d\n", // tm.tm_mday, tm.tm_mon+1, tm.tm_year+1900, tm.tm_hour, tm.tm_min, tm.tm_sec); *value = mklocaltime(&tm); return 1; }
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 char * fix_notes(const char *name, char *notes) { char *cleft, *cright, *cback, *ctmp; if ((! name) || (! notes)) return notes; /* do we have a BACKSLASH in shortname ? */ cback = strchr(name, '\\'); if ((! cback) || (cback == name)) return notes; /* do we have left, but no right parenthesis in notes ? */ if (! (cleft = strchr(notes, '('))) return notes; cright = strchr(notes, ')'); if (cright && (cright > cleft)) return notes; /* now contruct the new name */ ctmp = lrtrim(xstrndup(notes, cleft - notes)); xfree(notes); xasprintf(¬es, "%s (%*.*s)", ctmp, cback - name, cback - name, name); xfree(ctmp); return notes; }
static void compegps_data_read(void) { char *buff; int line = 0; int input_datum; waypoint *wpt = NULL; route_head *route = NULL; route_head *track = NULL; while ((buff = gbfgetstr(fin))) { char *cin = buff; char *ctail; if ((line++ == 0) && fin->unicode) cet_convert_init(CET_CHARSET_UTF8, 1); cin = lrtrim(buff); if (strlen(cin) == 0) continue; ctail = strchr(cin, ' '); if (ctail == NULL) continue; ctail = lrtrim(ctail); switch(*cin) { case 'G': input_datum = GPS_Lookup_Datum_Index(ctail); if (input_datum < 0) { fatal( MYNAME ": Unsupported datum \"%s\"!", ctail); } break; case 'U': switch(*ctail) { case '1': /* lat/lon, that's we want to see */ break; case '0': /* UTM not supported yet */ fatal(MYNAME "Sorry, UTM is not supported yet!\n"); default: fatal(MYNAME "Invalid system of coordinates (%s)!\n", cin); } break; case 'R': route = route_head_alloc(); route_add_head(route); parse_rte_info(ctail, route); break; case 'M': break; case 'W': wpt = parse_wpt(ctail); if (wpt != NULL) { if (route != NULL) route_add_wpt(route, wpt); else waypt_add(wpt); } break; case 'w': is_fatal((wpt == NULL), MYNAME ": No waypoint data before \"%s\"!", cin); parse_wpt_info(ctail, wpt); break; case 'T': wpt = parse_trkpt(ctail); if (wpt != NULL) { if (track == NULL) { track = route_head_alloc(); track_add_head(track); } track_add_wpt(track, wpt); } break; case 't': if (track != NULL) parse_track_info(ctail, track); break; } } }
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); }
static int ppdb_decode_tm(char *str, struct tm *tm) { int msec, d1, d2, d3, d4; int year; int temp=0; char *cx; str = lrtrim(str); /* time field may start/end with spaces, drop them */ if (*str == '\0') { if (global_opts.debug_level > 0) { warning(MYNAME ": Time value missing, reseting to 0\n"); warn_ = 1; } return 0; /* empty time field */ } if (strchr(str, '.')) /* time in hhmmss.ms */ { CHECK_INP(4, sscanf(str, "%02d%02d%02d.%d", &tm->tm_hour, &tm->tm_min, &tm->tm_sec, &msec), "decode_tm(1) hhmmss.ss", str); } else if (sscanf(str,"%06d",&temp)==1) /* WORKAROUND read time info only if a valid 6 digit string found */ { CHECK_INP(3, sscanf(str, "%02d%02d%02d", &tm->tm_hour, &tm->tm_min, &tm->tm_sec), "decode_tm(2) hhmmss", str); } else { if (global_opts.debug_level > 0) { warning(MYNAME ": Invalid time value, reseting to 0\n"); warn_ = 1; } return 0; /* WORKAROUND maybe invalid time, just ignore it and continue */ } cx = strchr(str, ' '); if (cx == NULL) { if (global_opts.debug_level > 0) { warning(MYNAME ": Date value missing, reseting to 0\n"); warn_ = 1; } return 0; /* empty date field */ } cx = lrtrim(cx); if (*cx == '\0') { if (global_opts.debug_level > 0) { warning(MYNAME ": Date value missing, found only spaces, reseting to 0\n"); warn_ = 1; } return 0; /* empty date field */ } if (datefmt) { struct tm tm2; if (NULL == strptime(cx, datefmt, &tm2)) { fatal(MYNAME ": Unable to convert date '%s' using format '%s' (%s)!\n", cx, datefmt, opt_date); } tm->tm_year = tm2.tm_year + 1900; tm->tm_mon = tm2.tm_mon + 1; tm->tm_mday = tm2.tm_mday; } else { time_t tnow; struct tm now; tnow = current_time(); now = *localtime(&tnow); now.tm_year += 1900; now.tm_mon++; if (strlen(cx) == 8) { CHECK_INP(4, sscanf(cx, "%02d%02d%02d%02d", &d1, &d2, &d3, &d4), "decode_tm(3) invalid date (YYYYMMDD)", cx); year = (d1 * 100) + d2; /* the coordinates comes before date and time in the dataset, so the flag "german_release" is set yet. */ /* next code works for most, except for 19. and 20. of month */ if ((german_release != 0) || (year < 1980) || (year > now.tm_year)) /* YYYYMMDD or DDMMYYYY ????? */ { tm->tm_year = (d3 * 100) + d4; tm->tm_mon = d2; tm->tm_mday = d1; } else { tm->tm_year = (d1 * 100) + d2; tm->tm_mon = d3; tm->tm_mday = d4; } } else if (strlen(cx) == 6) { CHECK_INP(3, sscanf(cx, "%02d%02d%02d", &d1, &d2, &d3), "decode_tm(3) invalid date (DDMMYY)", cx); if (d3 < 1970) /* Usual Y2K interpretation */ year = d3 + 2000; else year = d3 + 1900; /* I don't know how a german release handles this * so for now I will assume only DDMMYY if date has 6 digits */ tm->tm_year = year; tm->tm_mon = d2; tm->tm_mday = d1; } else /* date string is neither 8 nor 6 digits */ { printf(MYNAME ": Date from first record is %s.\n", cx); printf(MYNAME ": Please use option 'date' to specify how this is formatted.\n"); fatal(MYNAME ": (... -i pathaway,date=DDMMYY ...)\n"); } } return 1; }
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 magpdb_read_data(const char *data, const size_t data_len) { route_head *route; char *cin = (char *)data; char *cend = cin + data_len; route = route_head_alloc(); route_add_head(route); while (cin < cend) { char *lend; int len; lend = strchr(cin, '\x0A'); if (lend == NULL) break; len = (lend - cin); if (len > 0) { double distance; int hour, min; *lend = '\0'; if (case_ignore_strncmp(cin, "Wegname=", 8) == 0) /* This only works with the german release */ { /* test-data created with other releases are welcome */ cin += 8; if (*cin != '\0') route->rte_name = xstrdup(cin); } else if (case_ignore_strncmp(cin, "Fahrzeit=", 9) == 0) { } else if (case_ignore_strncmp(cin, "Kosten=", 7) == 0) { } else if (case_ignore_strncmp(cin, "Entfernung=", 11) == 0) { } /* check, if line starts with time and distance */ else if (3 == sscanf(cin, "%d:%d %lf", &hour, &min, &distance)) { char *buff, *comma; /* detect time-format settings, 12,0 or 12.0 */ comma = strchr(cin, '.'); buff = strchr(cin, ','); if (comma == NULL) comma = buff; else if ((buff != NULL) && (buff < comma)) comma = buff; if (comma != NULL) { char separator = *comma; /* now we are looking for a sequence like 0,1 NE (123456,654321) */ buff = xmalloc(strlen(cin) + 1); /* safe target space for sscanf( ... */ comma = cin; while ((comma = strchr(comma, separator))) { int i, xlat, xlon; waypoint *wpt; char *cx; comma++; if (isdigit(*comma) == 0) continue; if (isdigit(*(comma - 2)) == 0) continue; if (4 != sscanf(comma, "%d %s (%d,%d)", &i, buff, &xlon, &xlat)) continue; if (strchr("NESW", *buff) == NULL) continue; /* north, east, ... */ cx = comma - 2; /* go left over delta distance */ while (isdigit(*cx) != 0) *cx-- = '\0'; cin = lrtrim(cin); for (i = 0; i < 2; i++) /* skip time and distance at start of line */ { cin = strchr(cin, ' '); cin = lrtrim(cin); } wpt = waypt_new(); wpt->latitude = magpdb_to_degree(xlat); wpt->longitude = magpdb_to_degree(xlon); wpt->description = xstrdup(cin); cx = strchr(comma, ')'); /* find tailing notes after the coordinates */ if (cx != NULL) { char *tail = lrtrim(++cx); if (*tail != '\0') { wpt->notes = xstrdup(tail); } } /* generate some waypoints from our route-only format */ if ((*cin != '-') && (case_ignore_strncmp(cin, "bei ", 4) != 0)) waypt_add(waypt_dupe(wpt)); route_add_wpt(route, wpt); break; } xfree(buff); } } } cin = lend + 1; } }
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 LoadLangPack(const TCHAR *szLangPack) { FILE *fp; char line[4096] = ""; char *pszColon; char *pszLine; int entriesAlloced; int startOfLine=0; unsigned int linePos=1; LCID langID; UINT fileCp = CP_ACP; lstrcpy(langPack.filename,szLangPack); fp = _tfopen(szLangPack,_T("rt")); if(fp==NULL) return 1; fgets(line,SIZEOF(line),fp); size_t lineLen = strlen(line); if (lineLen >= 3 && line[0]=='\xef' && line[1]=='\xbb' && line[2]=='\xbf') { fileCp = CP_UTF8; memmove(line, line + 3, lineLen - 2); } lrtrim(line); if(lstrcmpA(line,"Miranda Language Pack Version 1")) {fclose(fp); return 2;} //headers while(!feof(fp)) { startOfLine=ftell(fp); if(fgets(line,SIZEOF(line),fp)==NULL) break; lrtrim(line); if(IsEmpty(line) || line[0]==';' || line[0]==0) continue; if(line[0]=='[') break; pszColon=strchr(line,':'); if(pszColon==NULL) {fclose(fp); return 3;} *pszColon++ = 0; if(!lstrcmpA(line,"Language")) {mir_snprintf(langPack.language,sizeof(langPack.language),"%s",pszColon); lrtrim(langPack.language);} else if(!lstrcmpA(line,"Last-Modified-Using")) {mir_snprintf(langPack.lastModifiedUsing,sizeof(langPack.lastModifiedUsing),"%s",pszColon); lrtrim(langPack.lastModifiedUsing);} else if(!lstrcmpA(line,"Authors")) {mir_snprintf(langPack.authors,sizeof(langPack.authors),"%s",pszColon); lrtrim(langPack.authors);} else if(!lstrcmpA(line,"Author-email")) {mir_snprintf(langPack.authorEmail,sizeof(langPack.authorEmail),"%s",pszColon); lrtrim(langPack.authorEmail);} else if(!lstrcmpA(line, "Locale")) { char szBuf[20], *stopped; lrtrim(pszColon + 1); langID = (USHORT)strtol(pszColon, &stopped, 16); langPack.localeID = MAKELCID(langID, 0); GetLocaleInfoA(langPack.localeID, LOCALE_IDEFAULTANSICODEPAGE, szBuf, 10); szBuf[5] = 0; // codepages have max. 5 digits langPack.defaultANSICp = atoi(szBuf); if (fileCp == CP_ACP) fileCp = langPack.defaultANSICp; } } //body fseek(fp,startOfLine,SEEK_SET); entriesAlloced=0; while(!feof(fp)) { if(fgets(line,SIZEOF(line),fp)==NULL) break; if(IsEmpty(line) || line[0]==';' || line[0]==0) continue; rtrim(line); ConvertBackslashes(line, fileCp); if(line[0]=='[' && line[lstrlenA(line)-1]==']') { if(langPack.entryCount && langPack.entry[langPack.entryCount-1].local==NULL) { if(langPack.entry[langPack.entryCount-1].english!=NULL) mir_free(langPack.entry[langPack.entryCount-1].english); langPack.entryCount--; } pszLine = line+1; line[lstrlenA(line)-1]='\0'; if(++langPack.entryCount>entriesAlloced) { entriesAlloced+=128; langPack.entry=(struct LangPackEntry*)mir_realloc(langPack.entry,sizeof(struct LangPackEntry)*entriesAlloced); } langPack.entry[langPack.entryCount-1].english=NULL; langPack.entry[langPack.entryCount-1].englishHash=hashstr(pszLine); langPack.entry[langPack.entryCount-1].local=NULL; langPack.entry[langPack.entryCount-1].wlocal = NULL; langPack.entry[langPack.entryCount-1].linePos=linePos++; } else if(langPack.entryCount) { struct LangPackEntry* E = &langPack.entry[langPack.entryCount-1]; if(E->local==NULL) { E->local=mir_strdup(line); if (fileCp == CP_UTF8) Utf8DecodeCP(E->local, langPack.defaultANSICp, NULL); { int iNeeded = MultiByteToWideChar(fileCp, 0, line, -1, 0, 0); E->wlocal = (wchar_t *)mir_alloc((iNeeded+1) * sizeof(wchar_t)); MultiByteToWideChar(fileCp, 0, line, -1, E->wlocal, iNeeded); } } else { size_t iOldLenA = strlen(E->local); E->local = (char*)mir_realloc(E->local, iOldLenA + strlen(line) + 2); strcat(E->local, "\n"); strcat(E->local, line); if (fileCp == CP_UTF8) Utf8DecodeCP(E->local + iOldLenA + 1, langPack.defaultANSICp, NULL); { int iNeeded = MultiByteToWideChar(fileCp, 0, line, -1, 0, 0); size_t iOldLen = wcslen(E->wlocal); E->wlocal = (wchar_t*)mir_realloc(E->wlocal, ( sizeof(wchar_t) * ( iOldLen + iNeeded + 2))); wcscat(E->wlocal, L"\n"); MultiByteToWideChar(fileCp, 0, line, -1, E->wlocal + iOldLen+1, iNeeded); } } } } fclose(fp); qsort(langPack.entry,langPack.entryCount,sizeof(LangPackEntry),(int(*)(const void*,const void*))SortLangPackHashesProc); return 0; }
static void mmo_read_CObjWaypoint(mmo_data_t *data) { #ifdef MMO_DBG const char *sobj = "CObjWaypoint"; #endif waypoint *wpt; time_t time; int rtelinks; mmo_data_t **rtelink = NULL; char *str; char buf[16]; int i, ux; DBG((sobj, ":-----------------------------------------------------\n")); DBG((sobj, "name = \"%s\" [ visible=%s, id=0x%04X ]\n", data->name, data->visible ? "yes" : "NO", data->objid)); wpt = waypt_new(); wpt->shortname = xstrdup(data->name); time = data->mtime; if (! time) time = data->ctime; if (time > 0) wpt->creation_time = time; wpt->latitude = gbfgetdbl(fin); wpt->longitude = gbfgetdbl(fin); DBG((sobj, "coordinates = %f / %f\n", wpt->latitude, wpt->longitude)); rtelinks = gbfgetuint16(fin); if (rtelinks > 0) { rtelink = xcalloc(sizeof(*rtelink), rtelinks); DBG((sobj, "rtelinks = %d\n", rtelinks)); for (i = 0; i < rtelinks; i++) { mmo_data_t *tmp; int objid; DBG((sobj, "read rtelink number %d\n", i + 1)); objid = gbfgetuint16(fin); gbfseek(fin, -2, SEEK_CUR); rtelink[i] = tmp = mmo_read_object(wpt); if ((objid < 0x8000) && (tmp != NULL) && (tmp->type == rtedata)) { route_head *rte = tmp->data; tmp->left--; route_add_wpt(rte, waypt_dupe(wpt)); DBG((sobj, "\"%s\" Added to route \"%s\"\n", wpt->shortname, rte->rte_name)); } } } str = mmo_readstr(); /* descr + url */ if (strncmp(str, "_FILE_ ", 7) == 0) { char *cx, *cend; cx = lrtrim(str + 7); cend = strchr(cx, '\n'); if (cend == NULL) cend = cx + strlen(cx); cx = lrtrim(xstrndup(cx, cend - cx)); if (*cx) wpt->url = cx; else xfree(cx); if (*cend++) wpt->notes = xstrdup(cend); if (wpt->url) DBG((sobj, "url = \"%s\"\n", wpt->url)); } else if (*str) wpt->notes = xstrdup(str); xfree(str); if (wpt->notes) DBG((sobj, "notes = \"%s\"\n", wpt->notes)); mmo_fillbuf(buf, 12, 1); i = le_read32(&buf[8]); /* icon */ if (i != -1) { char key[16]; char *name; snprintf(key, sizeof(key), "%d", i); if (avltree_find(icons, key, (void *)&name)) { wpt->icon_descr = xstrdup(name); wpt->wpt_flags.icon_descr_is_dynamic = 1; DBG((sobj, "icon = \"%s\"\n", wpt->icon_descr)); } } wpt->proximity = le_read_float(&buf[4]); if (wpt->proximity) { wpt->wpt_flags.proximity = 1; DBG((sobj, "proximity = %f\n", wpt->proximity)); } str = mmo_readstr(); /* name on gps ??? option ??? */ if (*str) { wpt->description = wpt->shortname; wpt->shortname = str; DBG((sobj, "name on gps = %s\n", str)); } else xfree(str); ux = gbfgetuint32(fin); DBG((sobj, "proximity type = %d\n", ux)); if (rtelinks) { int i; for (i = 0; i < rtelinks; i++) { int j; route_head *rte = rtelink[i]->data; for (j = 0; j < rtelinks; j++) { if ((i != j) && (rtelink[i] == rtelink[j])) { rtelink[i]->loop = 1; break; } } rtelink[i]->done++; if ((rtelink[i]->left == 0) && (rtelink[i]->done == rte->rte_waypt_ct)) { if (mmo_version <= 0x11) mmo_end_of_route(rtelink[i]); } } } if (rtelink) { xfree(rtelink); waypt_free(wpt); data->data = NULL; } else 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 discoverUPnP(void) { char* buf; int buflen; unsigned i, j, nip = 0; unsigned* ips = NULL; static const unsigned any = INADDR_ANY; static const TIMEVAL tv = { 1, 600000 }; char szUrl[256] = ""; char hostname[256]; PHOSTENT he; fd_set readfd; SOCKET sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); SOCKADDR_IN enetaddr; enetaddr.sin_family = AF_INET; enetaddr.sin_port = htons(1900); enetaddr.sin_addr.s_addr = inet_addr("239.255.255.250"); gethostname(hostname, sizeof(hostname)); he = gethostbyname(hostname); if (he) { while (he->h_addr_list[nip]) ++nip; ips = (unsigned*)mir_alloc(nip * sizeof(unsigned)); for (j = 0; j < nip; j++) ips[j] = *(unsigned*)he->h_addr_list[j]; } buf = (char*)mir_alloc(1500); for (i = 3; --i && szUrl[0] == 0;) { for (j = 0; j < nip; j++) { if (ips) setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF, (char *)&ips[j], sizeof(unsigned)); buflen = mir_snprintf(buf, 1500, search_request_msg, "WANIPConnection:1"); sendto(sock, buf, buflen, 0, (SOCKADDR*)&enetaddr, sizeof(enetaddr)); LongLog(buf); buflen = mir_snprintf(buf, 1500, search_request_msg, "WANPPPConnection:1"); sendto(sock, buf, buflen, 0, (SOCKADDR*)&enetaddr, sizeof(enetaddr)); LongLog(buf); } if (Miranda_Terminated()) break; FD_ZERO(&readfd); FD_SET(sock, &readfd); while (select(1, &readfd, NULL, NULL, &tv) >= 1) { buflen = recv(sock, buf, 1500, 0); if (buflen != SOCKET_ERROR) { buf[buflen] = 0; LongLog(buf); if (txtParseParam(buf, NULL, "LOCATION:", "\n", szUrl, sizeof(szUrl)) || txtParseParam(buf, NULL, "Location:", "\n", szUrl, sizeof(szUrl))) { char age[30]; char szHostNew[256], szHostExist[256]; lrtrim(szUrl); parseURL(szUrl, szHostNew, NULL, NULL); parseURL(szCtlUrl, szHostExist, NULL, NULL); if (mir_strcmp(szHostNew, szHostExist) == 0) { gatewayFound = true; break; } txtParseParam(buf, NULL, "ST:", "\n", szDev, sizeof(szDev)); txtParseParam(buf, "max-age", " = ", "\n", age, sizeof(age)); expireTime = atoi(lrtrimp(age)); lrtrim(szDev); if (getUPnPURLs(szUrl, sizeof(szUrl))) { gatewayFound = getExtIP() != 0; if (gatewayFound) break; } } } FD_ZERO(&readfd); FD_SET(sock, &readfd); } } mir_free(buf); mir_free(ips); setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF, (char *)&any, sizeof(unsigned)); closesocket(sock); }
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)); } } }