]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - android-sdk/arm-ds5-gator.git/blob - daemon/escape.c
gator: Version 5.14
[android-sdk/arm-ds5-gator.git] / daemon / escape.c
1 /**
2  * Copyright (C) ARM Limited 2010-2013. 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 /* 
10  * The Makefile in the daemon folder builds and executes 'escape'
11  * 'escape' creates configuration_xml.h from configuration.xml and events_xml.h from events-*.xml
12  * these genereated xml files are then #included and built as part of the gatord binary
13  */
15 #include <errno.h>
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <ctype.h>
21 static void print_escaped_path(char *path) {
22   if (isdigit(*path)) {
23     printf("__");
24   }
25   for (; *path != '\0'; ++path) {
26     printf("%c", isalnum(*path) ? *path : '_');
27   }
28 }
30 int main(int argc, char *argv[]) {
31   int i;
32   char *path;
33   FILE *in = NULL;
34   int ch;
35   unsigned int len = 0;
37   for (i = 1; i < argc && argv[i][0] == '-'; ++i) ;
38   if (i == argc) {
39     fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
40     return EXIT_FAILURE;
41   }
42   path = argv[i];
44   errno = 0;
45   if ((in = fopen(path, "r")) == NULL) {
46     fprintf(stderr, "Unable to open '%s': %s\n", path, strerror(errno));
47     return EXIT_FAILURE;
48   }
50   printf("static const unsigned char ");
51   print_escaped_path(path);
52   printf("[] = {");
53   for (; (ch = fgetc(in)) != EOF; ++len) {
54     if (len != 0) {
55       printf(",");
56     }
57     if (len % 12 == 0) {
58       printf("\n ");
59     }
60     printf(" 0x%.2x", ch);
61   }
62   printf("\n};\nstatic const unsigned int ");
63   print_escaped_path(path);
64   printf("_len = %i;\n", len);
66   fclose(in);
68   return EXIT_SUCCESS;
69 }