]> cygwin.com Git - cygwin-apps/setup.git/blob - iniparse.y
Sat Jun 30 11:01:00 2001 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / iniparse.y
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 /* Parse the setup.ini files. inilex.l provides the tokens for this. */
18
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22
23 #include "ini.h"
24 #include "iniparse.h"
25 #include "win32.h"
26 #include "filemanip.h"
27
28 extern "C" int yyerror (char *s, ...);
29 extern "C" int yylex ();
30
31 #include "port.h"
32
33 #define YYERROR_VERBOSE 1
34 /*#define YYDEBUG 1*/
35
36 static Package *cp;
37 static int trust;
38 extern unsigned int setup_timestamp;
39 extern char *setup_version;
40 extern int yylineno;
41
42 #define cpt (cp->info+trust)
43
44 %}
45
46 %token STRING
47 %token SETUP_TIMESTAMP SETUP_VERSION VERSION INSTALL SOURCE SDESC LDESC
48 %token CATEGORY REQUIRES
49 %token APATH PPATH INCLUDE_SETUP EXCLUDE_PACKAGE DOWNLOAD_URL
50 %token T_PREV T_CURR T_TEST T_UNKNOWN
51
52 %%
53
54 whole_file
55 : setup_headers packages
56 ;
57
58 setup_headers
59 : setup_header setup_headers
60 | /* empty */
61 ;
62
63 setup_header
64 : SETUP_TIMESTAMP STRING '\n' { setup_timestamp = strtoul ($2, 0, 0); }
65 | SETUP_VERSION STRING '\n' { setup_version = _strdup ($2); }
66 | '\n'
67 | error { yyerror ("unrecognized line in setup.ini headers (do you have the latest setup?)"); } '\n'
68 ;
69
70 packages
71 : package packages
72 | /* empty */
73 ;
74
75 package
76 : '@' STRING '\n' { new_package($2); }
77 lines
78 ;
79
80 lines
81 : simple_line '\n' lines
82 | simple_line
83 ;
84
85 simple_line
86 : VERSION STRING { cpt->version = $2; }
87 | SDESC STRING { cp->sdesc = $2; }
88 | LDESC STRING { cp->ldesc = $2; }
89 | CATEGORY categories
90 | REQUIRES requires
91 | INSTALL STRING STRING { cpt->install = $2;
92 cpt->install_size = atoi($3);
93 if (!cpt->version)
94 {
95 fileparse f;
96 if (parse_filename ($2, f))
97 cpt->version = strdup (f.ver);
98 }
99 }
100 | SOURCE STRING STRING { cpt->source = $2;
101 cpt->source_size = atoi($3); }
102 | T_PREV { trust = TRUST_PREV; }
103 | T_CURR { trust = TRUST_CURR; }
104 | T_TEST { trust = TRUST_TEST; }
105 | EXCLUDE_PACKAGE { cp->exclude = EXCLUDE_BY_SETUP; }
106 | T_UNKNOWN { trust = TRUST_UNKNOWN; }
107 | /* empty */
108 | error '\n' { yylineno --;
109 yyerror ("unrecognized line in package %s (do you have the latest setup?)", cp->name);
110 yylineno ++;
111 }
112 ;
113
114 requires
115 : STRING { new_requirement(cp, $1); } requires
116 | STRING { new_requirement(cp, $1); }
117 ;
118
119 categories
120 : STRING { add_category (cp, register_category ($1));
121 } categories
122 | STRING { add_category (cp, register_category ($1)); }
123 ;
124
125 %%
126
127 Package *package = NULL;
128 int npackages = 0;
129 static int maxpackages = 0;
130 Category *category = NULL;
131 int ncategories = 0;
132
133 Package *
134 new_package (char *name)
135 {
136 if (package == NULL)
137 maxpackages = npackages = 0;
138 if (npackages >= maxpackages)
139 {
140 maxpackages += 100;
141 if (package)
142 package = (Package *) realloc (package, (1 + maxpackages) * sizeof (Package));
143 else
144 package = (Package *) malloc ((1 + maxpackages) * sizeof (Package));
145 memset (package + npackages, 0, (1 + maxpackages - npackages) * sizeof (Package));
146 }
147 cp = getpkgbyname (name);
148 if (!cp)
149 {
150 cp = package + npackages;
151 npackages++;
152 cp->name = strdup (name);
153 trust = TRUST_CURR;
154 }
155
156 return cp;
157 }
158
159 void
160 new_requirement (Package *package, char *dependson)
161 {
162 Dependency *dp;
163 if (!dependson)
164 return;
165 dp = (Dependency *) malloc (sizeof (Dependency));
166 dp->next = cp->required;
167 dp->package = dependson;
168 cp->required = dp;
169 }
170
171 Category *
172 register_category (char *name)
173 {
174 Category *tempcat;
175 if (category == NULL)
176 ncategories = 0;
177 tempcat = getcategorybyname (name);
178 if (!tempcat)
179 {
180 Category *sortcat = category;
181 tempcat = new (Category);
182 memset (tempcat, '\0', sizeof (Category));
183 tempcat->name = strdup (name);
184 if (!sortcat || strcasecmp(sortcat->name, name) > 0)
185 {
186 tempcat->next = category;
187 category = tempcat;
188 }
189 else
190 {
191 while (sortcat->next &&
192 strcasecmp(sortcat->next->name, tempcat->name) < 0)
193 {
194 tempcat->next = sortcat->next;
195 sortcat->next = tempcat;
196 }
197 }
198 ncategories++;
199 }
200 return tempcat;
201 }
202
203 void
204 add_category (Package *package, Category *cat)
205 {
206 /* add a new record for the package list */
207 /* TODO: alpabetical inserts ? */
208 Category *tempcat;
209 CategoryPackage *templink;
210 tempcat = new (Category);
211 memset (tempcat, '\0', sizeof (Category));
212 tempcat->next = package->category;
213 tempcat->name = cat->name;
214 package->category = tempcat;
215
216 templink = new (CategoryPackage);
217 templink->next = cat->packages;
218 templink->pkg = package->name;
219 cat->packages = templink;
220
221 /* hack to ensure we allocate enough space */
222 ncategories++;
223 }
This page took 0.045157 seconds and 6 git commands to generate.