]> cygwin.com Git - cygwin-apps/setup.git/blame - inilex.l
2002-07-05 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / inilex.l
CommitLineData
23c9e63c
DD
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>
aa1e3b4d 14 * Maintained by Robert Collins <rbtcollins@hotmail.com>
23c9e63c
DD
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
b11b49f3 22#include "win32.h"
23c9e63c
DD
23#include <string.h>
24
25#include "ini.h"
26#include "iniparse.h"
3c054baf 27#include "String++.h"
aa1e3b4d 28#include "IniParseFeedback.h"
23c9e63c
DD
29
30#define YY_INPUT(buf,result,max_size) { result = ini_getchar(buf, max_size); }
31
32static int ini_getchar(char *buf, int max_size);
b24c88b3 33static void ignore_line (void);
23c9e63c
DD
34
35%}
36
b11b49f3 37/*%option debug */
23c9e63c 38%option noyywrap
b11b49f3
DD
39%option yylineno
40%option never-interactive
41
aa1e3b4d
RC
42%x descriptionstate
43%x eolstate
44
45STR [a-zA-Z0-9_./:\+-]+
23c9e63c
DD
46
47%%
48
58ee6135
RC
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';
076654e7 60 ((unsigned char *) yylval) [i / 2] += val << ((i % 2) ? 0 : 4);
58ee6135
RC
61 }
62 return MD5;
63}
64
5e0464a1
RC
65\"[^"]*\" { yylval = new char [strlen (yytext+1) + 1];
66 strcpy (yylval, yytext+1);
23c9e63c
DD
67 yylval[strlen (yylval)-1] = 0;
68 return STRING; }
69
70"setup-timestamp:" return SETUP_TIMESTAMP;
13d27274 71"setup-version:" return SETUP_VERSION;
aa1e3b4d
RC
72"Package:" return PACKAGENAME;
73[vV]"ersion:" return PACKAGEVERSION;
74"install:"|"Filename:" return INSTALL;
23c9e63c
DD
75"source:" return SOURCE;
76"sdesc:" return SDESC;
77"ldesc:" return LDESC;
aa1e3b4d
RC
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
86"category:"|"Section:" return CATEGORY;
87"Priority:" return PRIORITY;
38c97581 88"requires:" return REQUIRES;
aa1e3b4d
RC
89"Depends:" return DEPENDS;
90"Pre-Depends:" return PREDEPENDS;
91"Recommends:" return RECOMMENDS;
92"Suggests:" return SUGGESTS;
93"Conflicts:" return CONFLICTS;
94"Replaces:" return REPLACES;
95"Provides:" return PROVIDES;
38c97581 96
c46a33a9
CF
97"apath:" return APATH;
98"ppath:" return PPATH;
99
100"include-setup:" return INCLUDE_SETUP;
101
c46a33a9
CF
102"download-url:" return DOWNLOAD_URL;
103
b11b49f3
DD
104^{STR}":" ignore_line ();
105
23c9e63c
DD
106"[curr]" return T_CURR;
107"[test]" return T_TEST;
13d27274 108"[exp]" return T_TEST;
23c9e63c 109"[prev]" return T_PREV;
b11b49f3 110"["{STR}"]" return T_UNKNOWN;
23c9e63c 111
aa1e3b4d
RC
112"(" return OPENBRACE;
113")" return CLOSEBRACE;
114"<<" return LT;
115">>" return GT;
116">=" return GTEQUAL;
117"<=" return LTEQUAL;
118"=" return EQUAL;
119\, return COMMA;
120"|" return OR;
121"@" return AT;
122
123{STR}"@"{STR} { yylval = new char [strlen(yytext) + 1];
124 strcpy (yylval, yytext);
125 return EMAIL; }
5e0464a1
RC
126{STR} { yylval = new char [strlen(yytext) + 1];
127 strcpy (yylval, yytext);
23c9e63c
DD
128 return STRING; }
129
fb2cd8f6 130[ \t\r]+ /* do nothing */;
b11b49f3 131
aa1e3b4d
RC
132^"#".*\n /* do nothing */;
133<descriptionstate>[^\n]+ { yylval = new char [strlen(yytext) + 1];
134 strcpy (yylval, yytext);
135 return STRTOEOL; }
136<descriptionstate>\n { return NL; }
137<descriptionstate>"\n"+ {BEGIN(INITIAL); return PARAGRAPH;}
138<eolstate>[^\n]+ {return STRING; }
139<eolstate>\n {BEGIN(INITIAL); return NL; }
23c9e63c 140
aa1e3b4d
RC
141\n { return NL; }
142. { return *yytext;}
143<<EOF>> { return LEX_EOF; }
23c9e63c
DD
144
145%%
146
341988b9
RC
147#include "io_stream.h"
148
149static io_stream *input_stream = 0;
076654e7 150extern IniDBBuilder *iniBuilder;
aa1e3b4d 151static IniParseFeedback *iniFeedback;
341988b9 152
23c9e63c 153void
aa1e3b4d 154ini_init(io_stream *stream, IniDBBuilder *aBuilder, IniParseFeedback &aFeedback)
23c9e63c 155{
341988b9 156 input_stream = stream;
076654e7 157 iniBuilder = aBuilder;
aa1e3b4d 158 iniFeedback = &aFeedback;
0d4e0aad
CF
159 YY_FLUSH_BUFFER;
160 yylineno = 1;
23c9e63c
DD
161}
162
163static int
164ini_getchar(char *buf, int max_size)
165{
341988b9 166 if (input_stream)
23c9e63c 167 {
341988b9
RC
168 ssize_t len = input_stream->read (buf, max_size);
169 if (len < 1)
170 {
171 len = 0;
172 input_stream = 0;
23c9e63c 173 }
aa1e3b4d
RC
174 else
175 iniFeedback->progress (input_stream->tell(), input_stream->get_size());
341988b9 176 return len;
23c9e63c 177 }
341988b9 178 return 0;
23c9e63c 179}
b11b49f3
DD
180
181static void
182ignore_line ()
183{
184 char c;
341988b9 185 while ((c = yyinput ()))
b11b49f3
DD
186 {
187 if (c == EOF)
188 return;
189 if (c == '\n')
190 return;
191 }
192}
0d4e0aad
CF
193
194int
195yybol ()
196{
197 return !!YY_AT_BOL ();
198}
This page took 0.058098 seconds and 5 git commands to generate.