Adjust copyright for 2010
[bcusdk.git] / bcugen / configfile / readconfig.cpp
blob19736654e65647b53227e0613ed6d4ac54d636d7
1 /*
2 BCU SDK bcu development enviroment
3 Copyright (C) 2005-2010 Martin Koegler <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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include <stdio.h>
21 #include <stdarg.h>
22 #include <stdlib.h>
24 #include "scanner.h"
26 void
27 parserError (const char *msg, ...)
29 va_list ap;
30 va_start (ap, msg);
31 printf (_("Line %d: "), yylineno);
32 vprintf (msg, ap);
33 printf ("\n");
34 va_end (ap);
35 exit (1);
38 String *
39 unescapeString (const char *str)
41 String s = str;
42 char *a = (char *) s ();
43 char *b = a;
44 a++;
45 while (*a)
47 if (*a == '\\')
49 switch (*(a + 1))
51 case '"':
52 *b = '"';
53 a += 2;
54 b++;
55 break;
56 case 'b':
57 *b = '\b';
58 a += 2;
59 b++;
60 break;
61 case '\\':
62 *b = '\\';
63 a += 2;
64 b++;
65 break;
66 case 'f':
67 *b = '\f';
68 a += 2;
69 b++;
70 break;
71 case 'n':
72 *b = '\n';
73 a += 2;
74 b++;
75 break;
76 case 'r':
77 *b = '\r';
78 a += 2;
79 b++;
80 break;
81 case 't':
82 *b = '\t';
83 a += 2;
84 b++;
85 break;
86 case '0'...'7':
88 int no = *(a + 1) - '0';
89 a += 2;
90 while (('0' <= *a && *a <= '7'))
92 no = no * 8 + (*a - '0');
93 a++;
95 *b = no & 0xff;
96 b++;
98 break;
99 case 'X':
100 case 'x':
102 int no = 0;
103 a += 2;
104 while (('0' <= *a && *a <= '9') || ('a' <= *a && *a <= 'f')
105 || ('A' <= *a && *a <= 'F'))
107 int s;
108 if (('0' <= *a && *a <= '9'))
109 s = *a - '0';
110 if (('A' <= *a && *a <= 'Z'))
111 s = *a - 'A' + 10;
112 if (('a' <= *a && *a <= 'z'))
113 s = *a - 'a' + 10;
114 no = no * 16 + s;
115 a++;
117 *b = no & 0xff;
118 b++;
120 break;
121 default:
122 *b = *a;
123 a++;
124 b++;
125 *b = *a;
126 a++;
127 b++;
130 else if (*a == '"')
132 a++;
133 break;
135 else
137 *b = *a;
138 a++;
139 b++;
142 *b = 0;
143 return new String (s ());
146 extern void yyrestart (FILE * f);
148 Device *
149 ReadConfig (const char *file)
151 FILE *f = fopen (file, "r");
152 if (!f)
153 die (_("can not open %s"), file);
154 yyrestart (f);
155 yyparse ();
156 fclose (f);
157 return parser_dev;