[Rojav-commits] rocs/gen wgen.c,1.23,1.24
Brought to you by:
robvrs
|
From: rob v. <ro...@us...> - 2005-11-30 06:11:27
|
Update of /cvsroot/rojav/rocs/gen In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15326 Modified Files: wgen.c Log Message: external description files Index: wgen.c =================================================================== RCS file: /cvsroot/rojav/rocs/gen/wgen.c,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** wgen.c 17 Nov 2005 17:03:46 -0000 1.23 --- wgen.c 30 Nov 2005 06:11:18 -0000 1.24 *************** *** 36,41 **** --- 36,45 ---- #include "rocs/public/map.h" #include "rocs/public/thread.h" + #include "rocs/public/cmdln.h" static iOMap nodeMap = NULL; + static iOMap descMap = NULL; + + static int __fillDescMap( const char* descfile, const char* lang ); static int __gConstHdr( iONode node, const char* fileName, Boolean docAll ); *************** *** 61,64 **** --- 65,71 ---- int rc = 0; Boolean docAll = False; + iOCmdLn arg = NULL; + const char* lang = NULL; + const char* descfile = NULL; iOTrace trc = TraceOp.inst( TRCLEVEL_INFO, "wgen", True ); *************** *** 79,86 **** MemOp.resetDump(); ! if( argc > 2 ) { ! if( StrOp.equalsi( "-all", argv[2] ) ) ! docAll = True; } /* Read const.xml */ if( argc > 1 ) { --- 86,102 ---- MemOp.resetDump(); ! /* Check commandline arguments. */ ! arg = CmdLnOp.inst( argc, argv ); ! ! lang = CmdLnOp.getStrDef( arg, "-lang", "en" ); ! descfile = CmdLnOp.getStrDef( arg, "-desc", NULL ); ! descMap = MapOp.inst(); ! ! if( descfile != NULL ) { ! __fillDescMap( descfile, lang ); } + + docAll = CmdLnOp.hasKey( arg, "-all" ); + /* Read const.xml */ if( argc > 1 ) { *************** *** 149,152 **** --- 165,236 ---- + static const char* __getRemark( iONode node ) { + if( StrOp.equalsi( "var", NodeOp.getName( node ) ) || StrOp.equalsi( "const", NodeOp.getName( node ) ) ) { + iONode parent = NodeOp.getParent( node ); + char* id = NULL; + const char* desc = NULL; + + if( parent == NULL ) + return NodeOp.getStr( node, "remark", "" ); + id = StrOp.fmt( "%s.%s", NodeOp.getName( parent ), NodeOp.getStr( node, "name", "" ) ); + desc = (const char*)MapOp.get( descMap, StrOp.strlwr( id ) ); + StrOp.free( id ); + return desc == NULL ? NodeOp.getStr( node, "remark", "" ):desc; + } + else { + char* nodename = StrOp.dup( NodeOp.getName( node ) ); + const char* desc = (const char*)MapOp.get( descMap, StrOp.strlwr( nodename ) ); + StrOp.free( nodename ); + if( desc != NULL ) + return desc; + return NodeOp.getStr( node, "remark", "" ); + } + } + + static int __fillDescMap( const char* descfile, const char* lang ) { + + iOFile descXml = FileOp.inst( descfile, OPEN_READONLY ); + char* xmlStr = allocMem( FileOp.size( descXml ) + 1 ); + iODoc doc = NULL; + iONode root = NULL; + + TraceOp.println( "Reading %s...", descfile ); + FileOp.read( descXml, xmlStr, FileOp.size( descXml ) ); + FileOp.close( descXml ); + FileOp.base.del( descXml ); + + TraceOp.println( "Parsing %s...", descfile ); + doc = DocOp.parse( xmlStr ); + freeMem( xmlStr ); + if( doc == NULL ) + return 0; + root = DocOp.getRootNode( doc ); + + if( root == NULL ) + return 0; + + { + int childCnt = NodeOp.getChildCnt( root ); + int i = 0; + TraceOp.println( "Processing %d childs.", childCnt ); + for( i = 0; i < childCnt; i++ ) { + iONode child = NodeOp.getChild( root, i ); + if( NodeOp.getType( child ) == ELEMENT_NODE && StrOp.equalsi( NodeOp.getName(child), "description") ) { + iONode langnode = NodeOp.findNode( child, lang ); + if( langnode != NULL ) { + const char* id = NodeOp.getStr( child, "id", NULL ); + const char* text = NodeOp.getStr( langnode, "text", NULL ); + if( id != NULL && text != NULL ) { + MapOp.put( descMap, StrOp.strlwr( id ), (obj)StrOp.dup(text) ); + TraceOp.println( "descMap: %s, [%-20.20s...] added." ); + } + } + } + } + } + + } + + static int __processPrefix( iOFile fHdr, iOFile fImpl, iOFile fDoc, iOFile fIndex, const char* modulename, const char* title, const char* docname ) { *************** *** 516,520 **** FileOp.fmt( fImplC, "static struct __attrdef __%s = {\n", attrName ); FileOp.fmt( fImplC, " \"%s\",", NodeOp.getStr( var, "name", "?" ) ); ! FileOp.fmt( fImplC, " \"%s\",", NodeOp.getStr( var, "remark", "" ) ); FileOp.fmt( fImplC, " \"%s\",", NodeOp.getStr( var, "unit", "" ) ); FileOp.fmt( fImplC, " \"%s\",", NodeOp.getStr( var, "vt", "string" ) ); --- 600,604 ---- FileOp.fmt( fImplC, "static struct __attrdef __%s = {\n", attrName ); FileOp.fmt( fImplC, " \"%s\",", NodeOp.getStr( var, "name", "?" ) ); ! FileOp.fmt( fImplC, " \"%s\",", __getRemark(var) ); FileOp.fmt( fImplC, " \"%s\",", NodeOp.getStr( var, "unit", "" ) ); FileOp.fmt( fImplC, " \"%s\",", NodeOp.getStr( var, "vt", "string" ) ); *************** *** 569,573 **** FileOp.fmt( fImplC, "static struct __nodedef __%s = {\n", nodeName ); FileOp.fmt( fImplC, " \"%s\",", nodeName ); ! FileOp.fmt( fImplC, " \"%s\",", NodeOp.getStr( node, "remark", "" ) ); FileOp.fmt( fImplC, " %s,", NodeOp.getBool( node, "required", False )?"True":"False" ); FileOp.fmt( fImplC, " \"%s\",", NodeOp.getStr( node, "cardinality", "1" ) ); --- 653,657 ---- FileOp.fmt( fImplC, "static struct __nodedef __%s = {\n", nodeName ); FileOp.fmt( fImplC, " \"%s\",", nodeName ); ! FileOp.fmt( fImplC, " \"%s\",", __getRemark(node) ); FileOp.fmt( fImplC, " %s,", NodeOp.getBool( node, "required", False )?"True":"False" ); FileOp.fmt( fImplC, " \"%s\",", NodeOp.getStr( node, "cardinality", "1" ) ); *************** *** 656,660 **** FileOp.fmt( fImplC, "static struct __nodedef __%s = {\n", nodeName ); FileOp.fmt( fImplC, " \"%s\",", xmlName ); ! FileOp.fmt( fImplC, " \"%s\",", NodeOp.getStr( node, "remark", "" ) ); FileOp.fmt( fImplC, " %s,", NodeOp.getBool( node, "required", False )?"True":"False" ); FileOp.fmt( fImplC, " \"%s\",\n", NodeOp.getStr( node, "cardinality", "1" ) ); --- 740,744 ---- FileOp.fmt( fImplC, "static struct __nodedef __%s = {\n", nodeName ); FileOp.fmt( fImplC, " \"%s\",", xmlName ); ! FileOp.fmt( fImplC, " \"%s\",", __getRemark(node) ); FileOp.fmt( fImplC, " %s,", NodeOp.getBool( node, "required", False )?"True":"False" ); FileOp.fmt( fImplC, " \"%s\",\n", NodeOp.getStr( node, "cardinality", "1" ) ); *************** *** 868,872 **** level==0?"*root*":parent, "", ! NodeOp.getStr( child, "remark", "-" ), "", "", --- 952,956 ---- level==0?"*root*":parent, "", ! __getRemark(child), "", "", *************** *** 882,886 **** level==0?"*root*":parent, "", ! NodeOp.getStr( child, "remark", "-" ), "", "", --- 966,970 ---- level==0?"*root*":parent, "", ! __getRemark(child), "", "", *************** *** 904,908 **** NodeOp.getBool( var, "deprecated", False )?"</s>":"", NodeOp.getStr( var, "vt", "?" ), ! NodeOp.getStr( var, "remark", "-" ), NodeOp.getStr( var, "unit", "-" ), NodeOp.getStr( var, "val", "-" ), --- 988,992 ---- NodeOp.getBool( var, "deprecated", False )?"</s>":"", NodeOp.getStr( var, "vt", "?" ), ! __getRemark(var), NodeOp.getStr( var, "unit", "-" ), NodeOp.getStr( var, "val", "-" ), *************** *** 925,929 **** sizeAttr ? sizeAttr:"", sizeAttr ? "]":"", ! NodeOp.getStr( var, "remark", "-" ), NodeOp.getStr( var, "unit", "-" ), NodeOp.getStr( var, "defval", "-" ), --- 1009,1013 ---- sizeAttr ? sizeAttr:"", sizeAttr ? "]":"", ! __getRemark(var), NodeOp.getStr( var, "unit", "-" ), NodeOp.getStr( var, "defval", "-" ), |