3 * Copyright (c) 2000, Red Hat, Inc.
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 * A copy of the GNU General Public License can be found at
13 * Written by DJ Delorie <dj@cygnus.com>
14 * Maintained by Robert Collins <rbtcollins@hotmail.com>
18 /* tokenize the setup.ini files. We parse a string which we've
19 previously downloaded. The program must call ini_init() to specify
26 #include "iniparse.hh"
28 #include "IniParseFeedback.h"
31 #define YY_READ_BUF_SIZE 65536
32 #define YY_INPUT(buf,result,max_size) { result = ini_getchar(buf, max_size); }
34 static int ini_getchar(char *buf, int max_size);
35 static void ignore_line (void);
43 %option never-interactive
48 STR [!a-zA-Z0-9_./:\+~-]+
53 yylval = (char *) new unsigned char[16];
54 memset (yylval, 0, 16);
57 for (i = 0, j = 0; i < 32; i += 2, ++j)
59 v1 = hexnibble((unsigned char) yytext[i+0]);
60 v2 = hexnibble((unsigned char) yytext[i+1]);
61 ((unsigned char *) yylval) [j] = nibbled1(v1, v2);
67 yylval = (char *) new unsigned char[SHA512_DIGEST_LENGTH];
68 memset (yylval, 0, SHA512_DIGEST_LENGTH);
71 for (i = 0, j = 0; i < SHA512_BLOCK_LENGTH; i += 2, ++j)
73 v1 = hexnibble((unsigned char) yytext[i+0]);
74 v2 = hexnibble((unsigned char) yytext[i+1]);
75 ((unsigned char *) yylval) [j] = nibbled1(v1, v2);
81 /* base64url as defined in RFC4648 */
82 yylval = (char *) new unsigned char[SHA512_DIGEST_LENGTH];
83 memset (yylval, 0, SHA512_DIGEST_LENGTH);
85 unsigned char v1, v2, v3, v4;
86 for (i = 0, j = 0; i < 4*(SHA512_DIGEST_LENGTH/3); i += 4, j += 3)
88 v1 = b64url(((unsigned char) yytext[i+0]));
89 v2 = b64url(((unsigned char) yytext[i+1]));
90 v3 = b64url(((unsigned char) yytext[i+2]));
91 v4 = b64url(((unsigned char) yytext[i+3]));
92 ((unsigned char *) yylval) [j+0] = b64d1(v1, v2, v3, v4);
93 ((unsigned char *) yylval) [j+1] = b64d2(v1, v2, v3, v4);
94 ((unsigned char *) yylval) [j+2] = b64d3(v1, v2, v3, v4);
96 v1 = b64url((unsigned char) yytext[i+0]);
97 v2 = b64url((unsigned char) yytext[i+1]);
100 ((unsigned char *) yylval) [j+0] = b64d1(v1, v2, v3, v4);
104 \"[^"]*\" { yylval = new char [strlen (yytext+1) + 1];
105 strcpy (yylval, yytext+1);
106 yylval[strlen (yylval)-1] = 0;
109 "setup-timestamp:" return SETUP_TIMESTAMP;
110 "setup-version:" return SETUP_VERSION;
112 "release:" return RELEASE;
113 "Package:" return PACKAGENAME;
114 [vV]"ersion:" return PACKAGEVERSION;
115 "install:"|"Filename:" return INSTALL;
116 "source:" return SOURCE;
117 "sdesc:" return SDESC;
118 "ldesc:" return LDESC;
119 "message:" return MESSAGE;
120 "autodep:" return AUTODEP;
121 "Description:" BEGIN (descriptionstate); return DESCTAG;
122 "Size:" return FILESIZE;
123 "MD5sum:" return MD5LINE;
124 "SHA512:" return SHA512LINE;
125 "Installed-Size:" return INSTALLEDSIZE;
126 "Maintainer:" BEGIN (eolstate); return MAINTAINER;
127 "Architecture:" return ARCHITECTURE;
128 "Source:" return SOURCEPACKAGE;
129 "Binary:" return BINARYPACKAGE;
130 "Build-Depends:" return BUILDDEPENDS;
131 "Build-Depends-Indep:" return BUILDDEPENDS; /* technicallyincorrect :[ */
132 "Standards-Version:" return STANDARDSVERSION;
133 "Format:" return FORMAT;
134 "Directory:" return DIRECTORY;
135 "Files:" return FILES;
137 "category:"|"Section:" return CATEGORY;
138 "Priority:" return PRIORITY;
139 "requires:" return REQUIRES;
140 "Depends:" return DEPENDS;
141 "Pre-Depends:" return PREDEPENDS;
142 "Recommends:" return RECOMMENDS;
143 "Suggests:" return SUGGESTS;
144 "Conflicts:" return CONFLICTS;
145 "Replaces:" return REPLACES;
146 "Provides:" return PROVIDES;
148 "apath:" return APATH;
149 "ppath:" return PPATH;
151 "include-setup:" return INCLUDE_SETUP;
153 "download-url:" return DOWNLOAD_URL;
155 ^{STR}":" ignore_line ();
157 "[curr]" return T_CURR;
158 "[test]" return T_TEST;
159 "[exp]" return T_TEST;
160 "[prev]" return T_PREV;
162 "(" return OPENBRACE;
163 ")" return CLOSEBRACE;
164 "[" return OPENSQUARE;
165 "]" return CLOSESQUARE;
177 {STR}"@"{STR} { yylval = new char [strlen(yytext) + 1];
178 strcpy (yylval, yytext);
180 {STR} { yylval = new char [strlen(yytext) + 1];
181 strcpy (yylval, yytext);
184 [ \t\r]+ /* do nothing */;
186 ^"#".*\n /* do nothing */;
187 <descriptionstate>[^\n]+ { yylval = new char [strlen(yytext) + 1];
188 strcpy (yylval, yytext);
190 <descriptionstate>\n { return NL; }
191 <descriptionstate>"\n"+ {BEGIN(INITIAL); return PARAGRAPH;}
192 <eolstate>[^\n]+ {return STRING; }
193 <eolstate>\n {BEGIN(INITIAL); return NL; }
200 #include "io_stream.h"
202 static io_stream *input_stream = 0;
203 extern IniDBBuilder *iniBuilder;
204 static IniParseFeedback *iniFeedback;
205 std::string current_ini_name, yyerror_messages;
209 ini_init(io_stream *stream, IniDBBuilder *aBuilder, IniParseFeedback &aFeedback)
211 input_stream = stream;
212 iniBuilder = aBuilder;
213 iniFeedback = &aFeedback;
217 yyerror_messages.clear ();
221 ini_getchar(char *buf, int max_size)
225 ssize_t len = input_stream->read (buf, max_size);
232 iniFeedback->progress (input_stream->tell(), input_stream->get_size());
242 while ((c = yyinput ()))
252 yyerror (const std::string& s)
255 sprintf (tmp, "%d", yylineno - (!!YY_AT_BOL ()));
257 std::string e = current_ini_name + " line " + tmp + ": " + s;
259 if (!yyerror_messages.empty ())
260 yyerror_messages += "\n";
262 yyerror_messages += e;
263 // OutputDebugString (e.c_str ());
265 /* TODO: is return 0 correct? */