]>
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); | |
b11b49f3 | 30 | static void ignore_line (); |
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 | ||
b11b49f3 DD |
55 | ^{STR}":" ignore_line (); |
56 | ||
23c9e63c DD |
57 | "[curr]" return T_CURR; |
58 | "[test]" return T_TEST; | |
13d27274 | 59 | "[exp]" return T_TEST; |
23c9e63c | 60 | "[prev]" return T_PREV; |
b11b49f3 | 61 | "["{STR}"]" return T_UNKNOWN; |
23c9e63c | 62 | |
b11b49f3 | 63 | {STR} { yylval = strdup (yytext); |
23c9e63c DD |
64 | return STRING; } |
65 | ||
b11b49f3 DD |
66 | [ \t\r]+ /* do nothing */ |
67 | ||
68 | "#".*\n /* ignore comments */ | |
23c9e63c DD |
69 | |
70 | \n { return yytext[0]; } | |
71 | . { return yytext[0]; } | |
72 | ||
73 | %% | |
74 | ||
75 | static char *input_string = 0; | |
76 | static char *end_input_string; | |
77 | ||
78 | void | |
79 | ini_init(char *string) | |
80 | { | |
81 | input_string = string; | |
82 | end_input_string = input_string + strlen(input_string); | |
83 | } | |
84 | ||
85 | static int | |
86 | ini_getchar(char *buf, int max_size) | |
87 | { | |
88 | if (input_string) | |
89 | { | |
90 | int avail = end_input_string - input_string; | |
91 | if (avail == 0) | |
92 | { | |
93 | input_string = end_input_string = 0; | |
94 | return 0; | |
95 | } | |
96 | if (avail > max_size) | |
97 | avail = max_size; | |
98 | memcpy(buf, input_string, avail); | |
99 | input_string += avail; | |
100 | return avail; | |
101 | } | |
102 | else | |
103 | return 0; | |
104 | } | |
b11b49f3 DD |
105 | |
106 | static void | |
107 | ignore_line () | |
108 | { | |
109 | char c; | |
110 | while (c = input ()) | |
111 | { | |
112 | if (c == EOF) | |
113 | return; | |
114 | if (c == '\n') | |
115 | return; | |
116 | } | |
117 | } |