📄 main.c
字号:
expr = xmlStrcat(expr, "\" and not(rng:empty) and not(rng:notAllowed)]"); attrGrpDefNodes = findNodes(xpathCtx, expr); if (!attrGrpDefNodes->nodeNr) { fprintf(stdout, "Warning: found 0 non-empty or allowed definition for the Group of Attributes: %s\n", name); return NULL; } attgrp = NewSVGGenAttrGrp(); attgrp->name = strdup(name); svgNameToImplementationName(attgrp->name, attgrp->imp_name); gf_list_add(globalAttrGrp, attgrp); for (i = 0; i < attrGrpDefNodes->nodeNr; i++) { xmlNodePtr attrGrp = attrGrpDefNodes->nodeTab[i]; getRealAttributes(doc, xpathCtx, attrGrp, attgrp->attrs); { xmlNodeSetPtr refNodes; xpathCtx->node = attrGrp; refNodes = findNodes(xpathCtx, ".//rng:ref"); for (l = 0; l < refNodes->nodeNr; l++) { xmlNodePtr ref = refNodes->nodeTab[l]; xmlChar *rname = xmlGetProp(ref, "name"); if (xmlStrstr(rname, ".attr")) { SVGGenAttrGrp *g2 = getOneGlobalAttrGrp(doc, xpathCtx, rname); if (g2) { gf_list_add(attgrp->attrgrps, g2); } } } } } return attgrp;}void getAllGlobalAttrGrp(xmlDocPtr doc, xmlXPathContextPtr xpathCtx) { xmlNodeSetPtr elementNodes = findNodes(xpathCtx, "//rng:define"); int k; for (k = 0; k < elementNodes->nodeNr; k++) { xmlNodePtr elementNode = elementNodes->nodeTab[k]; if (elementNode->type == XML_ELEMENT_NODE) { xmlChar *name = NULL; name = xmlGetProp(elementNode, "name"); if (xmlStrstr(name, ".attr")) { getOneGlobalAttrGrp(doc, xpathCtx, name); } } }}GF_List *getElements(xmlDocPtr doc, xmlXPathContextPtr xpathCtx){ xmlChar *expr; GF_List *elements = gf_list_new(); xmlNodeSetPtr ATNodes; xmlNodeSetPtr refNodes, elementNodes = findNodes(xpathCtx, "//rng:element"); int k, j; u32 i; for (k = 0; k < elementNodes->nodeNr; k++) { xmlNodePtr elementNode = elementNodes->nodeTab[k]; if (elementNode->type == XML_ELEMENT_NODE) { SVGGenElement *e = NewSVGGenElement(); e->svg_name = xmlStrdup(xmlGetProp(elementNode, "name")); //fprintf(stdout, "\n\tElement %s\n", e->svg_name); svgNameToImplementationName(e->svg_name, e->implementation_name); /* getting the <define name="element.AT"/> */ expr = xmlStrdup("//rng:define[@name=\""); if (!xmlStrcmp(e->svg_name, "polygon") || !xmlStrcmp(e->svg_name, "polyline")) { expr = xmlStrcat(expr, "polyCommon"); } else { expr = xmlStrcat(expr, e->svg_name); } expr = xmlStrcat(expr, ".AT\"]"); ATNodes = findNodes(xpathCtx, expr); if (ATNodes->nodeNr) { /* dealing with attributes defined in groups of attributes */ xpathCtx->node = ATNodes->nodeTab[0]; refNodes = findNodes(xpathCtx, ".//rng:ref"); for (j = 0; j <refNodes->nodeNr; j++) { xmlNodePtr refNode = refNodes->nodeTab[j]; char *name = xmlGetProp(refNode, "name"); for (i = 0; i < gf_list_count(globalAttrGrp); i++) { SVGGenAttrGrp *a = gf_list_get(globalAttrGrp, i); if (!strcmp(a->name, name)) { if (isGenericAttributesGroup(a->name)) { setGenericAttributesFlags(a->name, e); flattenAttributeGroup(*a, e, 1); } else { flattenAttributeGroup(*a, e, 0); } break; } } } /* dealing with attributes defined directly here */ getRealAttributes(doc, xpathCtx, ATNodes->nodeTab[0], e->attributes); } /* checking if this element is already present in the list of possible elements and if not, adding it */ { Bool found = 0; for (i=0;i<gf_list_count(elements); i++) { SVGGenElement *etmp = gf_list_get(elements, i); if (!strcmp(etmp->svg_name, e->svg_name)) { found = 1; break; } } if (!found) gf_list_add(elements, e); } } } return elements;}/*type: 0: header, 1: source*/FILE *BeginFile(u32 type){ FILE *f; char sPath[GF_MAX_PATH]; if (!type) {#ifdef LOCAL_SVG_NODES sprintf(sPath, "nodes_svg.h", GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR);#else if (generation_mode == 1) sprintf(sPath, "..%c..%c..%c..%cinclude%cgpac%cnodes_svg_sa.h", GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR); else if (generation_mode == 2) sprintf(sPath, "..%c..%c..%c..%cinclude%cgpac%cnodes_svg_sani.h", GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR); else if (generation_mode == 3) sprintf(sPath, "..%c..%c..%c..%cinclude%cgpac%cnodes_svg_da.h", GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR); #endif } else if (type==1) {#ifdef LOCAL_SVG_NODES sprintf(sPath, "svg_nodes.c", GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR);#else if (generation_mode == 1) sprintf(sPath, "..%c..%c..%c..%csrc%cscenegraph%csvg_nodes_sa.c", GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR); else if (generation_mode == 2) sprintf(sPath, "..%c..%c..%c..%csrc%cscenegraph%csvg_nodes_sani.c", GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR); else if (generation_mode == 3) sprintf(sPath, "..%c..%c..%c..%csrc%cscenegraph%csvg_nodes_da.c", GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR);#endif } else {#ifdef LOCAL_SVG_NODES sprintf(sPath, "lsr_tables.c", GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR);#else if (generation_mode == 1) sprintf(sPath, "..%c..%c..%c..%csrc%claser%clsr_tables_sa.c", GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR); else if (generation_mode == 2) sprintf(sPath, "..%c..%c..%c..%csrc%claser%clsr_tables_sani.c", GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR); else if (generation_mode == 3) sprintf(sPath, "..%c..%c..%c..%csrc%claser%clsr_tables.c", GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR);#endif } f = fopen(sPath, "wt"); fprintf(f, "%s\n", COPYRIGHT); { time_t rawtime; time(&rawtime); fprintf(f, "\n/*\n\tDO NOT MOFIFY - File generated on GMT %s\n\tBY SVGGen for GPAC Version %s\n*/\n\n", asctime(gmtime(&rawtime)), GPAC_VERSION); } if (!type) { if (generation_mode == 1) { fprintf(f, "#ifndef _GF_SVG_SA_NODES_H\n"); fprintf(f, "#define _GF_SVG_SA_NODES_H\n\n"); } else if (generation_mode == 2) { fprintf(f, "#ifndef _GF_SVG_SANI_NODES_H\n"); fprintf(f, "#define _GF_SVG_SANI_NODES_H\n\n"); } else if (generation_mode == 3) { fprintf(f, "#ifndef _GF_SVG_NODES_H\n"); fprintf(f, "#define _GF_SVG_NODES_H\n\n"); } fprintf(f, "#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n"); } return f;}void EndFile(FILE *f, u32 type){ if (!type) { fprintf(f, "#ifdef __cplusplus\n}\n#endif\n\n"); if (generation_mode == 1) fprintf(f, "\n\n#endif\t\t/*_GF_SVG_SA_NODES_H*/\n\n"); if (generation_mode == 2) fprintf(f, "\n\n#endif\t\t/*_GF_SVG_SANI_NODES_H*/\n\n"); if (generation_mode == 3) fprintf(f, "\n\n#endif\t\t/*_GF_SVG_NODES_H*/\n\n"); } else { fprintf(f, "\n"); } fclose(f);}void generateAttributes(FILE *output, GF_List *attributes, Bool inDefine) { u32 i; for (i = 0; i<gf_list_count(attributes); i++) { SVGGenAttribute *att = (SVGGenAttribute *)gf_list_get(attributes, i); if (inDefine) if (i == gf_list_count(attributes) -1) fprintf(output, "\t%s %s;\n", att->impl_type, att->implementation_name); else fprintf(output, "\t%s %s; \\\n", att->impl_type, att->implementation_name); else fprintf(output, "\t%s %s;\n", att->impl_type, att->implementation_name); }}/*u32 generateAttributesGroupInfo(FILE *output, char * elt_imp_name, SVGGenAttrGrp *attgrp, u32 i){ u32 att_index = i; u32 k; for (k=0; k<gf_list_count(attgrp->attrgrps); k++) { SVGGenAttrGrp *ag = gf_list_get(attgrp->attrgrps, k); att_index = generateAttributesGroupInfo(output, elt_imp_name, ag, att_index); } for (k=0; k<gf_list_count(attgrp->attrs); k++) { SVGGenAttribute *at = gf_list_get(attgrp->attrs, k); generateAttributeInfo(output, elt_imp_name, at, att_index++); } return att_index;}*/void replaceIncludes(xmlDocPtr doc, xmlXPathContextPtr xpathCtx){ int k; xmlNodeSetPtr nodes; xmlXPathObjectPtr xpathObj; /* Get all the RNG elements */ xpathObj = xmlXPathEvalExpression("//rng:include", xpathCtx); if(xpathObj == NULL || xpathObj->type != XPATH_NODESET) return; nodes = xpathObj->nodesetval; for (k = 0; k < nodes->nodeNr; k++) { xmlNodePtr node = nodes->nodeTab[k]; if (node->type == XML_ELEMENT_NODE) { xmlChar *href; xmlDocPtr sub_doc; href = xmlGetNoNsProp(node, "href"); sub_doc = xmlParseFile(href); xmlReplaceNode(nodes->nodeTab[k], xmlDocGetRootElement(sub_doc)); } } xmlXPathFreeObject(xpathObj);}int main(int argc, char **argv){ xmlDocPtr doc = NULL; xmlXPathContextPtr xpathCtx = NULL; GF_List *svg_elements = NULL; xmlInitParser(); LIBXML_TEST_VERSION doc = xmlParseFile(argv[1]); if (!doc) { printf("error: could not parse file %s\n", argv[1]); return -1; } xpathCtx = xmlXPathNewContext(doc); if(xpathCtx == NULL) { fprintf(stderr,"Error: unable to create new XPath context\n"); xmlFreeDoc(doc); return(-1); } xmlXPathRegisterNs(xpathCtx, RNG_PREFIX, RNG_NS); xmlXPathRegisterNs(xpathCtx, RNGA_PREFIX, RNGA_NS); xmlXPathRegisterNs(xpathCtx, SVGA_PREFIX, SVGA_NS); replaceIncludes(doc, xpathCtx); xmlSaveFile("completerng_props.xml", doc); globalAttrGrp = gf_list_new(); getAllGlobalAttrGrp(doc, xpathCtx); svg_elements = getElements(doc, xpathCtx); svg_elements = sortElements(svg_elements); if (argv[2] && !strcmp(argv[2], "-html")) { generate_table(svg_elements); } else { if (generation_mode == 1) generateSVGCode_V1(svg_elements); if (generation_mode == 2) generateSVGCode_V2(svg_elements); if (generation_mode == 3) generateSVGCode_V3(svg_elements); } xmlXPathFreeContext(xpathCtx); //xmlFreeDoc(doc); xmlCleanupParser(); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -