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
45 STR [!a-zA-Z0-9_./:\+~-]+
52 yylval = (char *) new unsigned char[16];
53 memset (yylval, 0, 16);
56 for (i = 0, j = 0; i < 32; i += 2, ++j)
58 v1 = hexnibble((unsigned char) yytext[i+0]);
59 v2 = hexnibble((unsigned char) yytext[i+1]);
60 ((unsigned char *) yylval) [j] = nibbled1(v1, v2);
66 yylval = (char *) new unsigned char[SHA512_DIGEST_LENGTH];
67 memset (yylval, 0, SHA512_DIGEST_LENGTH);
70 for (i = 0, j = 0; i < SHA512_BLOCK_LENGTH; i += 2, ++j)
72 v1 = hexnibble((unsigned char) yytext[i+0]);
73 v2 = hexnibble((unsigned char) yytext[i+1]);
74 ((unsigned char *) yylval) [j] = nibbled1(v1, v2);
80 /* base64url as defined in RFC4648 */
81 yylval = (char *) new unsigned char[SHA512_DIGEST_LENGTH];
82 memset (yylval, 0, SHA512_DIGEST_LENGTH);
84 unsigned char v1, v2, v3, v4;
85 for (i = 0, j = 0; i < 4*(SHA512_DIGEST_LENGTH/3); i += 4, j += 3)
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);
95 v1 = b64url((unsigned char) yytext[i+0]);
96 v2 = b64url((unsigned char) yytext[i+1]);
99 ((unsigned char *) yylval) [j+0] = b64d1(v1, v2, v3, v4);
103 \"[^"]*\" { yylval = new char [strlen (yytext+1) + 1];
104 strcpy (yylval, yytext+1);
105 yylval[strlen (yylval)-1] = 0;
108 "setup-timestamp:" return SETUP_TIMESTAMP;
109 "setup-version:" return SETUP_VERSION;
110 "setup-minimum-version:" return SETUP_MINIMUM_VERSION;
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;
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;
133 ^{STR}":" ignore_line ();
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;
141 "(" return OPENBRACE;
142 ")" return CLOSEBRACE;
153 {STR} { yylval = new char [strlen(yytext) + 1];
154 strcpy (yylval, yytext);
157 [ \t\r]+ /* do nothing */;
159 ^"#".*\n /* do nothing */;
166 #include "io_stream.h"
168 static io_stream *input_stream = 0;
169 extern IniDBBuilder *iniBuilder;
170 static IniParseFeedback *iniFeedback;
173 ini_init(io_stream *stream, IniDBBuilder *aBuilder, IniParseFeedback &aFeedback)
175 input_stream = stream;
176 iniBuilder = aBuilder;
177 iniFeedback = &aFeedback;
183 ini_getchar(char *buf, int max_size)
187 ssize_t len = input_stream->read (buf, max_size);
194 iniFeedback->progress (input_stream->tell(), input_stream->get_size());
204 while ((c = yyinput ()))
214 yyerror (const std::string& s)
216 iniFeedback->note_error(yylineno - (!!YY_AT_BOL ()), s);