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