1 /**
2 * Copyright (C) ARM Limited 2010-2012. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
9 #include <errno.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <ctype.h>
15 static void print_escaped_path(char *path) {
16 if (isdigit(*path)) {
17 printf("__");
18 }
19 for (; *path != '\0'; ++path) {
20 printf("%c", isalnum(*path) ? *path : '_');
21 }
22 }
24 int main(int argc, char *argv[]) {
25 int i;
26 char *path;
27 FILE *in = NULL;
28 int ch;
29 unsigned int len = 0;
31 for (i = 1; i < argc && argv[i][0] == '-'; ++i) ;
32 if (i == argc) {
33 fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
34 return EXIT_FAILURE;
35 }
36 path = argv[i];
38 errno = 0;
39 if ((in = fopen(path, "r")) == NULL) {
40 fprintf(stderr, "Unable to open '%s': %s\n", path, strerror(errno));
41 return EXIT_FAILURE;
42 }
44 printf("static const unsigned char ");
45 print_escaped_path(path);
46 printf("[] = {");
47 for (; (ch = fgetc(in)) != EOF; ++len) {
48 if (len != 0) {
49 printf(",");
50 }
51 if (len % 12 == 0) {
52 printf("\n ");
53 }
54 printf(" 0x%.2x", ch);
55 }
56 printf("\n};\nstatic const unsigned int ");
57 print_escaped_path(path);
58 printf("_len = %i;\n", len);
60 fclose(in);
62 return EXIT_SUCCESS;
63 }