diff options
author | Andrey Konovalov <andrey.konovalov@linaro.org> | 2013-05-05 02:40:36 +0400 |
---|---|---|
committer | Andrey Konovalov <andrey.konovalov@linaro.org> | 2013-05-05 02:40:36 +0400 |
commit | 314864b5a538c5ec1f871d814974edc37bdc676e (patch) | |
tree | f0d341e6eae1cd5c4ca6180aeb29a00e21ff8a8e /tools/gator/daemon/escape.c | |
parent | e5f042c6edebec55bb20a5e399f892766ac65411 (diff) | |
parent | 8417d689429075fe59d92af4036e25424b13ea9c (diff) |
Merge branch 'tracking-integration-linux-vexpress' into merge-linux-linaro-lsklsk-20130505.0
Diffstat (limited to 'tools/gator/daemon/escape.c')
-rw-r--r-- | tools/gator/daemon/escape.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/tools/gator/daemon/escape.c b/tools/gator/daemon/escape.c new file mode 100644 index 00000000000..a1545158887 --- /dev/null +++ b/tools/gator/daemon/escape.c @@ -0,0 +1,69 @@ +/** + * Copyright (C) ARM Limited 2010-2013. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +/* + * The Makefile in the daemon folder builds and executes 'escape' + * 'escape' creates configuration_xml.h from configuration.xml and events_xml.h from events-*.xml + * these genereated xml files are then #included and built as part of the gatord binary + */ + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <ctype.h> + +static void print_escaped_path(char *path) { + if (isdigit(*path)) { + printf("__"); + } + for (; *path != '\0'; ++path) { + printf("%c", isalnum(*path) ? *path : '_'); + } +} + +int main(int argc, char *argv[]) { + int i; + char *path; + FILE *in = NULL; + int ch; + unsigned int len = 0; + + for (i = 1; i < argc && argv[i][0] == '-'; ++i) ; + if (i == argc) { + fprintf(stderr, "Usage: %s <filename>\n", argv[0]); + return EXIT_FAILURE; + } + path = argv[i]; + + errno = 0; + if ((in = fopen(path, "r")) == NULL) { + fprintf(stderr, "Unable to open '%s': %s\n", path, strerror(errno)); + return EXIT_FAILURE; + } + + printf("static const unsigned char "); + print_escaped_path(path); + printf("[] = {"); + for (; (ch = fgetc(in)) != EOF; ++len) { + if (len != 0) { + printf(","); + } + if (len % 12 == 0) { + printf("\n "); + } + printf(" 0x%.2x", ch); + } + printf("\n};\nstatic const unsigned int "); + print_escaped_path(path); + printf("_len = %i;\n", len); + + fclose(in); + + return EXIT_SUCCESS; +} |