]> cygwin.com Git - cygwin-apps/setup.git/blob - inilex.l
2002-01-27 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 *
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
27 #define YY_INPUT(buf,result,max_size) { result = ini_getchar(buf, max_size); }
28
29 static int ini_getchar(char *buf, int max_size);
30 static void ignore_line (void);
31
32 %}
33
34 /*%option debug */
35 %option noyywrap
36 %option yylineno
37 %option never-interactive
38
39 STR [a-zA-Z0-9_./+-]+
40
41 %%
42
43 \"[^"]*\" { yylval = new char [strlen (yytext+1) + 1];
44 strcpy (yylval, yytext+1);
45 yylval[strlen (yylval)-1] = 0;
46 return STRING; }
47
48 "setup-timestamp:" return SETUP_TIMESTAMP;
49 "setup-version:" return SETUP_VERSION;
50 "version:" return VERSION;
51 "install:" return INSTALL;
52 "source:" return SOURCE;
53 "sdesc:" return SDESC;
54 "ldesc:" return LDESC;
55
56 "category:" return CATEGORY;
57 "requires:" return REQUIRES;
58
59 "apath:" return APATH;
60 "ppath:" return PPATH;
61
62 "include-setup:" return INCLUDE_SETUP;
63
64 "download-url:" return DOWNLOAD_URL;
65
66 ^{STR}":" ignore_line ();
67
68 "[curr]" return T_CURR;
69 "[test]" return T_TEST;
70 "[exp]" return T_TEST;
71 "[prev]" return T_PREV;
72 "["{STR}"]" return T_UNKNOWN;
73
74 {STR} { yylval = new char [strlen(yytext) + 1];
75 strcpy (yylval, yytext);
76 return STRING; }
77
78 [ \t\r]+ /* do nothing */;
79
80 "#".*\n { return '\n'; }
81
82 \n { return *yytext; }
83 . { return *yytext; }
84
85 %%
86
87 #include "io_stream.h"
88
89 static io_stream *input_stream = 0;
90 extern char *parse_mirror;
91
92 void
93 ini_init(io_stream *stream, char const *mirror)
94 {
95 input_stream = stream;
96 if (parse_mirror)
97 delete[] parse_mirror;
98 parse_mirror = new char[strlen (mirror) + 1];
99 strcpy (parse_mirror, mirror);
100 }
101
102 static int
103 ini_getchar(char *buf, int max_size)
104 {
105 if (input_stream)
106 {
107 ssize_t len = input_stream->read (buf, max_size);
108 if (len < 1)
109 {
110 len = 0;
111 input_stream = 0;
112 }
113 return len;
114 }
115 return 0;
116 }
117
118 static void
119 ignore_line ()
120 {
121 char c;
122 while ((c = yyinput ()))
123 {
124 if (c == EOF)
125 return;
126 if (c == '\n')
127 return;
128 }
129 }
This page took 0.040275 seconds and 5 git commands to generate.