]>
Commit | Line | Data |
---|---|---|
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" | |
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); | |
b24c88b3 | 30 | static void ignore_line (void); |
23c9e63c DD |
31 | |
32 | %} | |
33 | ||
b11b49f3 | 34 | /*%option debug */ |
23c9e63c | 35 | %option noyywrap |
b11b49f3 DD |
36 | %option yylineno |
37 | %option never-interactive | |
38 | ||
9522028b | 39 | STR [a-zA-Z0-9_./+-]+ |
23c9e63c DD |
40 | |
41 | %% | |
42 | ||
43 | \"[^"]*\" { yylval = strdup (yytext+1); | |
44 | yylval[strlen (yylval)-1] = 0; | |
45 | return STRING; } | |
46 | ||
47 | "setup-timestamp:" return SETUP_TIMESTAMP; | |
13d27274 | 48 | "setup-version:" return SETUP_VERSION; |
23c9e63c DD |
49 | "version:" return VERSION; |
50 | "install:" return INSTALL; | |
51 | "source:" return SOURCE; | |
52 | "sdesc:" return SDESC; | |
53 | "ldesc:" return LDESC; | |
54 | ||
38c97581 CF |
55 | "category:" return CATEGORY; |
56 | "requires:" return REQUIRES; | |
57 | ||
c46a33a9 CF |
58 | "apath:" return APATH; |
59 | "ppath:" return PPATH; | |
60 | ||
61 | "include-setup:" return INCLUDE_SETUP; | |
62 | ||
c46a33a9 CF |
63 | "download-url:" return DOWNLOAD_URL; |
64 | ||
b11b49f3 DD |
65 | ^{STR}":" ignore_line (); |
66 | ||
23c9e63c DD |
67 | "[curr]" return T_CURR; |
68 | "[test]" return T_TEST; | |
13d27274 | 69 | "[exp]" return T_TEST; |
23c9e63c | 70 | "[prev]" return T_PREV; |
b11b49f3 | 71 | "["{STR}"]" return T_UNKNOWN; |
23c9e63c | 72 | |
b11b49f3 | 73 | {STR} { yylval = strdup (yytext); |
23c9e63c DD |
74 | return STRING; } |
75 | ||
fb2cd8f6 | 76 | [ \t\r]+ /* do nothing */; |
b11b49f3 | 77 | |
fb2cd8f6 | 78 | "#".*\n { return '\n'; } |
23c9e63c | 79 | |
fb2cd8f6 CF |
80 | \n { return *yytext; } |
81 | . { return *yytext; } | |
23c9e63c DD |
82 | |
83 | %% | |
84 | ||
341988b9 RC |
85 | #include "io_stream.h" |
86 | ||
87 | static io_stream *input_stream = 0; | |
bb849dbd | 88 | extern char *parse_mirror; |
341988b9 | 89 | |
23c9e63c | 90 | void |
341988b9 | 91 | ini_init(io_stream *stream, char const *mirror) |
23c9e63c | 92 | { |
341988b9 | 93 | input_stream = stream; |
bb849dbd RC |
94 | if (parse_mirror) |
95 | free (parse_mirror); | |
96 | parse_mirror = strdup (mirror); | |
23c9e63c DD |
97 | } |
98 | ||
99 | static int | |
100 | ini_getchar(char *buf, int max_size) | |
101 | { | |
341988b9 | 102 | if (input_stream) |
23c9e63c | 103 | { |
341988b9 RC |
104 | ssize_t len = input_stream->read (buf, max_size); |
105 | if (len < 1) | |
106 | { | |
107 | len = 0; | |
108 | input_stream = 0; | |
23c9e63c | 109 | } |
341988b9 | 110 | return len; |
23c9e63c | 111 | } |
341988b9 | 112 | return 0; |
23c9e63c | 113 | } |
b11b49f3 DD |
114 | |
115 | static void | |
116 | ignore_line () | |
117 | { | |
118 | char c; | |
341988b9 | 119 | while ((c = yyinput ())) |
b11b49f3 DD |
120 | { |
121 | if (c == EOF) | |
122 | return; | |
123 | if (c == '\n') | |
124 | return; | |
125 | } | |
126 | } |