diff options
author | Drew Richardson <drew.richardson@arm.com> | 2012-12-14 12:00:00 -0800 |
---|---|---|
committer | Drew Richardson <drew.richardson@arm.com> | 2014-12-19 15:33:02 -0800 |
commit | a01058e248133bb7c1ba0238ab380e4fac924e97 (patch) | |
tree | 8fc08c126fcb711fc9a2011eb6314c68d429b800 /daemon/escape.c | |
parent | b04e8aefeed42f23955e88c7aa1611e49bdf5909 (diff) |
gator: Version 5.135.13
Signed-off-by: Drew Richardson <drew.richardson@arm.com>
Diffstat (limited to 'daemon/escape.c')
-rw-r--r-- | daemon/escape.c | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/daemon/escape.c b/daemon/escape.c new file mode 100644 index 0000000..c0f47f1 --- /dev/null +++ b/daemon/escape.c @@ -0,0 +1,63 @@ +/** + * Copyright (C) ARM Limited 2010-2012. 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. + */ + +#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; +} |