void xml_node::add_attribute(const char * name, const char * value) { auto result = attributes_.emplace(name,xml_attribute(value)); if (!result.second) { MAPNIK_LOG_ERROR(xml_tree) << "ignoring duplicate attribute '" << name << "'"; } }
/** * @brief Print a list of XML attributes. */ std::string XmlWriter::print_attributes_list (StringMapType attr) { std::string xml; for (auto pair : attr) { xml += xml_attribute( pair.first, pair.second ); // xml += " " + pair.first + "=\"" + pair.second + "\""; } return xml; }
void xml_node::add_attribute(std::string const& name, std::string const& value) { attributes_.insert(std::make_pair(name,xml_attribute(value))); }
static void text_disp(const waypoint *wpt) { int latint, lonint; char tbuf[1024]; time_t tm = wpt->creation_time; gbint32 utmz; double utme, utmn; char utmzc; char *tmpout1, *tmpout2; char *altout; fs_xml *fs_gpx; waypoint_count++; if (split_output) { char *thisfname; xasprintf(&thisfname, "%s%d", output_name, waypoint_count); file_out = gbfopen(thisfname, "w", MYNAME); } lonint = abs((int) wpt->longitude); latint = abs((int) wpt->latitude); GPS_Math_WGS84_To_UTM_EN(wpt->latitude, wpt->longitude, &utme, &utmn, &utmz, &utmzc); if (tm == 0) tm = time(NULL); strftime(tbuf, sizeof(tbuf), "%d-%b-%Y", localtime(&tm)); tmpout1 = pretty_deg_format(wpt->latitude, wpt->longitude, degformat[2], " ", 0); if (wpt->altitude != unknown_alt) { xasprintf(&altout, " alt:%d", (int) ( (altunits[0]=='f')?METERS_TO_FEET(wpt->altitude):wpt->altitude) ); } else { altout = ""; } xasprintf (&tmpout2, "%s (%d%c %6.0f %7.0f)%s", tmpout1, utmz, utmzc, utme, utmn, altout ); gbfprintf(file_out, "%-16s %59s\n", (global_opts.synthesize_shortnames) ? mkshort_from_wpt(mkshort_handle, wpt) : wpt->shortname, tmpout2); xfree(tmpout2); xfree(tmpout1); if (altout[0]) xfree(altout); if (strcmp(wpt->description, wpt->shortname)) { gbfprintf(file_out, "%s", wpt->description); if (wpt->gc_data->placer) gbfprintf(file_out, " by %s", wpt->gc_data->placer); } if (wpt->gc_data->terr) { gbfprintf(file_out, " - %s / %s - (%d%s / %d%s)\n", gs_get_cachetype(wpt->gc_data->type), gs_get_container(wpt->gc_data->container), (int)(wpt->gc_data->diff / 10), (wpt->gc_data->diff%10)?".5":"", (int)(wpt->gc_data->terr / 10), (wpt->gc_data->terr%10)?".5":"" ); if (wpt->gc_data->desc_short.utfstring) { char *stripped_html = strip_html(&wpt->gc_data->desc_short); gbfprintf (file_out, "\n%s\n", stripped_html); xfree(stripped_html); } if (wpt->gc_data->desc_long.utfstring) { char *stripped_html = strip_html(&wpt->gc_data->desc_long); gbfprintf (file_out, "\n%s\n", stripped_html); xfree(stripped_html); } if (wpt->gc_data->hint) { char *hint = NULL; if ( txt_encrypt ) hint = rot13( wpt->gc_data->hint ); else hint = xstrdup( wpt->gc_data->hint ); gbfprintf (file_out, "\nHint: %s\n", hint); xfree( hint ); } } else if (wpt->notes && (!wpt->description || strcmp(wpt->notes,wpt->description))) { gbfprintf (file_out, "\n%s\n", wpt->notes); } fs_gpx = NULL; if ( includelogs ) { fs_gpx = (fs_xml *)fs_chain_find( wpt->fs, FS_GPX); } if ( fs_gpx && fs_gpx->tag ) { xml_tag *root = fs_gpx->tag; xml_tag *curlog = NULL; xml_tag *logpart = NULL; curlog = xml_findfirst( root, "groundspeak:log" ); while ( curlog ) { time_t logtime = 0; struct tm *logtm = NULL; gbfprintf( file_out, "\n" ); logpart = xml_findfirst( curlog, "groundspeak:type" ); if ( logpart ) { gbfprintf( file_out, "%s by ", logpart->cdata ); } logpart = xml_findfirst( curlog, "groundspeak:finder" ); if ( logpart ) { gbfprintf( file_out, "%s on ", logpart->cdata ); } logpart = xml_findfirst( curlog, "groundspeak:date" ); if ( logpart ) { logtime = xml_parse_time( logpart->cdata, NULL); logtm = localtime( &logtime ); if ( logtm ) { gbfprintf( file_out, "%4.4d-%2.2d-%2.2d\n", logtm->tm_year+1900, logtm->tm_mon+1, logtm->tm_mday ); } } logpart = xml_findfirst( curlog, "groundspeak:log_wpt" ); if ( logpart ) { char *coordstr = NULL; float lat = 0; float lon = 0; coordstr = xml_attribute( logpart, "lat" ); if ( coordstr ) { lat = atof( coordstr ); } coordstr = xml_attribute( logpart, "lon" ); if ( coordstr ) { lon = atof( coordstr ); } coordstr = pretty_deg_format(lat, lon, degformat[2], " ", 0); gbfprintf( file_out, "%s\n", coordstr); xfree(coordstr); } logpart = xml_findfirst( curlog, "groundspeak:text" ); if ( logpart ) { char *encstr = NULL; char *s = NULL; int encoded = 0; encstr = xml_attribute( logpart, "encoded" ); encoded = (encstr[0] != 'F'); if ( txt_encrypt && encoded ) { s = rot13( logpart->cdata ); } else { s = xstrdup( logpart->cdata ); } gbfprintf( file_out, "%s", s ); xfree( s ); } gbfprintf( file_out, "\n" ); curlog = xml_findnext( root, curlog, "groundspeak:log" ); } } if (! suppresssep) gbfprintf(file_out, "\n-----------------------------------------------------------------------------\n"); else gbfprintf(file_out, "\n"); if (split_output) { gbfclose(file_out); file_out = NULL; } }
int btdev_cache_load(int locked) { char buf[256]; FILE *cfd; size_t read; char *next = NULL, *elem, *attrs, *attr, *value; BD_ADDR bda; int found = 0, eof = 0; struct stat st; if (!devcache.file && btdev_cache_init() < 0) return -1; if (stat(devcache.file, &st) < 0) { return -1; } if (st.st_mtime == devcache.stamp) { if (locked && btdev_cache_lock() < 0) { return -1; } return 0; } devcache.stamp = st.st_mtime; if (btdev_cache_lock() < 0) { return -1; } cfd = fopen(devcache.file, "r"); if (!cfd){ fprintf(stderr, "Unable to open cache: %s\n", devcache.file); btdev_cache_unlock(); return -1; } if (devcache.head) { s_list_destroy(&devcache.head); devcache.head = NULL; devcache.count = 0; } for (;;) { int free; if (next) { /* we have some info in the buffer */ free = next - buf; memmove(buf, next, sizeof(buf) - free); } else free = sizeof(buf); if (!eof) { //printf("reading %d butes\n", free); read = fread(buf + sizeof(buf) - free, 1, free, cfd); if (!read) eof = 1; } next = (void*)buf; elem = xml_element(&next, &attrs); if (!elem) break; if (!found) if (strcmp(elem, "device-listing") == 0) { found = 1; continue; } if (strcmp(elem, "/device-listing") == 0) break; //printf("element: %s\n", elem); //printf("attr left: %s\n", attrs); // get attributes if (strcmp(elem, "device") == 0) { btdev_struct *entry; entry = NULL; while ((attr = xml_attribute(&attrs, &value))) { //printf("%s = %s\n", attr, value); if (!entry) { if (strcmp(attr, "bda") == 0) { str2bda(&bda, value); entry = btdev_cache_add(&bda); } } else if (strcmp(attr, "class") == 0) { sscanf(value, "%x", &entry->cod); } else if (strcmp(attr, "name") == 0) { strcpy(entry->name, value); } else if (strcmp(attr, "key") == 0) { unsigned int val; int i; /* convert key to binary format */ for (i = 0; sscanf(value, "%2x", &val) > 0 && i < 16; i++, value += 2) { entry->link_key[i] = val; } if (i) entry->flags |= BTDEV_KEY; } } } } fclose(cfd); if (!locked) btdev_cache_unlock(); return 0; }
void xml_node::add_attribute(const char * name, const char * value) { attributes_.emplace(name,xml_attribute(value)); }
void xml_node::add_attribute(const char * name, const char * value) { attributes_.insert(std::make_pair(name,xml_attribute(value))); }