And open APIs are sooooooooooo fine!
J'ai fait mon premier programme C qui serve vraiment à quelque chose (et non pas un simple "HelloWorld!"). Alors voilà, c'est basé sur libxml2 par Daniel Veillard, et ça processe les XIncludes (ou en français). Bon, c'est sûr, dans la catégorie truc-de-la-mort-qui-tue-les-canards-à-trois-pattes, on a vu mieux, mais bon ! Je suis 'achtement fier quand même :D ... même si, bon, en fait, c'est surtout une application de l'API libxml2... et que j'ai récupéré une partie du code dans les tutos du site de libxml2 (très bien fait, d'ailleurs). Et ça se compile (sous Debian, avec toutes les dépendances qui vont bien installées, principalement libxml2-dev), avec gcc -I/usr/include/libxml2 -lxml2 -o xincludeproc xinclude.c.
Le code de la chose
/*
* Simple XInclude Processor, based on libxml2.
*
* Vincent Tabard (based on examples by Daniel Veillard).
*/
#include <stdio.h>
#include <string.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xinclude.h>
#include <libxml/xmlIO.h>
#ifdef LIBXML_XINCLUDE_ENABLED
static const char *cur = NULL;
static int rlen;
int main(int argc, char **argv) {
xmlDocPtr doc;
char *filename;
char *outfile;
/*
* this initialize the library and check potential ABI mismatches
* between the version it was compiled for and the actual shared
* library used.
*/
LIBXML_TEST_VERSION
/*
* parse command-line options
*/
if(argc < 2)
{
fprintf(stderr, "Usage:\n %s [-o <output-file>] <file>\n", argv0);
return (1);
}
if(argc > 2)
{
outfile = argv[2];
filename = argv[3];
}
else
{
outfile = NULL;
filename = argv[1];
}
/*
* open file for inclusions
*/
doc = xmlReadFile(filename, NULL, 0);
if (doc == NULL) {
fprintf(stderr, "Failed to parse %s\n", filename);
return;
}
/*
* apply the XInclude process.
*/
if (xmlXIncludeProcess(doc) <= 0) {
fprintf(stderr, "XInclude processing failed\n");
exit(1);
}
#ifdef LIBXML_OUTPUT_ENABLED
/*
* save the output for checking to stdout
*/
if(outfile == NULL)
{
xmlDocDump(stdout, doc);
}
else
{
xmlDocDump(fopen(outfile, "w"), doc);
}
#endif
/*
* Free the document
*/
xmlFreeDoc(doc);
/*
* Cleanup function for the XML library.
*/
xmlCleanupParser();
return(0);
}
#else
int main(void) {
fprintf(stderr, "XInclude support not compiled in\n");
exit(1);
}
#endif
Now don't you worry about my boyfriend
The boy whose name is Vitorino
I don't want him, couldn't stand him
He was no good, so I...ha,ha,ha,ha,ha
Now come on, what was I supposed to do?
He was out of town and his two friends were soooooo fine.Macarena (English version)

Commentaires
Aucun commentaire pour le moment.
Ajouter un commentaire
Les commentaires pour ce billet sont fermés.