]> cygwin.com Git - cygwin-apps/setup.git/blob - iniparse.y
2002-05-01 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 void process_src (cygpackage *, packagesource &src, char *, char*, char* = 0);
53 %}
54
55 %token STRING
56 %token SETUP_TIMESTAMP SETUP_VERSION PACKAGEVERSION 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 %token MD5
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 = new char [strlen($2) + 1];strcpy (setup_version, $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' {packagedb db; cp = &db.packages.registerbykey($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 : PACKAGEVERSION 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 MD5 { process_src (cpv, cpv->bin, $2, $3, $4); }
103 | INSTALL STRING STRING { process_src (cpv, cpv->bin, $2, $3); }
104 | SOURCE STRING STRING MD5 { process_src (cpv, cpv->src, $2, $3, $4); }
105 | SOURCE STRING STRING { process_src (cpv, cpv->src, $2, $3); }
106 | T_PREV { trust = TRUST_PREV; cpv = new cygpackage (cp->name); }
107 | T_CURR { trust = TRUST_CURR; cpv = new cygpackage (cp->name); }
108 | T_TEST { trust = TRUST_TEST; cpv = new cygpackage (cp->name); }
109 | T_UNKNOWN { trust = TRUST_UNKNOWN; }
110 | /* empty */
111 | error '\n' { yylineno --;
112 yyerror ("unrecognized line in package %s (do you have the latest setup?)", cp->name.cstr_oneuse());
113 yylineno ++;
114 }
115 ;
116
117 requires
118 : STRING { cpv->new_requirement($1); } requires
119 | STRING { cpv->new_requirement($1); }
120 ;
121
122 categories
123 : STRING { packagedb db; cp->add_category (db.categories.registerbykey ($1));
124 } categories
125 | STRING { packagedb db; cp->add_category (db.categories.registerbykey ($1)); }
126 ;
127
128 %%
129
130 void
131 add_correct_version()
132 {
133 int merged = 0;
134 for (size_t n = 1; !merged && n <= cp->versions.number (); n++)
135 if (!cp->versions[n]->Canonical_version().casecompare(cpv->Canonical_version()))
136 {
137 /* ASSUMPTIONS:
138 categories and requires are consistent for the same version across
139 all mirrors
140 */
141 /* Copy the binary mirror across if this site claims to have an install */
142 if (cpv->bin.sites.number ())
143 cp->versions[n]->bin.sites.registerbykey (cpv->bin.sites[1]->key);
144 /* Ditto for src */
145 if (cpv->src.sites.number ())
146 cp->versions[n]->src.sites.registerbykey (cpv->src.sites[1]->key);
147 /* Copy the descriptions across */
148 if (cpv->SDesc ().size() && !cp->versions[n]->SDesc ().size())
149 cp->versions[n]->set_sdesc (cpv->SDesc ());
150 if (cpv->LDesc ().size() && !cp->versions[n]->LDesc ().size())
151 cp->versions[n]->set_ldesc (cpv->LDesc ());
152 cpv = (cygpackage *)cp->versions[n];
153 merged = 1;
154 }
155 if (!merged)
156 cp->add_version (*cpv);
157 /* trust setting */
158 switch (trust)
159 {
160 case TRUST_CURR:
161 if (cp->currtimestamp < setup_timestamp)
162 {
163 cp->currtimestamp = setup_timestamp;
164 cp->curr = cpv;
165 }
166 break;
167 case TRUST_PREV:
168 if (cp->prevtimestamp < setup_timestamp)
169 {
170 cp->prevtimestamp = setup_timestamp;
171 cp->prev = cpv;
172 }
173 break;
174 case TRUST_TEST:
175 if (cp->exptimestamp < setup_timestamp)
176 {
177 cp->exptimestamp = setup_timestamp;
178 cp->exp = cpv;
179 }
180 break;
181 }
182 }
183
184 void
185 process_src (cygpackage *cpv, packagesource &src, char *path, char*size, char*md5 )
186 {
187 if (!cpv->Canonical_version ().size())
188 {
189 fileparse f;
190 if (parse_filename (path, f))
191 {
192 cpv->set_canonical_version (f.ver);
193 add_correct_version ();
194 }
195 }
196
197 if (!src.size)
198 {
199 src.size = atoi(size);
200 src.set_canonical (path);
201 }
202 if (md5 && !src.md5.isSet())
203 src.md5.set((unsigned char *)md5);
204 src.sites.registerbykey (parse_mirror);
205 }
This page took 0.045201 seconds and 6 git commands to generate.