]> cygwin.com Git - cygwin-apps/setup.git/blame - iniparse.y
2001-11-13 Robert Collins <rbtcollins@hotmail.com>
[cygwin-apps/setup.git] / iniparse.y
CommitLineData
23c9e63c
DD
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
b11b49f3 19#include <stdio.h>
23c9e63c 20#include <stdlib.h>
cb2a4b55 21#include <string.h>
23c9e63c 22
55e204f6 23#include "win32.h"
23c9e63c
DD
24#include "ini.h"
25#include "iniparse.h"
0af2d779
CF
26#include "filemanip.h"
27
28extern "C" int yyerror (char *s, ...);
29extern "C" int yylex ();
23c9e63c 30
13d27274
DD
31#include "port.h"
32
b11b49f3
DD
33#define YYERROR_VERBOSE 1
34/*#define YYDEBUG 1*/
35
23c9e63c
DD
36static Package *cp;
37static int trust;
38extern unsigned int setup_timestamp;
13d27274 39extern char *setup_version;
b11b49f3 40extern int yylineno;
23c9e63c
DD
41
42#define cpt (cp->info+trust)
43
44%}
45
46%token STRING
13d27274 47%token SETUP_TIMESTAMP SETUP_VERSION VERSION INSTALL SOURCE SDESC LDESC
38c97581 48%token CATEGORY REQUIRES
c46a33a9 49%token APATH PPATH INCLUDE_SETUP EXCLUDE_PACKAGE DOWNLOAD_URL
b11b49f3 50%token T_PREV T_CURR T_TEST T_UNKNOWN
23c9e63c
DD
51
52%%
53
54whole_file
55 : setup_headers packages
56 ;
57
58setup_headers
59 : setup_header setup_headers
60 | /* empty */
61 ;
62
63setup_header
64 : SETUP_TIMESTAMP STRING '\n' { setup_timestamp = strtoul ($2, 0, 0); }
13d27274 65 | SETUP_VERSION STRING '\n' { setup_version = _strdup ($2); }
89725f30 66 | '\n'
13d27274 67 | error { yyerror ("unrecognized line in setup.ini headers (do you have the latest setup?)"); } '\n'
23c9e63c
DD
68 ;
69
70packages
71 : package packages
72 | /* empty */
73 ;
74
75package
76 : '@' STRING '\n' { new_package($2); }
77 lines
23c9e63c
DD
78 ;
79
80lines
81 : simple_line '\n' lines
82 | simple_line
83 ;
84
85simple_line
86 : VERSION STRING { cpt->version = $2; }
87 | SDESC STRING { cp->sdesc = $2; }
88 | LDESC STRING { cp->ldesc = $2; }
8f53e82a 89 | CATEGORY categories
38c97581 90 | REQUIRES requires
23c9e63c 91 | INSTALL STRING STRING { cpt->install = $2;
0af2d779
CF
92 cpt->install_size = atoi($3);
93 if (!cpt->version)
94 {
95 fileparse f;
96 if (parse_filename ($2, f))
97 cpt->version = strdup (f.ver);
98 }
99 }
23c9e63c
DD
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; }
c46a33a9 105 | EXCLUDE_PACKAGE { cp->exclude = EXCLUDE_BY_SETUP; }
b11b49f3 106 | T_UNKNOWN { trust = TRUST_UNKNOWN; }
23c9e63c 107 | /* empty */
b11b49f3 108 | error '\n' { yylineno --;
13d27274 109 yyerror ("unrecognized line in package %s (do you have the latest setup?)", cp->name);
b11b49f3
DD
110 yylineno ++;
111 }
23c9e63c
DD
112 ;
113
38c97581
CF
114requires
115 : STRING { new_requirement(cp, $1); } requires
116 | STRING { new_requirement(cp, $1); }
117 ;
118
8f53e82a
RC
119categories
120 : STRING { add_category (cp, register_category ($1));
121 } categories
122 | STRING { add_category (cp, register_category ($1)); }
123 ;
124
23c9e63c
DD
125%%
126
c46a33a9 127Package *package = NULL;
23c9e63c
DD
128int npackages = 0;
129static int maxpackages = 0;
8f53e82a
RC
130Category *category = NULL;
131int ncategories = 0;
23c9e63c
DD
132
133Package *
134new_package (char *name)
135{
8f53e82a 136 if (package == NULL)
2a1a01e0 137 maxpackages = npackages = 0;
23c9e63c
DD
138 if (npackages >= maxpackages)
139 {
c46a33a9 140 maxpackages += 100;
23c9e63c 141 if (package)
c46a33a9 142 package = (Package *) realloc (package, (1 + maxpackages) * sizeof (Package));
23c9e63c 143 else
c46a33a9
CF
144 package = (Package *) malloc ((1 + maxpackages) * sizeof (Package));
145 memset (package + npackages, 0, (1 + maxpackages - npackages) * sizeof (Package));
146 }
147 cp = getpkgbyname (name);
148 if (!cp)
149 {
150 cp = package + npackages;
151 npackages++;
e98d90bd 152 cp->name = strdup (name);
c46a33a9 153 trust = TRUST_CURR;
23c9e63c 154 }
23c9e63c
DD
155
156 return cp;
157}
38c97581
CF
158
159void
8f53e82a 160new_requirement (Package *package, char *dependson)
38c97581
CF
161{
162 Dependency *dp;
163 if (!dependson)
164 return;
165 dp = (Dependency *) malloc (sizeof (Dependency));
166 dp->next = cp->required;
167 dp->package = dependson;
168 cp->required = dp;
169}
8f53e82a
RC
170
171Category *
4bb38dfa 172register_category (const char *name)
8f53e82a
RC
173{
174 Category *tempcat;
175 if (category == NULL)
176 ncategories = 0;
177 tempcat = getcategorybyname (name);
178 if (!tempcat)
179 {
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)
185 {
186 tempcat->next = category;
187 category = tempcat;
188 }
189 else
190 {
3bcf85be
RC
191 tempcat->next = sortcat->next;
192 sortcat->next = tempcat;
8f53e82a
RC
193 while (sortcat->next &&
194 strcasecmp(sortcat->next->name, tempcat->name) < 0)
195 {
196 tempcat->next = sortcat->next;
197 sortcat->next = tempcat;
198 }
199 }
200 ncategories++;
201 }
202 return tempcat;
203}
204
205void
969a294c 206add_category (Package *pkg, Category *cat)
8f53e82a
RC
207{
208 /* add a new record for the package list */
209 /* TODO: alpabetical inserts ? */
210 Category *tempcat;
211 CategoryPackage *templink;
212 tempcat = new (Category);
213 memset (tempcat, '\0', sizeof (Category));
969a294c 214 tempcat->next = pkg->category;
8f53e82a 215 tempcat->name = cat->name;
969a294c 216 pkg->category = tempcat;
8f53e82a
RC
217
218 templink = new (CategoryPackage);
219 templink->next = cat->packages;
969a294c 220 templink->pkgname = pkg->name;
8f53e82a
RC
221 cat->packages = templink;
222
223 /* hack to ensure we allocate enough space */
224 ncategories++;
225}
This page took 0.053814 seconds and 5 git commands to generate.