release 0.0.4
[bcusdk.git] / archive / extractprogid.cpp
blob2ecac0b0ca5127565d983da3d0361a67d448a566
1 /*
2 BCU SDK bcu development enviroment
3 Copyright (C) 2005-2008 Martin Koegler <mkoegler@auto.tuwien.ac.at>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include <stdio.h>
21 #include <libxml/parser.h>
22 #include "types.h"
23 #include "common.h"
24 #include "hex.h"
26 void
27 writecontent (xmlNodePtr n, const char *file)
29 const uchar *c = (const uchar *) xmlNodeGetContent (n);
30 CArray p;
31 p.set (c, strlen ((const char *) c));
32 p = decode_hex (p);
34 FILE *f = fopen (file, "w");
35 if (!f)
36 die (_("can not write to %s"), file);
37 fwrite (p.array (), 1, p (), f);
38 fclose (f);
42 int
43 main (int ac, char *ag[])
45 CArray p;
46 uchar buf[200];
47 int set = 0;
49 if (ac != 3)
50 die (_("%s input output"), ag[0]);
51 xmlDocPtr f;
52 f = xmlParseFile (ag[1]);
53 if (!f)
54 die (_("can not parse %s"), ag[1]);
56 xmlNodePtr n = xmlDocGetRootElement (f);
58 if (n->type != XML_ELEMENT_NODE
59 || (strcmp ((const char *) n->name, "DeviceConfig")
60 && strcmp ((const char *) n->name, "DeviceDesc")))
61 die (_("wrong format"));
63 xmlNodePtr cld = n->children;
65 while (cld)
67 if (cld->type == XML_ELEMENT_NODE)
69 const char *name = (const char *) cld->name;
70 if (!strcmp (name, "ProgramID"))
72 writecontent (cld, ag[2]);
73 set = 1;
76 cld = cld->next;
78 if (!set)
79 die (_("ProgramID not found"));
81 xmlFreeDoc (f);