1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797
|
/*******************************************************/
/* CUDF solver: cudf.y */
/* Syntactic analyser for CUDF */
/* (c) Claude Michel I3S (UNSA-CNRS) 2009,2010,2011 */
/*******************************************************/
/* Based on Bison syntactic analyser generator */
%{
#include <stdio.h>
#include <string.h>
#include <cudf.h>
#include <cudf_hash_table.h>
extern int cudflineno; /* number of the current line */
extern int cudflex (void); /* lexical analyser */
/* Print out a CUDF problem error location */
void yyerror(const char *str)
{
fprintf(stderr,"cudf syntax error (line: %d): %s\n", cudflineno, str);
}
int package_line = 0; /* last line of a package declaration */
CUDFVersionedPackage *current_package = (CUDFVersionedPackage *)NULL; /* package under analysis */
int versioned_package_rank = 0; /* last rank of a versionned package */
CUDFproblem *current_problem = (CUDFproblem *)NULL; /* current problem */
CUDFVersionedPackageList all_packages; /* list of all versioned packages */
CUDFVirtualPackageList all_virtual_packages; /* list of all virtual packages */
CUDFVirtualPackageList version_installed_virtual_packages; /* list of all virtual packages with at least one version installed */
CUDFVirtualPackageList all_virtual_packages_with_version; /* list of all virtual packages with at least one */
CUDFVirtualPackageList uninstalled_virtual_packages_with_version; /* list of all virtual packages with at least one */
CUDFVersionedPackageList installed_packages; /* list of all installed versioned packages */
CUDFVersionedPackageList uninstalled_packages; /* list of all uninstalled versioned packages */
CUDFproblem *the_problem = (CUDFproblem *)NULL; /* the CUDF problem to solve */
CUDFVpkgFormula *current_vpkgformula = (CUDFVpkgFormula *)NULL; /* vpkgformula under analysis */
CUDFVpkgList *current_vpkglist = (CUDFVpkgList *)NULL; /* vpkglist under analysis */
CUDFVpkg *current_vpkg = (CUDFVpkg *)NULL; /* vpkg under analysis */
CUDFPropertyType current_pt_type = pt_vpkgformula; /* type of the user property under analysis */
CUDFVpkg *build_vpkg(const char *vpkgname, CUDFPackageOp op, CUDFVersion version) { /* internal construction of a vpkg */
return new CUDFVpkg(get_virtual_package(vpkgname), op, version);
}
void build_vpkgformula() { /* internal construction of a vpkg formula */
if (current_vpkgformula == (CUDFVpkgFormula *)NULL) {
current_vpkgformula = new CUDFVpkgFormula;
}
current_vpkgformula->push_back(current_vpkglist);
current_vpkglist = (CUDFVpkgList *)NULL;
}
void build_vpkglist(CUDFVpkg *avpkg) { /* internal construction of a vpkglist */
if (current_vpkglist == (CUDFVpkgList *)NULL) {
current_vpkglist = new CUDFVpkgList;
}
current_vpkglist->push_back(avpkg);
}
// internal construction of a veqpkglist ... only used by provides
void build_veqpkglist(CUDFVpkg *avpkg) {
CUDFVirtualPackage *vpackage = avpkg->virtual_package;
CUDFVersion version = avpkg->version;
if (current_vpkglist == (CUDFVpkgList *)NULL) {
current_vpkglist = new CUDFVpkgList;
}
current_vpkglist->push_back(avpkg);
switch(avpkg->op) {
case op_none:
vpackage->providers.push_back(current_package);
break;
case op_eq:
if ((current_package->installed) && (version > vpackage->highest_installed_provider_version))
vpackage->highest_installed_provider_version = version;
{
CUDFVersionedProviderListIterator ivpkgl = vpackage->versioned_providers.find(version);
if (ivpkgl == vpackage->versioned_providers.end())
vpackage->versioned_providers.insert(CUDFVersionedProviderList::value_type(version, CUDFProviderList(1, current_package)));
else
ivpkgl->second.push_back(current_package);
}
break;
default:
fprintf(stderr, "CUDF error (line %d): veqpkglist is restricted to = operator.\n", cudflineno);
exit(-1);
break;
}
}
// get package version
CUDFVersion getversion(const char *svalue) {
CUDFVersion version = 0;
if (svalue[0] != '-') {
sscanf(svalue, "%llu", &version);
if (version >= 0) return version; // WARNING : should be restricted to > 0
}
fprintf(stderr, "Package version must be a <posint>.\n");
exit(-1);
}
// list of the user required properties
vector<CUDFProperty *> required_properties;
// post process a versioned package declaration
void package_postprocess() {
if (current_package != (CUDFVersionedPackage *)NULL) {
CUDFVirtualPackage *vpackage = current_package->virtual_package;
if (vpackage->all_versions.find(current_package) == vpackage->all_versions.end())
vpackage->all_versions.insert(current_package);
else {
fprintf(stderr, "CUDF error (line %d): (package, version) must be unique (see package %s).\n", package_line, current_package->name);
exit(-1);
}
if (current_package->installed) {
installed_packages.push_back(current_package);
if (vpackage->highest_installed == (CUDFVersionedPackage *)NULL)
vpackage->highest_installed = current_package;
else if (current_package->version > vpackage->highest_installed->version)
vpackage->highest_installed = current_package;
if (current_package->provides != (CUDFVpkgList *)NULL)
for (CUDFVpkgListIterator iop = current_package->provides->begin(); iop != current_package->provides->end(); iop++)
if ((*iop)->op == op_eq) {
if ((*iop)->virtual_package->highest_installed_provider_version < (*iop)->version)
(*iop)->virtual_package->highest_installed_provider_version = (*iop)->version;
}
} else
uninstalled_packages.push_back(current_package);
if (current_package->version > vpackage->highest_version)
vpackage->highest_version = current_package->version;
for (vector<CUDFProperty *>::iterator prop = required_properties.begin(); prop != required_properties.end(); prop++) {
bool hasprop = false;
for (CUDFPropertyValueListIterator pval = current_package->properties.begin(); pval != current_package->properties.end(); pval++)
if ((*pval)->property == *prop) { hasprop = true; break; }
if (! hasprop) {
fprintf(stderr, "CUDF error (line %d): package (%s, %llu) lacks property %s.\n",
package_line, current_package->name, current_package->version, (*prop)->name);
exit(-1);
}
}
}
}
//#define YYMAXDEPTH 800000
//#define YYMAXDEPTH 80
// list of enum under analysis
CUDFEnums *enuml;
// build an enum
void build_enum(char *estr) {
char *the_enum;
if ((the_enum = (char *)malloc(strlen(estr)+1)) == (char *)NULL) {
fprintf(stderr, "CUDF error: can not alloc memory for enum %s.\n", estr);
exit(-1);
}
strcpy(the_enum, estr);
enuml->push_back(the_enum);
}
// get an enum from its name in an enum list
char *get_enum(CUDFEnums *e, char *estr) {
for (CUDFEnumsIterator ei = e->begin(); ei != e->end(); ei++)
if (strcmp((*ei), estr) == 0) return (*ei);
return (char *)NULL;
}
// get a property ident type from a user property name
extern int pidenttype(char *pname);
int pidenttype(char *pname) {
CUDFPropertiesIterator p = properties.find(string(pname));
if (p == properties.end())
return pt_none;
return p->second->type_id;
}
// get a CUDF type from a type name
CUDFPropertyType gettype(char *ident) {
/* enum CUDFPropertyType { pt_bool, pt_int, pt_nat, pt_posint, pt_enum, pt_string, */
int length = strlen(ident);
if (length >= 1)
switch (ident[0]) {
case 'b':
if ((length == 4) && (ident[1] == 'o') && (ident[2] == 'o') && (ident[3] == 'l') && (ident[4] == '\0')) return pt_bool;
case 'e':
if ((length == 4) && (ident[1] == 'n') && (ident[2] == 'u') && (ident[3] == 'm') && (ident[4] == '\0')) return pt_enum;
case 'i':
if ((length == 3) && (ident[1] == 'n') && (ident[2] == 't') && (ident[3] == '\0')) return pt_int;
case 'n':
if ((length == 3) && (ident[1] == 'a') && (ident[2] == 't') && (ident[3] == '\0')) return pt_nat;
case 'p':
if ((length == 6) && (ident[1] == 'o') && (ident[2] == 's') && (ident[3] == 'i') && (ident[4] == 'n') && (ident[5] == 't') && (ident[6] == '\0'))
return pt_posint;
case 's':
if ((length == 6) && (ident[1] == 't') && (ident[2] == 'r') && (ident[3] == 'i') && (ident[4] == 'n') && (ident[5] == 'g') && (ident[6] == '\0'))
return pt_string;
case 'v':
if (length >= 4) {
if (ident[1] == 'p') {
if ((ident[2] == 'k') && (ident[3] == 'g'))
switch (ident[4]) {
case '\0':
return pt_vpkg;
case 'l':
if ((length == 8) && (ident[5] == 'i') && (ident[6] == 's') && (ident[7] == 't') && (ident[8] == '\0')) return pt_vpkglist;
case 'f':
if ((length == 11) && (ident[5] == 'o') && (ident[6] == 'r') && (ident[7] == 'm') && (ident[8] == 'u')
&& (ident[9] == 'l') && (ident[10] == 'a') && (ident[11] == '\0')) return pt_vpkgformula;
}
} else if (ident[1] == 'e') {
if ((ident[2] == 'q') && (ident[3] == 'p') && (length >= 6) && (ident[4] == 'k') && (ident[5] == 'g'))
switch (ident[6]) {
case '\0':
return pt_veqpkg;
case 'l':
if ((length == 10) && (ident[7] == 'i') && (ident[8] == 's') && (ident[9] == 't') && (ident[10] == '\0')) return pt_veqpkglist;
}
}
}
}
fprintf(stderr, "CUDF error (line %d): property type awaited \"%s\" (%d).\n", cudflineno, ident, length);
exit(-1);
}
extern char astring[];
%}
%union {
// CUDFVersion value;
CUDFVpkg *avpkg;
char str[256];
}
%token PREAMBLE PROPERTYDEF
%token PACKAGE VERSION DEPENDS CONFLICTS PROVIDES INSTALLED
%token KEEP KEEPVERSION KEEPPACKAGE KEEPFEATURE KEEPNONE
%token EQ NEQ SUP SUPEQ INF INFEQ
%token TRUE FALSE VTRUE VFALSE
%token PROBLEM INSTALL WASINSTALLED REMOVE UPGRADE
%token <str> PIDENT_BOOL PIDENT_INT PIDENT_NAT PIDENT_POSINT PIDENT_ENUM PIDENT_STRING
%token <str> PIDENT_VPKG PIDENT_VEQPKG PIDENT_VPKGLIST PIDENT_VEQPKGLIST PIDENT_VPKGFORMULA
%token <str> INTEGER IDENT PIDENT
%token STRING
%type <avpkg> vpkg veqpkg
%%
cudf: preambles
| preambles package_declarations
| problem_declaration
| preambles package_declarations problem_declaration
;
preambles: /* empty */
| PREAMBLE property_definitions
property_definitions: typedecls
| PROPERTYDEF typedecls
;
typedecls: typedecl | typedecls ',' typedecl
typedecl: PIDENT IDENT { CUDFProperty *prop = new CUDFProperty($1, gettype($2)); properties[string($1)] = prop; required_properties.push_back(prop); }
typedecl: PIDENT IDENT EQ '[' TRUE ']' { if (gettype($2) == pt_bool)
properties[string($1)] = new CUDFProperty($1, pt_bool, 1);
else {
fprintf(stderr, "CUDF error (line %d): property value requires a boolean typed property (%s).\n", cudflineno, $2);
exit(-1);
}
}
typedecl: PIDENT IDENT EQ '[' FALSE ']' { if (gettype($2) == pt_bool)
properties[string($1)] = new CUDFProperty($1, pt_bool, 0);
else {
fprintf(stderr, "CUDF error (line %d): property value requires a boolean typed property (%s).\n", cudflineno, $2);
exit(-1);
}
}
typedecl: PIDENT IDENT EQ '[' INTEGER ']' { CUDFPropertyType pt = gettype($2);
if (pt == pt_int)
properties[string($1)] = new CUDFProperty($1, pt_int, atoi($5));
else if (pt == pt_posint)
properties[string($1)] = new CUDFProperty($1, pt_posint, atoi($5));
else if (pt == pt_nat)
properties[string($1)] = new CUDFProperty($1, pt_nat, atoi($5));
else {
fprintf(stderr, "CUDF error (line %d): property value requires an integer typed property (%s).\n", cudflineno, $2);
exit(-1);
}
}
typedecl: PIDENT IDENT EQ '[' STRING ']' { if (gettype($2) == pt_string)
properties[string($1)] = new CUDFProperty($1, pt_string, astring);
else {
fprintf(stderr, "CUDF error (line %d): property value requires a string typed property (%s).\n", cudflineno, $2);
exit(-1);
}
}
typedecl: PIDENT IDENT '[' enums ']' {
CUDFProperty *prop = new CUDFProperty($1, pt_enum, enuml);
if (gettype($2) != pt_enum) {
fprintf(stderr, "CUDF error (line %d): this must be an enum type (%s).\n", cudflineno, $2);
exit(-1);
}
properties[string($1)] = prop;
required_properties.push_back(prop);
}
typedecl: PIDENT IDENT '[' enums ']' EQ '[' IDENT ']' {
if (gettype($2) == pt_enum)
properties[string($1)] = new CUDFProperty($1, pt_enum, enuml, $8);
else {
fprintf(stderr, "CUDF error (line %d): property value requires an enum type (%s).\n", cudflineno, $2);
exit(-1);
}
}
/*
typedecl: PIDENT IDENT EQ '[' vpkg ']' {}
typedecl: PIDENT IDENT EQ '[' veqpkg ']' {}
typedecl: PIDENT IDENT EQ '[' vpkglist ']' {}
typedecl: PIDENT IDENT EQ '[' veqpkglist ']' {}
*/
typedecl: PIDENT IDENT EQ '[' ']' { // No type checking is done here ...
switch(gettype($2)) {
case pt_vpkglist:
properties[string($1)] = new CUDFProperty($1, pt_vpkglist, new CUDFVpkgList);
break;
case pt_veqpkglist:
properties[string($1)] = new CUDFProperty($1, pt_veqpkglist, new CUDFVpkgList);
break;
default:
fprintf(stderr, "CUDF error (line %d): property value requires a default value (%s).\n", cudflineno, $2);
exit(-1);
}
}
typedecl: PIDENT IDENT EQ '[' vpkgformula ']' { // No type checking is done here ...
CUDFPropertyType pt = gettype($2);
if (pt == pt_vpkg) {
properties[string($1)] = new CUDFProperty($1, pt_vpkg, current_vpkgformula[0][0]);
} else if (pt == pt_veqpkg)
properties[string($1)] = new CUDFProperty($1, pt_veqpkg, current_vpkgformula[0][0]);
else if (pt == pt_vpkglist)
properties[string($1)] = new CUDFProperty($1, pt_vpkglist, current_vpkgformula->front());
else if (pt == pt_veqpkglist)
properties[string($1)] = new CUDFProperty($1, pt_veqpkglist, current_vpkgformula->front());
else if (pt == pt_vpkgformula)
properties[string($1)] = new CUDFProperty($1, pt_vpkgformula, current_vpkgformula);
else {
fprintf(stderr, "CUDF error (line %d): property value requires a (sub)vpkgformula typed property (%s).\n", cudflineno, $2);
exit(-1);
}
current_vpkgformula = (CUDFVpkgFormula *)NULL;
}
enums: IDENT { enuml = new CUDFEnums; build_enum($1); }
| enums ',' IDENT { build_enum($3); }
/*
package_declarations: package_declaration
;
package_declarations: package_declarations package_declaration
;
*/
package_declarations: package_declaration
| package_declarations package_declaration /* Problem here : pushing this state for ever */
;
package_declaration: package_version package_options
;
package_version: PACKAGE IDENT {
package_postprocess();
package_line = cudflineno;
CUDFVirtualPackage *virtual_package = get_virtual_package($2);
current_package = new CUDFVersionedPackage($2, versioned_package_rank++);
all_packages.push_back(current_package);
current_package->virtual_package = virtual_package;
}
package_options: /* empty */
| package_options package_option
;
package_option: version | depends | conflicts | provides | installed | wasinstalled | keep | property
;
problem_declaration: problem | problem problem_actions
;
problem_actions: problem_action | problem_actions problem_action
;
problem_action: install | remove | upgrade
;
version: VERSION INTEGER { current_package->set_version(getversion($2)); }
depends: DEPENDS | DEPENDS vpkgformula {
if (current_package->depends == (CUDFVpkgFormula *)NULL) {
current_package->depends = current_vpkgformula;
current_vpkgformula = (CUDFVpkgFormula *)NULL;
} else {
fprintf(stderr, "CUDF error (line %d): depends declared twice for package %s.\n", cudflineno, current_package->name);
exit(-1);
}
}
conflicts: CONFLICTS | CONFLICTS vpkglist {
if (current_package->conflicts == (CUDFVpkgList *)NULL) {
current_package->conflicts = current_vpkglist;
current_vpkglist = (CUDFVpkgList *)NULL;
} else {
fprintf(stderr, "CUDF error (line %d): conflicts declared twice for package %s.\n", cudflineno, current_package->name);
exit(-1);
}
}
provides: PROVIDES | PROVIDES veqpkglist {
if (current_package->provides == (CUDFVpkgList *)NULL) {
current_package->provides = current_vpkglist;
current_vpkglist = (CUDFVpkgList *)NULL;
} else {
fprintf(stderr, "CUDF error (line %d): provides declared twice for package %s.\n", cudflineno, current_package->name);
exit(-1);
}
}
installed: INSTALLED TRUE { current_package->installed = true; }
installed: INSTALLED FALSE { current_package->installed = false; }
wasinstalled: WASINSTALLED TRUE { current_package->wasinstalled = true; }
wasinstalled: WASINSTALLED FALSE { current_package->wasinstalled = false; }
keep: KEEP keepvalue
;
/* properties: property | properties property ; */
property: PIDENT_BOOL TRUE {
CUDFPropertiesIterator p = properties.find(string($1));
if (p == properties.end()) {
fprintf(stderr, "CUDF error (line %d): property %s is not defined.\n", cudflineno, $1);
exit(-1);
}
switch (p->second->type_id) {
case pt_bool:
current_package->properties.push_back(new CUDFPropertyValue(p->second, 1));
break;
default:
fprintf(stderr, "CUDF error (line %d): bad value (true) for property %s.\n", cudflineno, $1);
exit(-1);
}
}
property: PIDENT_BOOL FALSE {
CUDFPropertiesIterator p = properties.find(string($1));
if (p == properties.end()) {
fprintf(stderr, "CUDF error (line %d): property %s is not defined.\n", cudflineno, $1);
exit(-1);
}
switch (p->second->type_id) {
case pt_bool:
current_package->properties.push_back(new CUDFPropertyValue(p->second, 0));
break;
default:
fprintf(stderr, "CUDF error (line %d): bad value (false) for property %s.\n", cudflineno, $1);
exit(-1);
}
}
property: PIDENT_INT INTEGER {
CUDFPropertiesIterator p = properties.find(string($1));
if (p == properties.end()) {
fprintf(stderr, "CUDF error (line %d): property %s is not defined.\n", cudflineno, $1);
print_properties(stdout, &properties);
exit(-1);
}
int value = atoi($2);
switch (p->second->type_id) {
case pt_int:
current_package->properties.push_back(new CUDFPropertyValue(p->second, value));
break;
default:
fprintf(stderr, "CUDF error (line %d): bad value (%d) for property %s.\n", cudflineno, value, $1);
exit(-1);
}
}
property: PIDENT_NAT INTEGER {
CUDFPropertiesIterator p = properties.find(string($1));
if (p == properties.end()) {
fprintf(stderr, "CUDF error (line %d): property %s is not defined.\n", cudflineno, $1);
print_properties(stdout, &properties);
exit(-1);
}
int value = atoi($2);
switch (p->second->type_id) {
case pt_nat:
if (value < 0) {
fprintf(stderr, "CUDF error (line %d): property %s (nat) requires values >= 0: %d.\n", cudflineno, $1, value);
exit(-1);
}
current_package->properties.push_back(new CUDFPropertyValue(p->second, value));
break;
default:
fprintf(stderr, "CUDF error (line %d): bad value (%d) for property %s.\n", cudflineno, value, $1);
exit(-1);
}
}
property: PIDENT_POSINT INTEGER {
CUDFPropertiesIterator p = properties.find(string($1));
if (p == properties.end()) {
fprintf(stderr, "CUDF error (line %d): property %s is not defined.\n", cudflineno, $1);
print_properties(stdout, &properties);
exit(-1);
}
int value = atoi($2);
switch (p->second->type_id) {
case pt_posint:
if (value <= 0) {
fprintf(stderr, "CUDF error (line %d): property %s (posint) requires values > 0: %d.\n", cudflineno, $1, value);
exit(-1);
}
current_package->properties.push_back(new CUDFPropertyValue(p->second, value));
break;
default:
fprintf(stderr, "CUDF error (line %d): bad value (%d) for property %s.\n", cudflineno, value, $1);
exit(-1);
}
}
property: PIDENT_ENUM IDENT {
CUDFPropertiesIterator p = properties.find(string($1));
if (p == properties.end()) {
fprintf(stderr, "CUDF error (line %d): property %s is not defined.\n", cudflineno, $1);
exit(-1);
}
char *value;
switch (p->second->type_id) {
case pt_enum:
value = get_enum(p->second->enuml, $2);
if (value == (char *)NULL) {
fprintf(stderr, "CUDF error (line %d): property %s (enum) can not take value %s.\n", cudflineno, $1, $2);
exit(-1);
}
current_package->properties.push_back(new CUDFPropertyValue(p->second, value));
break;
default:
fprintf(stderr, "CUDF error (line %d): bad value (%s) for property %s.\n", cudflineno, $2, $1);
exit(-1);
}
}
property: PIDENT_STRING STRING {
CUDFPropertiesIterator p = properties.find(string($1));
if (p == properties.end()) {
fprintf(stderr, "CUDF error (line %d): property %s is not defined.\n", cudflineno, $1);
exit(-1);
}
switch (p->second->type_id) {
case pt_string:
current_package->properties.push_back(new CUDFPropertyValue(p->second, astring));
break;
default:
fprintf(stderr, "CUDF error (line %d): bad value (%s) for property %s.\n", cudflineno, astring, $1);
exit(-1);
}
}
property: PIDENT_VPKG vpkg {
CUDFPropertiesIterator p = properties.find(string($1));
if (p == properties.end()) {
fprintf(stderr, "CUDF error (line %d): property %s is not defined.\n", cudflineno, $1);
exit(-1);
}
switch (p->second->type_id) {
case pt_vpkg:
current_package->properties.push_back(new CUDFPropertyValue(p->second, $1));
break;
default:
fprintf(stderr, "CUDF error (line %d): bad value for property %s.\n", cudflineno, $1);
exit(-1);
}
}
property: PIDENT_VEQPKG veqpkg {
CUDFPropertiesIterator p = properties.find(string($1));
if (p == properties.end()) {
fprintf(stderr, "CUDF error (line %d): property %s is not defined.\n", cudflineno, $1);
exit(-1);
}
switch (p->second->type_id) {
case pt_veqpkg:
current_package->properties.push_back(new CUDFPropertyValue(p->second, $1));
break;
default:
fprintf(stderr, "CUDF error (line %d): bad value for property %s.\n", cudflineno, $1);
exit(-1);
}
}
property: PIDENT_VPKGLIST | PIDENT_VPKGLIST vpkglist {
CUDFPropertiesIterator p = properties.find(string($1));
if (p == properties.end()) {
fprintf(stderr, "CUDF error (line %d): property %s is not defined.\n", cudflineno, $1);
exit(-1);
}
switch (p->second->type_id) {
case pt_vpkglist:
current_package->properties.push_back(new CUDFPropertyValue(p->second, current_vpkglist));
current_vpkglist = (CUDFVpkgList *)NULL;
break;
default:
fprintf(stderr, "CUDF error (line %d): bad value for property %s.\n", cudflineno, $1);
exit(-1);
}
}
property: PIDENT_VEQPKGLIST | PIDENT_VEQPKGLIST veqpkglist {
CUDFPropertiesIterator p = properties.find(string($1));
if (p == properties.end()) {
fprintf(stderr, "CUDF error (line %d): property %s is not defined.\n", cudflineno, $1);
exit(-1);
}
switch (p->second->type_id) {
case pt_veqpkglist:
current_package->properties.push_back(new CUDFPropertyValue(p->second, current_vpkglist));
current_vpkglist = (CUDFVpkgList *)NULL;
break;
default:
fprintf(stderr, "CUDF error (line %d): bad value for property %s.\n", cudflineno, $1);
exit(-1);
}
}
property: PIDENT_VPKGFORMULA vpkgformula {
CUDFPropertiesIterator p = properties.find(string($1));
if (p == properties.end()) {
fprintf(stderr, "CUDF error (line %d): property %s is not defined.\n", cudflineno, $1);
exit(-1);
}
switch (p->second->type_id) {
case pt_vpkgformula:
current_package->properties.push_back(new CUDFPropertyValue(p->second, current_vpkgformula));
current_vpkgformula = (CUDFVpkgFormula *)NULL;
break;
default:
fprintf(stderr, "CUDF error (line %d): bad value for property %s.\n", cudflineno, $1);
exit(-1);
}
}
problem: PROBLEM {
package_postprocess();
if (the_problem == (CUDFproblem *)NULL)
the_problem = current_problem = new CUDFproblem();
}
install: INSTALL | INSTALL vpkglist {
if (current_problem->install == (CUDFVpkgList *)NULL) {
current_problem->install = current_vpkglist;
current_vpkglist = (CUDFVpkgList *)NULL;
} else {
fprintf(stderr, "CUDF error (line %d): install declared twice.\n", cudflineno);
exit(-1);
}
}
remove: REMOVE | REMOVE vpkglist {
if (current_problem->remove == (CUDFVpkgList *)NULL) {
current_problem->remove = current_vpkglist;
current_vpkglist = (CUDFVpkgList *)NULL;
} else {
fprintf(stderr, "CUDF error (line %d): remove declared twice.\n", cudflineno);
exit(-1);
}
}
upgrade: UPGRADE | UPGRADE vpkglist {
if (current_problem->upgrade == (CUDFVpkgList *)NULL) {
current_problem->upgrade = current_vpkglist;
current_vpkglist = (CUDFVpkgList *)NULL;
} else {
fprintf(stderr, "CUDF error (line %d): upgrade declared twice.\n", cudflineno);
exit(-1);
}
}
keepvalue: KEEPVERSION {
if (current_package->keep == keep_none) {
current_package->keep = keep_version;
} else {
fprintf(stderr, "CUDF error (line %d): keep declared twice for package %s.\n", cudflineno, current_package->name);
exit(-1);
}
}
keepvalue: KEEPPACKAGE {
if (current_package->keep == keep_none) {
current_package->keep = keep_package;
} else {
fprintf(stderr, "CUDF error (line %d): keep declared twice for package %s.\n", cudflineno, current_package->name);
exit(-1);
}
}
keepvalue: KEEPFEATURE {
if (current_package->keep == keep_none) {
current_package->keep = keep_version;
} else {
fprintf(stderr, "CUDF error (line %d): keep declared twice for package %s.\n", cudflineno, current_package->name);
exit(-1);
}
}
keepvalue: KEEPNONE {
current_package->keep = keep_none;
}
vpkgformula: VTRUE { build_vpkglist(vpkg_true); build_vpkgformula(); }
vpkgformula: VFALSE { build_vpkglist(vpkg_false); build_vpkgformula(); }
vpkgformula: avpkgformula
avpkgformula: vpkgor { build_vpkgformula(); }
avpkgformula: avpkgformula ',' vpkgor { build_vpkgformula(); }
vpkgor: vpkg { build_vpkglist($1); }
vpkgor: vpkgor '|' vpkg { build_vpkglist($3); }
veqpkg: IDENT { current_vpkg = $$ = build_vpkg($1, op_none, 0); }
veqpkg: IDENT EQ INTEGER { current_vpkg = $$ = build_vpkg($1, op_eq, getversion($3)); }
vpkg: veqpkg { $$ = $1; }
vpkg: IDENT NEQ INTEGER { current_vpkg = $$ = build_vpkg($1, op_neq, getversion($3)); }
vpkg: IDENT SUP INTEGER { current_vpkg = $$ = build_vpkg($1, op_sup, getversion($3)); }
vpkg: IDENT SUPEQ INTEGER { current_vpkg = $$ = build_vpkg($1, op_supeq, getversion($3)); }
vpkg: IDENT INF INTEGER { current_vpkg = $$ = build_vpkg($1, op_inf, getversion($3)); }
vpkg: IDENT INFEQ INTEGER { current_vpkg = $$ = build_vpkg($1, op_infeq, getversion($3));}
vpkglist: vpkg { build_vpkglist($1); }
vpkglist: vpkglist ',' vpkg { build_vpkglist($3); }
veqpkglist: veqpkg { build_veqpkglist($1); }
veqpkglist: veqpkglist ',' veqpkg { build_veqpkglist($3); }
%%
extern FILE *cudfin;
// main parser function
int parse_cudf(FILE *input_file) {
int retval;
// cudfdebug = 1;
cudfin = input_file;
retval = cudfparse();
if (the_problem == (CUDFproblem *)NULL)
the_problem = current_problem = new CUDFproblem();
the_problem->properties = &properties;
the_problem->all_packages = &all_packages;
the_problem->installed_packages = &installed_packages;
the_problem->uninstalled_packages = &uninstalled_packages;
the_problem->all_virtual_packages = &all_virtual_packages;
return retval;
}
|