Exemplo n.º 1
0
xmlNodePtr tagElement(KEYVAL *tag)
{        

	char *key;
	
	key = getKey(tag);

	xmlNodePtr tagNode;
	tagNode = xmlNewNode(NULL, BAD_CAST "tag");
	xmlNewProp(tagNode, BAD_CAST "k", BAD_CAST xmlEscape(getKey(tag)));
	xmlNewProp(tagNode, BAD_CAST "v", BAD_CAST xmlEscape(getValue(tag)));
	return tagNode;
}
Exemplo n.º 2
0
void Reports::writeCheckStyle(std::ostream & os, bool omitDuplicates)
{
    std::string severity = prefix_;
    if (severity == "")
    {
        severity = "info";
    }
    os<< "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
    os << "<checkstyle version=\"5.0\">\n";

    for (MessagesCollection::iterator it = messages_.begin(), end = messages_.end();
         it != end; ++it)
    {
        const FileName & name = it->first;

        os << "    <file name=\"" << name << "\">\n";

        FileMessagesCollection & fileMessages = it->second;

        FileMessagesCollection::iterator fit = fileMessages.begin();
        FileMessagesCollection::iterator fend = fileMessages.end();

        int lastLineNumber = 0;
        SingleReport lastReport;
        for ( ; fit != fend; ++fit)
        {
            int lineNumber = fit->first;
            const SingleReport & report = fit->second;
            const Rules::RuleName & rule = report.first;
            const Message & msg = report.second;

            if (omitDuplicates == false ||
                lineNumber != lastLineNumber || report != lastReport)
            {
                os << "        <error source=\"" << xmlEscape(rule)
                    << "\" severity=\"" << xmlEscape(severity)
                    << "\" line=\"" << lineNumber
                    << "\" message=\"" << xmlEscape(msg)
                    << "\" />\n";

                lastLineNumber = lineNumber;
                lastReport = report;
            }
        }

        os << "    </file>\n";
    }

    os << "</checkstyle>\n";
}
Exemplo n.º 3
0
xmlNodePtr nodeElement(NODE node)
{
	if (strcmp(srid, "4326") != 0) 
	{
		node = transformPoint(node, srid);
	}

	xmlNodePtr osmNode;
	osmNode = xmlNewNode(NULL, BAD_CAST "node");
	xmlNewProp(osmNode, BAD_CAST "id", BAD_CAST xmlEscape(int2char(node.id)));
	xmlNewProp(osmNode, BAD_CAST "lon", BAD_CAST xmlEscape(dbl2char(node.x)));
	xmlNewProp(osmNode, BAD_CAST "lat", BAD_CAST xmlEscape(dbl2char(node.y))); 
	return osmNode;
	
}
Exemplo n.º 4
0
String Diagnostic::format(const DiagnosticsMap &diagnostics)
{
    String xmlDiagnostics = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n  <checkstyle>";
    if (!diagnostics.isEmpty()) {
        const char *severities[] = { "none", "warning", "error", "fixit", "skipped" };
        uint32_t lastFileId = 0;

        for (const auto &entry : diagnostics) {
            const Location &loc = entry.first;
            const Diagnostic &diagnostic = entry.second;
            if (loc.fileId() != lastFileId) {
                if (lastFileId)
                    xmlDiagnostics += "\n    </file>";
                lastFileId = loc.fileId();
                xmlDiagnostics += String::format<128>("\n    <file name=\"%s\">", loc.path().constData());
            }
            if (diagnostic.type != Diagnostic::None) {
                xmlDiagnostics += String::format("\n      <error line=\"%d\" column=\"%d\" %sseverity=\"%s\" message=\"%s\"/>",
                                                 loc.line(), loc.column(),
                                                 (diagnostic.length <= 0 ? ""
                                                  : String::format<32>("length=\"%d\" ", diagnostic.length).constData()),
                                                 severities[diagnostic.type], xmlEscape(diagnostic.message).constData());
            }
        }
        if (lastFileId)
            xmlDiagnostics += "\n    </file>";
    }

    xmlDiagnostics += "\n  </checkstyle>";
    return xmlDiagnostics;
}
Exemplo n.º 5
0
xmlNodePtr wayElement(int id)
{
	xmlNodePtr osmWay;
	osmWay = xmlNewNode(NULL, BAD_CAST "way");
	xmlNewProp(osmWay, BAD_CAST "id", BAD_CAST xmlEscape(int2char(id)));
	
	return osmWay;
}
Exemplo n.º 6
0
xmlNodePtr nodeRef(NODE node)
{
	xmlNodePtr nd;
	nd = xmlNewNode(NULL, BAD_CAST "nd");
	xmlNewProp(nd, BAD_CAST "ref", BAD_CAST xmlEscape(int2char(node.id)));
	
	return nd;
}
Exemplo n.º 7
0
void Reports::writeXml(std::ostream & os, bool omitDuplicates)
{
    os<< "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl;
    os << "<vera>\n";

    for (MessagesCollection::iterator it = messages_.begin(), end = messages_.end();
         it != end; ++it)
    {
        const FileName & name = it->first;

        os << "    <file name=\"" << name << "\">\n";

        FileMessagesCollection & fileMessages = it->second;

        FileMessagesCollection::iterator fit = fileMessages.begin();
        FileMessagesCollection::iterator fend = fileMessages.end();

        int lastLineNumber = 0;
        SingleReport lastReport;
        for ( ; fit != fend; ++fit)
        {
            int lineNumber = fit->first;
            const SingleReport & report = fit->second;
            const Rules::RuleName & rule = report.first;
            const Message & msg = report.second;

            if (omitDuplicates == false ||
                lineNumber != lastLineNumber || report != lastReport)
            {
                if (showRules_)
                {
                    os << "        <report rule=\"" << xmlEscape(rule)
                        << "\" line=\"" << lineNumber
                        << "\">![CDATA[" << msg << "]]</report>\n";
                }
                else
                {
                    os << "        <report line=\"" << lineNumber
                        << "\">![CDATA[" << msg << "]]</report>\n";
                }

                lastLineNumber = lineNumber;
                lastReport = report;
            }
        }

        os << "    </file>\n";
    }

    os << "</vera>\n";
}
Exemplo n.º 8
0
xmlDocPtr createXmlDoc(SHAPE *shape, RULESET *ruleset)
{
	int i, j;
	xmlDocPtr doc = NULL;
	xmlNodePtr root_node = NULL;

	srid = shape->srid;

	// apply ruleset, set alt field name to use for osm tags
	for (i = 0; i < (shape->num_fields - 1); i++)
	{
		for (j = 0; j < (ruleset->num_rules - 1); j++) {
			if ((strcmp(getKey(&shape->fields[i]), getKey(&ruleset->rules[j])) == 0))
			{
				setValue(&shape->fields[i], getValue(&ruleset->rules[j]));
			}
		}
	}	
	
	doc = xmlNewDoc(BAD_CAST "1.0");
	root_node = xmlNewNode(NULL, BAD_CAST "osm");
	xmlNewProp(root_node, BAD_CAST "version", BAD_CAST xmlEscape("0.6"));
	xmlDocSetRootElement(doc, root_node);

	if (shape->filetype == SHPT_POINT)
	{
		buildNodes(root_node, parsePoints(shape), shape);
	} else if (shape->filetype == SHPT_MULTIPOINT) {
		// TODO
		fprintf(stderr, "Error: Unknown or invalid shapefile type\n");
		exit(0);
	} else if (shape->filetype == SHPT_ARC) {
		parseLine(root_node, shape);
	} else {
		fprintf(stderr, "Error: Unknown or invalid shapefile type\n");
		exit(0);
	}

	fprintf(stderr, "Done: processed %d records.\n", shape->num_records);

	return doc;
}
Exemplo n.º 9
0
bool PropertyDict::writeXmlFile( FILE *fptr, int release )
{
    // Write out all properties to a string list for sorting
    QStringList propList;
    QDictIterator<Property> it( *this );
    Property *p;
    QString xml("");
    while( it.current() )
    {
        p = (Property *) it.current();
        if ( p->isCurrent( release ) )
        {
            if ( p->m_value.isNull()
              || p->m_value.isEmpty() )
            {
                xml = "";
            }
            else
            {
                xml = p->m_value;
                xmlEscape( xml );
            }
            propList.append(
                QString( "  <property name=\"%1\" value=\"%2\" />" )
                    .arg( it.currentKey() ).arg( xml ) );
        }
        ++it;
    }
    // Sort the list and write it to the file
    propList.sort();
    for ( QStringList::Iterator sit=propList.begin();
          sit != propList.end();
          ++sit )
    {
        fprintf( fptr, "%s\n", (*sit).latin1() );
    }
    return( true );
}
Exemplo n.º 10
0
void pfPrcHelper::writeParam(const char* name, const ST::string& value) {
    ST::string buf = ST::format(" {}=\"{}\"", name, xmlEscape(value));
    file->writeStr(buf);
}
Exemplo n.º 11
0
void pfPrcHelper::directWrite(const ST::string& text)
{
    file->writeStr(xmlEscape(text));
}
Exemplo n.º 12
0
bool ClangIndexer::diagnose()
{
    if (!mClangUnit) {
        return false;
    }

    List<String> compilationErrors;
    const unsigned diagnosticCount = clang_getNumDiagnostics(mClangUnit);

    Map<Location, XmlEntry> xmlEntries;

    for (unsigned i=0; i<diagnosticCount; ++i) {
        CXDiagnostic diagnostic = clang_getDiagnostic(mClangUnit, i);
        const CXSourceLocation diagLoc = clang_getDiagnosticLocation(diagnostic);
        const Location loc = createLocation(diagLoc, 0);
        const uint32_t fileId = loc.fileId();
        if (mData->visited.value(fileId)) {
            const String msg = RTags::eatString(clang_getDiagnosticSpelling(diagnostic));
            const CXDiagnosticSeverity sev = clang_getDiagnosticSeverity(diagnostic);
            XmlEntry::Type type = XmlEntry::None;
            switch (sev) {
            case CXDiagnostic_Warning:
                type = XmlEntry::Warning;
                break;
            case CXDiagnostic_Error:
            case CXDiagnostic_Fatal:
                type = XmlEntry::Error;
                break;
            default:
                break;
            }
            if (type != XmlEntry::None) {
                const unsigned rangeCount = clang_getDiagnosticNumRanges(diagnostic);
                bool ok = false;
                for (unsigned rangePos = 0; rangePos < rangeCount; ++rangePos) {
                    const CXSourceRange range = clang_getDiagnosticRange(diagnostic, rangePos);
                    const CXSourceLocation start = clang_getRangeStart(range);
                    const CXSourceLocation end = clang_getRangeEnd(range);

                    unsigned startOffset, endOffset;
                    clang_getSpellingLocation(start, 0, 0, 0, &startOffset);
                    clang_getSpellingLocation(end, 0, 0, 0, &endOffset);
                    if (!rangePos && !startOffset && !endOffset) {
                        // huh, range invalid? fall back to diag location
                        break;
                    } else {
                        unsigned int line, column;
                        clang_getPresumedLocation(start, 0, &line, &column);
                        const Location key(loc.fileId(), line, column);
                        xmlEntries[key] = XmlEntry(type, msg, endOffset - startOffset);
                        ok = true;
                        break;
                    }
                }
                if (!ok) {
                    unsigned line, column;
                    clang_getPresumedLocation(diagLoc, 0, &line, &column);
                    const Location key(loc.fileId(), line, column);
                    xmlEntries[key] = XmlEntry(type, msg);
                    // no length
                }
            }
            // logDirect(RTags::CompilationError, msg.constData());

            const unsigned fixItCount = clang_getDiagnosticNumFixIts(diagnostic);
            for (unsigned f=0; f<fixItCount; ++f) {
                CXSourceRange range;
                const CXStringScope stringScope = clang_getDiagnosticFixIt(diagnostic, f, &range);
                CXSourceLocation start = clang_getRangeStart(range);

                unsigned line, column;
                CXString file;
                clang_getPresumedLocation(start, &file, &line, &column);
                CXStringScope fileScope(file);

                const Location loc = createLocation(clang_getCString(file), line, column);
                if (mData->visited.value(loc.fileId())) {
                    unsigned int startOffset, endOffset;
                    CXSourceLocation end = clang_getRangeEnd(range);
                    clang_getSpellingLocation(start, 0, 0, 0, &startOffset);
                    clang_getSpellingLocation(end, 0, 0, 0, &endOffset);
                    const char *string = clang_getCString(stringScope);
                    error("Fixit for %s:%d:%d: Replace %d characters with [%s]", loc.path().constData(),
                          line, column, endOffset - startOffset, string);
                    XmlEntry &entry = xmlEntries[Location(loc.fileId(), line, column)];
                    entry.type = XmlEntry::Fixit;
                    if (entry.message.isEmpty()) {
                        entry.message = String::format<64>("did you mean '%s'?", string);
                    }
                    entry.length = endOffset - startOffset;
                    mData->fixIts[loc.fileId()].insert(FixIt(line, column, endOffset - startOffset, string));
                }
            }
        }

        clang_disposeDiagnostic(diagnostic);
    }

    mData->xmlDiagnostics = "<?xml version=\"1.0\" encoding=\"utf-8\"?><checkstyle>";
    if (!xmlEntries.isEmpty()) {
        Map<Location, XmlEntry>::const_iterator entry = xmlEntries.begin();
        const Map<Location, XmlEntry>::const_iterator end = xmlEntries.end();

        const char *severities[] = { "none", "warning", "error", "fixit" };

        uint32_t lastFileId = 0;
        while (entry != end) {
            const Location &loc = entry->first;
            const XmlEntry &xmlEntry = entry->second;
            if (loc.fileId() != lastFileId) {
                if (lastFileId)
                    mData->xmlDiagnostics += "</file>";
                lastFileId = loc.fileId();
                mData->xmlDiagnostics += String::format<128>("<file name=\"%s\">", loc.path().constData());
            }
            mData->xmlDiagnostics += String::format("<error line=\"%d\" column=\"%d\" %sseverity=\"%s\" message=\"%s\"/>",
                                                    loc.line(), loc.column(),
                                                    (xmlEntry.length <= 0 ? ""
                                                     : String::format<32>("length=\"%d\" ", xmlEntry.length).constData()),
                                                    severities[xmlEntry.type], xmlEscape(xmlEntry.message).constData());
            ++entry;
        }
        if (lastFileId)
            mData->xmlDiagnostics += "</file>";
    }

    for (Hash<uint32_t, bool>::const_iterator it = mData->visited.begin(); it != mData->visited.end(); ++it) {
        if (it->second) {
            const Map<Location, XmlEntry>::const_iterator x = xmlEntries.lower_bound(Location(it->first, 0, 0));
            if (x == xmlEntries.end() || x->first.fileId() != it->first) {
                const String fn = Location::path(it->first);
                mData->xmlDiagnostics += String::format("<file name=\"%s\"/>", fn.constData());
            }
        }
    }

    mData->xmlDiagnostics += "</checkstyle>";
    return true;
}
Exemplo n.º 13
0
static int writeCombine()
{
	const char* path;
	int i, j;

	if (!io_openfile(path_join(prj_get_path(), prj_get_name(), "cmbx")))
		return 0;

	io_print("<Combine fileversion=\"1.0\" name=\"%s\" description=\"\">\n", prj_get_name());

	/* TODO: select the first executable project */
	io_print("  <StartMode startupentry=\"\" single=\"True\">\n");

	/* Write out the startup entries */
	for (i = 0; i < prj_get_numpackages(); ++i)
	{
		prj_select_package(i);
		io_print("    <Execute entry=\"%s\" type=\"None\" />\n", prj_get_pkgname());
	}

	io_print("  </StartMode>\n");
	io_print("  <Entries>\n");

	/* Write out the project entries */
	for (i = 0; i < prj_get_numpackages(); ++i)
	{
		prj_select_package(i);
		path = prj_get_pkgfilename("prjx");
		io_print("    <Entry filename=\"");
		if (path[0] != '.')
			io_print("./");
		io_print("%s\" />\n", path);
	}

	io_print("  </Entries>\n");
	io_print("  <Configurations active=\"Debug\">\n");

	/* Write out the entries for each build configuration */
	for (i = 0; i < prj_get_numconfigs(); ++i)
	{
		prj_select_config(i);
		io_print("    <Configuration name=\"%s\">\n", xmlEscape(prj_get_cfgname()));

		/* List all packages under this configuration */
		prj_select_config(0);
		for(j = 0; j < prj_get_numpackages(); j++)
		{
			prj_select_package(j);
			io_print("      <Entry name=\"%s\" configurationname=\"%s\" build=\"False\" />\n", prj_get_pkgname(), xmlEscape(prj_get_cfgname()));
		}

		io_print("    </Configuration>\n");
	}

	/* Finish */
	io_print("  </Configurations>\n");
	io_print("</Combine>");
	io_closefile();

	/* MonoDevelop adds another file */
	if (sharpdev_target == MONODEV)
	{
		if (!io_openfile(path_join(prj_get_path(), prj_get_name(), "mdsx")))
			return 0;

		prj_select_config(0);
		io_print("<MonoDevelopSolution fileversion=\"1.0\">\n");
		io_print("  <RelativeOutputPath>%s</RelativeOutputPath>\n", prj_get_bindir());
		io_print("</MonoDevelopSolution>\n");

		io_closefile();
	}

	return 1;
}