]> cygwin.com Git - cygwin-apps/setup.git/blob - iniparse.y
2002-01-21 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 "win32.h"
24 #include "package_db.h"
25 #include "category.h"
26 #include "ini.h"
27 #include "iniparse.h"
28 #include "filemanip.h"
29
30 extern "C" int yyerror (char const *s, ...);
31 int yylex ();
32
33 #include "port.h"
34
35 #include "package_meta.h"
36 #include "package_version.h"
37 #include "cygpackage.h"
38
39 #define YYERROR_VERBOSE 1
40 /*#define YYDEBUG 1*/
41
42 static packagemeta *cp = 0;
43 extern unsigned int setup_timestamp;
44 extern char *setup_version;
45 extern int yylineno;
46
47 char * parse_mirror = 0;
48 static cygpackage *cpv = 0;
49 static int trust;
50
51 void add_correct_version();
52 %}
53
54 %token STRING
55 %token SETUP_TIMESTAMP SETUP_VERSION VERSION INSTALL SOURCE SDESC LDESC
56 %token CATEGORY REQUIRES
57 %token APATH PPATH INCLUDE_SETUP EXCLUDE_PACKAGE DOWNLOAD_URL
58 %token T_PREV T_CURR T_TEST T_UNKNOWN
59
60 %%
61
62 whole_file
63 : setup_headers packages
64 ;
65
66 setup_headers
67 : setup_header setup_headers
68 | /* empty */
69 ;
70
71 setup_header
72 : SETUP_TIMESTAMP STRING '\n' { setup_timestamp = strtoul ($2, 0, 0); }
73 | SETUP_VERSION STRING '\n' { setup_version = new char [strlen($2) + 1];strcpy (setup_version, $2); }
74 | '\n'
75 | error { yyerror ("unrecognized line in setup.ini headers (do you have the latest setup?)"); } '\n'
76 ;
77
78 packages
79 : package packages
80 | /* empty */
81 ;
82
83 package
84 : '@' STRING '\n' {packagedb db; cp = &db.packages.registerbykey($2); cpv = new cygpackage ($2); trust = TRUST_CURR;}
85 lines
86 ;
87
88 lines
89 : simple_line '\n' lines
90 | simple_line
91 ;
92
93 simple_line
94 : VERSION STRING { cpv->set_canonical_version ($2);
95 add_correct_version ();}
96 | SDESC STRING { cpv->set_sdesc ($2); }
97 | LDESC STRING { cpv->set_ldesc ($2); }
98 | CATEGORY categories
99 | REQUIRES requires
100 | INSTALL STRING STRING { if (!cpv->Canonical_version ())
101 {
102 fileparse f;
103 if (parse_filename ($2, f))
104 {
105 cpv->set_canonical_version (f.ver);
106 add_correct_version ();
107 }
108 }
109
110 if (!cpv->bin.size)
111 {
112 cpv->bin.size = atoi($3);
113 cpv->bin.set_canonical ($2);
114 }
115 cpv->bin.sites.registerbykey (parse_mirror);
116 }
117 | SOURCE STRING STRING { if (!cpv->src.size)
118 {
119 cpv->src.size = atoi($3);
120 cpv->src.set_canonical ($2);
121 }
122 cpv->src.sites.registerbykey (parse_mirror); }
123 | T_PREV { trust = TRUST_PREV; cpv = new cygpackage (cp->name); }
124 | T_CURR { trust = TRUST_CURR; cpv = new cygpackage (cp->name); }
125 | T_TEST { trust = TRUST_TEST; cpv = new cygpackage (cp->name); }
126 | T_UNKNOWN { trust = TRUST_UNKNOWN; }
127 | /* empty */
128 | error '\n' { yylineno --;
129 yyerror ("unrecognized line in package %s (do you have the latest setup?)", cp->name);
130 yylineno ++;
131 }
132 ;
133
134 requires
135 : STRING { cpv->new_requirement($1); } requires
136 | STRING { cpv->new_requirement($1); }
137 ;
138
139 categories
140 : STRING { packagedb db; cp->add_category (db.categories.registerbykey ($1));
141 } categories
142 | STRING { packagedb db; cp->add_category (db.categories.registerbykey ($1)); }
143 ;
144
145 %%
146
147 void
148 add_correct_version()
149 {
150 int merged = 0;
151 for (size_t n = 1; !merged && n <= cp->versions.number (); n++)
152 if (!strcasecmp(cp->versions[n]->Canonical_version(), cpv->Canonical_version()))
153 {
154 /* ASSUMPTIONS:
155 categories and requires are consistent for the same version across
156 all mirrors
157 */
158 /* Copy the binary mirror across if this site claims to have an install */
159 if (cpv->bin.sites.number ())
160 cp->versions[n]->bin.sites.registerbykey (cpv->bin.sites[1]->key);
161 /* Ditto for src */
162 if (cpv->src.sites.number ())
163 cp->versions[n]->src.sites.registerbykey (cpv->src.sites[1]->key);
164 /* Copy the descriptions across */
165 if (cpv->SDesc () && !cp->versions[n]->SDesc ())
166 cp->versions[n]->set_sdesc (cpv->SDesc ());
167 if (cpv->LDesc () && !cp->versions[n]->LDesc ())
168 cp->versions[n]->set_ldesc (cpv->LDesc ());
169 cpv = (cygpackage *)cp->versions[n];
170 merged = 1;
171 }
172 if (!merged)
173 cp->add_version (*cpv);
174 /* trust setting */
175 switch (trust)
176 {
177 case TRUST_CURR:
178 if (cp->currtimestamp < setup_timestamp)
179 {
180 cp->currtimestamp = setup_timestamp;
181 cp->curr = cpv;
182 }
183 break;
184 case TRUST_PREV:
185 if (cp->prevtimestamp < setup_timestamp)
186 {
187 cp->prevtimestamp = setup_timestamp;
188 cp->prev = cpv;
189 }
190 break;
191 case TRUST_TEST:
192 if (cp->exptimestamp < setup_timestamp)
193 {
194 cp->exptimestamp = setup_timestamp;
195 cp->exp = cpv;
196 }
197 break;
198 }
199 }
This page took 0.048664 seconds and 6 git commands to generate.