]> cygwin.com Git - cygwin-apps/setup.git/blob - inilex.l
2002-07-10 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / inilex.l
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.h"
27 #include "String++.h"
28 #include "IniParseFeedback.h"
29
30 #define YY_INPUT(buf,result,max_size) { result = ini_getchar(buf, max_size); }
31
32 static int ini_getchar(char *buf, int max_size);
33 static void ignore_line (void);
34
35 %}
36
37 /*%option debug */
38 %option noyywrap
39 %option yylineno
40 %option never-interactive
41
42 %x descriptionstate
43 %x eolstate
44
45 STR [a-zA-Z0-9_./:\+-]+
46
47 %%
48
49 [0123456789abcdef]{32,32} {
50 yylval = (char *) new unsigned char[16];
51 for (int i=0; i< 16; ++i)
52 ((unsigned char *) yylval) [i] = 0;
53 for (int i=0; i< 32; ++i)
54 {
55 unsigned char val = (unsigned char) yytext[i];
56 if (val > '9')
57 val = val - 'a' + 10;
58 else
59 val = val - '0';
60 ((unsigned char *) yylval) [i / 2] += val << ((i % 2) ? 0 : 4);
61 }
62 return MD5;
63 }
64
65 \"[^"]*\" { yylval = new char [strlen (yytext+1) + 1];
66 strcpy (yylval, yytext+1);
67 yylval[strlen (yylval)-1] = 0;
68 return STRING; }
69
70 "setup-timestamp:" return SETUP_TIMESTAMP;
71 "setup-version:" return SETUP_VERSION;
72 "Package:" return PACKAGENAME;
73 [vV]"ersion:" return PACKAGEVERSION;
74 "install:"|"Filename:" return INSTALL;
75 "source:" return SOURCE;
76 "sdesc:" return SDESC;
77 "ldesc:" return LDESC;
78 "Description:" BEGIN (descriptionstate); return DESCTAG;
79 "Size:" return FILESIZE;
80 "MD5sum:" return MD5LINE;
81 "Installed-Size:" return INSTALLEDSIZE;
82 "Maintainer:" BEGIN (eolstate); return MAINTAINER;
83 "Architecture:" return ARCHITECTURE;
84 "Source:" return SOURCEPACKAGE;
85 "Binary:" return BINARYPACKAGE;
86 "Build-Depends:" return BUILDDEPENDS;
87 "Standards-Version:" return STANDARDSVERSION;
88 "Format:" return FORMAT;
89 "Directory:" return DIRECTORY;
90 "Files:" return FILES;
91
92 "category:"|"Section:" return CATEGORY;
93 "Priority:" return PRIORITY;
94 "requires:" return REQUIRES;
95 "Depends:" return DEPENDS;
96 "Pre-Depends:" return PREDEPENDS;
97 "Recommends:" return RECOMMENDS;
98 "Suggests:" return SUGGESTS;
99 "Conflicts:" return CONFLICTS;
100 "Replaces:" return REPLACES;
101 "Provides:" return PROVIDES;
102
103 "apath:" return APATH;
104 "ppath:" return PPATH;
105
106 "include-setup:" return INCLUDE_SETUP;
107
108 "download-url:" return DOWNLOAD_URL;
109
110 ^{STR}":" ignore_line ();
111
112 "[curr]" return T_CURR;
113 "[test]" return T_TEST;
114 "[exp]" return T_TEST;
115 "[prev]" return T_PREV;
116 "["{STR}"]" return T_UNKNOWN;
117
118 "(" return OPENBRACE;
119 ")" return CLOSEBRACE;
120 "<<" return LT;
121 ">>" return GT;
122 ">=" return GTEQUAL;
123 "<=" return LTEQUAL;
124 "=" return EQUAL;
125 \, return COMMA;
126 "|" return OR;
127 "@" return AT;
128
129 {STR}"@"{STR} { yylval = new char [strlen(yytext) + 1];
130 strcpy (yylval, yytext);
131 return EMAIL; }
132 {STR} { yylval = new char [strlen(yytext) + 1];
133 strcpy (yylval, yytext);
134 return STRING; }
135
136 [ \t\r]+ /* do nothing */;
137
138 ^"#".*\n /* do nothing */;
139 <descriptionstate>[^\n]+ { yylval = new char [strlen(yytext) + 1];
140 strcpy (yylval, yytext);
141 return STRTOEOL; }
142 <descriptionstate>\n { return NL; }
143 <descriptionstate>"\n"+ {BEGIN(INITIAL); return PARAGRAPH;}
144 <eolstate>[^\n]+ {return STRING; }
145 <eolstate>\n {BEGIN(INITIAL); return NL; }
146
147 \n { return NL; }
148 . { return *yytext;}
149 <<EOF>> { return LEX_EOF; }
150
151 %%
152
153 #include "io_stream.h"
154
155 static io_stream *input_stream = 0;
156 extern IniDBBuilder *iniBuilder;
157 static IniParseFeedback *iniFeedback;
158
159 void
160 ini_init(io_stream *stream, IniDBBuilder *aBuilder, IniParseFeedback &aFeedback)
161 {
162 input_stream = stream;
163 iniBuilder = aBuilder;
164 iniFeedback = &aFeedback;
165 YY_FLUSH_BUFFER;
166 yylineno = 1;
167 }
168
169 static int
170 ini_getchar(char *buf, int max_size)
171 {
172 if (input_stream)
173 {
174 ssize_t len = input_stream->read (buf, max_size);
175 if (len < 1)
176 {
177 len = 0;
178 input_stream = 0;
179 }
180 else
181 iniFeedback->progress (input_stream->tell(), input_stream->get_size());
182 return len;
183 }
184 return 0;
185 }
186
187 static void
188 ignore_line ()
189 {
190 char c;
191 while ((c = yyinput ()))
192 {
193 if (c == EOF)
194 return;
195 if (c == '\n')
196 return;
197 }
198 }
199
200 int
201 yybol ()
202 {
203 return !!YY_AT_BOL ();
204 }
This page took 0.049582 seconds and 5 git commands to generate.