-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcreate_image_xml.c
54 lines (41 loc) · 1.25 KB
/
create_image_xml.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdio.h>
/* libxml2 */
#include <libxml/parser.h>
#include <libxml/xmlstring.h>
#include "common.h"
#define VERSION "0.75"
struct image_file_data
{
const char* type;
xmlNodePtr node;
};
static void image_list_callback(struct parse_callback_data* pcd)
{
struct image_file_data* data = (struct image_file_data*)pcd->user_data;
if( pcd->type == ENTRY_FILE ) {
xmlNodePtr image_node = xmlNewChild(data->node, NULL, (const xmlChar*)"image", NULL);
xmlNewProp(image_node, (const xmlChar*)data->type, (const xmlChar*)pcd->fullname);
}
}
static void build_image_list(const char* dirname, const char* type, xmlNodePtr node)
{
struct image_file_data data;
data.type = type;
data.node = node;
parse_directory(dirname, 0, image_list_callback, (void*)&data);
}
int main(int argc, char *argv[])
{
printf("create_image_xml %s\n", VERSION);
if( argc != 4 ) {
printf("usage: create_image_xml <path> <output> <type>\n");
return 1;
}
xmlDocPtr images_doc = xmlNewDoc((const xmlChar*)"1.0");
xmlNodePtr images_node = xmlNewNode(NULL, (const xmlChar*)"images");
xmlDocSetRootElement(images_doc, images_node);
build_image_list(argv[1], argv[3], images_node);
xmlSaveFormatFileEnc(argv[2], images_doc, "UTF-8", 1);
xmlFreeDoc(images_doc);
return 0;
}