]> cygwin.com Git - cygwin-apps/setup.git/blob - inilex.l
2002-05-26 Ralf Habacker <ralf.habacker@freenet.de>
[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 *
15 */
16
17 /* tokenize the setup.ini files. We parse a string which we've
18 previously downloaded. The program must call ini_init() to specify
19 that string. */
20
21 #include "win32.h"
22 #include <string.h>
23
24 #include "ini.h"
25 #include "iniparse.h"
26 #include "String++.h"
27
28 #define YY_INPUT(buf,result,max_size) { result = ini_getchar(buf, max_size); }
29
30 static int ini_getchar(char *buf, int max_size);
31 static void ignore_line (void);
32
33 %}
34
35 /*%option debug */
36 %option noyywrap
37 %option yylineno
38 %option never-interactive
39
40 STR [a-zA-Z0-9_./+-]+
41
42 %%
43
44 [0123456789abcdef]{32,32} {
45 yylval = (char *) new unsigned char[16];
46 for (int i=0; i< 16; ++i)
47 ((unsigned char *) yylval) [i] = 0;
48 for (int i=0; i< 32; ++i)
49 {
50 unsigned char val = (unsigned char) yytext[i];
51 if (val > '9')
52 val = val - 'a' + 10;
53 else
54 val = val - '0';
55 ((unsigned char *) yylval) [i / 2] += val << ((i % 2) ? 0 : 4);
56 }
57 return MD5;
58 }
59
60 \"[^"]*\" { yylval = new char [strlen (yytext+1) + 1];
61 strcpy (yylval, yytext+1);
62 yylval[strlen (yylval)-1] = 0;
63 return STRING; }
64
65 "setup-timestamp:" return SETUP_TIMESTAMP;
66 "setup-version:" return SETUP_VERSION;
67 "version:" return PACKAGEVERSION;
68 "install:" return INSTALL;
69 "source:" return SOURCE;
70 "sdesc:" return SDESC;
71 "ldesc:" return LDESC;
72
73 "category:" return CATEGORY;
74 "requires:" return REQUIRES;
75
76 "apath:" return APATH;
77 "ppath:" return PPATH;
78
79 "include-setup:" return INCLUDE_SETUP;
80
81 "download-url:" return DOWNLOAD_URL;
82
83 ^{STR}":" ignore_line ();
84
85 "[curr]" return T_CURR;
86 "[test]" return T_TEST;
87 "[exp]" return T_TEST;
88 "[prev]" return T_PREV;
89 "["{STR}"]" return T_UNKNOWN;
90
91 {STR} { yylval = new char [strlen(yytext) + 1];
92 strcpy (yylval, yytext);
93 return STRING; }
94
95 [ \t\r]+ /* do nothing */;
96
97 "#".*\n { return '\n'; }
98
99 \n { return *yytext; }
100 . { return *yytext; }
101
102 %%
103
104 #include "io_stream.h"
105
106 static io_stream *input_stream = 0;
107 extern IniDBBuilder *iniBuilder;
108
109 void
110 ini_init(io_stream *stream, IniDBBuilder *aBuilder)
111 {
112 input_stream = stream;
113 iniBuilder = aBuilder;
114 YY_FLUSH_BUFFER;
115 yylineno = 1;
116 }
117
118 static int
119 ini_getchar(char *buf, int max_size)
120 {
121 if (input_stream)
122 {
123 ssize_t len = input_stream->read (buf, max_size);
124 if (len < 1)
125 {
126 len = 0;
127 input_stream = 0;
128 }
129 return len;
130 }
131 return 0;
132 }
133
134 static void
135 ignore_line ()
136 {
137 char c;
138 while ((c = yyinput ()))
139 {
140 if (c == EOF)
141 return;
142 if (c == '\n')
143 return;
144 }
145 }
146
147 int
148 yybol ()
149 {
150 return !!YY_AT_BOL ();
151 }
This page took 0.042963 seconds and 5 git commands to generate.