]> cygwin.com Git - cygwin-apps/setup.git/blame - inilex.l
copyright
[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>
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
b11b49f3 21#include "win32.h"
23c9e63c
DD
22#include <string.h>
23
24#include "ini.h"
25#include "iniparse.h"
3c054baf 26#include "String++.h"
23c9e63c
DD
27
28#define YY_INPUT(buf,result,max_size) { result = ini_getchar(buf, max_size); }
29
30static int ini_getchar(char *buf, int max_size);
b24c88b3 31static void ignore_line (void);
23c9e63c
DD
32
33%}
34
b11b49f3 35/*%option debug */
23c9e63c 36%option noyywrap
b11b49f3
DD
37%option yylineno
38%option never-interactive
39
9522028b 40STR [a-zA-Z0-9_./+-]+
23c9e63c
DD
41
42%%
43
58ee6135
RC
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';
076654e7 55 ((unsigned char *) yylval) [i / 2] += val << ((i % 2) ? 0 : 4);
58ee6135
RC
56 }
57 return MD5;
58}
59
5e0464a1
RC
60\"[^"]*\" { yylval = new char [strlen (yytext+1) + 1];
61 strcpy (yylval, yytext+1);
23c9e63c
DD
62 yylval[strlen (yylval)-1] = 0;
63 return STRING; }
64
65"setup-timestamp:" return SETUP_TIMESTAMP;
13d27274 66"setup-version:" return SETUP_VERSION;
f6100b6f 67"version:" return PACKAGEVERSION;
23c9e63c
DD
68"install:" return INSTALL;
69"source:" return SOURCE;
70"sdesc:" return SDESC;
71"ldesc:" return LDESC;
72
38c97581
CF
73"category:" return CATEGORY;
74"requires:" return REQUIRES;
75
c46a33a9
CF
76"apath:" return APATH;
77"ppath:" return PPATH;
78
79"include-setup:" return INCLUDE_SETUP;
80
c46a33a9
CF
81"download-url:" return DOWNLOAD_URL;
82
b11b49f3
DD
83^{STR}":" ignore_line ();
84
23c9e63c
DD
85"[curr]" return T_CURR;
86"[test]" return T_TEST;
13d27274 87"[exp]" return T_TEST;
23c9e63c 88"[prev]" return T_PREV;
b11b49f3 89"["{STR}"]" return T_UNKNOWN;
23c9e63c 90
5e0464a1
RC
91{STR} { yylval = new char [strlen(yytext) + 1];
92 strcpy (yylval, yytext);
23c9e63c
DD
93 return STRING; }
94
fb2cd8f6 95[ \t\r]+ /* do nothing */;
b11b49f3 96
fb2cd8f6 97"#".*\n { return '\n'; }
23c9e63c 98
fb2cd8f6
CF
99\n { return *yytext; }
100. { return *yytext; }
23c9e63c
DD
101
102%%
103
341988b9
RC
104#include "io_stream.h"
105
106static io_stream *input_stream = 0;
076654e7 107extern IniDBBuilder *iniBuilder;
341988b9 108
23c9e63c 109void
076654e7 110ini_init(io_stream *stream, IniDBBuilder *aBuilder)
23c9e63c 111{
341988b9 112 input_stream = stream;
076654e7 113 iniBuilder = aBuilder;
23c9e63c
DD
114}
115
116static int
117ini_getchar(char *buf, int max_size)
118{
341988b9 119 if (input_stream)
23c9e63c 120 {
341988b9
RC
121 ssize_t len = input_stream->read (buf, max_size);
122 if (len < 1)
123 {
124 len = 0;
125 input_stream = 0;
23c9e63c 126 }
341988b9 127 return len;
23c9e63c 128 }
341988b9 129 return 0;
23c9e63c 130}
b11b49f3
DD
131
132static void
133ignore_line ()
134{
135 char c;
341988b9 136 while ((c = yyinput ()))
b11b49f3
DD
137 {
138 if (c == EOF)
139 return;
140 if (c == '\n')
141 return;
142 }
143}
This page took 0.043278 seconds and 5 git commands to generate.