# # You should have received a copy of the GNU General Public License # along with the srcML Toolkit; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # RelaxNG usage. import srcml if __name__ == "__main__": iarchive = srcml.create_archive() oarchive = None srcml.read_open_filename(iarchive, "project.xml") oarchive = srcml.clone_archive(iarchive) srcml.write_open_filename(oarchive, "relaxng.xml") srcml.append_transform_relaxng_filename(iarchive, "schema.rng"); srcml.apply_transforms(iarchive, oarchive); srcml.close_archive(iarchive); srcml.close_archive(oarchive); srcml.free_archive(iarchive); srcml.free_archive(oarchive);
</unit> """ # create a new srcml archive structure archive = srcml.create_archive() srcml.read_open_memory(archive, s, len(s)) # add all the files to the archive unit = srcml.read_unit(archive) while unit != None: # can inquire about the current unit language = srcml.unit_get_language(unit) filename = srcml.unit_get_filename(unit) # uparse and write to a file srcml.unparse_unit_memory(unit, buffer, size) print buffer.value # free((void *)buffer); srcml.free(buffer) srcml.free_unit(unit) unit = srcml.read_unit(archive) # close the srcML archive srcml.close_archive(archive) # free the srcML archive data srcml.free_archive(archive)
# options and attributes of cloned archive start the same as # the original archive includearchive = srcml.clone_archive(iarchive) otherarchive = srcml.clone_archive(iarchive) # open a srcML archive for output srcml.write_open_filename(includearchive, "project_include.xml") srcml.write_open_filename(otherarchive, "project_other.xml") # copy the files from the input archive to the output archive unit = srcml.read_unit(iarchive) while unit != None: # Get the filename filename = srcml.unit_get_filename(unit) if cmp(".h", filename[len(filename) - 2:]) == 0: srcml.write_unit(includearchive, unit) else: srcml.write_unit(otherarchive, unit) srcml.free_unit(unit) unit = srcml.read_unit(iarchive) # close the archives srcml.close_archive(includearchive) srcml.close_archive(otherarchive) srcml.close_archive(iarchive) # free the srcML archive data srcml.free_archive(includearchive) srcml.free_archive(otherarchive) srcml.free_archive(iarchive)