def parse(filename, output): global symbols global sections parser = CParser(filename) parser.collect_references() idx = parser.parse() info = parse_top_comment(filename, parser.top_comment) output.write(" <example filename='%s'>\n" % filename) try: synopsis = info['synopsis'] output.write(" <synopsis>%s</synopsis>\n" % escape(synopsis)); except: print "Example %s lacks a synopsis description" % (filename) try: purpose = info['purpose'] output.write(" <purpose>%s</purpose>\n" % escape(purpose)); except: print "Example %s lacks a purpose description" % (filename) try: usage = info['usage'] output.write(" <usage>%s</usage>\n" % escape(usage)); except: print "Example %s lacks an usage description" % (filename) try: test = info['test'] output.write(" <test>%s</test>\n" % escape(test)); progname=filename[0:-2] command=string.replace(test, progname, './' + progname, 1) tests.append(command) except: pass try: author = info['author'] output.write(" <author>%s</author>\n" % escape(author)); except: print "Example %s lacks an author description" % (filename) try: copy = info['copy'] output.write(" <copy>%s</copy>\n" % escape(copy)); except: print "Example %s lacks a copyright description" % (filename) try: section = info['section'] output.write(" <section>%s</section>\n" % escape(section)); if sections.has_key(section): sections[section].append(filename) else: sections[section] = [filename] except: print "Example %s lacks a section description" % (filename) for topic in info.keys(): if topic != "purpose" and topic != "usage" and \ topic != "author" and topic != "copy" and \ topic != "section" and topic != "synopsis" and topic != "test": str = info[topic] output.write(" <extra topic='%s'>%s</extra>\n" % ( escape(topic), escape(str))) output.write(" <includes>\n") for include in idx.includes.keys(): if include.find("libxml") != -1: output.write(" <include>%s</include>\n" % (escape(include))) output.write(" </includes>\n") output.write(" <uses>\n") for ref in idx.references.keys(): id = idx.references[ref] name = id.get_name() line = id.get_lineno() if symbols.has_key(name): sinfo = symbols[name] refs = sinfo[0] # gather at most 5 references per symbols if refs > 5: continue sinfo.append(filename) sinfo[0] = refs + 1 else: symbols[name] = [1, filename] info = find_symbol(name) if info != None: type = info[0] file = info[1] output.write(" <%s line='%d' file='%s' name='%s'/>\n" % (type, line, file, name)) else: type = id.get_type() output.write(" <%s line='%d' name='%s'/>\n" % (type, line, name)) output.write(" </uses>\n") output.write(" </example>\n") return idx