Skip to content

Instantly share code, notes, and snippets.

@mlcollard
Created October 6, 2014 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlcollard/0d3fc51f75934f058a3c to your computer and use it in GitHub Desktop.
Save mlcollard/0d3fc51f75934f058a3c to your computer and use it in GitHub Desktop.
srcML - Example of extracting source from a single-unit srcML file using the libsrcml API
/*
libsrcml_extract.cpp
Demonstrates use of libsrcml functions for reading
a srcML file
Error handling removed for clarity
*/
#include <srcml.h>
int main() {
// setup the overall srcML input
srcml_archive* srcml_arch = srcml_create_archive();
srcml_read_open_filename(srcml_arch, "main.cpp.xml");
// read the unit and write to filesystem
srcml_unit* unit = srcml_read_unit(srcml_arch);
srcml_unparse_unit_filename(unit, "newmain.cpp");
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