]> cygwin.com Git - cygwin-apps/setup.git/blob - iniparse.y
2001-11-26 Gary R. Van Sickle <g.r.vansickle@worldnet.att.net>
[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 "category_list.h"
27 #include "ini.h"
28 #include "iniparse.h"
29 #include "filemanip.h"
30
31 extern "C" int yyerror (char const *s, ...);
32 extern "C" int yylex ();
33
34 #include "port.h"
35
36 #include "package_meta.h"
37 #include "package_version.h"
38 #include "cygpackage.h"
39
40 #define YYERROR_VERBOSE 1
41 /*#define YYDEBUG 1*/
42
43 static packagemeta *cp = 0;
44 extern unsigned int setup_timestamp;
45 extern char *setup_version;
46 extern int yylineno;
47
48 char * parse_mirror = 0;
49 static packagedb db;
50 static cygpackage *cpv = 0;
51 static int trust;
52
53 void add_correct_version();
54 %}
55
56 %token STRING
57 %token SETUP_TIMESTAMP SETUP_VERSION VERSION INSTALL SOURCE SDESC LDESC
58 %token CATEGORY REQUIRES
59 %token APATH PPATH INCLUDE_SETUP EXCLUDE_PACKAGE DOWNLOAD_URL
60 %token T_PREV T_CURR T_TEST T_UNKNOWN
61
62 %%
63
64 whole_file
65 : setup_headers packages
66 ;
67
68 setup_headers
69 : setup_header setup_headers
70 | /* empty */
71 ;
72
73 setup_header
74 : SETUP_TIMESTAMP STRING '\n' { setup_timestamp = strtoul ($2, 0, 0); }
75 | SETUP_VERSION STRING '\n' { setup_version = _strdup ($2); }
76 | '\n'
77 | error { yyerror ("unrecognized line in setup.ini headers (do you have the latest setup?)"); } '\n'
78 ;
79
80 packages
81 : package packages
82 | /* empty */
83 ;
84
85 package
86 : '@' STRING '\n' { cp = &db.registerpackage($2); cpv = new cygpackage ($2); trust = TRUST_CURR;}
87 lines
88 ;
89
90 lines
91 : simple_line '\n' lines
92 | simple_line
93 ;
94
95 simple_line
96 : VERSION STRING { cpv->set_canonical_version ($2);
97 add_correct_version ();}
98 | SDESC STRING { cpv->set_sdesc ($2); }
99 | LDESC STRING { cpv->set_ldesc ($2); }
100 | CATEGORY categories
101 | REQUIRES requires
102 | INSTALL STRING STRING { if (!cpv->Canonical_version ())
103 {
104 fileparse f;
105 if (parse_filename ($2, f))
106 {
107 cpv->set_canonical_version (f.ver);
108 add_correct_version ();
109 }
110 }
111
112 if (!cpv->bin.size)
113 {
114 cpv->bin.size = atoi($3);
115 cpv->bin.set_canonical ($2);
116 }
117 cpv->bin.sites.registerbykey (parse_mirror);
118 }
119 | SOURCE STRING STRING { if (!cpv->src.size)
120 {
121 cpv->src.size = atoi($3);
122 cpv->src.set_canonical ($2);
123 }
124 cpv->src.sites.registerbykey (parse_mirror); }
125 | T_PREV { trust = TRUST_PREV; }
126 | T_CURR { trust = TRUST_CURR; }
127 | T_TEST { trust = TRUST_TEST; }
128 | T_UNKNOWN { trust = TRUST_UNKNOWN; }
129 | /* empty */
130 | error '\n' { yylineno --;
131 yyerror ("unrecognized line in package %s (do you have the latest setup?)", cp->name);
132 yylineno ++;
133 }
134 ;
135
136 requires
137 : STRING { cpv->new_requirement($1); } requires
138 | STRING { cpv->new_requirement($1); }
139 ;
140
141 categories
142 : STRING { cp->add_category (db.categories.register_category ($1));
143 } categories
144 | STRING { cp->add_category (db.categories.register_category ($1)); }
145 ;
146
147 %%
148
149 void add_correct_version()
150 {
151 int merged = 0;
152 for (size_t n = 0; n < cp->versioncount; n++)
153 if (!strcasecmp(cp->versions[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[n]->bin.sites.registerbykey (cpv->bin.sites.getnth(1)->key);
162 /* Ditto for src */
163 if (cpv->src.sites.number ())
164 cp->versions[n]->src.sites.registerbykey (cpv->src.sites.getnth(1)->key);
165 cpv = (cygpackage *)cp->versions[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.048504 seconds and 6 git commands to generate.