3 * Copyright (c) 2000, Red Hat, Inc.
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.
10 * A copy of the GNU General Public License can be found at
13 * Written by DJ Delorie <dj@cygnus.com>
17 /* Parse the setup.ini files. inilex.l provides the tokens for this. */
26 #include "filemanip.h"
28 extern "C" int yyerror (char *s, ...);
29 extern "C" int yylex ();
33 #define YYERROR_VERBOSE 1
38 extern unsigned int setup_timestamp;
39 extern char *setup_version;
42 #define cpt (cp->info+trust)
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
55 : setup_headers packages
59 : setup_header setup_headers
64 : SETUP_TIMESTAMP STRING '\n' { setup_timestamp = strtoul ($2, 0, 0); }
65 | SETUP_VERSION STRING '\n' { setup_version = _strdup ($2); }
67 | error { yyerror ("unrecognized line in setup.ini headers (do you have the latest setup?)"); } '\n'
76 : '@' STRING '\n' { new_package($2); }
81 : simple_line '\n' lines
86 : VERSION STRING { cpt->version = $2; }
87 | SDESC STRING { cp->sdesc = $2; }
88 | LDESC STRING { cp->ldesc = $2; }
91 | INSTALL STRING STRING { cpt->install = $2;
92 cpt->install_size = atoi($3);
96 if (parse_filename ($2, f))
97 cpt->version = strdup (f.ver);
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; }
108 | error '\n' { yylineno --;
109 yyerror ("unrecognized line in package %s (do you have the latest setup?)", cp->name);
115 : STRING { new_requirement(cp, $1); } requires
116 | STRING { new_requirement(cp, $1); }
120 : STRING { add_category (cp, register_category ($1));
122 | STRING { add_category (cp, register_category ($1)); }
127 Package *package = NULL;
129 static int maxpackages = 0;
130 Category *category = NULL;
134 new_package (char *name)
137 maxpackages = npackages = 0;
138 if (npackages >= maxpackages)
142 package = (Package *) realloc (package, (1 + maxpackages) * sizeof (Package));
144 package = (Package *) malloc ((1 + maxpackages) * sizeof (Package));
145 memset (package + npackages, 0, (1 + maxpackages - npackages) * sizeof (Package));
147 cp = getpkgbyname (name);
150 cp = package + npackages;
152 cp->name = strdup (name);
160 new_requirement (Package *package, char *dependson)
165 dp = (Dependency *) malloc (sizeof (Dependency));
166 dp->next = cp->required;
167 dp->package = dependson;
172 register_category (char *name)
175 if (category == NULL)
177 tempcat = getcategorybyname (name);
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)
186 tempcat->next = category;
191 while (sortcat->next &&
192 strcasecmp(sortcat->next->name, tempcat->name) < 0)
194 tempcat->next = sortcat->next;
195 sortcat->next = tempcat;
204 add_category (Package *package, Category *cat)
206 /* add a new record for the package list */
207 /* TODO: alpabetical inserts ? */
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;
216 templink = new (CategoryPackage);
217 templink->next = cat->packages;
218 templink->pkg = package->name;
219 cat->packages = templink;
221 /* hack to ensure we allocate enough space */