Created
October 6, 2014 13:38
-
-
Save mlcollard/3b3e944d9133a5d68c65 to your computer and use it in GitHub Desktop.
srcML - Example of creating a single-unit srcML file with the libsrcml API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
libsrcml_create.cpp | |
Demonstrates use of libsrcml functions for writing | |
a srcML file | |
Error handling removed for clarity | |
*/ | |
#include <srcml.h> | |
int main() { | |
// setup the overall srcML output | |
srcml_archive* srcml_arch = srcml_create_archive(); | |
srcml_archive_set_encoding(srcml_arch, "UTF-8"); | |
srcml_archive_disable_option(srcml_arch, SRCML_OPTION_ARCHIVE); | |
srcml_archive_disable_option(srcml_arch, SRCML_OPTION_HASH); | |
srcml_write_open_filename(srcml_arch, "main.cpp.xml"); | |
// extract and write the unit | |
srcml_unit* unit = unit = srcml_create_unit(srcml_arch); | |
srcml_unit_set_filename(unit, "main.cpp"); | |
srcml_parse_unit_filename(unit, "main.cpp"); | |
srcml_write_unit(srcml_arch, unit); | |
srcml_free_unit(unit); | |
// cleanup | |
srcml_close_archive(srcml_arch); | |
srcml_free_archive(srcml_arch); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment