Fix permissions
[bcusdk.git] / archive / embedprogid.cpp
blobb737ffb61ed397efaeef6424600d03004671ad2f
1 /*
2 BCU SDK bcu development enviroment
3 Copyright (C) 2005-2007 Martin Kögler <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 setcontent (xmlNodePtr n, CArray data)
29 CArray d = encode_hex (data);
30 xmlNodeSetContent (n, (const xmlChar *) d.array ());
33 int
34 main (int ac, char *ag[])
36 CArray p;
37 uchar buf[200];
38 int set = 0;
40 if (ac != 4)
41 die (_("%s input file output"), ag[0]);
44 FILE *f = fopen (ag[2], "r");
45 if (!f)
46 die (_("open of %s failed"), ag[1]);
48 while (!feof (f))
50 int i = fread (buf, 1, sizeof (buf), f);
51 p.setpart (buf, p (), i);
53 fclose (f);
56 xmlDocPtr f;
57 f = xmlParseFile (ag[1]);
58 if (!f)
59 die (_("can not parse %s"), ag[1]);
61 xmlNodePtr n = xmlDocGetRootElement (f);
63 if (n->type != XML_ELEMENT_NODE
64 || (strcmp ((const char *) n->name, "DeviceConfig")
65 && strcmp ((const char *) n->name, "DeviceDesc")))
66 die (_("wrong format"));
68 xmlNodePtr cld = n->children;
69 while (cld)
71 if (cld->type == XML_ELEMENT_NODE)
73 const char *name = (const char *) cld->name;
74 if (!strcmp (name, "ProgramID"))
76 setcontent (cld, p);
77 set = 1;
80 cld = cld->next;
82 if (!set)
83 die (_("ProgramID not found"));
85 if (xmlSaveFormatFileEnc (ag[3], f, "UTF-8", 1) < 0)
86 die (_("write to %s failed"), ag[3]);
88 xmlFreeDoc (f);