]> cygwin.com Git - cygwin-apps/setup.git/blob - inilex.ll
Suppress bogus free-nonheap-object warning in iniparse.cc
[cygwin-apps/setup.git] / inilex.ll
1 %{
2 /*
3 * Copyright (c) 2000, Red Hat, Inc.
4 *
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.
9 *
10 * A copy of the GNU General Public License can be found at
11 * http://www.gnu.org/
12 *
13 * Written by DJ Delorie <dj@cygnus.com>
14 * Maintained by Robert Collins <rbtcollins@hotmail.com>
15 *
16 */
17
18 /* tokenize the setup.ini files. We parse a string which we've
19 previously downloaded. The program must call ini_init() to specify
20 that string. */
21
22 #include "win32.h"
23 #include <string.h>
24
25 #include "ini.h"
26 #include "iniparse.hh"
27 #include "String++.h"
28 #include "IniParseFeedback.h"
29 #include "sha2.h"
30
31 #define YY_READ_BUF_SIZE 65536
32 #define YY_INPUT(buf,result,max_size) { result = ini_getchar(buf, max_size); }
33
34 static int ini_getchar(char *buf, int max_size);
35 static void ignore_line (void);
36
37 %}
38
39 /*%option debug */
40 %option nounput
41 %option noyywrap
42 %option yylineno
43 %option never-interactive
44
45 STR [!a-zA-Z0-9_./:\+~-]+
46 HEX [0-9a-f]
47 B64 [a-zA-Z0-9_-]
48
49 %%
50
51 {HEX}{32} {
52 yylval = (char *) new unsigned char[16];
53 memset (yylval, 0, 16);
54 int i, j;
55 unsigned char v1, v2;
56 for (i = 0, j = 0; i < 32; i += 2, ++j)
57 {
58 v1 = hexnibble((unsigned char) yytext[i+0]);
59 v2 = hexnibble((unsigned char) yytext[i+1]);
60 ((unsigned char *) yylval) [j] = nibbled1(v1, v2);
61 }
62 return MD5;
63 }
64
65 {HEX}{128} {
66 yylval = (char *) new unsigned char[SHA512_DIGEST_LENGTH];
67 memset (yylval, 0, SHA512_DIGEST_LENGTH);
68 int i, j;
69 unsigned char v1, v2;
70 for (i = 0, j = 0; i < SHA512_BLOCK_LENGTH; i += 2, ++j)
71 {
72 v1 = hexnibble((unsigned char) yytext[i+0]);
73 v2 = hexnibble((unsigned char) yytext[i+1]);
74 ((unsigned char *) yylval) [j] = nibbled1(v1, v2);
75 }
76 return SHA512;
77 }
78
79 {B64}{86} {
80 /* base64url as defined in RFC4648 */
81 yylval = (char *) new unsigned char[SHA512_DIGEST_LENGTH];
82 memset (yylval, 0, SHA512_DIGEST_LENGTH);
83 int i, j;
84 unsigned char v1, v2, v3, v4;
85 for (i = 0, j = 0; i < 4*(SHA512_DIGEST_LENGTH/3); i += 4, j += 3)
86 {
87 v1 = b64url(((unsigned char) yytext[i+0]));
88 v2 = b64url(((unsigned char) yytext[i+1]));
89 v3 = b64url(((unsigned char) yytext[i+2]));
90 v4 = b64url(((unsigned char) yytext[i+3]));
91 ((unsigned char *) yylval) [j+0] = b64d1(v1, v2, v3, v4);
92 ((unsigned char *) yylval) [j+1] = b64d2(v1, v2, v3, v4);
93 ((unsigned char *) yylval) [j+2] = b64d3(v1, v2, v3, v4);
94 }
95 v1 = b64url((unsigned char) yytext[i+0]);
96 v2 = b64url((unsigned char) yytext[i+1]);
97 v3 = 0;
98 v4 = 0;
99 ((unsigned char *) yylval) [j+0] = b64d1(v1, v2, v3, v4);
100 return SHA512;
101 }
102
103 \"[^"]*\" { yylval = new char [strlen (yytext+1) + 1];
104 strcpy (yylval, yytext+1);
105 yylval[strlen (yylval)-1] = 0;
106 return STRING; }
107
108 "setup-timestamp:" return SETUP_TIMESTAMP;
109 "setup-version:" return SETUP_VERSION;
110 "setup-minimum-version:" return SETUP_MINIMUM_VERSION;
111 "arch:" return ARCH;
112
113 "release:" return RELEASE;
114 "Package:" return PACKAGENAME;
115 [vV]"ersion:" return PACKAGEVERSION;
116 "install:"|"Filename:" return INSTALL;
117 "source:" return SOURCE;
118 "sdesc:" return SDESC;
119 "ldesc:" return LDESC;
120 "message:" return MESSAGE;
121 "Source:" return SOURCEPACKAGE;
122 [bB]"uild-"[dD]"epends:" return BUILDDEPENDS;
123 "replace-versions:" return REPLACE_VERSIONS;
124
125 "category:"|"Section:" return CATEGORY;
126 "requires:" return REQUIRES;
127 [dD]"epends:" return DEPENDS;
128 [dD]"epends2:" return DEPENDS;
129 [oO]"bsoletes:" return OBSOLETES;
130 [pP]"rovides:" return PROVIDES;
131 [cC]"onflicts:" return CONFLICTS;
132
133 ^{STR}":" ignore_line ();
134
135 "[curr]" return T_CURR;
136 "[test]" return T_TEST;
137 "[exp]" return T_TEST;
138 "[prev]" return T_PREV;
139 "["{STR}"]" return T_OTHER;
140
141 "(" return OPENBRACE;
142 ")" return CLOSEBRACE;
143 "<<" return LT;
144 ">>" return GT;
145 ">=" return GTEQUAL;
146 "<=" return LTEQUAL;
147 ">" return GT;
148 "<" return LT;
149 "=" return EQUAL;
150 \, return COMMA;
151 "@" return AT;
152
153 {STR} { yylval = new char [strlen(yytext) + 1];
154 strcpy (yylval, yytext);
155 return STRING; }
156
157 [ \t\r]+ /* do nothing */;
158
159 ^"#".*\n /* do nothing */;
160
161 \n { return NL; }
162 . { return *yytext;}
163
164 %%
165
166 #include "io_stream.h"
167
168 static io_stream *input_stream = 0;
169 extern IniDBBuilder *iniBuilder;
170 static IniParseFeedback *iniFeedback;
171
172 void
173 ini_init(io_stream *stream, IniDBBuilder *aBuilder, IniParseFeedback &aFeedback)
174 {
175 input_stream = stream;
176 iniBuilder = aBuilder;
177 iniFeedback = &aFeedback;
178 YY_FLUSH_BUFFER;
179 yylineno = 1;
180 }
181
182 static int
183 ini_getchar(char *buf, int max_size)
184 {
185 if (input_stream)
186 {
187 ssize_t len = input_stream->read (buf, max_size);
188 if (len < 1)
189 {
190 len = 0;
191 input_stream = 0;
192 }
193 else
194 iniFeedback->progress (input_stream->tell(), input_stream->get_size());
195 return len;
196 }
197 return 0;
198 }
199
200 static void
201 ignore_line ()
202 {
203 char c;
204 while ((c = yyinput ()))
205 {
206 if (c == EOF)
207 return;
208 if (c == '\n')
209 return;
210 }
211 }
212
213 void
214 yyerror (const std::string& s)
215 {
216 iniFeedback->note_error(yylineno - (!!YY_AT_BOL ()), s);
217 }
This page took 0.044925 seconds and 5 git commands to generate.