packup-0.6/0000755000175000010010000000000011573000741011745 5ustar mikolasNonepackup-0.6/basic_clause.hh0000644000175000010010000001463411573000740014712 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ //jpms:bc /*----------------------------------------------------------------------------*\ * File: basic_clause.hh * * Description: A basic clause is a vector of literals. * * Author: jpms * * Revision: $Id$. * * Copyright (c) 2009, Joao Marques-Silva \*----------------------------------------------------------------------------*/ //jpms:ec #ifndef _BASIC_CLAUSE_H #define _BASIC_CLAUSE_H 1 #include "globals.hh" //jpms:bc /*----------------------------------------------------------------------------*\ * Basic types for class BasicClause. \*----------------------------------------------------------------------------*/ //jpms:ec typedef vector LitVector; typedef vector::iterator Literator; typedef vector::reverse_iterator RLiterator; //jpms:bc /*----------------------------------------------------------------------------*\ * Class: BasicClause * * Purpose: New organization of clauses, to be used in future tools \*----------------------------------------------------------------------------*/ //jpms:ec class BasicClause { friend class ClauseRegistry; friend class BasicClauseSet; protected: BasicClause(vector& lits) : clits(lits), weight(0), id(0), grp_id(0) { assert(adjacent_find(lits.begin(),lits.end(),AbsLitGreater())==lits.end()); //sort_lits(); //N DBG(cout << "Creating clause: [" << *this << "]" << endl;); } //BasicClause(int nlits, const long int lits[]) : //clits(lits, lits+nlits), weight(0) { //sort_lits(); ////N //DBG(cout << "Creating clause: " << *this << endl;); //} virtual ~BasicClause() { clits.clear(); } public: ULINT size() { return clits.size(); } Literator begin() { return clits.begin(); } Literator end() { return clits.end(); } protected: void add_lit(LINT lit) { clits.push_back(lit); // Currently sorts; it is simpler to insert & shift assert(clits.size() > 0); if (abs(lit) < abs(clits[clits.size()-1])) { sort_lits(); // alternatively: /* => Seems to be less efficient Literator pos2 = clits.end(); Literator pos1 = clits.end(); --pos1; for (--pos1; abs(*pos1) > abs(lit); --pos1, --pos2) { *pos2 = *pos1; if (pos1 == clits.begin()) { break; } } *pos1 = lit; */ //update_internal_data((unsigned)lit); } } void del_lit(LINT lit) { for (Literator pos = clits.begin(); pos != clits.end(); ++pos) { if (*pos == lit) { *pos = clits.back(); break; } } clits.pop_back(); // Currently sorts; it is simpler to insert & shift //sort_lits(); // alternatively: //update_internal_data((unsigned)lit); // hash XOR removes bits due to lit } vector& cl_lits() { return clits; } //ULINT clhash() { return hashval; } ULINT get_min_lit() { ULINT minid=abs(clits[0]); return minid; } ULINT get_max_lit() { ULINT maxid=abs(clits[clits.size()-1]); return maxid; } public: // Weight/group/id functions void set_weight(XLINT nweight) { weight = nweight; } XLINT get_weight() { return weight; } void set_grp_id(ULINT grp) { grp_id = grp; } // ANTON: store it properly ULINT get_grp_id() { return grp_id; } // ANTON: store it properly void set_id(ULINT nid) { id = nid; } ULINT get_id() { return id; } public: // Comparison functions friend bool operator > (BasicClause& ptr1, BasicClause& ptr2) { return (ptr1.size() > ptr2.size()) || (ptr1.size() == ptr2.size() && ptr1.get_id() > ptr2.get_id()); } friend bool operator < (BasicClause& ptr1, BasicClause& ptr2) { return (ptr1.size() < ptr2.size()) || (ptr1.size() == ptr2.size() && ptr1.get_id() < ptr2.get_id()); } public: // Output functions void dump(ostream& outs=cout) { // +ANTON added group ID // outs << "[" << get_grp_id() << "] "; // -ANTON Literator lpos = clits.begin(); Literator lend = clits.end(); for (; lpos != lend; ++lpos) { outs << *lpos << " "; } outs << "0"; //outs << endl; } friend ostream & operator << (ostream& outs, BasicClause& cl) { cl.dump(outs); return outs; } protected: void sort_lits() { //cout << "Lits A: "; //copy(clits.begin(), clits.end(), ostream_iterator(cout, " ")); //cout << endl; //if (!is_sorted(clits.begin(), clits.end(), AbsLitLess())) { } sort(clits.begin(), clits.end(), AbsLitLess()); //cout << "Lits B: "; //copy(clits.begin(), clits.end(), ostream_iterator(cout, " ")); //cout << endl; } ULINT compute_hash() { // Not being used: see below new hash functions exit(0); register ULINT hashv = 0; for(vector::iterator pos = clits.begin(); pos != clits.end(); ++pos) { hashv ^= (*pos>0) ? *pos : -*pos; } cout << "Hash value: " << hashv << endl; cout.flush(); return hashv; } //void update_internal_data(ULINT uval) { sort_lits(); hashval ^= uval; } protected: vector clits; //ULINT hashval; XLINT weight; ULINT id; ULINT grp_id; // ANTON: the actual group ID, rather than using id }; #endif /* _BASIC_CLAUSE_H */ /*----------------------------------------------------------------------------*/ packup-0.6/basic_clset.hh0000644000175000010010000003107011573000741014542 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ //jpms:bc /*----------------------------------------------------------------------------*\ * File: basic_clset.hh * * Description: * * Author: jpms * * Revision: $Id$. * * Copyright (c) 2009, Joao Marques-Silva \*----------------------------------------------------------------------------*/ //jpms:ec #ifndef _BASIC_CLSET_H #define _BASIC_CLSET_H 1 #include #include #include // Location of STL hash extensions #include // Location of STL hash extensions using namespace std; using namespace __gnu_cxx; // Required for STL hash extensions #include "globals.hh" #include "basic_clause.hh" #include "cl_functors.hh" #include "cl_types.hh" #include "cl_registry.hh" #define SM_CL_SZ 3 //jpms:bc /*----------------------------------------------------------------------------*\ * Class: BasicClauseSet * * Purpose: Container for set of clauses. \*----------------------------------------------------------------------------*/ //jpms:ec class BasicClauseSet { public: BasicClauseSet() : clreg(ClauseRegistry::instance()), clauses(), g2cv_map(), clvect() { top_weight = LONG_MAX; def_clw = top_weight; def_cltype = CL_HARD; num_hard_cls = num_soft_cls = num_other_cls = num_weighted_cls = 0; soft_units = false; } virtual ~BasicClauseSet() { /* Clear actual clauses ... */ clauses.clear(); g2cv_map.clear(); clvect.clear(); } BasicClause* create_clause(LINT nlits, const LINT lits[]) { BasicClause* ncl = clreg.create_clause(nlits, lits); return insert_clause(ncl); } BasicClause* create_clause(vector& clits) { BasicClause* ncl = clreg.create_clause(clits); return insert_clause(ncl); } BasicClause* create_clause(vector& clits, LINT clid) { BasicClause* ncl = clreg.create_clause(clits); set_cl_id(ncl, clid); return insert_clause(ncl); } BasicClause* create_unit_clause(LINT lit) { assert(lit != 0); LINT lits[] = { lit }; return create_clause(1, lits); } BasicClause* create_binary_clause(LINT lit1, LINT lit2) { assert(lit1 != 0 && lit2 != 0); LINT lits[] = { lit1, lit2 }; return create_clause(2, lits); } BasicClause* create_ternary_clause(LINT lit1, LINT lit2, LINT lit3) { assert(lit1 != 0 && lit2 != 0 && lit3 != 0); LINT lits[] = { lit1, lit2, lit3 }; return create_clause(3, lits); } BasicClause* insert_clause(BasicClause* ncl) { // Clause is assumed to already exist; no need to set its type HashedClauseSet::iterator cpos = clauses.find(ncl); if (cpos == clauses.end()) { clauses.insert(ncl); clreg.incr_cl_refs(ncl); set_def_cltype(ncl); // Clause is new; set type as default type } DBG(else { cout << "Clause already exists: "<<*ncl<& clits) { return clreg.lookup_vect(clits); } BasicClause* lookup(LINT num, const LINT ivect[]) { return clreg.lookup_vect(num, ivect); } ULINT get_cl_min_lit(BasicClause* cl) { return cl->get_min_lit(); } ULINT get_cl_max_lit(BasicClause* cl) { return cl->get_max_lit(); } void set_num_vars(ULINT nvars) { } ULINT get_num_vars() { return -1; } void set_num_cls(ULINT ncls) { } ULINT get_num_cls() { return size(); } void set_top(XLINT topv) { assert(clauses.size() == 0); top_weight = topv; } XLINT get_top() { return top_weight; } void set_num_grp(XLINT ngrp) { top_weight = ngrp; } XLINT get_num_grp() { return top_weight; } vector& get_cl_lits(BasicClause* cl) { return cl->cl_lits(); } void cl_lits(BasicClause* cl, IntVector lvect) { Literator lpos = cl->begin(); Literator lend = cl->end(); for(; lpos != lend; ++lpos) { lvect.push_back(*lpos); } } // Preferably use incr_cl_weight void set_cl_weight(BasicClause* cl, XLINT clweight = 1) { // For repeated clauses, need to update existing weight cl->set_weight((clweight >= top_weight) ? top_weight : clweight); // Stats if (clweight == top_weight) { ++num_hard_cls; } else if (clweight == 1) { ++num_soft_cls; } else { ++num_other_cls; } ++num_weighted_cls; } XLINT get_cl_weight(BasicClause* cl) { return cl->get_weight(); } XLINT incr_cl_weight(BasicClause* cl, XLINT incr) { // For repeated clauses, need to update existing weight if (!is_cl_hard(cl)) { XLINT nw = (cl->get_weight() + incr < top_weight) ? (cl->get_weight() + incr) : top_weight; cl->set_weight(nw); } //else { assert(0); } return cl->get_weight(); } XLINT decr_cl_weight(BasicClause* cl, XLINT decr) { // For repeated clauses, need to update existing weight if (!is_cl_hard(cl)) { cl->set_weight(cl->get_weight() - decr); } else { assert(0); } return cl->get_weight(); } void set_cl_id(BasicClause* cl, ULINT clid) { cl->set_id(clid); } ULINT get_cl_id(BasicClause* cl) { return cl->get_id(); } void set_cl_grp_id(BasicClause* cl, ULINT gid) { cl->set_grp_id(gid); } ULINT get_cl__grp_id(BasicClause* cl) { return cl->get_grp_id(); } void set_cl_group(BasicClause* cl, XLINT clgrp) { cl->set_weight(clgrp); vector* bcvect = NULL; XLInt2ClVMap::iterator ipos = g2cv_map.find(clgrp); if (ipos == g2cv_map.end()) { bcvect = new vector(); g2cv_map.insert(make_pair(clgrp, bcvect)); } else { bcvect = ipos->second; bcvect->push_back(cl); } } XLINT get_cl_group(BasicClause* cl) { return cl->get_weight(); } void set_cl_hard(BasicClause* cl) { set_cl_weight(cl, top_weight); } void set_cl_soft(BasicClause* cl) { set_cl_weight(cl, 1); } bool is_cl_hard(BasicClause* cl) { XLINT clw = get_cl_weight(cl); return clw >= top_weight; } bool is_cl_soft(BasicClause* cl) { XLINT clw = get_cl_weight(cl); return clw < top_weight; } bool is_cl_unit(BasicClause* cl) { return cl->size() == 1; } void set_def_cl_hard() { def_cltype = CL_HARD; } void set_def_cl_soft() { def_cltype = CL_SOFT; } void set_def_cl_weight(XLINT nclw) { def_cltype = CL_WEIGHTED; def_clw = nclw; } public: // Properties of clause set: hard & soft clauses bool all_soft_unit() { return soft_units; } void compute_properties() { compute_hard_cl_properties(); compute_soft_cl_properties(); } void compute_hard_cl_properties() { } void compute_soft_cl_properties() { DBG(LINT clcnt = size(); LINT scnt = 0;); cset_iterator cpos = begin(); cset_iterator cend = end(); soft_units = true; for(; cpos!=cend; ++cpos) { BasicClause* cl = *cpos; if (is_cl_soft(cl)) { if (cl->size() != 1) { soft_units = false; break; } DBG(scnt++; if (cl->size() != 1) { soft_units = false; }); } } DBG(cout << "Number of clauses: " << clcnt << endl; cout << " Soft clauses: " << scnt << endl; cout << "All soft clauses are unit.\n";); } public: // Access to clauses cset_iterator begin() { return clauses.begin(); } cset_iterator end() { return clauses.end(); } cset_iterator find(BasicClause* cl) { return clauses.find(cl); } ULINT size() { return clauses.size(); } ClVectIterator svect_begin() { // Resize vector of cl pointers if (clvect.size() < clauses.size()) { clvect.resize(clauses.size()); } // Fill in vector of cl pointers ClSetIterator cpos = clauses.begin(); ClSetIterator cend = clauses.end(); ClVectIterator vpos = clvect.begin(); for (; cpos != cend; ++cpos, ++vpos) { *vpos = *cpos; } // Sort cl pointers sort(clvect.begin(), clvect.end(), PtrLess()); // Return iterator for sorted vector of cl pointers return clvect.begin(); } ClVectIterator svect_end() { return clvect.end(); } public: // Clean up inline void clear() { clear_direct(); //clear_indirect(); } // Simple clear, with a single pass, currently being tested (jpms@20100415) inline void clear_direct() { cset_iterator cpos = begin(); cset_iterator cend = end(); for(LINT i=0; cpos != cend; ++cpos, ++i) { BasicClause* cl = *cpos; if (clreg.decr_cl_refs(cl) == 0) { clreg.erase_clause(cl); } } clauses.clear(); } // Safe version of clear, using vector inline void clear_indirect() { BasicClauseVector clvect; clvect.resize(size(), NULL); cset_iterator cpos = begin(); cset_iterator cend = end(); for(LINT i=0; cpos != cend; ++cpos, ++i) { clvect[i] = *cpos; } clauses.clear(); BasicClauseVector::iterator dpos = clvect.begin(); BasicClauseVector::iterator dend = clvect.end(); for(; dpos != dend; ++dpos) { BasicClause* cl = *dpos; if (clreg.decr_cl_refs(cl) == 0) { clreg.erase_clause(cl); } } clvect.clear(); } public: // Stats ULINT get_num_hard_cls() { return num_hard_cls; } ULINT get_num_soft_cls() { return num_soft_cls; } ULINT get_num_nonsofthard_cls() { return num_other_cls; } ULINT get_num_weighted_cls() { return num_weighted_cls; } public: // Output functions void dump(ostream& outs=cout) { DBG(LINT clcnt = 0); cset_iterator cpos = clauses.begin(); cset_iterator cend = clauses.end(); for (; cpos != cend; ++cpos) { outs << **cpos << " "; outs << endl; DBG(clcnt++;) } DBG(outs<<"Done... CLSET Size: "<. * \******************************************************************************/ //jpms:bc /*----------------------------------------------------------------------------*\ * File: basic_types.h * * Description: Basic types used by BOLT. * * Author: jpms * * Revision: $Id$. * * Copyright (c) 2009, Joao Marques-Silva \*----------------------------------------------------------------------------*/ //jpms:ec #ifndef _BASIC_TYPES_H #define _BASIC_TYPES_H 1 /*----------------------------------------------------------------------------*\ * Values besides 0 and 1 \*----------------------------------------------------------------------------*/ #ifdef __LP64__ typedef unsigned long long int ULINT; typedef long long int LINT; #define MAXLINT LLONG_MAX; #define MINLINT LLONG_MIN; #define MAXULINT ULLONG_MAX; #else typedef unsigned long int ULINT; typedef long int LINT; #define MAXLINT LONG_MAX; #define MINLINT LONG_MIN; #define MAXULINT ULONG_MAX; #endif #ifdef GMPDEF #include typedef mpz_class XLINT; #define ToLint(x) x.get_si() #else typedef LINT XLINT; #define ToLint(x) (LINT)x #endif #endif /* _BASIC_TYPES_H */ /*----------------------------------------------------------------------------*/ packup-0.6/clause_utils.hh0000644000175000010010000000407311573000741014766 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ //jpms:bc /*----------------------------------------------------------------------------*\ * File: clause_utils.hh * * Description: Utilities for the * * Author: jpms * * Revision: $Id$. * * Copyright (c) 2009, Joao Marques-Silva \*----------------------------------------------------------------------------*/ //jpms:ec #ifndef _CLAUSE_UTILS_H #define _CLAUSE_UTILS_H 1 #include "basic_clause.hh" /*----------------------------------------------------------------------------*\ * Classes to be used in the definition of hash sets and maps \*----------------------------------------------------------------------------*/ #endif /* _CLAUSE_UTILS_H */ /*----------------------------------------------------------------------------*/ packup-0.6/cl_functors.hh0000644000175000010010000001247211573000741014615 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ //jpms:bc /*----------------------------------------------------------------------------*\ * File: cl_functors.hh * * Description: Functors based on clauses. * * Author: jpms * * Revision: $Id$. * * Copyright (c) 2009, Joao Marques-Silva \*----------------------------------------------------------------------------*/ //jpms:ec #ifndef _CL_FUNCTORS_H #define _CL_FUNCTORS_H 1 #include "basic_clause.hh" //jpms:bc /*----------------------------------------------------------------------------*\ * Functors based on class BasicClause \*----------------------------------------------------------------------------*/ //jpms:ec class ClauseHash { public: ULINT operator()(BasicClause* clref) const { // see below new hash functions //return clref->clhash(); // -> Very slow; unable to undertand why register ULINT hashv = 0; for(Literator pos = clref->begin(); pos != clref->end(); ++pos) { hashv ^= (*pos>0) ? *pos : -*pos; } cout << "Hash value: " << hashv << endl; cout.flush(); return hashv; } }; class ClauseEqual { public: bool operator()(BasicClause* cl1, BasicClause* cl2) const { if (cl1->size() != cl2->size()) { return false; } Literator pos1 = cl1->begin(); // Vectors assumed to be sorted Literator pos2 = cl2->begin(); for(; pos1 != cl1->end(); ++pos1, ++pos2) { if (*pos1 != *pos2) { return false; } } return true; } }; class ClPtrHash { public: ULINT operator()(const BasicClause* ptr) const { return (ULINT)ptr; } }; class ClPtrEqual { public: bool operator()(const BasicClause* ptr1, const BasicClause* ptr2) const { return ptr1 == ptr2; } }; class ClSizeIDLess { public: bool operator()(BasicClause* ptr1, BasicClause* ptr2) const { return ptr1->size() < ptr2->size() || ptr1->size() == ptr2->size() && ptr1->get_id() < ptr2->get_id(); } }; class ClSizeIDGreater { public: bool operator()(BasicClause* ptr1, BasicClause* ptr2) const { return ptr1->size() > ptr2->size() || ptr1->size() == ptr2->size() && ptr1->get_id() > ptr2->get_id(); } }; class ClIDLess { public: bool operator()(BasicClause* ptr1, BasicClause* ptr2) const { return ptr1->get_id() < ptr2->get_id(); } }; class ClIDGreater { public: bool operator()(BasicClause* ptr1, BasicClause* ptr2) const { return ptr1->get_id() > ptr2->get_id(); } }; #define HPSHIFT 3 #define HNSHIFT 2 class LitVectHash { public: ULINT operator()(vector* lvect) const { //cout << "VECT SIZE:" << lvect->size() <::iterator pos=lvect->begin(); pos!=lvect->end(); ++pos) { // v3: hashv = (hashv << HPSHIFT) ^ ((*pos>0) ? *pos : -*pos); /* // v5: hashv = (hashv << HPSHIFT) ^ (*pos); // v4: hashv = (*pos>0) ? ((hashv << HPSHIFT) ^ *pos) : ((hashv >> HNSHIFT) ^ -*pos); // v3: hashv = (hashv << HPSHIFT) ^ ((*pos>0) ? *pos : -*pos); // v2: hashv ^= ((*pos>0) ? *pos : -*pos); // v1: hashv *= fabs(*pos); */ } //cout << "Hash value: " << hashv << endl; cout.flush(); return hashv; } }; class LitVectEqual { public: bool operator()(vector* lv1, vector* lv2) const { if (lv1->size() != lv2->size()) { return false; } Literator pos1 = lv1->begin(); // Vectors assumed to be sorted Literator pos2 = lv2->begin(); for(; pos1 != lv1->end(); ++pos1, ++pos2) { // vectors w/ the same size if (*pos1 != *pos2) { return false; } } /* Not as efficient... for(register int k=0; ksize(); ++k) { // vectors w/ the same size if ((*lv1)[k] != (*lv2)[k]) { return false; } } //cout<<((pos1==lv1->end()&&pos2==lv2->end())?"TRUE":"FALSE B")<. * \******************************************************************************/ //jpms:bc /*----------------------------------------------------------------------------*\ * File: cl_globals.hh * * Description: Complete definitions for clauses and clause sets. * * Author: jpms * * Revision: $Id$. * * Copyright (c) 2009, Joao Marques-Silva \*----------------------------------------------------------------------------*/ //jpms:ec #ifndef _CL_GLOBALS_H #define _CL_GLOBALS_H 1 #include #include #include // Location of STL hash extensions #include // Location of STL hash extensions using namespace std; using namespace __gnu_cxx; // Required for STL hash extensions #include "globals.hh" #include "basic_clause.hh" #include "cl_functors.hh" #include "cl_types.hh" #include "cl_registry.hh" #endif /* _CL_GLOBALS_H */ /*----------------------------------------------------------------------------*/ packup-0.6/cl_registry.cc0000644000175000010010000000353011573000742014604 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ //jpms:bc /*----------------------------------------------------------------------------*\ * File: cl_registry.cc * * Description: Definition of static variables for the ClauseRegistry. * * Author: jpms * * Revision: $Id$. * * Copyright (c) 2009, Joao Marques-Silva \*----------------------------------------------------------------------------*/ //jpms:ec #include "cl_registry.hh" ClauseRegistry ClauseRegistry::clreg_instance; /*----------------------------------------------------------------------------*/ packup-0.6/cl_registry.hh0000644000175000010010000001366011573000742014623 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ //jpms:bc /*----------------------------------------------------------------------------*\ * File: cl_registry.hh * * Description: * * Author: jpms * * Revision: $Id$. * * Copyright (c) 2009, Joao Marques-Silva \*----------------------------------------------------------------------------*/ //jpms:ec #ifndef _CL_REGISTRY_H #define _CL_REGISTRY_H 1 #include #include #include // Location of STL hash extensions #include // Location of STL hash extensions #include // Location of STL hash extensions using namespace std; using namespace __gnu_cxx; // Required for STL hash extensions #include "globals.hh" #include "basic_clause.hh" #include "cl_functors.hh" #include "cl_types.hh" //jpms:bc /*----------------------------------------------------------------------------*\ * Class: ClauseRegistry * * Purpose: Unique registry for created clauses. \*----------------------------------------------------------------------------*/ //jpms:ec class ClauseRegistry { friend class BasicClauseSet; public: static ClauseRegistry& instance() { return clreg_instance; } protected: ClauseRegistry() : v2p_map(), c2n_map() { } virtual ~ClauseRegistry() { /* Clear actual clauses ... */ v2p_map.clear(); c2n_map.clear(); } BasicClause* create_clause(LINT nlits, const LINT lits[]) { vector clits(lits, lits+nlits); sort(clits.begin(), clits.end(), AbsLitLess()); remove_duplicates(clits); BasicClause* ncl = lookup_vect(clits); if (ncl != NULL) { return ncl; } ncl = new BasicClause(clits); register_clause(ncl); return ncl; } BasicClause* create_clause(vector& clits) { sort(clits.begin(), clits.end(), AbsLitLess()); remove_duplicates(clits); BasicClause* ncl = lookup_vect(clits); if (ncl != NULL) { DBG(cout << "Clause exists: " << *ncl << endl;); return ncl; } ncl = new BasicClause(clits); register_clause(ncl); return ncl; } LINT num_cl_refs(BasicClause* cl) { c2n_iterator cpos = c2n_map.find(cl); assert(cpos != c2n_map.end()); return cpos->second; } LINT incr_cl_refs(BasicClause* cl) { c2n_iterator cpos = c2n_map.find(cl); assert(cpos != c2n_map.end()); return ++cpos->second; } LINT decr_cl_refs(BasicClause* cl) { c2n_iterator cpos = c2n_map.find(cl); assert(cpos != c2n_map.end()); return --cpos->second; } void register_clause(BasicClause* ncl) { // Map from lit vect to cl vector& lits = ncl->cl_lits(); assert(v2p_map.find(&lits) == v2p_map.end()); v2p_map.insert(make_pair(&lits, ncl)); // Map from cl to ref cnt LINT nclref = 0; c2n_map.insert(make_pair(ncl, nclref)); } void add_literal(BasicClause* cl, LINT nlit) { CHK(ULINT mapsz = v2p_map.size();); vector& clits = cl->cl_lits(); v2p_map.erase(&clits); cl->add_lit(nlit); vector& nclits = cl->cl_lits(); v2p_map.insert(make_pair(&nclits, cl)); CHK(assert(mapsz == v2p_map.size())); } void erase_clause(BasicClause* cl) { NDBG(cout << "Erasing clause: " << *cl << endl;); vector& clits = cl->cl_lits(); assert(v2p_map.find(&clits) != v2p_map.end()); v2p_map.erase(&clits); delete cl; } BasicClause* lookup_vect(vector& clits) { assert(is_sorted(clits.begin(), clits.end(), AbsLitLess())); iv2cl_iterator ippos = v2p_map.find(&clits); return (ippos != v2p_map.end()) ? ippos->second : NULL; } BasicClause* lookup_vect(LINT num, const LINT ivect[]) { vector clits(ivect, ivect+num); iv2cl_iterator ippos = v2p_map.find(&clits); return (ippos != v2p_map.end()) ? ippos->second : NULL; } protected: // Remove duplicate literals void remove_duplicates(vector& clits) { DBG(PRINT_ELEMENTS(clits); cout << endl;); unsigned int i = 1; unsigned int j = 1; for(; i j) { clits.resize(j); } // Final clause size DBG(PRINT_ELEMENTS(clits, "Final cl: ", " ");) } protected: IVec2ClMap v2p_map; Clause2IntMap c2n_map; static ClauseRegistry clreg_instance; }; #endif /* _CL_REGISTRY_H */ /*----------------------------------------------------------------------------*/ packup-0.6/cl_types.hh0000644000175000010010000001106611573000741014114 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ //jpms:bc /*----------------------------------------------------------------------------*\ * File: cl_types.hh * * Description: Types derived from clauses and clause sets. * * Author: jpms * * Revision: $Id$. * * Copyright (c) 2009, Joao Marques-Silva \*----------------------------------------------------------------------------*/ //jpms:ec #ifndef _CL_TYPES_H #define _CL_TYPES_H 1 #include "basic_clause.hh" #include "cl_functors.hh" typedef enum ClTypes { CL_HARD = 0x10, CL_SOFT = 0x20, CL_WEIGHTED = 0x30 } ClauseTypes; //jpms:bc /*----------------------------------------------------------------------------*\ * Type definitions. \*----------------------------------------------------------------------------*/ //jpms:ec class BasicClauseSet; typedef BasicClause* BasicClausePtr; typedef BasicClause** BasicClausePtrPtr; //typedef hash_set HashedClauseSet; typedef hash_set HashedClauseSet; typedef HashedClauseSet::iterator ClSetIterator; typedef HashedClauseSet::iterator cset_iterator; typedef hash_map Clause2IntMap; typedef hash_map IVec2ClMap; typedef IVec2ClMap::iterator iv2cl_iterator; typedef vector BasicClauseVector; typedef BasicClauseVector::iterator ClVectIterator; typedef slist BasicClauseSList; typedef list BasicClauseList; typedef vector BasicClauseSetVector; typedef IntKeyMap*> Int2ClVectMap; //typedef hash_map*,IntHash,IntEqual> Int2ClVectMap; typedef hash_map*,ClPtrHash,ClPtrEqual> Cl2IntVMap; typedef hash_map*,ClPtrHash,ClPtrEqual> Cl2ClVMap; typedef hash_map Cl2IntMap; typedef Cl2IntMap::iterator c2n_iterator; typedef hash_map Int2ClMap; //typedef hash_map*,IntHash,IntEqual> Int2IntVMap; typedef hash_map Cl2ClMap; typedef vector ClauseSetVector; typedef hash_map Int2ClVMap; typedef hash_map XLInt2ClVMap; typedef hash_map*,ClPtrHash,ClPtrEqual> Cl2IntVMap; typedef hash_map*,ClPtrHash,ClPtrEqual> Cl2ClVMap; typedef hash_map Cl2IntMap; typedef hash_map Int2ClMap; typedef hash_map*,IntHash,IntEqual> Int2IntVMap; //typedef //hash_map Int2ClVMap; typedef vector VectCl2IntMap; typedef vector VectClSet; typedef vector VectHashedClauseSet; //typedef //vector*> IntVCl2IntMap; //typedef hash_map,IntHash,IntEqual> Int2ClVMap; //typedef //hash_map Cl2ClPMap; #endif /* _CL_TYPES_H */ /*----------------------------------------------------------------------------*/ packup-0.6/cl_utils.hh0000644000175000010010000001255311573000741014112 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ //jpms:bc /*----------------------------------------------------------------------------*\ * File: cl_utils.hh * * Description: Clause set utilities. * * Author: jpms * * Copyright (c) 2010, Joao Marques-Silva \*----------------------------------------------------------------------------*/ //jpms:ec #ifndef _CL_UTILS_H #define _CL_UTILS_H 1 //jpms:bc /*----------------------------------------------------------------------------*\ * Namespace: ClSetUtils * * Purpose: Clause set utilities. Examples include intersection of two clsets. \*----------------------------------------------------------------------------*/ //jpms:ec namespace ClSetUtils { // Template functions for performing intersection of two sets P and Q, // such that Q is a subset of P // Version 1: Direct deletion of elements from P template void intersect_clset(T& P, U& Q) { CHK(int psz = P.size(); int qsz = Q.size();); // Create temporary container vector vect; vect.resize(P.size()+Q.size(), NULL); typename vector::iterator vpos = vect.begin(); // Fill container with contents of P and Q I ppos = P.begin(); I pend = P.end(); for(; ppos != pend; ++ppos, ++vpos) { assert(vpos != vect.end()); *vpos = *ppos; } typename U::iterator qpos = Q.begin(); typename U::iterator qend = Q.end(); for(; qpos != qend; ++qpos, ++vpos) { assert(vpos != vect.end()); *vpos = *qpos; } // Sort contents of container sort(vect.begin(), vect.end()); // Keep duplicates; remove everything else typename vector::iterator vref = vect.begin(); typename vector::iterator vend = vect.end(); vpos = vect.begin(); ++vpos; for(; vref != vend; vref++, vpos++) { if (vpos == vend || *vref != *vpos) { assert(P.find(*vref) != P.end()); P.rm_clause(*vref); } else { vref++; vpos++; } } CHK(cout << "Init P size: " << psz << endl; cout << "Init Q size: " << qsz << endl; cout << " Final P size: " << P.size() << endl); assert((LINT)P.size() == qsz); vect.clear(); } // Version 2: with callback for removing elements template void intersect_clset(T& P, U& Q, E& robj, V rm_elem) { CHK(int psz = P.size(); int qsz = Q.size();); // Create temporary container vector vect; vect.resize(P.size()+Q.size(), NULL); typename vector::iterator vpos = vect.begin(); // Fill container with contents of P and Q I ppos = P.begin(); I pend = P.end(); for(; ppos != pend; ++ppos, ++vpos) { assert(vpos != vect.end()); *vpos = *ppos; } typename U::iterator qpos = Q.begin(); typename U::iterator qend = Q.end(); for(; qpos != qend; ++qpos, ++vpos) { assert(vpos != vect.end()); *vpos = *qpos; } // Sort contents of container sort(vect.begin(), vect.end()); // Keep duplicates; remove everything else typename vector::iterator vref = vect.begin(); typename vector::iterator vend = vect.end(); vpos = vect.begin(); ++vpos; for(; vref != vend; vref++, vpos++) { if (vpos == vend || *vref != *vpos) { (robj->*rm_elem)(*vref); } else { vref++; vpos++; } } CHK(cout << "Init P size: " << psz << endl; cout << "Init Q size: " << qsz << endl; cout << " Final P size: " << P.size() << endl); assert((LINT)P.size() == qsz); vect.clear(); } // Export clause set in WCNF format template void export_wcnf(C& cset, U nv, ostream& outs=cout) { ULINT topw = cset.get_top(); outs << "p wcnf " << nv << " " << cset.size() << " " << topw << endl; ClSetIterator cpos = cset.begin(); ClSetIterator cend = cset.end(); for (; cpos != cend; ++cpos) { if (cset.is_cl_soft(*cpos)) { outs << "1 " << **cpos << endl; } else { outs << topw << " " << **cpos << endl; } } } } #endif /* _CL_UTILS_H */ /*----------------------------------------------------------------------------*/ packup-0.6/collections.cc0000644000175000010010000000365611573000736014610 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* Copyright (C) 2011, Mikolas Janota*/ #include "collections.hh" void collection_printing::print(CONSTANT PackageVersionsList &pvl,ostream& out) { for (UINT i=0;i0) out << ", "; pvl[i].print(out); } } void collection_printing::print(CONSTANT PackageVersionList &pvl,ostream& out) { for (UINT i=0;i0) out << ", "; out << pvl[i].to_string(); } } void collection_printing::print(CONSTANT PackageVersionsCNF &pvs_cnf, ostream& out) { for (UINT i=0;i0) out << " & "; print(*(pvs_cnf[i]), out); } } packup-0.6/collections.hh0000644000175000010010000000620211573000736014610 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: collections.hh * Author: mikolas * * Created on September 19, 2010, 3:04 PM * Copyright (C) 2011, Mikolas Janota */ #ifndef COLLECTIONS_HH #define COLLECTIONS_HH #include "common_types.hh" #include "PackageVersions.hh" #include "package_version.hh" typedef unordered_map VariableToName; typedef vector VersionsList; typedef vector PackageVersionsList; typedef vector PackageVersionsCNF; typedef vector PackageVersionList; typedef unordered_map< const char*,string,__gnu_cxx::hash, streq > Str2Str; typedef unordered_map PackageVersionMap; typedef unordered_map VariableToPackageVersion; typedef vector VersionVector; typedef vector LiteralVector; typedef unordered_set VersionSet; typedef unordered_set VariableSet; typedef unordered_map PackageToVersions; typedef unordered_map PackageToVersion; typedef unordered_map FeaturesToPackages; typedef unordered_map PackageToFeatureVersions; typedef unordered_set PackageVersionSet; typedef unordered_set PackageVersionsSet; typedef unordered_map FeatureToVersions; typedef unordered_set StringSet; namespace collection_printing { void print(CONSTANT PackageVersionsList& pvl,ostream& out); void print(CONSTANT PackageVersionList& pvl, ostream& out); void print(CONSTANT PackageVersionsCNF& pvs_cnf, ostream& out); } #endif /* COLLECTIONS_HH */ packup-0.6/common_types.cc0000644000175000010010000000713211573000737015000 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* Copyright (C) 2011, Mikolas Janota */ #include #include #include "common_types.hh" using namespace version_operators; bool version_operators::evaluate(Version version_1, Operator op, Version version_2) { switch (op) { case VERSIONS_NONE: return true; case VERSIONS_EQUALS: return version_1 == version_2; case VERSIONS_NOT_EQUALS: return version_1 != version_2; case VERSIONS_GREATER_EQUALS: return version_1 >= version_2; case VERSIONS_GREATER: return version_1 > version_2; case VERSIONS_LESS_EQUALS: return version_1 <= version_2; case VERSIONS_LESS: return version_1 < version_2; } assert(false); return NULL; } const char* version_operators::to_string(Operator op) { switch (op) { case VERSIONS_NONE: return ""; case VERSIONS_EQUALS: return "="; case VERSIONS_NOT_EQUALS: return "!="; case VERSIONS_GREATER_EQUALS: return ">="; case VERSIONS_GREATER: return ">"; case VERSIONS_LESS_EQUALS: return "<="; case VERSIONS_LESS: return "<"; } assert(false); return NULL; } const string to_string(const Objective& o) { return string(o.second ? "+" : "-") + to_string(o.first); } const char* to_string(OBJECTIVE_FUNCTION f) { switch (f) { case COUNT_NEW: return "new"; case COUNT_UNMET_RECOMMENDS: return "unmet_recommends"; case COUNT_REMOVED: return "removed"; case COUNT_NOT_UP_TO_DATE: return "notuptodate"; case COUNT_CHANGED: return "changed"; } assert(false); return NULL; } void print(const vector& ls, ostream& o) { bool f = true; FOR_EACH(vector::const_iterator, i, ls) { if (!f) o << ','; f = false; o << to_string(*i); } } const char* to_string(KeepValue value) { switch (value) { case KEEP_NONE: return "KEEP_NONE"; case KEEP_VERSION: return "KEEP_VERSION"; case KEEP_PACKAGE: return "KEEP_PACKAGE"; case KEEP_FEATURE: return "KEEP_FEATURE"; } assert(false); return NULL; } const char* to_string(Criterion value) { switch (value) { case NO_OPTIMIZATION: return "no_optimization"; case PARANOID: return "paranoid"; case TRENDY: return "trendy"; } assert(false); return NULL; } packup-0.6/common_types.hh0000644000175000010010000000737311573000737015021 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: common_types.hh * Author: mikolas * * Created on August 23, 2010, 8:53 PM * Copyright (C) 2011, Mikolas Janota */ #ifndef COMMON_TYPES_H #define COMMON_TYPES_H #include #include #include #include "types.hh" using __gnu_cxx::hash; using __gnu_cxx::hash_map; using __gnu_cxx::hash_set; using std::string; using std::vector; using std::ostream; #define CNF_OUT(c) #define CONSTANT const #define CONTAINS(s,e) ( ((s).find(e))!=(s).end() ) #define SAME_PACKAGE_NAME(n1,n2) (n1.data()==n2.data()) #define unordered_set hash_set #define unordered_map hash_map typedef unsigned int UINT; typedef UINT Version; typedef set< XLINT, greater > WeightSet; #ifdef CONV_DBG #define MAPPING #undef NDEBUG #define OUT(c) { c } #define __PL (cerr << __FILE__ << ":" << __LINE__ << endl).flush(); #else #define OUT(c) #define __PL #endif #define FOR_EACH(iterator_type,index,iterated)\ for (iterator_type index = (iterated).begin(); index != (iterated).end();++index) #define FOR_EACH_REV(iterator_type,index,iterated)\ for (iterator_type index = (iterated).rbegin(); index != (iterated).rend();++index) enum Criterion { TRENDY, PARANOID, NO_OPTIMIZATION }; enum OBJECTIVE_FUNCTION { COUNT_NEW, COUNT_UNMET_RECOMMENDS, COUNT_REMOVED, COUNT_NOT_UP_TO_DATE, COUNT_CHANGED }; typedef pair Objective; const string to_string(const Objective& o); const char* to_string(OBJECTIVE_FUNCTION f); void print(const vector& ls, ostream& o); namespace version_operators { enum Operator { VERSIONS_NONE, VERSIONS_EQUALS, VERSIONS_NOT_EQUALS, VERSIONS_GREATER_EQUALS, VERSIONS_GREATER, VERSIONS_LESS_EQUALS, VERSIONS_LESS }; bool evaluate (Version version_1, Operator op, Version version_2); const char* to_string (Operator op); } /*end of namespace version_operators */ enum KeepValue { KEEP_NONE, KEEP_VERSION, KEEP_PACKAGE, KEEP_FEATURE }; typedef UINT Variable; struct streq { bool operator()(const char* s1, const char* s2) const {return strcmp(s1, s2) == 0;} }; namespace __gnu_cxx { template<> struct hash { size_t operator()(const std::string& s) const { hash h; return h(s.data()); } }; } /*end of namespace __gnu_cxx */ const char* to_string (KeepValue value); const char* to_string (Criterion value); inline LINT neg(Variable v) { return -((LINT)v); } #endif /* COMMON_TYPES_H */ packup-0.6/config.hh0000644000175000010010000000524511573000737013546 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /*----------------------------------------------------------------------------*\ * Version: $Id: config.hh 73 2007-07-26 15:16:48Z jpms $ * * Author: jpms * * Description: Defines used throughout * * Copyright (c) 2006, Joao Marques-Silva \*----------------------------------------------------------------------------*/ #ifndef _CONFIG_HH_ #define _CONFIG_HH_ 1 /*----------------------------------------------------------------------------*\ * Data structure fine-tuning configuration \*----------------------------------------------------------------------------*/ //#define NO_NOTOS_OPT 1 // **Uncomment** to use std map structures #ifdef NO_NOTOS_OPT // Define if goal is *not* to optimize data structures #define USE_RBTREE_MAPS 1 // Use std RBTree-based maps (instead of hash maps) #define USE_RBTREE_SETS 1 // Use std RBTree-based sets (instead of hash sets) #else #undef USE_RBTREE_MAPS // Use (optimized and so preferred) hash maps #undef USE_RBTREE_SETS // Use (optimized and so preferred) hash sets #endif #define PRINTOUT 1 // **Comment** to prevent printing of msgs to stdout #define LOGGING 1 // **Comment** to prevent logging to file //#define RBC_NOCOLLAPSE 1 // **Uncomment** to prevent node collapsing in RBCs #endif /* _CONFIG_HH_ */ /*----------------------------------------------------------------------------*/ packup-0.6/ConverterMem.cc0000644000175000010010000000724311573000733014671 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: ConverterMem.cc * Author: mikolas * * Created on September 25, 2010, 5:46 PM * Copyright (C) 2011, Mikolas Janota */ #include "ConverterMem.hh" ConverterMem::~ConverterMem() {} #ifdef MAPPING void ConverterMem::set_maping_file (const char* filen) {encoder.get_mapping().open(filen);} #endif void ConverterMem::solution_check(const char* file_name) { sr.read(file_name); encoder.cs = true; encoder.stc=&(sr.installed_package_versions); } void ConverterMem::start_package() { current_unit = new InstallableUnit(); current_unit->name=read_package_name; // default values for a unit current_unit->keep=KEEP_NONE; current_unit->installed=false; has_version = false; } void ConverterMem::close_package() { // current_unit->dump(cerr); // cerr << endl; encoder.add_unit(current_unit); } void ConverterMem::close_universe(){} void ConverterMem::close_input () { solve(); } void ConverterMem::package_provides() { PackageVersionList ¤t_provides=current_unit->provides; current_provides.insert(current_provides.end(), read_feature_list.begin (), read_feature_list.end()); } void ConverterMem::package_conflicts() { PackageVersionsList& current_conflicts = current_unit->conflicts; current_conflicts.insert (current_conflicts.end(), read_package_versions_list.begin(), read_package_versions_list.end()); } void ConverterMem::package_depends() { PackageVersionsCNF ¤t_depends = current_unit->depends_cnf; current_depends.insert(current_depends.end(), read_CNF.begin(),read_CNF.end()); } void ConverterMem::package_recommends() { PackageVersionsCNF ¤t_recommends = current_unit->recommends_cnf; current_recommends.insert(current_recommends.end(), read_CNF.begin(),read_CNF.end()); } void ConverterMem::package_keep() { current_unit->keep=read_keep_value; } void ConverterMem::package_installed(bool installed_value) {current_unit->installed=installed_value;} void ConverterMem::end_processed_package_version () { current_unit->version = read_version; has_version = true; } void ConverterMem::request_install() { encoder.add_install(read_package_versions_list); } void ConverterMem::request_remove() { encoder.add_remove(read_package_versions_list); } void ConverterMem::upgrade() { encoder.add_upgrade(read_package_versions_list); } Encoder& ConverterMem::get_encoder() { return encoder; } packup-0.6/ConverterMem.hh0000644000175000010010000000627711573000733014711 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: ConverterMem.hh * Author: mikolas * * Created on September 25, 2010, 5:46 PM * Copyright (C) 2011, Mikolas Janota */ #ifndef CONVERTERMEM_HH #define CONVERTERMEM_HH #include "parser.hh" #include "InstallableUnit.hh" #include "Encoder.hh" #include "SolutionReader.hh" class ConverterMem : public Parser { public: ConverterMem(SolverWrapper& solver,IDManager &id_manager) : sr(package_names_set),encoder (solver, id_manager) {} virtual ~ConverterMem(); inline void set_criterion(Criterion optimization_criterion) {encoder.set_criterion(optimization_criterion);} inline void disable_solving () {encoder.disable_solving ();} inline bool solve () { encoder.encode(); return encoder.solution(); } void solution_check(const char* file_name); #ifdef MAPPING void set_maping_file (const char* filen); #endif /** Processing of a new package started.*/ virtual void start_package(); /** Processing of a package stopped.*/ virtual void close_package(); /**The version of currently processed package was read.*/ virtual void end_processed_package_version(); /** The package universe has been fully read.*/ virtual void close_universe(); /**The whole input was read.*/ virtual void close_input (); //Package stanza virtual void package_provides(); virtual void package_conflicts(); // A list of conflicting versions was read. virtual void package_depends(); virtual void package_recommends(); virtual void package_keep(); virtual void package_installed(bool installed_value); //Request stanzas virtual void request_install(); virtual void request_remove(); virtual void upgrade(); Encoder& get_encoder(); private: bool has_version; InstallableUnit *current_unit; SolutionReader sr; Encoder encoder; }; #endif /* CONVERTERMEM_HH */ packup-0.6/cudf_msu.cc0000644000175000010010000002063311573000736014071 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* Copyright (C) 2011, Mikolas Janota */ #include #include #include #include #include "common_types.hh" #include "Lexer.hh" #include "ConverterMem.hh" #include "SolutionReader.hh" #include "SolverWrapperTypes.hh" #include "Options.hh" using std::ifstream; static const char* dist_date = ""DISTDATE""; static const char* changeset = ""CHANGESET""; static const char* release = "0.6"; IDManager id_manager; SolverType solver(id_manager); ConverterMem parser(solver,id_manager); extern int yyparse (void); extern Lexer* lexer; bool parse_lexicographic_specification (const char* specification,vector& lexicographic) { std::stringstream ss(specification); std::string item; while(std::getline(ss, item, ',')) { CONSTANT bool maximize(item[0]=='+'); CONSTANT string sfunction(item.substr(1)); OBJECTIVE_FUNCTION function; if (sfunction.compare("new")==0) function = COUNT_NEW; else if (sfunction.compare("unmet_recommends")==0) function = COUNT_UNMET_RECOMMENDS; else if (sfunction.compare("removed")==0) function = COUNT_REMOVED; else if (sfunction.compare("notuptodate")==0) function = COUNT_NOT_UP_TO_DATE; else if (sfunction.compare("changed")==0) function = COUNT_CHANGED; else { cerr << "unknown criterion " << sfunction << endl ; return false; } lexicographic.push_back(Objective(function, maximize)); } return true; } #ifndef EXTERNAL_SOLVER static void SIG_handler(int signum) { cerr << "# received external signal " << signum << "(" << (RUSAGE::read_cpu_time()) << ")" << endl; parser.get_encoder().print_solution(); cerr << "Terminating ..." << endl; exit(0); } #endif /* !EXTERNAL_SOLVER */ void print_usage(ostream &output) { output << "USAGE " << endl; output << "\t[OPTIONS] instance_file_name [output_file_name]" << endl; output << "\t--help,-h \t print this message" << endl; output << "\t-t \t\t trendy" << endl; output << "\t-p \t\t paranoid" << endl; output << "\t-u cs \t\t user criteria" << endl; output << "\t--external-solver\t\t command for the external solver" << endl; output << "\t\t\t\t\t default 'minisat+ -ansi -cs'"<< endl; output << "\t--multiplication-string\t\t string between coefficients and variables when communicating to the solver"<< endl; output << "\t\t\t\t\t default '*'"<< endl; output << "\t--temporary-directory DIR\t where temporary files should be placed"<< endl; output << "\t\t\t\t\t default '/tmp'"<< endl; output << "\t--leave-temporary-files\t\t do not delete temporary files" << endl; output << "\t--max-sat\t\t\t The external solver is a MaxSAT solver, only one call is made to the solver." << endl; output << "NOTE" << endl; output << "If the input file is '-', input is read from the standard input." << endl; output << "If the output filename is omitted, output is produced to the standard output." << endl; } #define TIMETOL 1 void print_header() { cout << "# authors: Mikolas Janota, Joao Marques-Silva" << endl; cout << "# contributors: Ines Lynce, Vasco Manquinho" << endl; cout << "# email mikolas@sat.inesc-id.pt" << endl; cout << "# (C) 2011 Mikolas Janota" << endl; cout << "# release: " << release << " distribution date: " << dist_date << " change set: " << changeset << endl; cout << "# Released under the GPL license." << endl; } int main(int argc, char** argv) { print_header(); /* set up signals */ #ifdef EXTERNAL_SOLVER // assuming external solver received as well struct sigaction new_act1; new_act1.sa_handler = SIG_IGN; sigaction(SIGTERM, &new_act1, 0); struct sigaction new_act2; new_act2.sa_handler = SIG_IGN; sigaction(SIGUSR1, &new_act2, 0); struct sigaction new_act3; new_act3.sa_handler = SIG_IGN; sigaction(SIGUSR2, &new_act3, 0); #else signal(SIGHUP, SIG_handler); signal(SIGTERM, SIG_handler); signal(SIGABRT, SIG_handler); signal(SIGUSR1, SIG_handler); //signal(SIGALRM,SIG_handler); //alarm(290); // Specify alarm interrupt given timeout #endif /* parse options */ Options options; if (!options.parse(argc, argv)) { cerr << "Error parsing options. Exiting." << endl; print_usage(cerr); exit(1); } if (options.get_help()) { print_usage(cout); exit(0); } #ifdef MAPPING if (!options.get_mapping_file().empty()) parser.set_maping_file(options.get_mapping_file().c_str()); #endif /* handling of input and output */ ifstream input_file; ofstream output_file; const bool use_stdin = options.get_input_file_name().compare("-")==0; const bool use_stdout = options.get_output_file_name().empty(); if (!use_stdin) { input_file.open(options.get_input_file_name().c_str()); if (input_file.fail()) { cerr<<"Failed to read the input file. Exiting." << endl; exit(1); } } if (!use_stdout) { output_file.open(options.get_output_file_name().c_str()); if (output_file.fail()) { cerr<<"Failed to open the output file. Exiting." << endl; exit(1); } } istream& input_stream(use_stdin ? cin : input_file); ostream& output_stream(use_stdout ? cout : output_file); /* set up of the encoder */ if (options.get_solving_disabled()) parser.disable_solving(); parser.get_encoder().set_opt_edges(1); parser.get_encoder().set_iv(3); parser.get_encoder().set_opt_not_removed(true); #ifdef EXTERNAL_SOLVER if (!options.get_external_solver().empty ()) solver.set_solver_command(options.get_external_solver ()); if (!options.get_multiplication_string().empty ()) solver.set_multiplication_string(options.get_multiplication_string()); if (options.get_leave_temporary_files()) solver.set_leave_temporary_files(); if (options.get_max_solver()) solver.set_iterative(false); if (!options.get_temporary_directory().empty ()) { solver.set_temporary_directory(options.get_temporary_directory()); } else { char * pPath; pPath = getenv("TMPDIR"); if (pPath!=NULL) { string s(pPath); solver.set_temporary_directory(s); } } #endif if (options.get_trendy()) parser.get_encoder().set_criterion(TRENDY); if (options.get_paranoid()) parser.get_encoder().set_criterion(PARANOID); if (!options.get_user_criterion().empty()) { vector lexicographic; if (!parse_lexicographic_specification(options.get_user_criterion().c_str(), lexicographic)) { cerr<<"Failed to parse the user defined criteria (" << options.get_user_criterion() << "). Exiting." << endl; exit(1); } parser.get_encoder().set_lexicographic(lexicographic); } /* run the whole thang */ lexer=new Lexer(input_stream); parser.get_encoder().set_solution_file(&output_stream); try { yyparse(); } catch(ReadException e) { cerr << "Error in parsing the input file:" << e.what() << endl; cerr << "Terminating." << endl; } exit(0); } packup-0.6/dbg_prt.hh0000644000175000010010000000531011573000740013705 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /*----------------------------------------------------------------------------*\ * Version: $Id: dbg_prt.hh 73 2007-07-26 15:16:48Z jpms $ * * Author: jpms * * Description: Utilities for printing containers. * * Copyright (c) 2005-2006, Joao Marques-Silva \*----------------------------------------------------------------------------*/ #ifndef _DBG_PRT_HH_ #define _DBG_PRT_HH_ 1 #include template inline void PRINT_ELEMENTS (const T& coll, const char* optcstr="", const char* sepstr=" ") { typename T::const_iterator pos; std::cout << optcstr; for(pos=coll.begin(); pos!=coll.end(); ++pos) { std::cout << *pos << sepstr; } std::cout << std::endl; } template inline void PACK_PRINT_ELEMENTS (const T& coll, const char* optcstr="") { typename T::const_iterator pos; std::cout << optcstr; for(pos=coll.begin(); pos!=coll.end(); ++pos) { std::cout << *pos; //((bool)*pos)?1:0; // -> This only works for bool's } std::cout << std::endl; } template inline void PRINT_PTR_ELEMENTS (const T& coll, const char* optcstr="", const char* sepstr=" ") { typename T::const_iterator pos; std::cout << optcstr; for(pos=coll.begin(); pos!=coll.end(); ++pos) { std::cout << **pos << sepstr; } std::cout << std::endl; } #endif /* _DBG_PRT_HH_ */ /*----------------------------------------------------------------------------*/ packup-0.6/Encoder.cc0000644000175000010010000024214111573000733013640 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: Encoder.cc * Author: mikolas * * Created on September 26, 2010, 2:01 PM * Copyright (C) 2011, Mikolas Janota */ #include "Encoder.hh" #include "PackageVersionVariables.hh" #include "Encoder.hh" #include "SolverWrapper.hh" #include "NotRemoved.hh" Encoder::Encoder(SolverWrapper& solver,IDManager& id_manager) :unit_count(0) ,cut_off(INT_MAX) ,psolution_file(NULL) //---- scalar values initialization ,should_solve(true) ,solver(solver) ,id_manager(id_manager) //----- variables initialization , variables(id_manager #ifdef MAPPING , variable_names,mapping #endif ) // ---- interval_vars initialization ,interval_vars(id_manager #ifdef MAPPING , variable_names,mapping #endif ) #ifdef CONV_DBG // ---- printer initialization , printer (variable_names) #endif , valuation(false) , opt_edges(0) , iv(3) , printing_started_or_finished(false) , opt_not_removed(false) , not_removed(needed_units) , cs(false) //===== end of variable initialization { #ifdef CONV_DBG solver.set_printer(&printer); #endif solver.init(); } Encoder::~Encoder() {} void Encoder::add_unit(InstallableUnit* unit) { unit->needed = false; // Insert the unit into a collection of units record_unit(read_units, unit); // Record information about the provides field handle_provides(unit); // Record information about the keep field handle_keep(unit); } void Encoder::add_install(CONSTANT PackageVersionsList& list) { FOR_EACH(PackageVersionsList::const_iterator, i, list) install.insert(*i); } void Encoder::add_upgrade (CONSTANT PackageVersionsList& list) {upgrade.insert (upgrade.end(), list.begin(), list.end ());} void Encoder::add_remove (CONSTANT PackageVersionsList& list) {remove.insert (remove.end(), list.begin(), list.end ());} void Encoder::set_lexicographic(const vector& lexicographic_ordering) { OUT ( cerr << "lex: "; print(lexicographic_ordering,cerr); cerr << endl; ) // store the ordering lexicographic.insert(lexicographic.end(), lexicographic_ordering.begin(),lexicographic_ordering.end()); OUT ( cerr << "lex: "; print(lexicographic,cerr); cerr << endl; ) // determine which information needs to be stored to be able to address the required functions process_recommends=false; _process_not_uptodate=false; FOR_EACH (vector::const_iterator, objective_index, lexicographic) { CONSTANT Objective objective = *objective_index; switch (objective.first) { case COUNT_UNMET_RECOMMENDS: if (!objective.second) process_recommends=true; break; case COUNT_NOT_UP_TO_DATE: if (!objective.second) _process_not_uptodate=true; break; case COUNT_NEW: case COUNT_REMOVED: case COUNT_CHANGED: break; } } } void Encoder::set_criterion(Criterion optimization_criterion) { vector lexicographic_ordering; switch (optimization_criterion) { case PARANOID: lexicographic_ordering.push_back(Objective(COUNT_REMOVED, false)); lexicographic_ordering.push_back(Objective(COUNT_CHANGED, false)); break; case TRENDY: lexicographic_ordering.push_back(Objective(COUNT_REMOVED, false)); lexicographic_ordering.push_back(Objective(COUNT_NOT_UP_TO_DATE, false)); lexicographic_ordering.push_back(Objective(COUNT_UNMET_RECOMMENDS, false)); lexicographic_ordering.push_back(Objective(COUNT_NEW, false)); break; case NO_OPTIMIZATION: break; } set_lexicographic(lexicographic_ordering); } void Encoder::handle_keep(InstallableUnit* unit) { if (!unit->installed) return; switch (unit->keep) { case KEEP_VERSION: install.insert(PackageVersions(unit->name,VERSIONS_EQUALS,unit->version)); break; case KEEP_PACKAGE: install.insert(PackageVersions(unit->name,VERSIONS_NONE,0)); break; case KEEP_FEATURE: FOR_EACH (PackageVersionList::const_iterator,i,unit->provides) { PackageVersion f=*i; if (f.version()==0) install.insert(PackageVersions(f.name(),VERSIONS_NONE,0)); else install.insert(PackageVersions(f.name(),VERSIONS_EQUALS,f.version())); } break; case KEEP_NONE: break; } } void Encoder::handle_provides(InstallableUnit* unit) { CONSTANT PackageVersionList &provides = unit->provides; FOR_EACH(PackageVersionList::const_iterator, i, provides) { CONSTANT PackageVersion& feature = *i; record_unit(feature_units, feature, unit); record_version(feature_versions, feature.name(), feature.version()); } } void Encoder::slice () { //process upgrade FOR_EACH(PackageVersionsList::const_iterator,i,upgrade) need (*i); //process install FOR_EACH(PackageVersionsSet::const_iterator,i,install) need (*i); //process preference if (gt(COUNT_REMOVED, lexicographic)==CT_MIN) { FOR_EACH(PackageUnits::const_iterator,index,read_units) { UnitVector &unit_vector=*(index->second); CONSTANT bool any_installed = is_any_installed_package(unit_vector); //if any package is installed, then all of its versions are needed if (any_installed) need_packages(index->first, VERSIONS_NONE, 0); } } if (gt(COUNT_NEW, lexicographic)==CT_MAX) { FOR_EACH(PackageUnits::const_iterator,index,read_units) { UnitVector &unit_vector=*(index->second); CONSTANT bool any_installed = is_any_installed_package(unit_vector); //if no versions are installed, then all of its versions are needed if (!any_installed) need_packages(index->first, VERSIONS_NONE, 0); } } if (gt(COUNT_UNMET_RECOMMENDS, lexicographic) == CT_MAX) { FOR_EACH(PackageUnits::const_iterator,index,read_units) { UnitVector &unit_vector=*(index->second); FOR_EACH (UnitVector::iterator, unit_index, unit_vector) { InstallableUnit* unit=*unit_index; if (!unit->recommends_cnf.empty()) need(unit); } } } if (gt(COUNT_NOT_UP_TO_DATE, lexicographic)==CT_MAX) { FOR_EACH(PackageUnits::const_iterator,index,read_units) { UnitVector &unit_vector=*(index->second); if (unit_vector.size()<=1) continue;// if a package is only one version it cannot be not up to date need_packages(index->first, VERSIONS_NONE, 0); } } slice_changed(); // make sure that variables are introduced for all features provided by needed packages FOR_EACH(PackageUnits::const_iterator,index,needed_units) { UnitVector &unit_vector = *(index->second); FOR_EACH(UnitVector::iterator, unit_index, unit_vector) { CONSTANT InstallableUnit& unit = **unit_index; FOR_EACH(PackageVersionList::const_iterator, feature_index, (unit.provides)) { CONSTANT PackageVersion& feature = *feature_index; if (CONTAINS(required_features, feature)) continue; //feature already required, therefore all of its providers have been recorded if (!variables.has_variable(feature)) { variables.add_variable_feature(feature); record_version(needed_feature_versions, feature.name(), feature.version()); } } } } OUT( cerr << "number of packages: " << unit_count << endl; ) } void Encoder::slice_changed() { if (gt(COUNT_CHANGED, lexicographic)==CT_NO) return; CONSTANT bool maximize = (gt(COUNT_CHANGED, lexicographic)==CT_MAX); FOR_EACH(PackageUnits::const_iterator,index,read_units) { UnitVector &unit_vector=*(index->second); FOR_EACH (UnitVector::iterator, unit_index, unit_vector) { InstallableUnit* unit=*unit_index; if (maximize && !unit->installed) need(unit); if (!maximize && unit->installed) need(unit); } } } void Encoder::need_packages(CONSTANT string &package_name, Operator version_operator, Version operand) { CONSTANT PackageUnits::const_iterator i = read_units.find(package_name); if (i==read_units.end()) return; CONSTANT UnitVector &vector=*(i->second); CONSTANT UINT size = vector.size(); for (UINT index = 0; index < size; ++index) { InstallableUnit *unit = vector[index]; if (evaluate(unit->version, version_operator, operand)) need (unit); } } void Encoder::need_feature(CONSTANT PackageVersion &feature) { if (CONTAINS(required_features, feature)) return; // already traversed FeatureToUnits::const_iterator i0=feature_units.find(feature); if (i0!=feature_units.end()) { OUT ( cerr << "need: " << (feature.name()) << ":" << (feature.version()) << endl; ) // Add the information that the feature is needed required_features.insert (feature); variables.add_variable_feature (feature); record_version (needed_feature_versions,feature.name(),feature.version ()); // All of the providers of the feature are needed CONSTANT UnitVector &providers_vector=*(i0->second); FOR_EACH (UnitVector::const_iterator,vi,providers_vector) need(*vi); } } void Encoder::need_features(CONSTANT string &feature_name, Operator version_operator, Version operand) { // Process unversioned providers need_feature(PackageVersion (feature_name,0)); CONSTANT FeatureToVersions::const_iterator i = feature_versions.find(feature_name); if (i==feature_versions.end()) return; CONSTANT VersionSet &vs=*(i->second); FOR_EACH (VersionSet::const_iterator,vi,vs) { CONSTANT Version version=*vi; if (evaluate(version, version_operator, operand)) need_feature(PackageVersion(feature_name,version)); } } void Encoder::need (InstallableUnit* unit) { if (unit->needed) return; if (unit_count > cut_off) return; ++unit_count; OUT ( cerr << "need: " << (unit->name) << ":" << (unit->version) << endl; ) unit->needed=true; unit->variable=variables.add_variable_package(PackageVersion (unit->name,unit->version)); OUT( cerr<< "var: " << unit->variable << endl; ) record_unit(needed_units,unit); need (unit->depends_cnf); if (process_recommends) need(unit->recommends_cnf); if (process_not_uptodate()) need_latest(unit->name); } void Encoder::need_latest(const string& package_name) { PackageUnits::const_iterator index = read_units.find(package_name); if (index == read_units.end ()) return; UnitVector &unit_vector=*(index->second); InstallableUnit* l=NULL; Version lv=0; FOR_EACH(UnitVector::const_iterator,ui,unit_vector) { InstallableUnit* u=*ui; if (lvversion) { lv=u->version; l=u; } } if (l!=NULL) need(l); } void Encoder::need (PackageVersionsCNF cnf) { FOR_EACH (PackageVersionsCNF::const_iterator,i,cnf) FOR_EACH (PackageVersionsList::const_iterator,vi, (**i)) need(*vi); } void Encoder::need (CONSTANT PackageVersions& versions) { if (is_feature (versions.name())) need_features(versions.name(),versions.op(),versions.version()); else need_packages(versions.name(),versions.op(),versions.version()); } void Encoder::encode() { OUT ( cerr << "encode ()" << endl; ) refine_upgrade_request(); // Compute needed units and features (slicing) slice(); // top bound solver.set_top(get_top(lexicographic)); //Sort versions InstallableUnitCmp cmp; FOR_EACH(PackageUnits::iterator,i,needed_units) { UnitVector &uv=*(i->second); sort(uv.begin(),uv.end(),cmp); } FOR_EACH(PackageToVersions::iterator,i,needed_feature_versions) { VersionVector &vv=*(i->second); sort(vv.begin(),vv.end()); } /// features encode_provides(); // Package dependencies FOR_EACH(PackageUnits::const_iterator,i,needed_units) { CONSTANT UnitVector &uv = *(i->second); FOR_EACH(UnitVector::const_iterator,vi,uv) { CONSTANT InstallableUnit *unit = *vi; encode(unit); } } // Install OUT ( cerr << "install [" <name())) not_removed.add(i->name()); } OUT ( cerr << "]" <second; LiteralVector not_remove_clause; require_up_to_clause(package_name, 0, unit_vector, NULL, not_remove_clause); solver.output_clause(not_remove_clause); } } bool Encoder::is_any_installed_package(const UnitVector& unit_vector) { bool any_installed = false; FOR_EACH (UnitVector::const_iterator, unit_index, unit_vector) { CONSTANT InstallableUnit* unit=*unit_index; if (unit->installed) { any_installed = true; break; } } return any_installed; } bool Encoder::is_installed_feature(const PackageVersion& feature) { assert (is_feature(feature.name())); CONSTANT FeatureToUnits::const_iterator providers_index = feature_units.find(feature); if (providers_index==feature_units.end()) { assert(false); return false; } CONSTANT UnitVector& providers =*(providers_index->second); FOR_EACH (UnitVector::const_iterator, provider_index, providers) { CONSTANT InstallableUnit& provider =**provider_index; if (provider.installed) return true; } return false; } bool Encoder::find_latest_installed_version_in_original_problem(const string& name, Version& version) { Version latest_installed = 0; bool any_installed = false; if (is_feature (name)) { FeatureToVersions::const_iterator i = feature_versions.find(name); if (i!=feature_versions.end()) { CONSTANT VersionSet& vs=*(i->second); FOR_EACH (VersionSet::const_iterator,vi,vs) { CONSTANT Version cv=*vi; if ((cv > latest_installed) && is_installed_feature (PackageVersion (name,cv))) { any_installed = true; latest_installed = cv; } } } } else { PackageUnits::const_iterator i=read_units.find(name); if (i!=read_units.end()) { CONSTANT UnitVector& uv=*(i->second); for (int k=uv.size()-1;k>=0;--k) { CONSTANT Version cv=uv[k]->version; if ((cv>latest_installed) && uv[k]->installed) { latest_installed = uv[k]->version; any_installed=true; } } } } if (any_installed) { version = latest_installed; return true; } else return false; } void Encoder::refine_upgrade_request() { OUT(cerr << "upgrade refine" << endl << " from: "; collection_printing::print(upgrade,cerr); cerr << endl; ) PackageVersionsList refined_list; FOR_EACH (PackageVersionsList::const_iterator, versions_index, upgrade) { CONSTANT PackageVersions& versions = *versions_index; if (versions.op()!=VERSIONS_NONE) { refined_list.push_back(versions); continue; } Version latest_version; CONSTANT string& name=versions.name(); if (find_latest_installed_version_in_original_problem(name,latest_version)) refined_list.push_back(PackageVersions(name,VERSIONS_GREATER_EQUALS,latest_version)); else refined_list.push_back(versions); } upgrade.clear(); upgrade.insert(upgrade.end(),refined_list.begin(),refined_list.end()); OUT(cerr << " to: "; collection_printing::print(upgrade,cerr); cerr << endl; ) } bool Encoder::latest_installed_package_version (CONSTANT string &name,Version& latest_version) { assert (!is_feature(name)); PackageUnits::const_iterator i=needed_units.find(name); if (i==needed_units.end()) return false; //no versions of the package CONSTANT UnitVector& uv=*(i->second); for (int k=uv.size()-1;k>=0;--k) { if (uv[k]->installed) { latest_version = uv[k]->version; return true; } } return false; //no installed versions of the package } bool Encoder::latest_installed_feature_version (CONSTANT string &name,Version& version) { assert (is_feature(name)); PackageToVersions::const_iterator i = needed_feature_versions.find(name); if (i==needed_feature_versions.end()) return false; const VersionVector& vv=*(i->second); for (int k=vv.size()-1;k>=0;--k) { CONSTANT Version ver=vv[k]; CONSTANT PackageVersion f(name,ver); if (is_installed_feature (f)) { version = ver; return true; } } return false; } void Encoder::encode_upgrade() { OUT(cerr << "upgrade () [" << endl;) // encode as the request semantics first, // this is needed if such requirement is stronger than the one given by upgrade semantics // TODO: possibly can be pruned FOR_EACH (PackageVersionsList::const_iterator,i,upgrade) { LiteralVector literals; request_to_clause(*i,literals); solver.output_clause(literals); } FOR_EACH (PackageVersionsList::const_iterator,index,upgrade) { CONSTANT PackageVersions& request =*index; CONSTANT string& name = request.name(); if (is_feature (name)) { Version latest_version; bool any_installed=latest_installed_feature_version(name,latest_version); if (any_installed) { solver.output_unary_clause (interval_vars.get_require_up(PackageVersion(name,latest_version))); atmost_1_feature(name,latest_version); } Version var; CONSTANT PackageVersion ipv(name,0); if (variables.find_variable(ipv,var)) { solver.output_unary_clause(neg(var)); } } else { if (opt_not_removed) not_removed.add(name); Version latest_version = 0; if (latest_installed_package_version(name, latest_version)) { solver.output_unary_clause (interval_vars.get_require_up(PackageVersion(name,latest_version))); atmost_1(name,latest_version); } } } OUT(cerr << "]" << endl;) } void Encoder::atmost_1_feature (CONSTANT string& name, Version from) { assert (is_feature (name)); CONSTANT PackageToVersions::const_iterator i=needed_feature_versions.find(name); if (i==needed_feature_versions.end ()) return; CONSTANT VersionVector& vv=*(i->second); for (UINT i=0;i= from); CONSTANT Variable variable_j = get_package_version_variable (PackageVersion(name, version_j)); solver.output_binary_clause(neg(variable_i), neg(variable_j)); } } } void Encoder::atmost_1(CONSTANT string& package_name, Version from) { assert (!is_feature(package_name)); PackageUnits::const_iterator fi=needed_units.find(package_name); if (fi==needed_units.end()) return; CONSTANT UnitVector& vv=*(fi->second); for (UINT i=0;i= from); solver.output_binary_clause(neg(ui.variable), neg(uj.variable)); } } } void Encoder::encode_request_remove() { OUT(cerr << "request_remove ()" << endl;) PackageVersionsList::const_iterator index = remove.begin(); CONSTANT PackageVersionsList::const_iterator e = remove.end(); for (; index != e; ++index) { const PackageVersions& pvs = *index; LiteralVector term; disable_to_term(pvs,term); FOR_EACH(LiteralVector::const_iterator, i, term) solver.output_unary_clause(*i); } } void Encoder::encode_new(XLINT& total_weight,bool maximize) { OUT(cerr<< "new[" << endl;) const XLINT new_weight=total_weight+1; FOR_EACH(PackageUnits::const_iterator,index,needed_units) { CONSTANT UnitVector& units=*(index->second); if (units.empty() || is_any_installed_package(units)) continue; const string& package_name=index->first; CONSTANT PackageVersion first_version(package_name, units[0]->version); if (maximize) {//maximization requires at least one version to be installed solver.output_unary_weighted_clause( interval_vars.get_require_up(first_version), new_weight); } else {//minimization requires all of them to be uninstalled solver.output_unary_weighted_clause( interval_vars.get_disable_up(first_version), new_weight); } total_weight+=new_weight; } OUT(cerr<< "]";) } void Encoder::encode_removed(XLINT& total_weight,bool maximize) { OUT(cerr<< "removed [" << endl;) assert(solver.get_soft_clauses_weight()==total_weight); CONSTANT XLINT not_rm_weight=total_weight+1; FOR_EACH(PackageUnits::const_iterator,index,needed_units) { CONSTANT UnitVector& unit_vector=*(index->second); const string& package_name=index->first; bool any_installed = is_any_installed_package(unit_vector); if (!any_installed) continue;//if nothing was installed, it cannot be removed if (opt_not_removed && not_removed.is_not_removed(package_name)) continue; //package detected unremovable if (maximize) { // disable all versions of this package Variable v=interval_vars.get_disable_up(PackageVersion(package_name,unit_vector[0]->version)); solver.output_unary_weighted_clause(v, not_rm_weight); } else { // minimization---require at least one version of this package LiteralVector ls; require_up_to_clause(package_name,0,index->second,NULL,ls); solver.output_weighted_clause( ls, not_rm_weight); } total_weight+=not_rm_weight; } OUT(cerr<< "]" << endl;) } void Encoder::encode_unmet_recommends(XLINT& total_weight,bool maximize) { OUT(cerr<< "recommends[" << endl;) CONSTANT XLINT recommends_weight=total_weight+1; assert(solver.get_soft_clauses_weight()==total_weight); if (maximize) { //when maximizing made the clauses of unsat FOR_EACH(PackageUnits::const_iterator,index,needed_units) { CONSTANT UnitVector& units=*(index->second); FOR_EACH (UnitVector::const_iterator, unit_index, units) { InstallableUnit *unit =*unit_index; if (unit->recommends_cnf.empty()) continue; FOR_EACH (PackageVersionsCNF::const_iterator, clause_index, unit->recommends_cnf) { PackageVersionsList& clause =**clause_index; Variable is_broken = id_manager.new_id(); //encode the condition for the clauses to be broken FOR_EACH (PackageVersionsList::const_iterator, literal_index, clause) { CONSTANT PackageVersions literal =*literal_index; vector term; disable_to_term(literal, term); FOR_EACH (vector::const_iterator,t, term) solver.output_binary_clause(neg(is_broken),*t); } Variable v = id_manager.new_id(); solver.output_binary_clause(neg(v), is_broken); solver.output_binary_clause(neg(v), unit->variable); solver.output_unary_weighted_clause(v,recommends_weight);//we are getting a point if the unit is installed and the recommends is broken } } } } else { //when minimizing try to satisfy the clauses FOR_EACH(vector::const_iterator,i,recommends_clauses_pointers) { ClausePointer cp=*i; solver.increase_weight(cp, recommends_weight); total_weight+=recommends_weight; } } OUT(cerr<< "]";) } void Encoder::encode_not_up_to_date(XLINT& total_weight,bool maximize) { OUT(cerr<< "not up to date[" << endl;) assert(solver.get_soft_clauses_weight()==total_weight); CONSTANT XLINT up_to_date_weight=total_weight+1; FOR_EACH(PackageUnits::const_iterator,index,needed_units) { CONSTANT UnitVector& units=*(index->second); if (units.size() <= 1) continue; //If only one version of the package exists, the criterion is satisfied automatically CONSTANT InstallableUnit* latest_version = units[units.size()-1]; CONSTANT Variable v_latest = latest_version->variable; if (opt_not_removed && not_removed.is_not_removed(index->first)) {//at least one version of this package will be installed if (maximize) {//disable the latest version solver.output_unary_weighted_clause(neg(v_latest), up_to_date_weight); } else {//require the latest version solver.output_unary_weighted_clause(v_latest, up_to_date_weight); } } else { CONSTANT Variable any_will_be_installed = new_variable(); vector literals; if (maximize) literals.push_back(neg(any_will_be_installed)); for (UINT vi=0;vivariable; if (maximize) literals.push_back(vv); else solver.output_binary_clause(neg(vv),any_will_be_installed); } if (maximize) {//require that at least one version is installed and the last one isn't Variable auxiliary = id_manager.new_id(); solver.output_clause(literals); solver.output_binary_clause(neg(auxiliary), any_will_be_installed); solver.output_binary_clause(neg(auxiliary), neg(v_latest)); solver.output_unary_weighted_clause(auxiliary, up_to_date_weight); } else { //if any version is installed, then the latest one should be installed as well solver.output_binary_weighted_clause(neg(any_will_be_installed), v_latest, up_to_date_weight); } } total_weight+=up_to_date_weight; } OUT(cerr<< "]";) } void Encoder::encode_changed(XLINT& total_weight,bool maximize) { CONSTANT XLINT w=total_weight+1; vector literals; FOR_EACH(PackageUnits::const_iterator,index,needed_units) { CONSTANT UnitVector &unit_vector=*(index->second); Variable unchanged=-1; // variables that represents that all versions stayed the same, used only for minimization if (!maximize) { unchanged=id_manager.new_id(); #ifdef CONV_DBG string nm="unchanged_" + index->first; variable_names[unchanged] = nm; mapping << unchanged << "->" << nm << endl; #endif } else { literals.clear(); } FOR_EACH (UnitVector::const_iterator, unit_index, unit_vector) { CONSTANT InstallableUnit& unit =**unit_index; LINT l = unit.installed ? unit.variable : neg(unit.variable); if (!maximize) solver.output_binary_clause(neg(unchanged),l); // each version needs to stay the same else literals.push_back(-l);//at least one version changed } if (!maximize) solver.output_unary_weighted_clause(unchanged,w); else solver.output_weighted_clause(literals,w); total_weight+=w; } } XLINT Encoder::get_top(CONSTANT Objective& objective) const { switch (objective.first) { case COUNT_NEW: return needed_units.size(); case COUNT_UNMET_RECOMMENDS: { UINT recommend_cl_counter=0; FOR_EACH(PackageUnits::const_iterator,index,needed_units) { CONSTANT UnitVector& units=*(index->second); for (UINT vi=0;virecommends_cnf.size(); } return recommend_cl_counter; } case COUNT_REMOVED: return needed_units.size(); case COUNT_NOT_UP_TO_DATE: return needed_units.size(); case COUNT_CHANGED: return needed_units.size(); } assert (false); return 0; } XLINT Encoder::get_top(const vector& lexicographic) const { XLINT total_weight = 0; FOR_EACH(vector::const_iterator,objective_index,lexicographic) { CONSTANT Objective objective = *objective_index; total_weight += (total_weight + 1) * get_top(objective); } return total_weight + 1; } void Encoder::encode_lexicographic() { XLINT total_weight = 0; //FOR_EACH_REV(vector::const_reverse_iterator,objective_index,lexicographic) for (size_t i=lexicographic.size(); i>0; --i) { CONSTANT Objective objective = lexicographic[i-1]; solver.register_weight(total_weight+1); switch (objective.first) { case COUNT_NEW: encode_new(total_weight, objective.second); break; case COUNT_UNMET_RECOMMENDS: encode_unmet_recommends(total_weight, objective.second); break; case COUNT_REMOVED: encode_removed(total_weight, objective.second); break; case COUNT_NOT_UP_TO_DATE: encode_not_up_to_date(total_weight, objective.second); break; case COUNT_CHANGED: encode_changed(total_weight, objective.second); break; } } } void Encoder::encode_provides() { FOR_EACH (PackageToVersions::const_iterator, versions_index, needed_feature_versions) { CONSTANT VersionVector& vs = *(versions_index->second); CONSTANT string& name= versions_index->first; Variable infinite_variable=-1; bool infinite_provided = variables.find_variable(PackageVersion (name, 0), infinite_variable); FOR_EACH (VersionVector::const_iterator,version_index,vs) { CONSTANT Version ver =*version_index; CONSTANT PackageVersion pv(name,ver); CONSTANT Variable var=get_package_version_variable (pv); LiteralVector literals; literals.push_back(neg(var)); if (infinite_provided && ver != 0) { solver.output_binary_clause (neg(infinite_variable),var); literals.push_back(infinite_variable); } CONSTANT FeatureToUnits::const_iterator providers_index = feature_units.find(pv); if (providers_index!= feature_units.end()) { CONSTANT UnitVector& providers =*(providers_index->second); FOR_EACH (UnitVector::const_iterator, provider_index, providers) { CONSTANT InstallableUnit& provider =**provider_index; CONSTANT Variable provider_variable=provider.variable; if (!provider.needed) continue; solver.output_binary_clause (neg (provider_variable),var); literals.push_back(provider_variable); } } solver.output_clause (literals); } } } void Encoder::encode(const InstallableUnit* unit) { OUT ( cerr << "encode " << unit->name << " " << unit->version <<"[" <recommends_cnf; FOR_EACH (PackageVersionsCNF::const_iterator,ci,depends) { CONSTANT PackageVersionsList* clause=*ci; CONSTANT PackageVersionsList::const_iterator e=clause->end(); CONSTANT PackageVersionsList::const_iterator b=clause->begin(); LiteralVector literals; literals.push_back(neg(unit->variable)); requests_to_clause(b,e, literals); ClausePointer p=solver.record_clause(literals); recommends_clauses_pointers.push_back(p); } } void Encoder::encode_depends(const InstallableUnit* unit) { CONSTANT PackageVersionsCNF& depends = unit->depends_cnf; FOR_EACH (PackageVersionsCNF::const_iterator,ci,depends) { CONSTANT PackageVersionsList* clause=*ci; CONSTANT PackageVersionsList::const_iterator e=clause->end(); CONSTANT PackageVersionsList::const_iterator b=clause->begin(); LiteralVector literals; literals.push_back(neg(unit->variable)); requests_to_clause(b,e, literals); solver.output_clause(literals); } } void Encoder::encode_conflicts(const InstallableUnit* unit) { OUT (cerr<< "local conflicts[" <version > 0); assert (unit->needed); FOR_EACH (PackageVersionsList::const_iterator, index, unit->conflicts) { CONSTANT PackageVersions pvs=*index; CONSTANT bool pvs_is_feature = is_feature(pvs.name()); if (pvs_is_feature) { bool self_feature_conflict = false; FOR_EACH (PackageVersionList::const_iterator,feature_index,unit->provides) { CONSTANT PackageVersion& feature =*feature_index; if (SAME_PACKAGE_NAME(pvs.name(),feature.name())) { self_feature_conflict = true; break; } } if (self_feature_conflict) { VariableSet providers; add_providers(pvs,providers); providers.erase(unit->variable); conflict_all (unit->variable,providers); continue; } // otherwise treat in not_self_conflict } if (SAME_PACKAGE_NAME(pvs.name(),unit->name)) { encode_package_self_conflict(unit,pvs); continue; } encode_not_self_conflict (unit,pvs); } OUT (cerr<< "]"<name); CONSTANT UnitVector& units = *(i->second); if (pvs.op()==VERSIONS_NONE) { LiteralVector term; disable_up_to_term(unit->name, unit->version+1, i->second, NULL, term); disable_down_to_term(unit->name, unit->version-1, i->second, NULL, term); FOR_EACH(LiteralVector::const_iterator, i, term) solver.output_binary_clause(neg(unit->variable),*i); return; } FOR_EACH (UnitVector::const_iterator, unit_index, units) { InstallableUnit* conflicting_unit = *unit_index; if (conflicting_unit->version==unit->version) continue; if (evaluate(conflicting_unit->version,pvs.op(),pvs.version())) solver.output_binary_clause (neg(unit->variable),neg(conflicting_unit->variable)); } } void Encoder::disable_to_term(const PackageVersions& pvs, LiteralVector& term) { CONSTANT string& name = pvs.name(); //Check whether it is a feature or not CONSTANT PackageToVersions::const_iterator fi = needed_feature_versions.find(name); CONSTANT bool is_feature = fi!=needed_feature_versions.end(); VersionVector* version_vector = NULL; UnitVector *unit_vector = NULL; if (is_feature) { version_vector = fi->second; } else { //If it is not a feature, look up the pertaining units CONSTANT PackageUnits::const_iterator pi = needed_units.find(name); if (pi==needed_units.end()) return;//there is no feature or package of that name unit_vector = pi->second; } UINT old_sz=term.size(); switch (pvs.op()) { case VERSIONS_NONE: disable_up_to_term(name, 0, unit_vector, version_vector, term); break; case VERSIONS_EQUALS: { CONSTANT PackageVersion pv=PackageVersion(pvs.name(), pvs.version()); Variable v; if (variables.find_variable(pv,v)) { // generated only if the exact version exists term.push_back(neg(v)); } } break; case VERSIONS_NOT_EQUALS: disable_up_to_term(name, pvs.version()+1, unit_vector, version_vector, term); disable_down_to_term(name, pvs.version()-1, unit_vector, version_vector, term); break; case VERSIONS_GREATER_EQUALS: disable_up_to_term(name, pvs.version(), unit_vector, version_vector, term); break; case VERSIONS_GREATER: disable_up_to_term(name, pvs.version()+1, unit_vector, version_vector, term); break; case VERSIONS_LESS_EQUALS: disable_down_to_term(name, pvs.version(), unit_vector, version_vector, term); break; case VERSIONS_LESS: disable_down_to_term(name, pvs.version()-1, unit_vector, version_vector, term); } assert (term.size() >= old_sz); bool generated = old_sz!=term.size(); if (is_feature && !generated) { CONSTANT PackageVersion pv(pvs.name(), 0); Variable v; if (variables.find_variable(pv,v)) term.push_back(neg(v)); } } void Encoder::encode_not_self_conflict(const InstallableUnit* unit, const PackageVersions& pvs) { LiteralVector term; disable_to_term(pvs,term); CONSTANT Variable current_variable = unit->variable; FOR_EACH(LiteralVector::const_iterator, i, term) solver.output_binary_clause(neg(current_variable),*i); } void Encoder::requests_to_clause (CONSTANT PackageVersionsList::const_iterator begin, CONSTANT PackageVersionsList::const_iterator end, LiteralVector& literals) { for (PackageVersionsList::const_iterator i=begin;i!=end; ++i) { CONSTANT PackageVersions& pvs=*i; request_to_clause (pvs, literals); } } bool Encoder::require_up_to_clause(const string& name, Version from, const UnitVector* unit_vector, const VersionVector* version_vector, LiteralVector& literals) { assert ((version_vector != NULL) ^ (unit_vector != NULL)); CONSTANT bool is_feature = version_vector != NULL; if (is_feature) { int pos; UINT count=0; for (pos=version_vector->size() - 1; pos >= 0 && (version_vector->at(pos) >= from); --pos) ++count; if (count==0) return false;//no versions greater or equal to from if (count > iv) {// use interval variable literals.push_back(interval_vars.get_require_up(PackageVersion(name,version_vector->at(pos+1)))); } else { // use directly the variables of the feature for (UINT i=pos+1;isize();++i) { CONSTANT Version version=version_vector->at(i); Variable var=-1; const bool f=variables.find_variable(PackageVersion (name, version), var); if (!f) assert(0); literals.push_back(var); } } } else { int pos; UINT count=0; for (pos=unit_vector->size() - 1; pos >= 0 && (unit_vector->at(pos)->version >= from); --pos) ++count; if (count==0) return false; //no versions greater or equal to from if (count > iv) { // use interval variable literals.push_back(interval_vars.get_require_up(PackageVersion(name,unit_vector->at(pos+1)->version))); } else { // use directly the variables of the unit for (UINT i=pos+1;isize();++i) literals.push_back(unit_vector->at(i)->variable); } } return true; } bool Encoder::disable_up_to_term(const string& name, Version from, const UnitVector* unit_vector, const VersionVector* version_vector, LiteralVector& literals) { assert ((version_vector != NULL) ^ (unit_vector != NULL)); CONSTANT bool is_feature = version_vector != NULL; if (is_feature) { int pos; UINT count=0; for (pos=version_vector->size() - 1; pos >= 0 && (version_vector->at(pos) >= from); --pos) ++count; if (count==0) return false;//no versions greater or equal to from if (count > iv) {// use interval variable literals.push_back(interval_vars.get_disable_up(PackageVersion(name,version_vector->at(pos+1)))); } else { // use directly the variables of the feature for (UINT i=pos+1;isize();++i) { CONSTANT Version version=version_vector->at(i); Variable var=-1; bool f=variables.find_variable(PackageVersion (name, version), var); if (!f) assert(0); literals.push_back(neg(var)); } } } else { int pos; UINT count=0; for (pos=unit_vector->size() - 1; pos >= 0 && (unit_vector->at(pos)->version >= from); --pos) ++count; if (count==0) return false; //no versions greater or equal to from if (count > iv) { // use interval variable literals.push_back(interval_vars.get_disable_up(PackageVersion(name,unit_vector->at(pos+1)->version))); } else { // use directly the variables of the unit for (UINT i=pos+1;isize();++i) literals.push_back(neg(unit_vector->at(i)->variable)); } } return true; } bool Encoder::require_down_to_clause(const string& name, Version from, const UnitVector* unit_vector, const VersionVector* version_vector, LiteralVector& literals) { assert ((version_vector != NULL) ^ (unit_vector != NULL)); CONSTANT bool is_feature = version_vector != NULL; if (is_feature) { UINT pos; UINT count=0; for (pos=0; (pos < version_vector->size()) && (version_vector->at(pos) <= from); ++pos) ++count; if (count==0) return false;//no versions greater or equal to from assert(pos>0); if (count > iv) {// use interval variable literals.push_back(interval_vars.get_require_down(PackageVersion(name,version_vector->at(pos-1)))); } else { // use directly the variables of the feature for (int i=pos-1;i>=0;--i) { CONSTANT Version version=version_vector->at(i); Variable var=-1; bool f=variables.find_variable(PackageVersion (name, version), var); if (!f) assert(0); literals.push_back(var); } } } else { UINT pos; UINT count=0; for (pos=0; (pos < unit_vector->size()) && (unit_vector->at(pos)->version <= from); ++pos) ++count; if (count==0) return false; //no versions greater or equal to from assert(pos>0); if (count > iv) { // use interval variable literals.push_back(interval_vars.get_require_down(PackageVersion(name,unit_vector->at(pos-1)->version))); } else { // use directly the variables of the unit for (int i=pos-1;i>=0;--i) literals.push_back(unit_vector->at(i)->variable); } } return true; } bool Encoder::disable_down_to_term(const string& name, Version from, const UnitVector* unit_vector, const VersionVector* version_vector, LiteralVector& literals) { assert ((version_vector != NULL) ^ (unit_vector != NULL)); CONSTANT bool is_feature = version_vector != NULL; if (is_feature) { UINT pos; UINT count=0; for (pos=0; (pos < version_vector->size()) && (version_vector->at(pos) <= from); ++pos) ++count; if (count==0) return false;//no versions greater or equal to from assert(pos>0); if (count > iv) {// use interval variable literals.push_back(interval_vars.get_disable_down(PackageVersion(name,version_vector->at(pos-1)))); } else { // use directly the variables of the feature for (int i=pos-1;i>=0;--i) { CONSTANT Version version=version_vector->at(i); Variable var=-1; bool f=variables.find_variable(PackageVersion (name, version), var); if (!f) assert(0); literals.push_back(neg(var)); } } } else { UINT pos; UINT count=0; for (pos=0; (pos < unit_vector->size()) && (unit_vector->at(pos)->version <= from); ++pos) ++count; if (count==0) return false; //no versions greater or equal to from assert(pos>0); if (count > iv) { // use interval variable literals.push_back(interval_vars.get_disable_down(PackageVersion(name,unit_vector->at(pos-1)->version))); } else { // use directly the variables of the unit for (int i=pos-1;i>=0;--i) literals.push_back(neg(unit_vector->at(i)->variable)); } } return true; } void Encoder::request_to_clause (CONSTANT PackageVersions& pvs,LiteralVector& literals) { CONSTANT string& name = pvs.name(); UnitVector *unit_vector = NULL; VersionVector *version_vector = NULL; //Check whether it is a feature or not CONSTANT PackageToVersions::const_iterator fi = needed_feature_versions.find(name); CONSTANT bool is_feature = fi!=needed_feature_versions.end(); if (is_feature) { version_vector = fi->second; } else { //if it is not a feature, look up the pertaining installable units CONSTANT PackageUnits::const_iterator pi = needed_units.find(name); if (pi==needed_units.end()) return;//there is no feature or package of that name unit_vector = pi->second; } bool generated=false; #ifndef NDEBUG const size_t old_sz=literals.size(); #endif switch (pvs.op()) { case VERSIONS_NONE: generated = require_up_to_clause(name, 0, unit_vector, version_vector, literals); break; case VERSIONS_EQUALS: { CONSTANT PackageVersion pv=PackageVersion(name,pvs.version()); Variable variable; if (variables.find_variable(pv,variable)) { generated = true; literals.push_back(variable);// insert the requirement only if such version exists } } break; case VERSIONS_NOT_EQUALS: { const bool ug=require_up_to_clause(name, pvs.version()+1, unit_vector, version_vector, literals); const bool dg=require_down_to_clause(name, pvs.version()-1, unit_vector, version_vector, literals); generated=ug||dg; } break; case VERSIONS_GREATER_EQUALS: generated = require_up_to_clause(name, pvs.version(), unit_vector, version_vector, literals); break; case VERSIONS_GREATER: generated = require_up_to_clause(name, pvs.version()+1, unit_vector, version_vector, literals); break; case VERSIONS_LESS_EQUALS: generated = require_down_to_clause(name, pvs.version(), unit_vector, version_vector, literals); break; case VERSIONS_LESS: generated = require_down_to_clause(name, pvs.version()-1, unit_vector, version_vector, literals); } assert (literals.size() >= old_sz); assert (generated == (old_sz!=literals.size())); if (is_feature && !generated) { //if infinite version provided, use that as an option Variable variable=-1; if (variables.find_variable(PackageVersion(name,0), variable)) literals.push_back(variable);//if infinite version provided, use that as an option } } bool Encoder::solution() { CNF_OUT(cout << "p wcnf " << id_manager.top_id() << " " << solver.get_clause_count() << " " << (solver.get_soft_clauses_weight() + 1) << endl;) if (!should_solve) { cerr << "not solving" << endl; solver.dump(cout); return false; } else if (cs) { cerr << "not solving,cs" << endl; check_solution(); return false; } cerr << "# solving " << endl; double st = RUSAGE::read_cpu_time(); const bool has_solution = solver.solve(); double et = RUSAGE::read_cpu_time(); cerr << "# solving time:" << et << "--" << st << "s" << endl; print_solution(); return has_solution; } void Encoder::print_solution() { if (printing_started_or_finished) return; printing_started_or_finished = true; ostream& solution_file((psolution_file==NULL) ? cout : *psolution_file); cerr << "# sol printing (" << RUSAGE::read_cpu_time() << ")" << endl; const bool has_solution = solver.has_solution(); if (has_solution) { solution_file << "# beginning of solution from packup" << endl; CONSTANT IntVector& solution = solver.get_model(); OUT(cerr << "solution:"; printer.print_solution(solution, cerr, true); cerr << endl;) if (valuation) { print_valuation(cerr, solver.get_model()); cerr << endl; cerr << "MSUNCore min unsat: " << solver.get_min_unsat_cost() << endl; } FOR_EACH(PackageUnits::const_iterator, i, needed_units) { CONSTANT UnitVector &vs = *(i->second); FOR_EACH(UnitVector::const_iterator, vi, vs) { CONSTANT InstallableUnit& unit = **vi; CONSTANT Variable pvv = unit.variable; assert(pvv < solution.size()); if (solution[pvv] > 0) { solution_file << "package: " << unit.name << endl; solution_file << "version: " << unit.version << endl; solution_file << "installed: true" << endl; solution_file << endl; } } } solution_file << "# end of solution from packup" << endl; } else { cerr << "no solution" << endl; solution_file << "FAIL" << endl << "no solution (UNSAT)" << endl; } cerr.flush(); solution_file.flush(); cerr << "# sol printed" << endl; } void Encoder::conflict_all(CONSTANT Variable& pv, CONSTANT VariableSet& set) { FOR_EACH(VariableSet::const_iterator, index, set) { Variable v = *index; solver.output_binary_clause(neg(pv), neg(v)); } } void Encoder::add_providers(CONSTANT PackageVersion& feature, VariableSet& providers) { // Add all providers of the non-versioned feature CONSTANT FeatureToUnits::const_iterator iii = feature_units.find(feature); if (iii != feature_units.end()) { CONSTANT UnitVector& units = *(iii->second); FOR_EACH(UnitVector::const_iterator, ui, units) { InstallableUnit *unit = *ui; if (unit->needed) { Variable v=-1; const bool f = variables.find_variable(PackageVersion(unit->name, unit->version), v); if (!f) assert(0); providers.insert(v); } } } } void Encoder::add_providers(CONSTANT PackageVersions& features, VariableSet& providers) { // Add all providers of the non-versioned feature add_providers(PackageVersion(features.name(), 0), providers); // Look at all the features corresponding to {@code features} and had their providers to the set PackageToVersions::const_iterator i = needed_feature_versions.find(features.name()); if (i == needed_feature_versions.end()) return; CONSTANT VersionVector& vs = *(i->second); FOR_EACH(VersionVector::const_iterator, index, vs) { CONSTANT Version version = *index; if (evaluate(version, features.op(), features.version())) { add_providers(PackageVersion(features.name(), version), providers); } } } void to_versions(CONSTANT UnitVector& units, VersionVector& versions) { FOR_EACH(UnitVector::const_iterator, i, units) versions.push_back((*i)->version); } void Encoder::process_interval_variables () { OUT (cerr << "Interval variables[" << endl;) CONSTANT PackageToVersions& ru=interval_vars.get_require_up (); CONSTANT PackageToVersions& rd=interval_vars.get_require_down(); CONSTANT PackageToVersions& du=interval_vars.get_disable_up(); CONSTANT PackageToVersions& dd=interval_vars.get_disable_down(); CONSTANT VersionVector empty_vector; FOR_EACH (PackageToVersions::const_iterator, index, ru) { CONSTANT string name = index->first; VersionVector& intervals=*(index->second); sort (intervals.begin(),intervals.end()); OUT ( cerr << "intervals " << name; FOR_EACH (VersionVector::const_iterator,i,intervals) cerr << " " << *i; cerr<second) : empty_vector ; process_require_up(name, intervals, vers, true); } else { PackageUnits::const_iterator i = needed_units.find(name); assert (i!= needed_units.end ()); VersionVector versions; to_versions(*(i->second), versions); process_require_up(name, intervals, versions, false); } } FOR_EACH (PackageToVersions::const_iterator, index, rd) { CONSTANT string name = index->first; VersionVector& intervals=*(index->second); sort (intervals.begin(),intervals.end()); OUT ( cerr << "intervals " << name; FOR_EACH (VersionVector::const_iterator,i,intervals) cerr << " " << *i; cerr<second) : empty_vector ; process_require_down(name, intervals, vers, true); } else { PackageUnits::const_iterator i = needed_units.find(name); VersionVector versions; if (i!=needed_units.end ()) to_versions(*(i->second), versions); process_require_down(name, intervals, versions, false); } } FOR_EACH (PackageToVersions::const_iterator, index, du) { CONSTANT string name = index->first; VersionVector& intervals=*(index->second); sort (intervals.begin(),intervals.end()); OUT ( cerr << "intervals " << name; FOR_EACH (VersionVector::const_iterator,i,intervals) cerr << " " << *i; cerr<second) : empty_vector ; process_disable_up(name, intervals, vers, true); } else { PackageUnits::const_iterator i = needed_units.find(name); assert (i!= needed_units.end ()); VersionVector versions; if (i!=needed_units.end ()) to_versions(*(i->second), versions); process_disable_up(name, intervals, versions, false); } } FOR_EACH (PackageToVersions::const_iterator, index, dd) { CONSTANT string name = index->first; VersionVector& intervals=*(index->second); sort (intervals.begin(),intervals.end()); OUT ( cerr << "intervals " << name; FOR_EACH (VersionVector::const_iterator,i,intervals) cerr << " " << *i; cerr<second) : empty_vector ; process_disable_down(name, intervals, vers, true); } else { PackageUnits::const_iterator i = needed_units.find(name); assert (i!= needed_units.end ()); VersionVector versions; if (i!=needed_units.end ()) to_versions(*(i->second), versions); process_disable_down(name, intervals, versions, false); } } if (opt_edges) encode_edges(); OUT (cerr << "]" << endl;) } void Encoder::encode_edges() { CONSTANT PackageToVersions& ru=interval_vars.get_require_up (); CONSTANT PackageToVersions& rd=interval_vars.get_require_down(); CONSTANT PackageToVersions& du=interval_vars.get_disable_up(); CONSTANT PackageToVersions& dd=interval_vars.get_disable_down(); FOR_EACH (PackageToVersions::const_iterator, index, ru) { CONSTANT string name = index->first; assert((index->second)!=NULL); VersionVector& ru_intervals=*(index->second); PackageToVersions::const_iterator i=du.find(name); if (i == du.end()) continue; assert((i->second)!=NULL); VersionVector& du_intervals =*(i->second); UINT rui=0; UINT dui=0; while ((rui < ru_intervals.size()) && (duifirst; assert((index->second)!=NULL); VersionVector& rd_intervals=*(index->second); PackageToVersions::const_iterator i=dd.find(name); if (i == dd.end()) continue; assert((i->second)!=NULL); VersionVector& dd_intervals =*(i->second); int rdi=rd_intervals.size()-1; int ddi=dd_intervals.size ()-1; while ((rdi>=0) && (ddi>=0)) { if (rd_intervals[rdi]>dd_intervals[ddi]) --rdi; else { solver.output_binary_clause(neg(interval_vars.get_require_down(PackageVersion(name,rd_intervals[rdi]))), neg(interval_vars.get_disable_down(PackageVersion(name,dd_intervals[ddi])))); --ddi; } } } // FOR_EACH (PackageToVersions::const_iterator, index, ru) // { // CONSTANT string name = index->first; // assert((index->second)!=NULL); // VersionVector& ru_intervals=*(index->second); // } } void Encoder::process_require_down(const string& package, const VersionVector& intervals, const VersionVector& package_versions, bool is_feature) { if (intervals.empty()) return;//No intervals to process, nothing to do const UINT vsz=package_versions.size(); const UINT isz=intervals.size(); int current_interval_index=isz-1; int current_version_index=vsz-1; // find first package version that is within the first interval within an interval for ( ;current_version_index >= 0; --current_version_index) { if (intervals[current_interval_index]>=package_versions[current_version_index]) break; } LiteralVector literals; //Initialize literals with intervals[0] => ... { Variable v=interval_vars.get_require_down(PackageVersion(package,intervals[current_interval_index])); literals.push_back(neg(v)); } int next_interval_index= current_interval_index>0 ? current_interval_index-1 : -1; while (current_interval_index>=0) { // Flush the current literals IF // all package versions have been processed // OR the current package version belongs into the next interval while (current_version_index<0 || (next_interval_index>=0 && intervals[next_interval_index]>=package_versions[current_version_index]) ) { Variable next_v=0; if (next_interval_index>=0) {// link to the next interval (if there is such) next_v=interval_vars.get_require_down(PackageVersion(package,intervals[next_interval_index])); literals.push_back(next_v); } else if (is_feature) { // PackageVersion (package,0) has already encoutered, if present // Unversioned feature makes everything true //Variable infinite_var; // if (variables.find_variable(PackageVersion (package,0), infinite_var)) // literals.push_back(infinite_var); } solver.output_clause(literals); // flush current clause literals.clear(); // move to the next interval current_interval_index=next_interval_index; next_interval_index=current_interval_index>0 ? current_interval_index-1 : -1; if (current_interval_index>=0) { literals.push_back(neg(next_v)); // Initialize literals for the next interval } else { assert (current_version_index<0); return; } } // Add current package version to the current interval and move to the next package version if (current_interval_index>=0 && current_version_index>=0) { Variable v=get_package_version_variable( PackageVersion (package,package_versions[current_version_index])); literals.push_back(v); --current_version_index; } } } void Encoder::process_require_up(const string& package, const VersionVector& intervals, const VersionVector& package_versions, bool is_feature/*=false*/) { if (intervals.empty()) return;//No intervals to process, nothing to do UINT current_interval_index=0; UINT current_version_index=0; const UINT vsz=package_versions.size(); // find first package version that is within the first interval within an interval for ( ;current_version_index < vsz; ++current_version_index) { if (package_versions[current_version_index]>=intervals[current_interval_index]) break; } const UINT isz=intervals.size(); LiteralVector literals; //Initialize literals with intervals[0] => ... { Variable v=interval_vars.get_require_up(PackageVersion(package,intervals[current_interval_index])); literals.push_back(neg(v)); } UINT next_interval_index= (current_interval_index+1)=vsz || (next_interval_index=intervals[next_interval_index]) ) { Variable next_v=0; if (next_interval_index=vsz); return; } } // Add current package version to the current interval and move to the next package version if (current_interval_index=intervals[current_interval_index]) break; } const UINT isz=intervals.size(); UINT next_interval_index= (current_interval_index+1)=vsz || (next_interval_index=intervals[next_interval_index]) ) { Variable next_v; if (next_interval_index=isz) { assert (current_version_index>=vsz); return; } } // Add current package version to the current interval and move to the next package version if (current_interval_index=0; --current_version_index) { if (intervals[current_interval_index]>=package_versions[current_version_index]) break; } int next_interval_index= (current_interval_index-1)>=0 ? current_interval_index-1 : -1; Variable current_interval_variable = interval_vars.get_disable_down(PackageVersion(package,intervals[current_interval_index])); while (current_interval_index>=0) { // Moved to next interval IF // all package versions have been processed // OR the current package version belongs into the next interval while (current_version_index<0 || (next_interval_index>=0 && intervals[next_interval_index]>=package_versions[current_version_index]) ) { Variable next_v; if (next_interval_index>=0) {// link to the next interval (if there is such) next_v=interval_vars.get_disable_down(PackageVersion(package,intervals[next_interval_index])); solver.output_binary_clause(neg(current_interval_variable), next_v); } else if (is_feature){ // unversioned feature must be disabled in any case Variable infinite_var=-1; if (variables.find_variable(PackageVersion (package,0), infinite_var)) solver.output_binary_clause(neg(current_interval_variable), neg(infinite_var)); } // move to the next interval current_interval_index=next_interval_index; current_interval_variable=next_v; next_interval_index=(current_interval_index-1)>=0 ? current_interval_index-1 : -1; if (current_interval_index<0) { return; } } // Add current package version to the current interval and move to the next package version if (current_interval_index>=0 && current_version_index>=0) { Variable v=get_package_version_variable( PackageVersion (package,package_versions[current_version_index])); solver.output_binary_clause(neg(current_interval_variable), neg(v)); --current_version_index; } } } int Encoder::new_score(IntVector& model) { int new_packages = 0; FOR_EACH(PackageUnits::const_iterator, index, read_units) { UnitVector &unit_vector = *(index->second); bool was_any_installed = false; bool is_any_installed = false; FOR_EACH(UnitVector::iterator, unit_index, unit_vector) { InstallableUnit *unit = *unit_index; CONSTANT bool installed = is_installed(unit, model); if (unit->installed) was_any_installed = true; if (installed) is_any_installed = true; } if (!was_any_installed && is_any_installed) ++new_packages; } return new_packages; } int Encoder::removed_score(IntVector& model) { int removed_packages = 0; FOR_EACH(PackageUnits::const_iterator,index,read_units) { UnitVector &unit_vector=*(index->second); bool was_any_installed = false; bool is_any_installed = false; FOR_EACH (UnitVector::iterator, unit_index, unit_vector) { InstallableUnit *unit =*unit_index; CONSTANT bool is_installed = (unit->needed && (model[unit->variable]>0)); if (unit->installed) was_any_installed = true; if (is_installed) is_any_installed = true; } if (was_any_installed && !is_any_installed) --removed_packages; } return removed_packages; } int Encoder::notuptodate_score(IntVector& model) { int violated = 0; FOR_EACH(PackageUnits::const_iterator,index,read_units) { UnitVector &unit_vector=*(index->second); bool is_any_installed = false; bool latest_installed = false; Version latest_version = 0; FOR_EACH (UnitVector::iterator, unit_index, unit_vector) { CONSTANT InstallableUnit *unit = *unit_index; CONSTANT bool installed = is_installed(unit, model); if (unit->version > latest_version) { latest_installed = installed; latest_version = unit->version; } if (installed) is_any_installed = true; } if (is_any_installed && !latest_installed) { OUT(cerr << "nu: " << index->first << endl;) --violated; } } return violated; } int Encoder::changed_score(IntVector& model) { int changed_version_sets = 0; FOR_EACH(PackageUnits::const_iterator,index,read_units) { UnitVector &unit_vector=*(index->second); bool version_set_changed = false; FOR_EACH (UnitVector::iterator, unit_index, unit_vector) { InstallableUnit *unit =*unit_index; CONSTANT bool is_installed = (unit->needed && (model[unit->variable]>0)); if ((unit->installed) != is_installed) version_set_changed=true; } if (version_set_changed) --changed_version_sets; } return changed_version_sets; } int Encoder::recommends_score(IntVector& model) { int score = 0; FOR_EACH(PackageUnits::const_iterator,index,read_units) { const UnitVector &unit_vector=*(index->second); FOR_EACH (UnitVector::const_iterator, unit_index, unit_vector) { CONSTANT InstallableUnit *unit =*unit_index; if (!is_installed(unit, model)) continue;//ignore things that are not installed CONSTANT PackageVersionsCNF& cnf = unit->recommends_cnf; FOR_EACH (PackageVersionsCNF::const_iterator, clause_index, cnf) { CONSTANT PackageVersionsList& clause = **clause_index; bool sat = false; FOR_EACH (PackageVersionsList::const_iterator,literal_index, clause) { PackageVersions literal = *literal_index; if (sat || is_any_installed(literal, model)) sat = true; } if (!sat) { OUT (cerr << "unsatisfied recommends: ["<< unit->name <<":" << unit->version<<"]"; collection_printing::print(clause,cerr); cerr<needed && (model[unit->variable]>0); } bool Encoder::is_any_installed_feature(CONSTANT string &feature_name, Operator version_operator, Version operand, IntVector& model) { // Process unversioned providers if (is_installed_feature(PackageVersion(feature_name,0))) return true; CONSTANT FeatureToVersions::const_iterator i = feature_versions.find(feature_name); if (i==feature_versions.end()) return false; CONSTANT VersionSet &vs=*(i->second); FOR_EACH (VersionSet::const_iterator,vi,vs) { CONSTANT Version version=*vi; if (evaluate(version, version_operator, operand)) if (is_installed_feature(PackageVersion(feature_name,version))) return true; } return false; } bool Encoder::is_any_installed(PackageVersions& package, IntVector& model) { if (is_feature (package.name())) return is_any_installed_feature(package.name(), package.op(), package.version(), model); const PackageUnits::const_iterator i=needed_units.find(package.name()); if (i==needed_units.end()) return false; UnitVector& unit_vector = *(i->second); FOR_EACH (UnitVector::const_iterator, unit_index, unit_vector) { InstallableUnit* unit =*unit_index; if (evaluate(unit->version, package.op(), package.version())) if (is_installed (unit, model)) return true; } return false; } bool Encoder::is_installed_feature(const PackageVersion& feature, IntVector& model) { assert (is_feature(feature.name())); CONSTANT FeatureToUnits::const_iterator providers_index = feature_units.find(feature); if (providers_index==feature_units.end()) { assert(false); return false; } CONSTANT UnitVector& providers =*(providers_index->second); FOR_EACH (UnitVector::const_iterator, provider_index, providers) { CONSTANT InstallableUnit* provider =*provider_index; if (is_installed(provider,model)) return true; } return false; } void Encoder::trendy_score(IntVector& model) { cerr << "trendy score[" << removed_score(model) << "," << notuptodate_score(model) << "," << recommends_score(model) << "," << new_score(model) << "]" << endl; } void Encoder::paranoid_score(IntVector& model) { const int removed_packages = recommends_score(model); const int changed_version_sets = changed_score(model); cerr << "score[" << removed_packages << "," << changed_version_sets << "]" << endl; } void Encoder::print_valuation(ostream& output,IntVector& model) { output <<"removed(" << removed_score(model) << ")," <<"not up-to-date (" << notuptodate_score(model) << ")," <<"recommends (" << recommends_score(model) << ")," <<"new (" << new_score(model) <<")"; } void Encoder::check_solution() { cerr << "cheking solution" <second); FOR_EACH(UnitVector::const_iterator,vi,uv) { CONSTANT InstallableUnit *unit = *vi; const Version v=unit->version; PackageVersion pv=PackageVersion(unit->name, v); const bool c=(stc->find(pv) != stc->end()); // cerr << pv.to_string() << ( c ? " installed" : " not installed" ) << endl; if (!c) solver.output_unary_clause(neg(unit->variable)); } } FOR_EACH(PackageVersionSet::const_iterator, i, (*stc)) { const PackageVersion &pv=*i; Variable var; bool f=variables.find_variable(pv,var); if (f) { solver.output_unary_clause(var); } else { cerr << "using sliced pck: " << pv.to_string() << endl; } } bool has_solution = solver.solve(); if (has_solution) { cerr << "is sol" << endl; cerr << "MSUNCore min unsat: " << solver.get_min_unsat_cost() << endl; } else { cerr << "is not sol" << endl; } } packup-0.6/Encoder.hh0000644000175000010010000002706611573000733013661 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: Encoder.hh * Author: mikolas * * Created on September 26, 2010, 2:01 PM * Copyright (C) 2011, Mikolas Janota */ #ifndef ENCODER_HH #define ENCODER_HH #include "common_types.hh" #include "SolverWrapperTypes.hh" #include "SolutionReader.hh" #include "InstallableUnit.hh" #include "EncoderTypes.hh" #include "IntervalVariables.hh" #include "PackageVersionVariables.hh" #include "SolverWrapper.hh" #include "Printer.hh" #include "NotRemoved.hh" using namespace version_operators; class Encoder { public: Encoder(SolverWrapper& solver,IDManager& id_manager); virtual ~Encoder(); void add_unit (InstallableUnit* unit); void add_install (CONSTANT PackageVersionsList& list); void add_upgrade (CONSTANT PackageVersionsList& list); void add_remove (CONSTANT PackageVersionsList& list); void set_criterion(Criterion optimization_criterion); void set_lexicographic(CONSTANT vector& lexicographic_ordering); void set_solution_file(ostream* file) {psolution_file = file;} inline CONSTANT vector& get_lexicographic() const {return lexicographic;} inline void disable_solving () {should_solve=false;} inline void set_iv(UINT piv) {iv=piv;} inline void set_opt_edges(int v=1) {opt_edges=v;} inline void set_opt_not_removed(bool v=true) {opt_not_removed=v;} inline bool get_opt_edges(bool v=true) const {return opt_edges;} inline bool get_opt_not_removed(bool v=true) const {return opt_not_removed;} inline void enable_valuation() {valuation = true;} void encode(); bool solution(); void print_solution(); SolverWrapper& get_solver_wrapper(); UINT unit_count; UINT cut_off; #ifdef MAPPING inline unordered_map& get_variable_names() {return variable_names;} inline ofstream& get_mapping() {return mapping;} #endif private: vector lexicographic; ostream* psolution_file; bool should_solve; SolverWrapper& solver; IDManager& id_manager; #ifdef MAPPING VariableToName variable_names;// Names of variables for debugging purposes. ofstream mapping; // file for recording mapping from variable numbers to their names #endif PackageVersionVariables variables; IntervalVariables interval_vars; #ifdef CONV_DBG Printer printer; #endif bool valuation; int opt_edges; // add redundancy implications between interval variables bool process_recommends; // flag whether recommends should be taken into account (currently used only for the trendy criterion) UINT iv; bool printing_started_or_finished; vector recommends_clauses_pointers; PackageUnits read_units; // installable PackageUnits needed_units;//installable units after slicing FeatureToUnits feature_units; //units that provide a given feature FeatureToVersions feature_versions;//versions of a given feature PackageToVersions needed_feature_versions;//versions of a feature after slicing PackageVersionSet required_features;//not needed, replace with needed_feature_versions TODO!! PackageVersionsSet install; // entities that must be installed PackageVersionsList upgrade; // upgrade requirement PackageVersionsList remove; // remove requirement bool opt_not_removed; // flag whether to use optimization "not removed" NotRemoved not_removed; // a set of packages that will certainly be in the final solution, valid only if opt_not_removed is on bool is_any_installed_package(const UnitVector& unit_vector); bool is_installed_feature (CONSTANT PackageVersion& feature); bool find_latest_installed_version_in_original_problem (CONSTANT string &name,Version& version); bool latest_installed_feature_version (CONSTANT string &name,Version& version); bool latest_installed_package_version (CONSTANT string &name,Version& version); inline bool is_feature (CONSTANT string &name) {return feature_versions.find(name) != feature_versions.end();} void handle_keep (InstallableUnit* unit); void handle_provides (InstallableUnit* unit); void refine_upgrade_request (); void encode_lexicographic(); void encode_new(XLINT& total_weight, bool maximize); void encode_unmet_recommends(XLINT& total_weight,bool maximize); void encode_not_up_to_date(XLINT& total_weight,bool maximize); void encode_removed(XLINT& total_weight,bool maximize); void encode_changed(XLINT& total_weight,bool maximize); XLINT get_top(CONSTANT Objective& objective) const; XLINT get_top(CONSTANT vector& lexicographic) const; void encode_provides (); void encode_keep (); void encode_upgrade (); void atmost_1 (CONSTANT string& package_name, Version from); void atmost_1_feature (CONSTANT string& package_name, Version from); void encode_request_remove(); void encode (CONSTANT InstallableUnit* unit); void encode_conflicts (CONSTANT InstallableUnit* unit); void encode_depends (CONSTANT InstallableUnit* unit); void encode_recommends (CONSTANT InstallableUnit* unit); void encode_package_self_conflict (CONSTANT InstallableUnit* unit, CONSTANT PackageVersions& pvs); void encode_not_self_conflict (CONSTANT InstallableUnit* unit, CONSTANT PackageVersions& pvs); void slice (); void slice_changed (); void need (CONSTANT PackageVersions& versions); void need_packages(CONSTANT string &package_name, Operator version_operator, Version operand); void need_features(CONSTANT string &feature_name, Operator version_operator, Version operand); void need (InstallableUnit* unit); void need_latest (CONSTANT string& package_name); void need (PackageVersionsCNF cnf); void need_feature(CONSTANT PackageVersion &feature); void request_to_clause (CONSTANT PackageVersions& pvs, LiteralVector& literals); void disable_to_term (CONSTANT PackageVersions& pvs, LiteralVector& term); bool require_up_to_clause (CONSTANT string& name, Version from, const UnitVector *unit_vector, const VersionVector *version_vector, LiteralVector& literals); bool require_down_to_clause (CONSTANT string& name, Version from, const UnitVector *unit_vector, const VersionVector *version_vector, LiteralVector& literals); bool disable_up_to_term (CONSTANT string& name, Version from, const UnitVector *unit_vector, const VersionVector *version_vector, LiteralVector& literals); bool disable_down_to_term (CONSTANT string& name, Version from, const UnitVector *unit_vector, const VersionVector *version_vector, LiteralVector& literals); void requests_to_clause (CONSTANT VersionsList::const_iterator begin, CONSTANT VersionsList::const_iterator end, LiteralVector& literals); inline Variable new_variable() { return id_manager.new_id(); } void conflict_all (CONSTANT Variable& pv, CONSTANT VariableSet& set); void add_providers(CONSTANT PackageVersions& features, VariableSet& providers); void add_providers(CONSTANT PackageVersion& feature, VariableSet& providers); inline Variable get_package_version_variable(CONSTANT PackageVersion& pv) { Variable return_value=0; CONSTANT bool found = variables.find_variable(pv, return_value); #ifdef CONV_DBG if (!found) { cerr << "no variable for: " << pv.to_string() << endl;} #endif if (!found) assert(0);//getting rid of the compiler warning return return_value; } //global processing (for whole package repository) void process_interval_variables (); void process_require_up(const string& package, const VersionVector& intervals, const VersionVector& package_versions, bool is_feature=false); void process_require_down(const string& package, const VersionVector& intervals, const VersionVector& package_versions, bool is_feature=false); void process_disable_up(const string& package, const VersionVector& intervals, const VersionVector& package_versions, bool is_feature=false); void process_disable_down(const string& package, const VersionVector& intervals, const VersionVector& package_versions, bool is_feature=false); void encode_edges(); void assert_not_removed(); void paranoid_score (IntVector& model); void trendy_score(IntVector& model); int removed_score(IntVector& model); int new_score(IntVector& model); int changed_score(IntVector& model); int notuptodate_score(IntVector& model); int recommends_score (IntVector& model); bool is_installed (const InstallableUnit* unit,IntVector& model); bool is_any_installed (PackageVersions& package,IntVector& model); bool is_any_installed_feature(CONSTANT string &feature_name, Operator version_operator, Version operand, IntVector& model); bool is_installed_feature(const PackageVersion& feature, IntVector& model); bool _process_not_uptodate; inline bool process_not_uptodate() {return _process_not_uptodate;} enum CT { CT_MIN, CT_MAX, CT_NO }; CT gt(OBJECTIVE_FUNCTION o,vector& lex) { FOR_EACH(vector::const_iterator,oi,lex) { if (oi->first==o) return oi->second ? CT_MAX : CT_MIN; } return CT_NO; } void print_valuation(ostream& output,IntVector& model); public: bool cs; PackageVersionSet* stc; void check_solution(); }; #endif /* ENCODER_HH */ packup-0.6/EncoderTypes.cc0000644000175000010010000000526711573000733014673 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* Copyright (C) 2011, Mikolas Janota */ #include "EncoderTypes.hh" #include "collections.hh" void record_version (PackageToVersions& vvs, const string& name, Version version) { PackageToVersions::iterator i=vvs.find(name); VersionVector* vs; if (i == vvs.end ()) { vs=new VersionVector(); vvs [name]=vs; } else { vs=i->second; } vs->push_back(version); } void record_version (FeatureToVersions& vvs, const string& name, Version version) { FeatureToVersions::iterator i=vvs.find(name); VersionSet* vs; if (i == vvs.end ()) { vs=new VersionSet(); vvs[name]=vs; } else { vs=i->second; } vs->insert(version); } void record_unit(FeatureToUnits& ftu, CONSTANT PackageVersion& feature, InstallableUnit *unit) { FeatureToUnits::iterator fi=ftu.find(feature); UnitVector *vector; if (fi==ftu.end()) { vector = new UnitVector (); ftu[feature]=vector; } else { vector = fi->second; } vector->push_back(unit); } void record_unit (PackageUnits& pu, InstallableUnit *unit) { CONSTANT string &package_name=unit->name; PackageUnits::const_iterator i = pu.find (package_name); UnitVector *vector; if (i!=pu.end()) vector = i->second; else { vector = new UnitVector(); pu[package_name]=vector; } vector->push_back(unit); } packup-0.6/EncoderTypes.hh0000644000175000010010000000431011573000733014671 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: EncoderTypes.hh * Author: mikolas * * Created on September 26, 2010, 7:35 PM * Copyright (C) 2011, Mikolas Janota */ #ifndef ENCODERTYPES_HH #define ENCODERTYPES_HH #include "collections.hh" #include "InstallableUnit.hh" typedef vector UnitVector; typedef vector UnitConstantVector; typedef unordered_map PackageUnits; typedef unordered_map PackageConstantUnits; typedef unordered_map FeatureToUnits; void record_version (PackageToVersions& vvs, const string& name, Version version); void record_version (FeatureToVersions& vvs, const string& name, Version version); void record_unit(FeatureToUnits& ftu, CONSTANT PackageVersion& feature, InstallableUnit *unit); void record_unit (PackageUnits& pu, InstallableUnit *unit); #endif /* ENCODERTYPES_HH */ packup-0.6/err_utils.hh0000644000175000010010000000423711573000740014303 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ //jpms:bc /*----------------------------------------------------------------------------*\ * File: err_utils.hh * * Description: Utilities to handle errors. * * Author: jpms * * Copyright (c) 2010, Joao Marques-Silva \*----------------------------------------------------------------------------*/ //jpms:ec #ifndef _ERR_UTILS_H #define _ERR_UTILS_H 1 #include using namespace std; template void tool_abort(S msg) { std::cout << "ERROR: " << msg << std::endl; std::cout.flush(); exit(5); } template void tool_warn(S msg) { std::cout << "WARN: " << msg << std::endl; std::cout.flush(); } template void tool_info(S msg) { std::cout << "INFO: " << msg << std::endl; std::cout.flush(); } #endif /* _ERR_UTILS_H */ /*----------------------------------------------------------------------------*/ packup-0.6/ExternalWrapper.cc0000644000175000010010000003425311573000733015407 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: ExternalWrapper.cc * Author: mikolas * * Created on April 19, 2011, 8:33 AM * Copyright (C) 2011, Mikolas Janota */ #include #include #include #include "ExternalWrapper.hh" #include "fmtutils.hh" using std::sort; ExternalWrapper::ExternalWrapper(IDManager& id_manager) :min_cost(LONG_MAX) ,solution_value (-1) ,_id_manager(id_manager) ,solver_command("minisat+ -cs -ansi") ,multiplication_string("*") ,temporary_directory("/tmp") ,leave_temporary_files(false) ,iterative(true) {} void clause_to_constraint(BasicClause& clause, vector& constraint); bool ExternalWrapper::solve() { stamp = time(NULL); // set up datastructures const size_t function_count = weights.size(); sorted_weights.insert(sorted_weights.end (),weights.begin(), weights.end ()); sort(sorted_weights.begin(), sorted_weights.end(),greater()); solution_weights.resize(function_count,-1); functions.resize(function_count); clause_split.resize(function_count); split(); // split clauses into the classes according to weight min_cost=get_top(); return iterative ? solve_it() : solve_max(); } bool ExternalWrapper::solve_it() { const size_t function_count = weights.size(); // generate hard clauses size_t i=constraints.size(); constraints.resize(i+hard_clauses.size()); FOR_EACH(cset_iterator, clause_index, hard_clauses) { vector& constraint = constraints[i++]; clause_to_constraint(**clause_index, constraint); } bool solution_found = false; if (function_count==0) { vector dummy; external_solve(dummy, constraints, model); solution_found = !model.empty(); } //solve one by one for (size_t function_index = 0;function_index < function_count ;++function_index) { solution_found = solve(function_index); if (!solution_found) break; } return solution_found; } bool ExternalWrapper::has_solution() {return !model.empty();} bool ExternalWrapper::solve(const size_t function_index) { cerr << "# starting function level " << function_index << endl; // relaxation of current function vector& relaxation_literals = functions[function_index]; const BasicClauseVector& clauses=clause_split[function_index]; FOR_EACH(BasicClauseVector::const_iterator,clause_index,clauses) { BasicClause& clause = **clause_index; if (clause.size()==1) { relaxation_literals.push_back(-(*(clause.begin()))); } else { vector constraint; const LINT relaxation_variable = _id_manager.new_id(); relaxation_literals.push_back(relaxation_variable); constraint.push_back(relaxation_variable); clause_to_constraint(clause, constraint); constraints.push_back(constraint); } } // call external solver vector temporary_model; external_solve(relaxation_literals, constraints, temporary_model); if (temporary_model.empty()) return false; // stop here // copy solution to the output model model.clear(); model.insert (model.end(), temporary_model.begin(), temporary_model.end()); //constrain the following computation based on the score LINT score = 0; FOR_EACH(vector::const_iterator,literal_index,relaxation_literals) { const LINT literal = *literal_index; const bool fsign = literal>0; const size_t var = fsign ? (size_t)literal : (size_t)(-literal); const bool msign = model[var] > 0; if (!msign) continue; if (fsign) ++score; else --score; } solution_weights[function_index] = score; const vector& cs = functions[function_index]; if (cs.size() != 0) { vector c; FOR_EACH(vector::const_iterator, literal_index, cs) c.push_back(-(*literal_index)); c.push_back(-score); constraints.push_back(c); } //min_cost = abs(score); //todo return model.size() != 0; // ? -1 : score; } int ExternalWrapper::external_solve(const vector& function, vector< vector >& constraints ,IntVector& tmp_model) { stringstream strstr; strstr<::const_iterator, literal_index, function) { const LINT literal = *literal_index; const bool sign = literal > 0; output << " " << (sign ? "+1" : "-1") << multiplication_string << "x" << (sign ? literal : -literal); } output << ";" << endl; } FOR_EACH(vector< vector >::const_iterator,constraint_index,constraints) { print_constraint(*constraint_index, output) << endl;// print constraints } output.close(); // call the solver stringstream scommand; const string output_filename = input_file_name + ".out"; scommand << solver_command << " " << input_file_name << " >" << output_filename; const string command = scommand.str(); const int retv = system (command.c_str()); cerr << "# " << "external command finished with exit value " << retv << endl; gzFile of=gzopen(output_filename.c_str(), "rb"); assert(of!=NULL);//TODO StreamBuffer r(of); bool sat=false; tmp_model.resize((size_t)(_id_manager.top_id()+1),0); while (*r != EOF) { if (*r != 'v') {// ignore all the other lines skipLine(r); } else { sat=true; ++r; // skip 'v' while ( (*r != '\n') && (*r != EOF) && (*r != '\r') ) { skipTrueWhitespace(r); const bool sign = (*r) != '-'; if ((*r == '+') || (*r == '-')) ++r; if ((*r == 'x')) ++r; if (*r < '0' || *r > '9') break; const LINT l = parseInt(r); // if ( model.size()<=(size_t)l ) //cerr << "# " << l << " " << (sign ? l : -l) << endl; assert(tmp_model.size()>(size_t)l); tmp_model[l] = (sign ? l : -l); } assert (*r=='\n'); ++r; // skip '\n' } } if (!sat) tmp_model.clear(); if (!leave_temporary_files) { remove(input_file_name.c_str()); remove(output_filename.c_str()); } return retv; } bool ExternalWrapper::solve_max() { // call external solver vector temporary_model; external_solve_max(temporary_model); if (temporary_model.empty()) return false; // stop here // copy solution to the output model model.clear(); model.insert (model.end(), temporary_model.begin(), temporary_model.end()); //min_cost = abs(score); //todo return model.size() != 0; // ? -1 : score; } int ExternalWrapper::external_solve_max(IntVector& tmp_model) { stringstream strstr; strstr<" << output_filename; const string command = scommand.str(); const int retv = system (command.c_str()); cerr << "# " << "external command finished with exit value " << retv << endl; gzFile of=gzopen(output_filename.c_str(), "rb"); assert(of!=NULL);//TODO StreamBuffer r(of); bool sat=false; tmp_model.resize((size_t)(_id_manager.top_id()+1),0); while (*r != EOF) { if (*r != 'v') {// ignore all the other lines skipLine(r); } else { sat=true; ++r; // skip 'v' while ( (*r != '\n') && (*r != EOF) && (*r != '\r') ) { skipTrueWhitespace(r); const bool sign = (*r) != '-'; if ((*r == '+') || (*r == '-')) ++r; if (*r < '0' || *r > '9') break; const LINT l = parseInt(r); assert(tmp_model.size()>(size_t)l); tmp_model[l] = (sign ? l : -l); } assert (*r=='\n'); ++r; // skip '\n' } } if (!sat) tmp_model.clear(); if (!leave_temporary_files) { remove(input_file_name.c_str()); remove(output_filename.c_str()); } return retv; } void ExternalWrapper::split() { FOR_EACH(cset_iterator, clause_index, clause_set) { BasicClause* clause = *clause_index; if (clause_set.is_cl_hard(clause)) { hard_clauses.attach_clause(clause); } else { XLINT total_weight = clause_set.get_cl_weight(clause); FOR_EACH(WeightSet::const_iterator,weight_index, weights) { // split into duplicate clauses const XLINT weight = *weight_index; const XLINT k = total_weight/weight; total_weight %= weight; for (XLINT i = 0; i& constraint,ostream& output) { const size_t sz = constraint.size(); assert(sz>=2); for (size_t index=0; index0; output << (sign ? "+1" : "-1") << multiplication_string << "x" << (sign ? literal : -literal) << " "; } output << " >= " << constraint[sz-1] << ";"; return output; } void clause_to_constraint(BasicClause& clause, vector& constraint) { LINT rh=1; FOR_EACH(Literator, literal_index, clause) { const LINT literal = *literal_index; constraint.push_back(literal); if (literal<0) --rh; } constraint.push_back(rh); } size_t ExternalWrapper::get_weight_index(XLINT weight) const { for (size_t i=0; i::const_iterator, i, clause_split) { c+=i->size(); } out << "p wcnf" << " " << _id_manager.top_id() << " " << c << " " << clause_set.get_top() << endl; FOR_EACH(cset_iterator, clause_index, hard_clauses) { BasicClause& clause = **clause_index; out << get_top() << " " << clause << endl; } for (size_t i=0;i. * \******************************************************************************/ /* * File: ExternalWrapper.hh * Author: mikolas * * Created on April 19, 2011, 8:33 AM * Copyright (C) 2011, Mikolas Janota */ #ifndef EXTERNALWRAPPER_HH #define EXTERNALWRAPPER_HH #include #include "common_types.hh" #include "id_manager.hh" #include "basic_clset.hh" #include "SolverWrapperBase.hh" class ExternalWrapper : public SolverWrapperBase { public: ExternalWrapper(IDManager& id_manager); ~ExternalWrapper() {}; virtual void init(); virtual XLINT get_top(); virtual void set_top(XLINT top); virtual bool solve(); virtual IntVector& get_model() { return model; } virtual XLINT get_min_unsat_cost() {return min_cost;} virtual bool register_weight(XLINT weight) { std::pair r = weights.insert(weight); return r.second; } inline void set_solver_command(const string& solver_command); inline void set_multiplication_string(const string& _multiplication_string); inline void set_temporary_directory(const string& value); inline void set_leave_temporary_files(bool value=true); void _output_clause (/*const*/ LiteralVector& literals); void _output_unary_clause(LINT l); void _output_binary_clause(LINT l1, LINT l2); void _output_weighted_clause(/*const*/ LiteralVector& literals,XLINT weight); void _output_unary_weighted_clause(LINT l, XLINT weight); void _output_binary_weighted_clause(LINT l1, LINT l2, XLINT weight); BasicClause* _record_clause(LiteralVector& literals); virtual void _increase_weight(BasicClause* clause, XLINT weight); virtual void dump(ostream& out); virtual bool has_solution(); void set_iterative(bool iterative) {this->iterative = iterative;} bool is_iterative() const {return iterative;} private: XLINT min_cost; XLINT solution_value; IDManager& _id_manager; BasicClauseSet clause_set; BasicClauseSet hard_clauses; vector clause_split; vector solution_weights; vector< vector > functions; IntVector model; WeightSet weights; vector sorted_weights; int call_counter; time_t stamp; string solver_command; string multiplication_string; string temporary_directory; bool leave_temporary_files; bool iterative; vector< vector > constraints; void split(); size_t get_weight_index(XLINT weight) const; bool solve(size_t function_index); bool solve_max(); bool solve_it(); int external_solve(const vector& function ,vector< vector >& constraints ,IntVector& tmodel); int external_solve_max(IntVector& tmodel); bool has_weight(XLINT weight) const { FOR_EACH(WeightSet::const_iterator,weight_index, weights) if (*weight_index==weight) return true; return false; } ostream& print_constraint (const vector& constraint,ostream& output); }; inline void ExternalWrapper::set_solver_command(const string& _solver_command) { solver_command =_solver_command; } inline void ExternalWrapper::set_multiplication_string(const string& _multiplication_string) { multiplication_string =_multiplication_string; } inline void ExternalWrapper::set_temporary_directory(const string& value) { temporary_directory = value; } inline void ExternalWrapper::set_leave_temporary_files(bool value/*=true*/) { leave_temporary_files = value; } #endif /* EXTERNALWRAPPER_HH */ packup-0.6/fmtutils.hh0000644000175000010010000001210611573000740014134 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ //jpms:bc /*----------------------------------------------------------------------------*\ * File: fmtutils.hh * * Description: Utils for parsing DIMACS-based formats. * * Author: jpms * * Revision: $Id$. * * Copyright (c) 2009, Joao Marques-Silva \*----------------------------------------------------------------------------*/ //jpms:ec #ifndef _FMTUTILS_H #define _FMTUTILS_H 1 //jpms:bc /*----------------------------------------------------------------------------*\ * Utils for DIMACS format parsing * (This borrows **extensively** from the MiniSAT parser) \*----------------------------------------------------------------------------*/ //jpms:ec #define CHUNK_LIMIT 1048576 #define SMALL_CHUNK_LIMIT 1024 class StreamBuffer { protected: gzFile in; char *buf; //buf[CHUNK_LIMIT]; int pos; int size; void assureLookahead() { if (pos >= size) { pos = 0; size = gzread(in, buf, sizeof(buf)); } } virtual void resize_buffer() { buf = new char[CHUNK_LIMIT]; } public: StreamBuffer(gzFile i) : in(i), pos(0), size(0) { resize_buffer(); assureLookahead(); } virtual ~StreamBuffer() { delete buf; } int operator * () { return (pos >= size) ? EOF : buf[pos]; } void operator ++ () { pos++; assureLookahead(); } }; class SmallStreamBuffer : public StreamBuffer { protected: virtual void resize_buffer() { buf = new char[SMALL_CHUNK_LIMIT]; } public: SmallStreamBuffer(gzFile i) : StreamBuffer(i) { } //virtual ~SmallStreamBuffer() { delete buf; } virtual ~SmallStreamBuffer() { } }; //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - template static void skipWhitespace(B& in) { while ((*in >= 9 && *in <= 13) || *in == 32) ++in; } template static void skipTrueWhitespace(B& in) { // not including newline while (*in == ' ' || *in == '\t') ++in; } template static void skipTabSpace(B& in) { while (*in == 9 || *in == 32) ++in; } template static void skipLine(B& in) { for (;;){ if (*in == EOF) return; if (*in == '\n') { ++in; return; } if (*in == '\r') { ++in; return; } ++in; } } template static bool skipEndOfLine(B& in) { // skip newline AND trailing comment/empty lines if (*in == '\n' || *in == '\r') ++in; else return false; skipComments(in); return true; } template static bool skipText(B& in, char* text) { while (*text != 0){ if (*in != *text) return false; ++in, ++text; } return true; } template static string readString(B& in) { string rstr; skipWhitespace(in); while (*in >= '0' && *in <= '9' || *in >= 'a' && *in <= 'z' || *in >= 'A' && *in <= 'Z' || (*in == '_') || (*in == '.')) { rstr.push_back(*in); ++in; } return rstr; } template static LINT parseInt(B& in) { LINT val = 0; bool neg = false; skipWhitespace(in); if (*in == '-') neg = true, ++in; else if (*in == '+') ++in; if (*in < '0' || *in > '9') fprintf(stderr, "PARSE ERROR! Unexpected char: %c\n", *in), exit(3); while (*in >= '0' && *in <= '9') val = val*10 + (*in - '0'), ++in; return neg ? -val : val; } template static XLINT parseLongInt(B& in) { XLINT val = 0; bool neg = false; skipWhitespace(in); if (*in == '-') neg = true, ++in; else if (*in == '+') ++in; if (*in < '0' || *in > '9') fprintf(stderr, "PARSE ERROR! Unexpected char: %c\n", *in), exit(3); while (*in >= '0' && *in <= '9') val = val*10 + (*in - '0'), ++in; XLINT rval = (neg) ? (-1*val) : val; return rval; } #endif /* _FMTUTILS_H */ /*----------------------------------------------------------------------------*/ packup-0.6/functors.hh0000644000175000010010000000416011573000740014131 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ //jpms:bc /*----------------------------------------------------------------------------*\ * File: functors.hh * * Description: * * Author: jpms * * Revision: $Id$. * * Copyright (c) 2009, Joao Marques-Silva \*----------------------------------------------------------------------------*/ //jpms:ec #ifndef _FUNCTORS_H #define _FUNCTORS_H 1 template struct defprint : public unary_function { defprint(ostream& out) : os(out) {} void operator() (T x) { os << x << ' '; } ostream& os; }; template struct ptrprint : public unary_function { ptrprint(ostream& out) : os(out) {} void operator() (T x) { os << *x << endl; } ostream& os; }; #endif /* _FUNCTORS_H */ /*----------------------------------------------------------------------------*/ packup-0.6/globals.hh0000644000175000010010000000720611573000740013715 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /*----------------------------------------------------------------------------*\ * Version: $Id: globals.hh 73 2007-07-26 15:16:48Z jpms $ * * Author: jpms * * Description: Include file that includes all other key include files. * This is the include file to be included by the header * files of libraries and tools. * * Copyright (c) 2005-2006, Joao Marques-Silva \*----------------------------------------------------------------------------*/ #ifndef _GLOBALS_HH_ #define _GLOBALS_HH_ 1 #include #include #include #include #include #include #include using namespace std; /*----------------------------------------------------------------------------*\ * System configuration \*----------------------------------------------------------------------------*/ #include "config.hh" /*----------------------------------------------------------------------------*\ * Macro definition \*----------------------------------------------------------------------------*/ #include "macros.hh" /*----------------------------------------------------------------------------*\ * Utils for printing debug information \*----------------------------------------------------------------------------*/ #include "dbg_prt.hh" /*----------------------------------------------------------------------------*\ * Definition of types used throughout \*----------------------------------------------------------------------------*/ #include "basic_types.h" #include "types.hh" /*----------------------------------------------------------------------------*\ * Definition of functors used throughout \*----------------------------------------------------------------------------*/ #include "functors.hh" /*----------------------------------------------------------------------------*\ * Utils for terminating program execution \*----------------------------------------------------------------------------*/ #include "err_utils.hh" /*----------------------------------------------------------------------------*\ * Utils for printing resourse usage information \*----------------------------------------------------------------------------*/ #include "rusage.hh" #endif /* _GLOBALS_HH_ */ /*----------------------------------------------------------------------------*/ packup-0.6/id_manager.hh0000644000175000010010000000613711573000740014362 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /*----------------------------------------------------------------------------*\ * Version: $Id: id_manager.hh 73 2007-07-26 15:16:48Z jpms $ * * Author: jpms * * Description: Management of var IDs. Var ids *must* start at k>0. * * Copyright (c) 2005-2006, Joao Marques-Silva \*----------------------------------------------------------------------------*/ #ifndef _ID_MANAGER_HH_ #define _ID_MANAGER_HH_ 1 #include "globals.hh" /*----------------------------------------------------------------------------*\ * Class: IDManager * * Purpose: Manager of var IDs. \*----------------------------------------------------------------------------*/ class IDManager { public: IDManager(ULINT _min_id) : id_count(_min_id-1), min_id(_min_id) { assert(_min_id>0); } IDManager() : id_count(0), min_id(1) { } ~IDManager() { } public: inline ULINT new_id() { return ++id_count; } inline ULINT new_id(ULINT& id) { id = ++id_count; return 1; } inline ULINT new_ids(ULINT num, ULINT& lb, ULINT& ub) { lb = id_count + 1; ub = id_count + num; id_count += num; return 1; } inline void reg_ids(ULINT maxid) { if (id_count < maxid) { id_count = maxid; } } inline bool exists(ULINT id) { return id <= id_count && id >= min_id; } inline ULINT top_id() { return id_count; } inline ULINT range() { return id_count - min_id + 1; } inline void clear() { id_count = min_id-1; } void dump(ostream& outs=cout) { outs << "ID count: " << (id_count-min_id+1) << endl; } friend ostream & operator << (ostream& outs, IDManager& idmgr) { idmgr.dump(outs); return outs; } private: ULINT id_count; // number of ids used ULINT min_id; // min id used }; #endif /* _ID_MANAGER_HH_ */ /*----------------------------------------------------------------------------*/ packup-0.6/InstallableUnit.hh0000644000175000010010000000536411573000733015371 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: InstallableUnit.hh * Author: mikolas * * Created on September 25, 2010, 5:27 PM * Copyright (C) 2011, Mikolas Janota */ #ifndef INSTALLABLEUNIT_HH #define INSTALLABLEUNIT_HH #include "collections.hh" class InstallableUnit { public: string name; bool installed; Version version; PackageVersionList provides; PackageVersionsList conflicts; PackageVersionsCNF depends_cnf; // cnf that must be true because of depends PackageVersionsCNF recommends_cnf; // cnf that is recommended to be true because of reccommends KeepValue keep; bool needed; Variable variable; inline void dump(ostream& out) { out << "package: " << name << endl; out << "version: " << version << endl; out << "installed: " << (installed ? "true" : "false") << endl; out << "provides: "; collection_printing::print(provides,out); out << endl; out << "conflicts: "; collection_printing::print(conflicts,out); out << endl; out << "depends: "; collection_printing::print(depends_cnf,out); out << endl; out << "recommends: "; collection_printing::print(recommends_cnf,out); out << endl; out << "keep: " << to_string(keep) << endl; } }; struct InstallableUnitCmp { inline bool operator()(const InstallableUnit* u1,const InstallableUnit* u2) const { return u1->version < u2->version; } }; #endif /* INSTALLABLEUNIT_HH */ packup-0.6/IntervalVariables.cc0000644000175000010010000000421511573000734015675 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: IntervalVariables.cc * Author: mikolas * * Created on September 26, 2010, 7:41 PM * Copyright (C) 2011, Mikolas Janota */ #include "IntervalVariables.hh" #include "EncoderTypes.hh" Variable IntervalVariables::get_variable(const PackageVersion& pv, PackageVersionMap& map, PackageToVersions& vvs, const string& map_name, bool& is_fresh) { PackageVersionMap::const_iterator index = map.find(pv); if (index != map.end()) { is_fresh = false; return index->second; } //cerr << "adding " << pv.to_string() << " to " << map_name << endl; is_fresh = true; Variable nv = new_variable(); map[pv] = nv; #ifdef MAPPING string nm= map_name + pv.to_string(); variable_names[nv] = nm; mapping << nv << "->" << nm << endl; #endif record_version(vvs, pv.name(), pv.version()); return nv; } packup-0.6/IntervalVariables.hh0000644000175000010010000001005711573000734015710 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: IntervalVariables.hh * Author: mikolas * * Created on September 26, 2010, 7:41 PM * Copyright (C) 2011, Mikolas Janota */ #ifndef INTERVALVARIABLES_HH #define INTERVALVARIABLES_HH #include "collections.hh" #include "id_manager.hh" #include using std::ofstream; class IntervalVariables { public: IntervalVariables(IDManager& idm #ifdef MAPPING , unordered_map& variable_names, ofstream& mapping #endif ) : id_manager (idm) #ifdef MAPPING , variable_names(variable_names), mapping(mapping) #endif {} bool _dummy; Variable get_require_up(const PackageVersion& pv) {return get_variable(pv, require_package_versions_up, require_up, "require_up", _dummy);} Variable get_require_down(const PackageVersion& pv) {return get_variable(pv, require_package_versions_down, require_down, "require_down", _dummy);} Variable get_disable_up(const PackageVersion& pv) {return get_variable(pv, disable_package_versions_up, disable_up, "disable_up", _dummy);} Variable get_disable_down(const PackageVersion& pv) {return get_variable(pv, disable_package_versions_down, disable_down, "disable_down", _dummy);} inline PackageToVersions get_require_up () const { return require_up; } inline PackageToVersions get_require_down () const { return require_down; } inline PackageToVersions get_disable_up () const { return disable_up; } inline PackageToVersions get_disable_down () const { return disable_down; } private: IDManager& id_manager; #ifdef MAPPING unordered_map& variable_names;// Names of variables for debugging purposes. ofstream& mapping; #endif // Maps from intervals to the corresponding variables PackageVersionMap require_package_versions_up,require_package_versions_down; PackageVersionMap disable_package_versions_up,disable_package_versions_down; // For each package the following maps record the version intervals used in the dependencies PackageToVersions require_up; PackageToVersions require_down; PackageToVersions disable_up; PackageToVersions disable_down; inline Variable new_variable () { return id_manager.new_id(); } /** * Get a variable corresponding to the given pair package-version. * @param pv package-version pair * @param map a map storing variable IDs for package-version pairs * @return Variable corresponding to {@code pv} in {@code map}. * A fresh variable, if {@code pv} is not in {@code map}. */ Variable get_variable (const PackageVersion& pv, PackageVersionMap& map, unordered_map & vvs, const string& map_name, bool& is_fresh); }; #endif /* INTERVALVARIABLES_HH */ packup-0.6/Lexer.cc0000644000175000010010000006332611573000734013347 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ #line 1 "l.rl" #include #include #include #include #include using namespace std; using std::cerr; using std::cout; using std::cin; using std::endl; #include "Lexer.hh" #include "p.tab.hh" extern YYSTYPE yylval; char* stop; char* token_start; int token_length; #define EMIT(t) { token = t; token_start=ts; token_length =te-ts; stop =p+1; token_read = true;} #line 152 "l.rl" #line 30 "Lexer.cc" static const char _cud_actions[] = { 0, 1, 1, 1, 2, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 12, 1, 14, 1, 15, 1, 16, 1, 17, 1, 18, 1, 19, 1, 23, 1, 24, 1, 25, 1, 26, 1, 27, 1, 28, 1, 29, 1, 30, 1, 31, 1, 32, 1, 33, 1, 34, 1, 35, 1, 36, 1, 37, 1, 38, 1, 39, 1, 40, 1, 41, 1, 42, 1, 43, 1, 44, 1, 45, 1, 46, 1, 47, 1, 48, 1, 49, 1, 50, 1, 51, 1, 52, 1, 53, 1, 54, 1, 55, 1, 56, 1, 57, 1, 58, 1, 59, 1, 60, 2, 0, 13, 2, 0, 16, 2, 0, 23, 2, 2, 3, 2, 5, 0, 2, 5, 20, 2, 5, 21, 2, 5, 22 }; static const short _cud_key_offsets[] = { 0, 0, 1, 7, 14, 21, 28, 35, 42, 49, 56, 63, 69, 76, 83, 90, 97, 104, 111, 117, 124, 131, 138, 145, 152, 159, 166, 173, 179, 186, 193, 200, 206, 214, 221, 228, 235, 242, 249, 255, 263, 270, 277, 284, 291, 298, 304, 311, 318, 325, 332, 339, 345, 352, 361, 368, 375, 382, 389, 396, 403, 410, 416, 423, 430, 437, 443, 450, 457, 464, 471, 477, 484, 491, 498, 505, 512, 519, 525, 532, 539, 546, 553, 560, 567, 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, 605, 607, 621, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 645, 648, 649, 650, 651, 656, 657, 685, 686, 688, 698, 710, 711, 712, 725, 739, 753, 767, 781, 795, 809, 823, 837 }; static const char _cud_trans_keys[] = { 10, 45, 58, 48, 57, 97, 122, 45, 58, 111, 48, 57, 97, 122, 45, 58, 110, 48, 57, 97, 122, 45, 58, 102, 48, 57, 97, 122, 45, 58, 108, 48, 57, 97, 122, 45, 58, 105, 48, 57, 97, 122, 45, 58, 99, 48, 57, 97, 122, 45, 58, 116, 48, 57, 97, 122, 45, 58, 115, 48, 57, 97, 122, 45, 58, 48, 57, 97, 122, 45, 58, 101, 48, 57, 97, 122, 45, 58, 112, 48, 57, 97, 122, 45, 58, 101, 48, 57, 97, 122, 45, 58, 110, 48, 57, 97, 122, 45, 58, 100, 48, 57, 97, 122, 45, 58, 115, 48, 57, 97, 122, 45, 58, 48, 57, 97, 122, 45, 58, 110, 48, 57, 97, 122, 45, 58, 115, 48, 57, 97, 122, 45, 58, 116, 48, 57, 97, 122, 45, 58, 97, 48, 57, 98, 122, 45, 58, 108, 48, 57, 97, 122, 45, 58, 108, 48, 57, 97, 122, 45, 58, 101, 48, 57, 97, 122, 45, 58, 100, 48, 57, 97, 122, 45, 58, 48, 57, 97, 122, 45, 58, 101, 48, 57, 97, 122, 45, 58, 101, 48, 57, 97, 122, 45, 58, 112, 48, 57, 97, 122, 45, 58, 48, 57, 97, 122, 45, 58, 97, 114, 48, 57, 98, 122, 45, 58, 99, 48, 57, 97, 122, 45, 58, 107, 48, 57, 97, 122, 45, 58, 97, 48, 57, 98, 122, 45, 58, 103, 48, 57, 97, 122, 45, 58, 101, 48, 57, 97, 122, 45, 58, 48, 57, 97, 122, 45, 58, 101, 111, 48, 57, 97, 122, 45, 58, 97, 48, 57, 98, 122, 45, 58, 109, 48, 57, 97, 122, 45, 58, 98, 48, 57, 97, 122, 45, 58, 108, 48, 57, 97, 122, 45, 58, 101, 48, 57, 97, 122, 45, 58, 48, 57, 97, 122, 45, 58, 118, 48, 57, 97, 122, 45, 58, 105, 48, 57, 97, 122, 45, 58, 100, 48, 57, 97, 122, 45, 58, 101, 48, 57, 97, 122, 45, 58, 115, 48, 57, 97, 122, 45, 58, 48, 57, 97, 122, 45, 58, 101, 48, 57, 97, 122, 45, 58, 99, 109, 113, 48, 57, 97, 122, 45, 58, 111, 48, 57, 97, 122, 45, 58, 109, 48, 57, 97, 122, 45, 58, 109, 48, 57, 97, 122, 45, 58, 101, 48, 57, 97, 122, 45, 58, 110, 48, 57, 97, 122, 45, 58, 100, 48, 57, 97, 122, 45, 58, 115, 48, 57, 97, 122, 45, 58, 48, 57, 97, 122, 45, 58, 111, 48, 57, 97, 122, 45, 58, 118, 48, 57, 97, 122, 45, 58, 101, 48, 57, 97, 122, 45, 58, 48, 57, 97, 122, 45, 58, 117, 48, 57, 97, 122, 45, 58, 101, 48, 57, 97, 122, 45, 58, 115, 48, 57, 97, 122, 45, 58, 116, 48, 57, 97, 122, 45, 58, 48, 57, 97, 122, 45, 58, 112, 48, 57, 97, 122, 45, 58, 103, 48, 57, 97, 122, 45, 58, 114, 48, 57, 97, 122, 45, 58, 97, 48, 57, 98, 122, 45, 58, 100, 48, 57, 97, 122, 45, 58, 101, 48, 57, 97, 122, 45, 58, 48, 57, 97, 122, 45, 58, 101, 48, 57, 97, 122, 45, 58, 114, 48, 57, 97, 122, 45, 58, 115, 48, 57, 97, 122, 45, 58, 105, 48, 57, 97, 122, 45, 58, 111, 48, 57, 97, 122, 45, 58, 110, 48, 57, 97, 122, 45, 58, 48, 57, 97, 122, 32, 101, 97, 116, 117, 114, 101, 111, 110, 101, 97, 99, 107, 97, 103, 101, 101, 114, 115, 105, 111, 110, 97, 108, 115, 101, 114, 117, 101, 61, 34, 92, 34, 92, 9, 10, 32, 35, 99, 100, 105, 107, 112, 114, 117, 118, 97, 122, 9, 32, 10, 32, 32, 32, 32, 32, 32, 10, 32, 32, 32, 32, 10, 32, 32, 9, 10, 32, 102, 110, 112, 118, 9, 10, 32, 32, 10, 32, 9, 10, 32, 102, 116, 32, 9, 10, 32, 33, 34, 37, 44, 58, 60, 61, 62, 91, 93, 102, 116, 124, 40, 41, 43, 45, 46, 47, 48, 57, 64, 90, 97, 122, 32, 34, 92, 37, 43, 40, 41, 45, 57, 64, 90, 97, 122, 37, 43, 40, 41, 45, 47, 48, 57, 64, 90, 97, 122, 61, 61, 37, 43, 45, 40, 41, 46, 47, 48, 57, 64, 90, 97, 122, 37, 43, 45, 97, 40, 41, 46, 47, 48, 57, 64, 90, 98, 122, 37, 43, 45, 108, 40, 41, 46, 47, 48, 57, 64, 90, 97, 122, 37, 43, 45, 115, 40, 41, 46, 47, 48, 57, 64, 90, 97, 122, 37, 43, 45, 101, 40, 41, 46, 47, 48, 57, 64, 90, 97, 122, 33, 37, 43, 45, 40, 41, 46, 47, 48, 57, 64, 90, 97, 122, 37, 43, 45, 114, 40, 41, 46, 47, 48, 57, 64, 90, 97, 122, 37, 43, 45, 117, 40, 41, 46, 47, 48, 57, 64, 90, 97, 122, 37, 43, 45, 101, 40, 41, 46, 47, 48, 57, 64, 90, 97, 122, 33, 37, 43, 45, 40, 41, 46, 47, 48, 57, 64, 90, 97, 122, 0 }; static const char _cud_single_lengths[] = { 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 2, 4, 3, 3, 3, 3, 3, 2, 4, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 2, 3, 5, 3, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 2, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 12, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 7, 3, 1, 1, 1, 5, 1, 16, 1, 2, 2, 2, 1, 1, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4 }; static const char _cud_range_lengths[] = { 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 4, 5, 0, 0, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 }; static const short _cud_index_offsets[] = { 0, 0, 2, 7, 13, 19, 25, 31, 37, 43, 49, 55, 60, 66, 72, 78, 84, 90, 96, 101, 107, 113, 119, 125, 131, 137, 143, 149, 154, 160, 166, 172, 177, 184, 190, 196, 202, 208, 214, 219, 226, 232, 238, 244, 250, 256, 261, 267, 273, 279, 285, 291, 296, 302, 310, 316, 322, 328, 334, 340, 346, 352, 357, 363, 369, 375, 380, 386, 392, 398, 404, 409, 415, 421, 427, 433, 439, 445, 450, 456, 462, 468, 474, 480, 486, 491, 493, 495, 497, 499, 501, 503, 505, 507, 509, 511, 513, 515, 517, 519, 521, 523, 525, 527, 529, 531, 533, 535, 537, 539, 541, 543, 545, 547, 549, 551, 554, 557, 571, 574, 576, 578, 580, 582, 584, 586, 588, 590, 592, 594, 596, 598, 600, 602, 604, 612, 616, 618, 620, 622, 628, 630, 653, 655, 658, 665, 673, 675, 677, 686, 696, 706, 716, 726, 736, 746, 756, 766 }; static const unsigned char _cud_indicies[] = { 1, 0, 2, 4, 2, 2, 3, 2, 4, 5, 2, 2, 3, 2, 4, 6, 2, 2, 3, 2, 4, 7, 2, 2, 3, 2, 4, 8, 2, 2, 3, 2, 4, 9, 2, 2, 3, 2, 4, 10, 2, 2, 3, 2, 4, 11, 2, 2, 3, 2, 4, 12, 2, 2, 3, 2, 13, 2, 2, 3, 2, 4, 14, 2, 2, 3, 2, 4, 15, 2, 2, 3, 2, 4, 16, 2, 2, 3, 2, 4, 17, 2, 2, 3, 2, 4, 18, 2, 2, 3, 2, 4, 19, 2, 2, 3, 2, 20, 2, 2, 3, 2, 4, 21, 2, 2, 3, 2, 4, 22, 2, 2, 3, 2, 4, 23, 2, 2, 3, 2, 4, 24, 2, 2, 3, 2, 4, 25, 2, 2, 3, 2, 4, 26, 2, 2, 3, 2, 27, 28, 2, 2, 3, 2, 4, 29, 2, 2, 3, 2, 30, 2, 2, 3, 2, 4, 31, 2, 2, 3, 2, 4, 32, 2, 2, 3, 2, 4, 33, 2, 2, 3, 2, 34, 2, 2, 3, 2, 4, 35, 36, 2, 2, 3, 2, 4, 37, 2, 2, 3, 2, 4, 38, 2, 2, 3, 2, 4, 39, 2, 2, 3, 2, 4, 40, 2, 2, 3, 2, 4, 41, 2, 2, 3, 2, 42, 2, 2, 3, 2, 4, 43, 44, 2, 2, 3, 2, 4, 45, 2, 2, 3, 2, 4, 46, 2, 2, 3, 2, 4, 47, 2, 2, 3, 2, 4, 48, 2, 2, 3, 2, 4, 49, 2, 2, 3, 2, 50, 2, 2, 3, 2, 4, 51, 2, 2, 3, 2, 4, 52, 2, 2, 3, 2, 4, 53, 2, 2, 3, 2, 4, 54, 2, 2, 3, 2, 4, 55, 2, 2, 3, 2, 56, 2, 2, 3, 2, 4, 57, 2, 2, 3, 2, 4, 58, 59, 60, 2, 2, 3, 2, 4, 61, 2, 2, 3, 2, 4, 62, 2, 2, 3, 2, 4, 63, 2, 2, 3, 2, 4, 64, 2, 2, 3, 2, 4, 65, 2, 2, 3, 2, 4, 66, 2, 2, 3, 2, 4, 67, 2, 2, 3, 2, 68, 2, 2, 3, 2, 4, 69, 2, 2, 3, 2, 4, 70, 2, 2, 3, 2, 4, 71, 2, 2, 3, 2, 72, 2, 2, 3, 2, 4, 73, 2, 2, 3, 2, 4, 74, 2, 2, 3, 2, 4, 75, 2, 2, 3, 2, 4, 76, 2, 2, 3, 2, 77, 2, 2, 3, 2, 4, 78, 2, 2, 3, 2, 4, 79, 2, 2, 3, 2, 4, 80, 2, 2, 3, 2, 4, 81, 2, 2, 3, 2, 4, 82, 2, 2, 3, 2, 4, 83, 2, 2, 3, 2, 84, 2, 2, 3, 2, 4, 85, 2, 2, 3, 2, 4, 86, 2, 2, 3, 2, 4, 87, 2, 2, 3, 2, 4, 88, 2, 2, 3, 2, 4, 89, 2, 2, 3, 2, 4, 90, 2, 2, 3, 2, 91, 2, 2, 3, 93, 92, 94, 3, 95, 3, 96, 3, 97, 3, 98, 3, 99, 3, 100, 3, 101, 3, 102, 3, 103, 3, 104, 3, 105, 3, 106, 3, 107, 3, 108, 3, 109, 3, 110, 3, 111, 3, 112, 3, 113, 3, 114, 3, 115, 3, 116, 3, 117, 3, 118, 3, 119, 3, 120, 3, 121, 3, 122, 3, 125, 126, 124, 127, 126, 124, 128, 129, 128, 0, 130, 131, 132, 133, 134, 135, 136, 137, 2, 3, 128, 128, 138, 129, 139, 141, 140, 142, 140, 143, 140, 144, 140, 145, 140, 146, 140, 147, 50, 148, 140, 149, 140, 150, 140, 151, 140, 152, 151, 153, 140, 154, 140, 155, 156, 155, 157, 158, 159, 160, 3, 155, 162, 155, 161, 93, 163, 165, 164, 167, 166, 168, 169, 168, 170, 171, 3, 173, 172, 174, 175, 174, 176, 124, 177, 179, 181, 182, 183, 184, 185, 186, 188, 189, 190, 177, 178, 177, 180, 177, 187, 3, 192, 191, 125, 126, 124, 177, 177, 177, 177, 177, 177, 194, 177, 177, 177, 177, 180, 177, 177, 123, 196, 195, 198, 197, 177, 177, 187, 177, 177, 187, 177, 187, 199, 177, 177, 187, 200, 177, 177, 187, 177, 187, 199, 177, 177, 187, 201, 177, 177, 187, 177, 187, 199, 177, 177, 187, 202, 177, 177, 187, 177, 187, 199, 177, 177, 187, 203, 177, 177, 187, 177, 187, 199, 204, 177, 177, 187, 177, 177, 187, 177, 187, 199, 177, 177, 187, 205, 177, 177, 187, 177, 187, 199, 177, 177, 187, 206, 177, 177, 187, 177, 187, 199, 177, 177, 187, 207, 177, 177, 187, 177, 187, 199, 208, 177, 177, 187, 177, 177, 187, 177, 187, 199, 0 }; static const unsigned char _cud_trans_targs[] = { 1, 117, 2, 0, 117, 4, 5, 6, 7, 8, 9, 10, 11, 120, 13, 14, 15, 16, 17, 18, 121, 20, 21, 22, 23, 24, 25, 122, 26, 27, 123, 29, 30, 31, 124, 33, 39, 34, 35, 36, 37, 38, 125, 40, 46, 41, 42, 43, 44, 45, 126, 47, 48, 49, 50, 51, 127, 53, 54, 62, 66, 55, 56, 57, 58, 59, 60, 61, 128, 63, 64, 65, 129, 67, 68, 69, 70, 130, 72, 73, 74, 75, 76, 77, 132, 79, 80, 81, 82, 83, 84, 133, 134, 135, 87, 88, 89, 90, 91, 134, 93, 94, 134, 96, 97, 98, 99, 100, 134, 102, 103, 104, 105, 106, 134, 108, 109, 110, 139, 112, 113, 139, 141, 141, 115, 141, 116, 143, 118, 119, 3, 12, 19, 28, 32, 52, 71, 78, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 117, 131, 117, 117, 117, 135, 136, 86, 92, 95, 101, 134, 85, 134, 137, 138, 137, 137, 139, 140, 107, 111, 139, 139, 141, 142, 114, 144, 145, 141, 145, 141, 146, 141, 147, 141, 141, 148, 149, 154, 141, 141, 141, 141, 141, 141, 141, 141, 141, 141, 150, 151, 152, 153, 141, 155, 156, 157, 141 }; static const unsigned char _cud_trans_actions[] = { 0, 75, 0, 0, 99, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21, 123, 0, 0, 0, 0, 0, 15, 0, 0, 9, 0, 0, 0, 0, 0, 13, 0, 0, 0, 0, 0, 11, 0, 0, 0, 31, 0, 0, 29, 51, 73, 0, 37, 0, 126, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 101, 103, 109, 85, 83, 91, 87, 77, 79, 105, 89, 97, 93, 0, 107, 95, 81, 7, 1, 0, 0, 0, 0, 17, 0, 19, 23, 1, 25, 111, 27, 1, 0, 0, 33, 114, 35, 1, 0, 0, 132, 43, 129, 45, 0, 49, 0, 39, 41, 0, 0, 0, 47, 61, 117, 63, 71, 67, 55, 65, 53, 69, 0, 0, 0, 0, 59, 0, 0, 0, 57 }; static const unsigned char _cud_to_state_actions[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 3, 0, 3, 0, 120, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; static const unsigned char _cud_from_state_actions[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 5, 0, 5, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; static const short _cud_eof_trans[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 93, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 124, 124, 0, 139, 140, 141, 141, 141, 141, 141, 141, 148, 141, 141, 141, 141, 153, 141, 141, 0, 162, 164, 0, 167, 0, 173, 0, 192, 194, 195, 124, 196, 198, 200, 200, 200, 200, 200, 200, 200, 200, 200, 200 }; static const int cud_start = 117; static const int cud_error = 0; static const int cud_en_keep_line = 134; static const int cud_en_skip_line = 137; static const int cud_en_bool_line = 139; static const int cud_en_middle_line = 141; static const int cud_en_main = 117; #line 155 "l.rl" char* Lexer::mkstring(const char* ts, unsigned int length) { char* return_value = new char[length+1]; return_value[length]='\0'; memcpy(return_value, ts, length); return return_value; } Lexer::Lexer(istream& input_stream) : input(input_stream) { current_line = 1; token = -1; done = false; token_read = false; should_read = true; last_buffer = false; // Ragel variables cs=act=have = 0; ts=te = 0; eof = 0; std::ios::sync_with_stdio(false); #line 520 "Lexer.cc" { cs = cud_start; ts = 0; te = 0; act = 0; } #line 181 "l.rl" } int Lexer::get_current_line() { return current_line;} int Lexer::yylex_internal() { if (done) return LEXER_END; if (should_read) { should_read = false; p = buf + have; int space = BUFSIZE - have; if (space == 0) { /* We filled up the buffer trying to scan a token. */ cerr << "OUT OF BUFFER SPACE" << endl; exit(1); } input.read(p, space); int len = input.gcount(); //fwrite(p, 1, len, stdout ); pe = p + len; /* If we see eof then append the EOF char. */ if (input.eof()) { last_buffer = true; eof = pe; } else eof = 0; } // Run automaton #line 559 "Lexer.cc" { int _klen; unsigned int _trans; const char *_acts; unsigned int _nacts; const char *_keys; if ( p == pe ) goto _test_eof; if ( cs == 0 ) goto _out; _resume: _acts = _cud_actions + _cud_from_state_actions[cs]; _nacts = (unsigned int) *_acts++; while ( _nacts-- > 0 ) { switch ( *_acts++ ) { case 4: #line 1 "NONE" {ts = p;} break; #line 580 "Lexer.cc" } } _keys = _cud_trans_keys + _cud_key_offsets[cs]; _trans = _cud_index_offsets[cs]; _klen = _cud_single_lengths[cs]; if ( _klen > 0 ) { const char *_lower = _keys; const char *_mid; const char *_upper = _keys + _klen - 1; while (1) { if ( _upper < _lower ) break; _mid = _lower + ((_upper-_lower) >> 1); if ( (*p) < *_mid ) _upper = _mid - 1; else if ( (*p) > *_mid ) _lower = _mid + 1; else { _trans += (_mid - _keys); goto _match; } } _keys += _klen; _trans += _klen; } _klen = _cud_range_lengths[cs]; if ( _klen > 0 ) { const char *_lower = _keys; const char *_mid; const char *_upper = _keys + (_klen<<1) - 2; while (1) { if ( _upper < _lower ) break; _mid = _lower + (((_upper-_lower) >> 1) & ~1); if ( (*p) < _mid[0] ) _upper = _mid - 2; else if ( (*p) > _mid[1] ) _lower = _mid + 2; else { _trans += ((_mid - _keys)>>1); goto _match; } } _trans += _klen; } _match: _trans = _cud_indicies[_trans]; _eof_trans: cs = _cud_trans_targs[_trans]; if ( _cud_trans_actions[_trans] == 0 ) goto _again; _acts = _cud_actions + _cud_trans_actions[_trans]; _nacts = (unsigned int) *_acts++; while ( _nacts-- > 0 ) { switch ( *_acts++ ) { case 0: #line 24 "l.rl" {current_line += 1;} break; case 1: #line 25 "l.rl" {current_line += 1;} break; case 5: #line 1 "NONE" {te = p+1;} break; case 6: #line 63 "l.rl" {te = p+1;{ EMIT (KEEP_NONE_TOKEN); {p++; goto _out; } }} break; case 7: #line 64 "l.rl" {te = p+1;{ EMIT (KEEP_VERSION_TOKEN); {p++; goto _out; } }} break; case 8: #line 65 "l.rl" {te = p+1;{ EMIT (KEEP_PACKAGE_TOKEN); {p++; goto _out; } }} break; case 9: #line 66 "l.rl" {te = p+1;{ EMIT (KEEP_FEATURE_TOKEN); {p++; goto _out; } }} break; case 10: #line 62 "l.rl" {te = p;p--;} break; case 11: #line 67 "l.rl" {te = p;p--;{ EMIT (NEW_LINE); cs = 117; {p++; goto _out; } }} break; case 12: #line 62 "l.rl" {{p = ((te))-1;}} break; case 13: #line 71 "l.rl" {te = p+1;} break; case 14: #line 73 "l.rl" {te = p+1;} break; case 15: #line 72 "l.rl" {te = p;p--;{ {cs = 117; goto _again;} }} break; case 16: #line 77 "l.rl" {te = p+1;} break; case 17: #line 80 "l.rl" {te = p+1;{ EMIT(BOOL_TRUE); {p++; goto _out; }}} break; case 18: #line 81 "l.rl" {te = p+1;{ EMIT(BOOL_FALSE); {p++; goto _out; }}} break; case 19: #line 79 "l.rl" {te = p;p--;{ cs = 117; EMIT(NEW_LINE); {p++; goto _out; }}} break; case 20: #line 89 "l.rl" {act = 18;} break; case 21: #line 113 "l.rl" {act = 32;} break; case 22: #line 115 "l.rl" {act = 34;} break; case 23: #line 85 "l.rl" {te = p+1;} break; case 24: #line 89 "l.rl" {te = p+1;{ EMIT(STRING_VALUE); // fwrite( token_start, 1, token_length, stdout ); // printf ("\n"); {p++; goto _out; } }} break; case 25: #line 96 "l.rl" {te = p+1;{ EMIT(OPEN_SQUARE); {p++; goto _out; }}} break; case 26: #line 97 "l.rl" {te = p+1;{ EMIT(CLOSE_SQUARE); {p++; goto _out; }}} break; case 27: #line 98 "l.rl" {te = p+1;{ EMIT(COMMA); {p++; goto _out; }}} break; case 28: #line 99 "l.rl" {te = p+1;{ EMIT(COLON); {p++; goto _out; }}} break; case 29: #line 100 "l.rl" {te = p+1;{EMIT(PIPE); {p++; goto _out; }}} break; case 30: #line 102 "l.rl" {te = p+1;{EMIT (EQUALS); {p++; goto _out; }}} break; case 31: #line 103 "l.rl" {te = p+1;{EMIT (NOT_EQUALS); {p++; goto _out; }}} break; case 32: #line 104 "l.rl" {te = p+1;{EMIT (GREATER_EQUALS); {p++; goto _out; }}} break; case 33: #line 106 "l.rl" {te = p+1;{EMIT (LESS_EQUALS); {p++; goto _out; }}} break; case 34: #line 109 "l.rl" {te = p+1;{ EMIT(TRUE_BANG); {p++; goto _out; }}} break; case 35: #line 110 "l.rl" {te = p+1;{ EMIT(FALSE_BANG); {p++; goto _out; }}} break; case 36: #line 87 "l.rl" {te = p;p--;{ cs = 117; EMIT(NEW_LINE); {p++; goto _out; }}} break; case 37: #line 89 "l.rl" {te = p;p--;{ EMIT(STRING_VALUE); // fwrite( token_start, 1, token_length, stdout ); // printf ("\n"); {p++; goto _out; } }} break; case 38: #line 105 "l.rl" {te = p;p--;{EMIT (GREATER); {p++; goto _out; }}} break; case 39: #line 107 "l.rl" {te = p;p--;{EMIT (LESS); {p++; goto _out; }}} break; case 40: #line 114 "l.rl" {te = p;p--;{ yylval.str=mkstring(ts, te-ts); EMIT(IDENTIFIER); {p++; goto _out; } }} break; case 41: #line 115 "l.rl" {te = p;p--;{ yylval.str=mkstring(ts, te-ts); EMIT(PACKAGE_NAME); {p++; goto _out; } }} break; case 42: #line 1 "NONE" { switch( act ) { case 0: {{cs = 0; goto _again;}} break; case 18: {{p = ((te))-1;} EMIT(STRING_VALUE); // fwrite( token_start, 1, token_length, stdout ); // printf ("\n"); {p++; goto _out; } } break; case 32: {{p = ((te))-1;} yylval.str=mkstring(ts, te-ts); EMIT(NUMBER); {p++; goto _out; } } break; case 34: {{p = ((te))-1;} yylval.str=mkstring(ts, te-ts); EMIT(PACKAGE_NAME); {p++; goto _out; } } break; } } break; case 43: #line 121 "l.rl" {te = p+1;} break; case 44: #line 123 "l.rl" {te = p+1;{ EMIT (KEEP); cs = 134; {p++; goto _out; } }} break; case 45: #line 126 "l.rl" {te = p+1;{ EMIT (PACKAGE); cs = 141; {p++; goto _out; }}} break; case 46: #line 127 "l.rl" {te = p+1;{ EMIT (VERSION); cs = 141; {p++; goto _out; } }} break; case 47: #line 129 "l.rl" {te = p+1;{ EMIT (DEPENDS); cs = 141; {p++; goto _out; } }} break; case 48: #line 130 "l.rl" {te = p+1;{EMIT (CONFLICTS); cs = 141; {p++; goto _out; }}} break; case 49: #line 131 "l.rl" {te = p+1;{EMIT (INSTALLED); cs = 139; {p++; goto _out; }}} break; case 50: #line 132 "l.rl" {te = p+1;{EMIT (PROVIDES); cs = 141; {p++; goto _out; }}} break; case 51: #line 133 "l.rl" {te = p+1;{EMIT (INSTALL); cs = 141; {p++; goto _out; }}} break; case 52: #line 134 "l.rl" {te = p+1;{EMIT (REMOVE); cs = 141; {p++; goto _out; }}} break; case 53: #line 135 "l.rl" {te = p+1;{EMIT (UPGRADE); cs = 141; {p++; goto _out; }}} break; case 54: #line 136 "l.rl" {te = p+1;{EMIT (RECOMMENDS); cs = 141; {p++; goto _out; }}} break; case 55: #line 150 "l.rl" {te = p+1;{ {cs = 137; goto _again;}}} break; case 56: #line 119 "l.rl" {te = p;p--;} break; case 57: #line 120 "l.rl" {te = p;p--;} break; case 58: #line 125 "l.rl" {te = p;p--;{EMIT (PREAMBLE);cs = 141; {p++; goto _out; } }} break; case 59: #line 128 "l.rl" {te = p;p--;{ EMIT (REQUEST); cs = 141; {p++; goto _out; } }} break; case 60: #line 150 "l.rl" {te = p;p--;{ {cs = 137; goto _again;}}} break; #line 907 "Lexer.cc" } } _again: _acts = _cud_actions + _cud_to_state_actions[cs]; _nacts = (unsigned int) *_acts++; while ( _nacts-- > 0 ) { switch ( *_acts++ ) { case 2: #line 1 "NONE" {ts = 0;} break; case 3: #line 1 "NONE" {act = 0;} break; #line 924 "Lexer.cc" } } if ( cs == 0 ) goto _out; if ( ++p != pe ) goto _resume; _test_eof: {} if ( p == eof ) { if ( _cud_eof_trans[cs] > 0 ) { _trans = _cud_eof_trans[cs] - 1; goto _eof_trans; } } _out: {} } #line 211 "l.rl" // End of automaton /* Check if we failed. */ if (cs == cud_error) { /* Machine failed before finding a token. */ printf("LEXER ERROR:%d:", current_line); fwrite(token_start, 1, token_length, stdout); exit(1); } if (token_read) { token_read = false; if (stop == pe) { if (last_buffer) { done = true; } else { should_read = true; have = 0; } } /*printf("read "); printf("'"); fwrite( token_start, 1, token_length, stdout );printf("'"); printf("\n"); */ return token; } else if (last_buffer) { done = true; } else { // The current buffer was finished without // reading a token at the end should_read = true; if (ts == 0) have = 0; else { /* There is data that needs to be shifted over. */ have = pe - ts; memmove(buf, ts, have); te -= (ts - buf); ts = buf; } } assert (!token_read); return yylex_internal(); } Lexer* lexer; int get_current_line() { return lexer->get_current_line();} int yylex() {return lexer->yylex_internal ();} packup-0.6/Lexer.hh0000644000175000010010000000437711573000734013362 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: Lexer.hh * Author: mikolas * * Created on September 2, 2010, 12:34 AM * Copyright (C) 2011, Mikolas Janota */ #ifndef LEXER_HH #define LEXER_HH #include #include #include #include using namespace std; using std::cerr; using std::cout; using std::cin; using std::endl; #include "p.tab.hh" #define BUFSIZE 124 int get_current_line(); int yylex(); class Lexer { public: Lexer(istream& input_stream); int get_current_line(); int yylex_internal(); private: istream& input; char buf[BUFSIZE]; int current_line; int token;// Token that was just read int done; // Everything has been processed bool token_read; // There was a token read bool should_read; // New buffer should be read bool last_buffer; // Last buffer is being processed // Ragel variables int cs, act, have; char *ts, *te; char *pe; char *p; char *eof; char* mkstring(const char* ts, unsigned int length); }; #endif /* LEXER_HH */ packup-0.6/LICENSE0000644000175000010010000010451311573000732012756 0ustar mikolasNone GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . packup-0.6/macros.hh0000644000175000010010000001206211573000740013552 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /*----------------------------------------------------------------------------*\ * Version: $Id: macros.hh 73 2007-07-26 15:16:48Z jpms $ * * Author: jpms * * Description: Macro definitions * * Copyright (c) 2006, Joao Marques-Silva \*----------------------------------------------------------------------------*/ #ifndef _MACROS_HH_ #define _MACROS_HH_ 1 /*----------------------------------------------------------------------------*\ * Utility macros (minof, maxof, ...) \*----------------------------------------------------------------------------*/ #define minof(x,y) ((x)<(y))?(x):(y) #define maxof(x,y) ((x)>(y))?(x):(y) /*----------------------------------------------------------------------------*\ * Swap utility \*----------------------------------------------------------------------------*/ // Swap utility #define tswap(T, x, y) { T tmp = y; y = x; x = tmp; } template string convert(T val) { stringstream ss; // Create a stringstream ss << val; // Add value to the stream return ss.str(); // Return string with the contents of the stream } /*----------------------------------------------------------------------------*\ * Macros for gathering statistics about msu algorithms \*----------------------------------------------------------------------------*/ #ifdef STATISTICS #define STATS(x) x #else #define STATS(x) #endif /*----------------------------------------------------------------------------*\ * Macros for printing generic debug info anf for controlling debug actions * (Some parts are based on examples from Eckel's book) \*----------------------------------------------------------------------------*/ #ifndef DBGMACROS #define DBGMACROS #define NDBG(x) #define NDBGPRT(x) #ifdef FULLDEBUG #define DBG(x) x #define CDBG(v,x) if(v,=TRACEVERB) { x } #define DBGPRT(x) std::cout << x << std::endl; std::cout.flush() #define DEBUG(x) std::cout << #x " = " << x << std::endl; std::cout.flush() #define TRACEP(x) std::cout << x << std::endl; #define TRACEX(x) std::cout << #x << std::endl; x #else #define DBG(x) #define CDBG(v,x) #define DBGPRT(x) #define DEBUG(x) #define TRACEP(x) #define TRACEX(x) x #endif #ifndef NCHECK #define CHK(x) x #define CCHK(v,x) if(v<=TRACEVERB) { x } #define CHKPRT(x) std::cout<<#x<<((x)?" passes":" fails")<. * \******************************************************************************/ /* * File: NotRemoved.cc * Author: mikolas * * Created on October 11, 2010, 6:51 PM * Copyright (C) 2011, Mikolas Janota */ #include "NotRemoved.hh" #include "InstallableUnit.hh" NotRemoved::NotRemoved(const PackageUnits& units) : units (units) { } NotRemoved::~NotRemoved() { } void NotRemoved::add(CONSTANT string& package_name) { if (CONTAINS (not_removed, package_name)) return; #ifdef CONV_DBG cerr << "not removed: " << package_name << endl; #endif not_removed.insert(package_name); StringSet required; PackageUnits::const_iterator i = units.find(package_name); if (i==units.end()) return; CONSTANT UnitVector & unit_vector =*(i->second); bool first=true; FOR_EACH (UnitVector::const_iterator, unit_index, unit_vector) { CONSTANT InstallableUnit& unit=**unit_index; StringSet new_required; FOR_EACH (PackageVersionsCNF::const_iterator,clause_index,unit.depends_cnf) { CONSTANT PackageVersionsList& literals = **clause_index; if (literals.size() != 1) continue;//considering only unit requirements CONSTANT string& requirement_name = literals[0].name(); if (first || CONTAINS(required,requirement_name)) new_required.insert(requirement_name); } required = new_required; first=false; } FOR_EACH (StringSet::const_iterator, requirement_index, required) { add (*requirement_index); } } packup-0.6/NotRemoved.hh0000644000175000010010000000376611573000734014366 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: NotRemoved.hh * Author: mikolas * * Created on October 11, 2010, 6:51 PM * Copyright (C) 2011, Mikolas Janota */ #ifndef NOTREMOVED_HH #define NOTREMOVED_HH #include "EncoderTypes.hh" class NotRemoved { public: NotRemoved(const PackageUnits& units); void add(CONSTANT string& package_name); inline bool is_not_removed (CONSTANT string& package_name) const { return CONTAINS (not_removed, package_name); } virtual ~NotRemoved(); inline StringSet::const_iterator begin() const {return not_removed.begin();} inline StringSet::const_iterator end() const {return not_removed.end();} private: CONSTANT PackageUnits& units; StringSet not_removed; }; #endif /* NOTREMOVED_HH */ packup-0.6/Options.cc0000644000175000010010000001013411573000734013710 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: Options.cc * Author: mikolas * * Created on April 23, 2011, 4:23 PM * Copyright (C) 2011, Mikolas Janota */ #include #include #include #include #include "Options.hh" using std::cerr; using std::endl; Options::Options() : help (0) , solving_disabled(0) , paranoid(0) , trendy(0) , leave_temporary_files(0) , max_solver(0) {} bool Options::parse(int argc,char **argv) { bool return_value = true; static struct option long_options[] = { {"help", no_argument, &help, 1} , {"no-sol", no_argument, &solving_disabled, 1} ,{"external-solver", required_argument, 0, 500} ,{"solution-check", required_argument, 0, 501} #ifdef MAPPING ,{"mapping-file", required_argument, 0, 502} #endif ,{"multiplication-string", required_argument, 0, 503} ,{"temporary-directory", required_argument, 0, 504} ,{"leave-temporary-files", no_argument, &leave_temporary_files, 1} ,{"max-sat", no_argument, &max_solver, 1} ,{0, 0, 0, 0} }; int c; while (1) { /* getopt_long stores the option index here. */ int option_index = 0; c = getopt_long(argc, argv, "hu:pt", long_options, &option_index); opterr = 0; /* Detect the end of the options. */ if (c == -1) break; switch (c) { case 0: if (long_options[option_index].flag != 0) break; else return false; case 'p': paranoid = 1; break; case 't': trendy = 1; break; case 'h': help = 1; break; case 'u': user_criterion = optarg; break; case 500: external_solver = optarg; break; case 501: solution_check = optarg; break; case 502: mapping_file = optarg; break; case 503: multiplication_string = optarg; break; case 504: temporary_directory = optarg; break; case '?': if ( (optopt == 'u') ) fprintf(stderr, "Option -%c requires an argument.\n", optopt); else if (isprint (optopt)) fprintf (stderr, "Unknown option `-%c'.\n", optopt); else fprintf (stderr,"Unknown option character `\\x%x'.\n",optopt); return_value = false; break; default: return false; } } if (!get_help()) { if (optind >= argc) { cerr << "cudf file expected" << endl; return_value = false; } else { input_file_name=argv[optind++]; } if (optind < argc) { output_file_name = argv[optind++]; } } if (optind < argc) { cerr << "WARNING: Unprocessed options at the end." << endl; } return return_value; } Options::~Options() {} packup-0.6/Options.hh0000644000175000010010000000571411573000734013732 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: Options.hh * Author: mikolas * * Created on April 23, 2011, 4:23 PM * Copyright (C) 2011, Mikolas Janota */ #ifndef OPTIONS_HH #define OPTIONS_HH #include #include #include using std::string; class Options { public: Options(); virtual ~Options(); bool parse(int count,char** arguments); int get_solving_disabled() const { return solving_disabled; } string get_external_solver() const { return external_solver; } int get_paranoid() const { return paranoid; } int get_trendy() const { return trendy; } string get_solution_check() const { return solution_check; } string get_mapping_file() const { return mapping_file; } string get_user_criterion() const { return user_criterion; } string get_input_file_name() const { return input_file_name; } string get_output_file_name() const { return output_file_name; } string get_multiplication_string() const { return multiplication_string; } string get_temporary_directory() const { return temporary_directory; } int get_leave_temporary_files() const { return leave_temporary_files; } int get_max_solver() const { return max_solver; } int get_help() const { return help; } private: int help; int solving_disabled; string external_solver; int paranoid; int trendy; string solution_check; string mapping_file; string user_criterion; string input_file_name; string output_file_name; string multiplication_string; int leave_temporary_files; string temporary_directory; int max_solver; }; #endif /* OPTIONS_HH */ packup-0.6/p.tab.cc0000644000175000010010000015671411573000736013302 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* A Bison parser, made by GNU Bison 2.4.2. */ /* Skeleton implementation for Bison's Yacc-like parsers in C Copyright (C) 1984, 1989-1990, 2000-2006, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work under terms of your choice, so long as that work isn't itself a parser generator using the skeleton or a modified version thereof as a parser skeleton. Alternatively, if you modify or redistribute the parser skeleton itself, you may (at your option) remove this special exception, which will cause the skeleton and the resulting Bison output files to be licensed under the GNU General Public License without this special exception. This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ /* C LALR(1) parser skeleton written by Richard Stallman, by simplifying the original so-called "semantic" parser. */ /* All symbols defined below should begin with yy or YY, to avoid infringing on user name space. This should be done even for local variables, as they might otherwise be expanded by user macros. There are some unavoidable exceptions within include files to define necessary library symbols; they are noted "INFRINGES ON USER NAME SPACE" below. */ /* Identify Bison output. */ #define YYBISON 1 /* Bison version. */ #define YYBISON_VERSION "2.4.2" /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" /* Pure parsers. */ #define YYPURE 0 /* Push parsers. */ #define YYPUSH 0 /* Pull parsers. */ #define YYPULL 1 /* Using locations. */ #define YYLSP_NEEDED 0 /* Copy the first part of user declarations. */ /* Line 189 of yacc.c */ #line 1 "p.bison" #include #include #include #include #include "parser.hh" #include "ConverterMem.hh" #include "common_types.hh" using std::string; using std::cout; using std::endl; extern int get_current_line(); extern int yylex(); extern ConverterMem parser; // better error reporting #define YYERROR_VERBOSE // bison requires that you supply this function void yyerror(const char *msg) { printf("ERROR(PARSER):%i: %s\n", get_current_line(), msg); } /* Line 189 of yacc.c */ #line 100 "p.tab.cc" /* Enabling traces. */ #ifndef YYDEBUG # define YYDEBUG 0 #endif /* Enabling verbose error messages. */ #ifdef YYERROR_VERBOSE # undef YYERROR_VERBOSE # define YYERROR_VERBOSE 1 #else # define YYERROR_VERBOSE 0 #endif /* Enabling the token table. */ #ifndef YYTOKEN_TABLE # define YYTOKEN_TABLE 0 #endif /* Tokens. */ #ifndef YYTOKENTYPE # define YYTOKENTYPE /* Put the tokens into the symbol table, so that GDB and other debuggers know about them. */ enum yytokentype { LEXER_END = 0, PACKAGE_NAME = 258, IDENTIFIER = 259, NUMBER = 260, PREAMBLE = 261, PACKAGE = 262, PROPERTY = 263, DEPENDS = 264, VERSION = 265, NEW_LINE = 266, COMMA = 267, EQUALS = 268, NOT_EQUALS = 269, GREATER_EQUALS = 270, GREATER = 271, LESS_EQUALS = 272, LESS = 273, KEEP = 274, REQUEST = 275, OPEN_SQUARE = 276, CLOSE_SQUARE = 277, COLON = 278, CONFLICTS = 279, INSTALLED = 280, PROVIDES = 281, INSTALL = 282, REMOVE = 283, UPGRADE = 284, PIPE = 285, KEEP_NONE_TOKEN = 286, KEEP_VERSION_TOKEN = 287, KEEP_PACKAGE_TOKEN = 288, KEEP_FEATURE_TOKEN = 289, TRUE_BANG = 290, FALSE_BANG = 291, BOOL_TRUE = 292, BOOL_FALSE = 293, RECOMMENDS = 294, STRING_VALUE = 295 }; #endif #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef union YYSTYPE { /* Line 214 of yacc.c */ #line 29 "p.bison" char* str; bool Boolean; /* Line 214 of yacc.c */ #line 184 "p.tab.cc" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 #endif /* Copy the second part of user declarations. */ /* Line 264 of yacc.c */ #line 196 "p.tab.cc" #ifdef short # undef short #endif #ifdef YYTYPE_UINT8 typedef YYTYPE_UINT8 yytype_uint8; #else typedef unsigned char yytype_uint8; #endif #ifdef YYTYPE_INT8 typedef YYTYPE_INT8 yytype_int8; #elif (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) typedef signed char yytype_int8; #else typedef short int yytype_int8; #endif #ifdef YYTYPE_UINT16 typedef YYTYPE_UINT16 yytype_uint16; #else typedef unsigned short int yytype_uint16; #endif #ifdef YYTYPE_INT16 typedef YYTYPE_INT16 yytype_int16; #else typedef short int yytype_int16; #endif #ifndef YYSIZE_T # ifdef __SIZE_TYPE__ # define YYSIZE_T __SIZE_TYPE__ # elif defined size_t # define YYSIZE_T size_t # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) # include /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # else # define YYSIZE_T unsigned int # endif #endif #define YYSIZE_MAXIMUM ((YYSIZE_T) -1) #ifndef YY_ # if defined YYENABLE_NLS && YYENABLE_NLS # if ENABLE_NLS # include /* INFRINGES ON USER NAME SPACE */ # define YY_(msgid) dgettext ("bison-runtime", msgid) # endif # endif # ifndef YY_ # define YY_(msgid) msgid # endif #endif /* Suppress unused-variable warnings by "using" E. */ #if ! defined lint || defined __GNUC__ # define YYUSE(e) ((void) (e)) #else # define YYUSE(e) /* empty */ #endif /* Identity function, used to suppress warnings about constant conditions. */ #ifndef lint # define YYID(n) (n) #else #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static int YYID (int yyi) #else static int YYID (yyi) int yyi; #endif { return yyi; } #endif #if ! defined yyoverflow || YYERROR_VERBOSE /* The parser invokes alloca or malloc; define the necessary symbols. */ # ifdef YYSTACK_USE_ALLOCA # if YYSTACK_USE_ALLOCA # ifdef __GNUC__ # define YYSTACK_ALLOC __builtin_alloca # elif defined __BUILTIN_VA_ARG_INCR # include /* INFRINGES ON USER NAME SPACE */ # elif defined _AIX # define YYSTACK_ALLOC __alloca # elif defined _MSC_VER # include /* INFRINGES ON USER NAME SPACE */ # define alloca _alloca # else # define YYSTACK_ALLOC alloca # if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) # include /* INFRINGES ON USER NAME SPACE */ # ifndef _STDLIB_H # define _STDLIB_H 1 # endif # endif # endif # endif # endif # ifdef YYSTACK_ALLOC /* Pacify GCC's `empty if-body' warning. */ # define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0)) # ifndef YYSTACK_ALLOC_MAXIMUM /* The OS might guarantee only one guard page at the bottom of the stack, and a page size can be as small as 4096 bytes. So we cannot safely invoke alloca (N) if N exceeds 4096. Use a slightly smaller number to allow for a few compiler-allocated temporary stack slots. */ # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */ # endif # else # define YYSTACK_ALLOC YYMALLOC # define YYSTACK_FREE YYFREE # ifndef YYSTACK_ALLOC_MAXIMUM # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM # endif # if (defined __cplusplus && ! defined _STDLIB_H \ && ! ((defined YYMALLOC || defined malloc) \ && (defined YYFREE || defined free))) # include /* INFRINGES ON USER NAME SPACE */ # ifndef _STDLIB_H # define _STDLIB_H 1 # endif # endif # ifndef YYMALLOC # define YYMALLOC malloc # if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */ # endif # endif # ifndef YYFREE # define YYFREE free # if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) void free (void *); /* INFRINGES ON USER NAME SPACE */ # endif # endif # endif #endif /* ! defined yyoverflow || YYERROR_VERBOSE */ #if (! defined yyoverflow \ && (! defined __cplusplus \ || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ union yyalloc { yytype_int16 yyss_alloc; YYSTYPE yyvs_alloc; }; /* The size of the maximum gap between one aligned stack and the next. */ # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) /* The size of an array large to enough to hold all stacks, each with N elements. */ # define YYSTACK_BYTES(N) \ ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \ + YYSTACK_GAP_MAXIMUM) /* Copy COUNT objects from FROM to TO. The source and destination do not overlap. */ # ifndef YYCOPY # if defined __GNUC__ && 1 < __GNUC__ # define YYCOPY(To, From, Count) \ __builtin_memcpy (To, From, (Count) * sizeof (*(From))) # else # define YYCOPY(To, From, Count) \ do \ { \ YYSIZE_T yyi; \ for (yyi = 0; yyi < (Count); yyi++) \ (To)[yyi] = (From)[yyi]; \ } \ while (YYID (0)) # endif # endif /* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of elements in the stack, and YYPTR gives the new location of the stack. Advance YYPTR to a properly aligned location for the next stack. */ # define YYSTACK_RELOCATE(Stack_alloc, Stack) \ do \ { \ YYSIZE_T yynewbytes; \ YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \ Stack = &yyptr->Stack_alloc; \ yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ yyptr += yynewbytes / sizeof (*yyptr); \ } \ while (YYID (0)) #endif /* YYFINAL -- State number of the termination state. */ #define YYFINAL 7 /* YYLAST -- Last index in YYTABLE. */ #define YYLAST 84 /* YYNTOKENS -- Number of terminals. */ #define YYNTOKENS 41 /* YYNNTS -- Number of nonterminals. */ #define YYNNTS 30 /* YYNRULES -- Number of rules. */ #define YYNRULES 65 /* YYNRULES -- Number of states. */ #define YYNSTATES 96 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ #define YYUNDEFTOK 2 #define YYMAXUTOK 295 #define YYTRANSLATE(YYX) \ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ static const yytype_uint8 yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 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 }; #if YYDEBUG /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in YYRHS. */ static const yytype_uint8 yyprhs[] = { 0, 0, 3, 4, 5, 13, 14, 17, 18, 22, 23, 29, 30, 33, 37, 41, 45, 49, 53, 57, 61, 63, 65, 67, 68, 70, 72, 76, 78, 82, 84, 88, 91, 92, 95, 97, 99, 101, 103, 105, 107, 111, 112, 115, 119, 123, 127, 129, 131, 133, 134, 136, 138, 142, 145, 146, 149, 151, 153, 155, 157, 159, 161, 163, 165, 166 }; /* YYRHS -- A `-1'-separated list of the rules' RHS. */ static const yytype_int8 yyrhs[] = { 42, 0, -1, -1, -1, 45, 46, 70, 43, 59, 44, 70, -1, -1, 6, 69, -1, -1, 46, 70, 47, -1, -1, 7, 62, 48, 69, 49, -1, -1, 49, 50, -1, 10, 5, 69, -1, 26, 63, 69, -1, 24, 52, 69, -1, 9, 51, 69, -1, 19, 68, 69, -1, 39, 51, 69, -1, 25, 67, 69, -1, 35, -1, 36, -1, 54, -1, -1, 53, -1, 56, -1, 53, 12, 56, -1, 55, -1, 54, 12, 55, -1, 56, -1, 55, 30, 56, -1, 62, 57, -1, -1, 58, 5, -1, 13, -1, 14, -1, 15, -1, 16, -1, 17, -1, 18, -1, 20, 69, 60, -1, -1, 60, 61, -1, 27, 52, 69, -1, 28, 52, 69, -1, 29, 52, 69, -1, 3, -1, 4, -1, 5, -1, -1, 64, -1, 65, -1, 64, 12, 65, -1, 62, 66, -1, -1, 13, 5, -1, 37, -1, 38, -1, 31, -1, 32, -1, 33, -1, 34, -1, 11, -1, 0, -1, -1, 70, 11, -1 }; /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const yytype_uint8 yyrline[] = { 0, 78, 78, 78, 78, 81, 82, 85, 86, 89, 89, 92, 93, 96, 97, 98, 99, 100, 101, 102, 105, 106, 107, 110, 111, 114, 115, 118, 119, 121, 122, 125, 128, 131, 134, 135, 136, 137, 138, 139, 142, 145, 146, 148, 149, 150, 153, 154, 155, 158, 159, 162, 163, 165, 167, 168, 174, 175, 178, 179, 180, 181, 184, 185, 188, 189 }; #endif #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = { "\"end of file\"", "error", "$undefined", "PACKAGE_NAME", "IDENTIFIER", "NUMBER", "PREAMBLE", "PACKAGE", "PROPERTY", "DEPENDS", "VERSION", "NEW_LINE", "COMMA", "EQUALS", "NOT_EQUALS", "GREATER_EQUALS", "GREATER", "LESS_EQUALS", "LESS", "KEEP", "REQUEST", "OPEN_SQUARE", "CLOSE_SQUARE", "COLON", "CONFLICTS", "INSTALLED", "PROVIDES", "INSTALL", "REMOVE", "UPGRADE", "PIPE", "KEEP_NONE_TOKEN", "KEEP_VERSION_TOKEN", "KEEP_PACKAGE_TOKEN", "KEEP_FEATURE_TOKEN", "TRUE_BANG", "FALSE_BANG", "BOOL_TRUE", "BOOL_FALSE", "RECOMMENDS", "STRING_VALUE", "$accept", "input", "$@1", "$@2", "preamble", "packages", "package", "$@3", "package_descriptions", "package_description", "package_cnf", "package_versions_list", "package_versions_list_plus", "conjunction_plus", "disjunction_plus", "package_versions", "version_specification", "operator", "request", "request_descriptions", "request_description", "package_name", "feature_list", "feature_list_plus", "feature", "feature_version", "boolean_value", "keep_value", "break_line", "new_lines", 0 }; #endif # ifdef YYPRINT /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to token YYLEX-NUM. */ static const yytype_uint16 yytoknum[] = { 0, 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 }; # endif /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ static const yytype_uint8 yyr1[] = { 0, 41, 43, 44, 42, 45, 45, 46, 46, 48, 47, 49, 49, 50, 50, 50, 50, 50, 50, 50, 51, 51, 51, 52, 52, 53, 53, 54, 54, 55, 55, 56, 57, 57, 58, 58, 58, 58, 58, 58, 59, 60, 60, 61, 61, 61, 62, 62, 62, 63, 63, 64, 64, 65, 66, 66, 67, 67, 68, 68, 68, 68, 69, 69, 70, 70 }; /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ static const yytype_uint8 yyr2[] = { 0, 2, 0, 0, 7, 0, 2, 0, 3, 0, 5, 0, 2, 3, 3, 3, 3, 3, 3, 3, 1, 1, 1, 0, 1, 1, 3, 1, 3, 1, 3, 2, 0, 2, 1, 1, 1, 1, 1, 1, 3, 0, 2, 3, 3, 3, 1, 1, 1, 0, 1, 1, 3, 2, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 0, 2 }; /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state STATE-NUM when YYTABLE doesn't specify something else to do. Zero means the default is an error. */ static const yytype_uint8 yydefact[] = { 5, 0, 0, 7, 63, 62, 6, 1, 64, 2, 0, 65, 0, 8, 46, 47, 48, 9, 0, 3, 0, 41, 64, 11, 40, 4, 10, 23, 23, 23, 42, 0, 0, 0, 23, 0, 49, 0, 12, 0, 24, 25, 32, 0, 0, 20, 21, 0, 22, 27, 29, 0, 58, 59, 60, 61, 0, 0, 56, 57, 0, 54, 0, 50, 51, 0, 43, 0, 34, 35, 36, 37, 38, 39, 31, 0, 44, 45, 16, 0, 0, 13, 17, 15, 19, 0, 53, 14, 0, 18, 26, 33, 28, 30, 55, 52 }; /* YYDEFGOTO[NTERM-NUM]. */ static const yytype_int8 yydefgoto[] = { -1, 2, 12, 22, 3, 8, 13, 20, 26, 38, 47, 39, 40, 48, 49, 41, 74, 75, 19, 24, 30, 42, 62, 63, 64, 86, 60, 56, 6, 9 }; /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */ #define YYPACT_NINF -31 static const yytype_int8 yypact[] = { 27, 4, 5, -31, -31, -31, -31, -31, -31, -1, 19, -31, 16, -31, -31, -31, -31, -31, 4, -31, 4, -31, -31, -31, 0, 14, 45, 19, 19, 19, -31, 9, 34, 26, 19, -6, 19, 9, -31, 4, 28, -31, 3, 4, 4, -31, -31, 4, 29, 13, -31, 4, -31, -31, -31, -31, 4, 4, -31, -31, 4, 33, 4, 40, -31, 4, -31, 19, -31, -31, -31, -31, -31, -31, -31, 56, -31, -31, -31, 19, 19, -31, -31, -31, -31, 57, -31, -31, 19, -31, -31, -31, 13, -31, -31, -31 }; /* YYPGOTO[NTERM-NUM]. */ static const yytype_int8 yypgoto[] = { -31, -31, -31, -31, -31, -31, -31, -31, -31, -31, 30, -26, -31, -31, -16, -30, -31, -31, -31, -31, -31, -10, -31, -31, -23, -31, -31, -31, -9, 44 }; /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If positive, shift that token. If negative, reduce the rule which number is the opposite. If zero, do what YYDEFACT says. If YYTABLE_NINF, syntax error. */ #define YYTABLE_NINF -1 static const yytype_uint8 yytable[] = { 17, 50, 43, 44, 4, 7, 10, 50, 57, 21, 11, 23, 14, 15, 16, 5, 68, 69, 70, 71, 72, 73, 14, 15, 16, 11, 61, 27, 28, 29, 66, 58, 59, 1, 76, 77, 18, 90, 78, 51, 67, 79, 81, 80, 45, 46, 85, 82, 83, 50, 93, 84, 88, 87, 31, 32, 89, 52, 53, 54, 55, 91, 94, 92, 33, 95, 25, 65, 0, 34, 35, 36, 0, 0, 0, 0, 0, 0, 61, 0, 0, 0, 0, 0, 37 }; static const yytype_int8 yycheck[] = { 10, 31, 28, 29, 0, 0, 7, 37, 34, 18, 11, 20, 3, 4, 5, 11, 13, 14, 15, 16, 17, 18, 3, 4, 5, 11, 36, 27, 28, 29, 39, 37, 38, 6, 43, 44, 20, 67, 47, 5, 12, 12, 51, 30, 35, 36, 13, 56, 57, 79, 80, 60, 12, 62, 9, 10, 65, 31, 32, 33, 34, 5, 5, 79, 19, 88, 22, 37, -1, 24, 25, 26, -1, -1, -1, -1, -1, -1, 88, -1, -1, -1, -1, -1, 39 }; /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing symbol of state STATE-NUM. */ static const yytype_uint8 yystos[] = { 0, 6, 42, 45, 0, 11, 69, 0, 46, 70, 7, 11, 43, 47, 3, 4, 5, 62, 20, 59, 48, 69, 44, 69, 60, 70, 49, 27, 28, 29, 61, 9, 10, 19, 24, 25, 26, 39, 50, 52, 53, 56, 62, 52, 52, 35, 36, 51, 54, 55, 56, 5, 31, 32, 33, 34, 68, 52, 37, 38, 67, 62, 63, 64, 65, 51, 69, 12, 13, 14, 15, 16, 17, 18, 57, 58, 69, 69, 69, 12, 30, 69, 69, 69, 69, 13, 66, 69, 12, 69, 56, 5, 55, 56, 5, 65 }; #define yyerrok (yyerrstatus = 0) #define yyclearin (yychar = YYEMPTY) #define YYEMPTY (-2) #define YYEOF 0 #define YYACCEPT goto yyacceptlab #define YYABORT goto yyabortlab #define YYERROR goto yyerrorlab /* Like YYERROR except do call yyerror. This remains here temporarily to ease the transition to the new meaning of YYERROR, for GCC. Once GCC version 2 has supplanted version 1, this can go. However, YYFAIL appears to be in use. Nevertheless, it is formally deprecated in Bison 2.4.2's NEWS entry, where a plan to phase it out is discussed. */ #define YYFAIL goto yyerrlab #if defined YYFAIL /* This is here to suppress warnings from the GCC cpp's -Wunused-macros. Normally we don't worry about that warning, but some users do, and we want to make it easy for users to remove YYFAIL uses, which will produce warnings from Bison 2.5. */ #endif #define YYRECOVERING() (!!yyerrstatus) #define YYBACKUP(Token, Value) \ do \ if (yychar == YYEMPTY && yylen == 1) \ { \ yychar = (Token); \ yylval = (Value); \ yytoken = YYTRANSLATE (yychar); \ YYPOPSTACK (1); \ goto yybackup; \ } \ else \ { \ yyerror (YY_("syntax error: cannot back up")); \ YYERROR; \ } \ while (YYID (0)) #define YYTERROR 1 #define YYERRCODE 256 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. If N is 0, then set CURRENT to the empty location which ends the previous symbol: RHS[0] (always defined). */ #define YYRHSLOC(Rhs, K) ((Rhs)[K]) #ifndef YYLLOC_DEFAULT # define YYLLOC_DEFAULT(Current, Rhs, N) \ do \ if (YYID (N)) \ { \ (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \ (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \ (Current).last_line = YYRHSLOC (Rhs, N).last_line; \ (Current).last_column = YYRHSLOC (Rhs, N).last_column; \ } \ else \ { \ (Current).first_line = (Current).last_line = \ YYRHSLOC (Rhs, 0).last_line; \ (Current).first_column = (Current).last_column = \ YYRHSLOC (Rhs, 0).last_column; \ } \ while (YYID (0)) #endif /* YY_LOCATION_PRINT -- Print the location on the stream. This macro was not mandated originally: define only if we know we won't break user code: when these are the locations we know. */ #ifndef YY_LOCATION_PRINT # if defined YYLTYPE_IS_TRIVIAL && YYLTYPE_IS_TRIVIAL # define YY_LOCATION_PRINT(File, Loc) \ fprintf (File, "%d.%d-%d.%d", \ (Loc).first_line, (Loc).first_column, \ (Loc).last_line, (Loc).last_column) # else # define YY_LOCATION_PRINT(File, Loc) ((void) 0) # endif #endif /* YYLEX -- calling `yylex' with the right arguments. */ #ifdef YYLEX_PARAM # define YYLEX yylex (YYLEX_PARAM) #else # define YYLEX yylex () #endif /* Enable debugging if requested. */ #if YYDEBUG # ifndef YYFPRINTF # include /* INFRINGES ON USER NAME SPACE */ # define YYFPRINTF fprintf # endif # define YYDPRINTF(Args) \ do { \ if (yydebug) \ YYFPRINTF Args; \ } while (YYID (0)) # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ do { \ if (yydebug) \ { \ YYFPRINTF (stderr, "%s ", Title); \ yy_symbol_print (stderr, \ Type, Value); \ YYFPRINTF (stderr, "\n"); \ } \ } while (YYID (0)) /*--------------------------------. | Print this symbol on YYOUTPUT. | `--------------------------------*/ /*ARGSUSED*/ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) #else static void yy_symbol_value_print (yyoutput, yytype, yyvaluep) FILE *yyoutput; int yytype; YYSTYPE const * const yyvaluep; #endif { if (!yyvaluep) return; # ifdef YYPRINT if (yytype < YYNTOKENS) YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); # else YYUSE (yyoutput); # endif switch (yytype) { default: break; } } /*--------------------------------. | Print this symbol on YYOUTPUT. | `--------------------------------*/ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep) #else static void yy_symbol_print (yyoutput, yytype, yyvaluep) FILE *yyoutput; int yytype; YYSTYPE const * const yyvaluep; #endif { if (yytype < YYNTOKENS) YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); else YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); yy_symbol_value_print (yyoutput, yytype, yyvaluep); YYFPRINTF (yyoutput, ")"); } /*------------------------------------------------------------------. | yy_stack_print -- Print the state stack from its BOTTOM up to its | | TOP (included). | `------------------------------------------------------------------*/ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop) #else static void yy_stack_print (yybottom, yytop) yytype_int16 *yybottom; yytype_int16 *yytop; #endif { YYFPRINTF (stderr, "Stack now"); for (; yybottom <= yytop; yybottom++) { int yybot = *yybottom; YYFPRINTF (stderr, " %d", yybot); } YYFPRINTF (stderr, "\n"); } # define YY_STACK_PRINT(Bottom, Top) \ do { \ if (yydebug) \ yy_stack_print ((Bottom), (Top)); \ } while (YYID (0)) /*------------------------------------------------. | Report that the YYRULE is going to be reduced. | `------------------------------------------------*/ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void yy_reduce_print (YYSTYPE *yyvsp, int yyrule) #else static void yy_reduce_print (yyvsp, yyrule) YYSTYPE *yyvsp; int yyrule; #endif { int yynrhs = yyr2[yyrule]; int yyi; unsigned long int yylno = yyrline[yyrule]; YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n", yyrule - 1, yylno); /* The symbols being reduced. */ for (yyi = 0; yyi < yynrhs; yyi++) { YYFPRINTF (stderr, " $%d = ", yyi + 1); yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi], &(yyvsp[(yyi + 1) - (yynrhs)]) ); YYFPRINTF (stderr, "\n"); } } # define YY_REDUCE_PRINT(Rule) \ do { \ if (yydebug) \ yy_reduce_print (yyvsp, Rule); \ } while (YYID (0)) /* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */ int yydebug; #else /* !YYDEBUG */ # define YYDPRINTF(Args) # define YY_SYMBOL_PRINT(Title, Type, Value, Location) # define YY_STACK_PRINT(Bottom, Top) # define YY_REDUCE_PRINT(Rule) #endif /* !YYDEBUG */ /* YYINITDEPTH -- initial size of the parser's stacks. */ #ifndef YYINITDEPTH # define YYINITDEPTH 200 #endif /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only if the built-in stack extension method is used). Do not make this value too large; the results are undefined if YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH) evaluated with infinite-precision integer arithmetic. */ #ifndef YYMAXDEPTH # define YYMAXDEPTH 10000 #endif #if YYERROR_VERBOSE # ifndef yystrlen # if defined __GLIBC__ && defined _STRING_H # define yystrlen strlen # else /* Return the length of YYSTR. */ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static YYSIZE_T yystrlen (const char *yystr) #else static YYSIZE_T yystrlen (yystr) const char *yystr; #endif { YYSIZE_T yylen; for (yylen = 0; yystr[yylen]; yylen++) continue; return yylen; } # endif # endif # ifndef yystpcpy # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE # define yystpcpy stpcpy # else /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in YYDEST. */ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static char * yystpcpy (char *yydest, const char *yysrc) #else static char * yystpcpy (yydest, yysrc) char *yydest; const char *yysrc; #endif { char *yyd = yydest; const char *yys = yysrc; while ((*yyd++ = *yys++) != '\0') continue; return yyd - 1; } # endif # endif # ifndef yytnamerr /* Copy to YYRES the contents of YYSTR after stripping away unnecessary quotes and backslashes, so that it's suitable for yyerror. The heuristic is that double-quoting is unnecessary unless the string contains an apostrophe, a comma, or backslash (other than backslash-backslash). YYSTR is taken from yytname. If YYRES is null, do not copy; instead, return the length of what the result would have been. */ static YYSIZE_T yytnamerr (char *yyres, const char *yystr) { if (*yystr == '"') { YYSIZE_T yyn = 0; char const *yyp = yystr; for (;;) switch (*++yyp) { case '\'': case ',': goto do_not_strip_quotes; case '\\': if (*++yyp != '\\') goto do_not_strip_quotes; /* Fall through. */ default: if (yyres) yyres[yyn] = *yyp; yyn++; break; case '"': if (yyres) yyres[yyn] = '\0'; return yyn; } do_not_strip_quotes: ; } if (! yyres) return yystrlen (yystr); return yystpcpy (yyres, yystr) - yyres; } # endif /* Copy into YYRESULT an error message about the unexpected token YYCHAR while in state YYSTATE. Return the number of bytes copied, including the terminating null byte. If YYRESULT is null, do not copy anything; just return the number of bytes that would be copied. As a special case, return 0 if an ordinary "syntax error" message will do. Return YYSIZE_MAXIMUM if overflow occurs during size calculation. */ static YYSIZE_T yysyntax_error (char *yyresult, int yystate, int yychar) { int yyn = yypact[yystate]; if (! (YYPACT_NINF < yyn && yyn <= YYLAST)) return 0; else { int yytype = YYTRANSLATE (yychar); YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]); YYSIZE_T yysize = yysize0; YYSIZE_T yysize1; int yysize_overflow = 0; enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; int yyx; # if 0 /* This is so xgettext sees the translatable formats that are constructed on the fly. */ YY_("syntax error, unexpected %s"); YY_("syntax error, unexpected %s, expecting %s"); YY_("syntax error, unexpected %s, expecting %s or %s"); YY_("syntax error, unexpected %s, expecting %s or %s or %s"); YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"); # endif char *yyfmt; char const *yyf; static char const yyunexpected[] = "syntax error, unexpected %s"; static char const yyexpecting[] = ", expecting %s"; static char const yyor[] = " or %s"; char yyformat[sizeof yyunexpected + sizeof yyexpecting - 1 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2) * (sizeof yyor - 1))]; char const *yyprefix = yyexpecting; /* Start YYX at -YYN if negative to avoid negative indexes in YYCHECK. */ int yyxbegin = yyn < 0 ? -yyn : 0; /* Stay within bounds of both yycheck and yytname. */ int yychecklim = YYLAST - yyn + 1; int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; int yycount = 1; yyarg[0] = yytname[yytype]; yyfmt = yystpcpy (yyformat, yyunexpected); for (yyx = yyxbegin; yyx < yyxend; ++yyx) if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) { if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) { yycount = 1; yysize = yysize0; yyformat[sizeof yyunexpected - 1] = '\0'; break; } yyarg[yycount++] = yytname[yyx]; yysize1 = yysize + yytnamerr (0, yytname[yyx]); yysize_overflow |= (yysize1 < yysize); yysize = yysize1; yyfmt = yystpcpy (yyfmt, yyprefix); yyprefix = yyor; } yyf = YY_(yyformat); yysize1 = yysize + yystrlen (yyf); yysize_overflow |= (yysize1 < yysize); yysize = yysize1; if (yysize_overflow) return YYSIZE_MAXIMUM; if (yyresult) { /* Avoid sprintf, as that infringes on the user's name space. Don't have undefined behavior even if the translation produced a string with the wrong number of "%s"s. */ char *yyp = yyresult; int yyi = 0; while ((*yyp = *yyf) != '\0') { if (*yyp == '%' && yyf[1] == 's' && yyi < yycount) { yyp += yytnamerr (yyp, yyarg[yyi++]); yyf += 2; } else { yyp++; yyf++; } } } return yysize; } } #endif /* YYERROR_VERBOSE */ /*-----------------------------------------------. | Release the memory associated to this symbol. | `-----------------------------------------------*/ /*ARGSUSED*/ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) static void yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep) #else static void yydestruct (yymsg, yytype, yyvaluep) const char *yymsg; int yytype; YYSTYPE *yyvaluep; #endif { YYUSE (yyvaluep); if (!yymsg) yymsg = "Deleting"; YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp); switch (yytype) { default: break; } } /* Prevent warnings from -Wmissing-prototypes. */ #ifdef YYPARSE_PARAM #if defined __STDC__ || defined __cplusplus int yyparse (void *YYPARSE_PARAM); #else int yyparse (); #endif #else /* ! YYPARSE_PARAM */ #if defined __STDC__ || defined __cplusplus int yyparse (void); #else int yyparse (); #endif #endif /* ! YYPARSE_PARAM */ /* The lookahead symbol. */ int yychar; /* The semantic value of the lookahead symbol. */ YYSTYPE yylval; /* Number of syntax errors so far. */ int yynerrs; /*-------------------------. | yyparse or yypush_parse. | `-------------------------*/ #ifdef YYPARSE_PARAM #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) int yyparse (void *YYPARSE_PARAM) #else int yyparse (YYPARSE_PARAM) void *YYPARSE_PARAM; #endif #else /* ! YYPARSE_PARAM */ #if (defined __STDC__ || defined __C99__FUNC__ \ || defined __cplusplus || defined _MSC_VER) int yyparse (void) #else int yyparse () #endif #endif { int yystate; /* Number of tokens to shift before error messages enabled. */ int yyerrstatus; /* The stacks and their tools: `yyss': related to states. `yyvs': related to semantic values. Refer to the stacks thru separate pointers, to allow yyoverflow to reallocate them elsewhere. */ /* The state stack. */ yytype_int16 yyssa[YYINITDEPTH]; yytype_int16 *yyss; yytype_int16 *yyssp; /* The semantic value stack. */ YYSTYPE yyvsa[YYINITDEPTH]; YYSTYPE *yyvs; YYSTYPE *yyvsp; YYSIZE_T yystacksize; int yyn; int yyresult; /* Lookahead token as an internal (translated) token number. */ int yytoken; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; #if YYERROR_VERBOSE /* Buffer for error messages, and its allocated size. */ char yymsgbuf[128]; char *yymsg = yymsgbuf; YYSIZE_T yymsg_alloc = sizeof yymsgbuf; #endif #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N)) /* The number of symbols on the RHS of the reduced rule. Keep to zero when no symbol should be popped. */ int yylen = 0; yytoken = 0; yyss = yyssa; yyvs = yyvsa; yystacksize = YYINITDEPTH; YYDPRINTF ((stderr, "Starting parse\n")); yystate = 0; yyerrstatus = 0; yynerrs = 0; yychar = YYEMPTY; /* Cause a token to be read. */ /* Initialize stack pointers. Waste one element of value and location stack so that they stay on the same level as the state stack. The wasted elements are never initialized. */ yyssp = yyss; yyvsp = yyvs; goto yysetstate; /*------------------------------------------------------------. | yynewstate -- Push a new state, which is found in yystate. | `------------------------------------------------------------*/ yynewstate: /* In all cases, when you get here, the value and location stacks have just been pushed. So pushing a state here evens the stacks. */ yyssp++; yysetstate: *yyssp = yystate; if (yyss + yystacksize - 1 <= yyssp) { /* Get the current used size of the three stacks, in elements. */ YYSIZE_T yysize = yyssp - yyss + 1; #ifdef yyoverflow { /* Give user a chance to reallocate the stack. Use copies of these so that the &'s don't force the real ones into memory. */ YYSTYPE *yyvs1 = yyvs; yytype_int16 *yyss1 = yyss; /* Each stack pointer address is followed by the size of the data in use in that stack, in bytes. This used to be a conditional around just the two extra args, but that might be undefined if yyoverflow is a macro. */ yyoverflow (YY_("memory exhausted"), &yyss1, yysize * sizeof (*yyssp), &yyvs1, yysize * sizeof (*yyvsp), &yystacksize); yyss = yyss1; yyvs = yyvs1; } #else /* no yyoverflow */ # ifndef YYSTACK_RELOCATE goto yyexhaustedlab; # else /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) goto yyexhaustedlab; yystacksize *= 2; if (YYMAXDEPTH < yystacksize) yystacksize = YYMAXDEPTH; { yytype_int16 *yyss1 = yyss; union yyalloc *yyptr = (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); if (! yyptr) goto yyexhaustedlab; YYSTACK_RELOCATE (yyss_alloc, yyss); YYSTACK_RELOCATE (yyvs_alloc, yyvs); # undef YYSTACK_RELOCATE if (yyss1 != yyssa) YYSTACK_FREE (yyss1); } # endif #endif /* no yyoverflow */ yyssp = yyss + yysize - 1; yyvsp = yyvs + yysize - 1; YYDPRINTF ((stderr, "Stack size increased to %lu\n", (unsigned long int) yystacksize)); if (yyss + yystacksize - 1 <= yyssp) YYABORT; } YYDPRINTF ((stderr, "Entering state %d\n", yystate)); if (yystate == YYFINAL) YYACCEPT; goto yybackup; /*-----------. | yybackup. | `-----------*/ yybackup: /* Do appropriate processing given the current state. Read a lookahead token if we need one and don't already have one. */ /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; if (yyn == YYPACT_NINF) goto yydefault; /* Not known => get a lookahead token if don't already have one. */ /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); yychar = YYLEX; } if (yychar <= YYEOF) { yychar = yytoken = YYEOF; YYDPRINTF ((stderr, "Now at end of input.\n")); } else { yytoken = YYTRANSLATE (yychar); YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc); } /* If the proper action on seeing token YYTOKEN is to reduce or to detect an error, take that action. */ yyn += yytoken; if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) goto yydefault; yyn = yytable[yyn]; if (yyn <= 0) { if (yyn == 0 || yyn == YYTABLE_NINF) goto yyerrlab; yyn = -yyn; goto yyreduce; } /* Count tokens shifted since error; after three, turn off error status. */ if (yyerrstatus) yyerrstatus--; /* Shift the lookahead token. */ YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc); /* Discard the shifted token. */ yychar = YYEMPTY; yystate = yyn; *++yyvsp = yylval; goto yynewstate; /*-----------------------------------------------------------. | yydefault -- do the default action for the current state. | `-----------------------------------------------------------*/ yydefault: yyn = yydefact[yystate]; if (yyn == 0) goto yyerrlab; goto yyreduce; /*-----------------------------. | yyreduce -- Do a reduction. | `-----------------------------*/ yyreduce: /* yyn is the number of a rule to reduce with. */ yylen = yyr2[yyn]; /* If YYLEN is nonzero, implement the default value of the action: `$$ = $1'. Otherwise, the following line sets YYVAL to garbage. This behavior is undocumented and Bison users should not rely upon it. Assigning to YYVAL unconditionally makes the parser a bit smaller, and it avoids a GCC warning that YYVAL may be used uninitialized. */ yyval = yyvsp[1-yylen]; YY_REDUCE_PRINT (yyn); switch (yyn) { case 2: /* Line 1464 of yacc.c */ #line 78 "p.bison" {parser.close_universe ();;} break; case 3: /* Line 1464 of yacc.c */ #line 78 "p.bison" {parser.close_input ();;} break; case 9: /* Line 1464 of yacc.c */ #line 89 "p.bison" {parser.start_package ();;} break; case 10: /* Line 1464 of yacc.c */ #line 89 "p.bison" { parser.close_package ();;} break; case 13: /* Line 1464 of yacc.c */ #line 96 "p.bison" { parser.action_version((yyvsp[(2) - (3)].str)); parser.end_processed_package_version (); ;} break; case 14: /* Line 1464 of yacc.c */ #line 97 "p.bison" { parser.package_provides(); ;} break; case 15: /* Line 1464 of yacc.c */ #line 98 "p.bison" { parser.package_conflicts(); ;} break; case 16: /* Line 1464 of yacc.c */ #line 99 "p.bison" { parser.package_depends(); ;} break; case 17: /* Line 1464 of yacc.c */ #line 100 "p.bison" { parser.package_keep(); ;} break; case 18: /* Line 1464 of yacc.c */ #line 101 "p.bison" { parser.package_recommends(); ;} break; case 19: /* Line 1464 of yacc.c */ #line 102 "p.bison" { parser.package_installed((yyvsp[(2) - (3)].Boolean)); ;} break; case 20: /* Line 1464 of yacc.c */ #line 105 "p.bison" {parser.action_CNF_true ();;} break; case 21: /* Line 1464 of yacc.c */ #line 106 "p.bison" {parser.action_CNF_false ();;} break; case 23: /* Line 1464 of yacc.c */ #line 110 "p.bison" { parser.package_versions_list_empty (); ;} break; case 25: /* Line 1464 of yacc.c */ #line 114 "p.bison" { parser.package_versions_list_first (); ;} break; case 26: /* Line 1464 of yacc.c */ #line 115 "p.bison" { parser.package_versions_list_next (); ;} break; case 27: /* Line 1464 of yacc.c */ #line 118 "p.bison" { parser.action_first_disjunction (); ;} break; case 28: /* Line 1464 of yacc.c */ #line 119 "p.bison" { parser.action_next_disjunction ();;} break; case 29: /* Line 1464 of yacc.c */ #line 121 "p.bison" { parser.action_first_literal();;} break; case 30: /* Line 1464 of yacc.c */ #line 122 "p.bison" { parser.action_next_literal();;} break; case 31: /* Line 1464 of yacc.c */ #line 125 "p.bison" {parser.action_package_versions ();;} break; case 32: /* Line 1464 of yacc.c */ #line 128 "p.bison" { parser.action_version_operator(VERSIONS_NONE); ;} break; case 33: /* Line 1464 of yacc.c */ #line 131 "p.bison" { parser.action_version ((yyvsp[(2) - (2)].str)); ;} break; case 34: /* Line 1464 of yacc.c */ #line 134 "p.bison" {parser.action_version_operator(VERSIONS_EQUALS);;} break; case 35: /* Line 1464 of yacc.c */ #line 135 "p.bison" {parser.action_version_operator(VERSIONS_NOT_EQUALS);;} break; case 36: /* Line 1464 of yacc.c */ #line 136 "p.bison" {parser.action_version_operator(VERSIONS_GREATER_EQUALS);;} break; case 37: /* Line 1464 of yacc.c */ #line 137 "p.bison" {parser.action_version_operator(VERSIONS_GREATER);;} break; case 38: /* Line 1464 of yacc.c */ #line 138 "p.bison" {parser.action_version_operator(VERSIONS_LESS_EQUALS);;} break; case 39: /* Line 1464 of yacc.c */ #line 139 "p.bison" {parser.action_version_operator(VERSIONS_LESS);;} break; case 43: /* Line 1464 of yacc.c */ #line 148 "p.bison" { parser.request_install (); ;} break; case 44: /* Line 1464 of yacc.c */ #line 149 "p.bison" { parser.request_remove ();;} break; case 45: /* Line 1464 of yacc.c */ #line 150 "p.bison" { parser.upgrade (); ;} break; case 46: /* Line 1464 of yacc.c */ #line 153 "p.bison" {parser.action_package_name ((yyvsp[(1) - (1)].str));;} break; case 47: /* Line 1464 of yacc.c */ #line 154 "p.bison" {parser.action_package_name ((yyvsp[(1) - (1)].str));;} break; case 48: /* Line 1464 of yacc.c */ #line 155 "p.bison" {parser.action_package_name ((yyvsp[(1) - (1)].str));;} break; case 49: /* Line 1464 of yacc.c */ #line 158 "p.bison" {parser.action_empty_feature_list();;} break; case 51: /* Line 1464 of yacc.c */ #line 162 "p.bison" {parser.action_first_feature();;} break; case 52: /* Line 1464 of yacc.c */ #line 163 "p.bison" {parser.action_next_feature();;} break; case 53: /* Line 1464 of yacc.c */ #line 165 "p.bison" {parser.action_feature();;} break; case 54: /* Line 1464 of yacc.c */ #line 167 "p.bison" {parser.action_version_operator(VERSIONS_NONE);;} break; case 55: /* Line 1464 of yacc.c */ #line 168 "p.bison" { parser.action_version_operator(VERSIONS_EQUALS); parser.action_version ((yyvsp[(2) - (2)].str)); ;} break; case 56: /* Line 1464 of yacc.c */ #line 174 "p.bison" { (yyval.Boolean) = true; ;} break; case 57: /* Line 1464 of yacc.c */ #line 175 "p.bison" { (yyval.Boolean) = false; ;} break; case 58: /* Line 1464 of yacc.c */ #line 178 "p.bison" { parser.action_keep_value (KEEP_NONE); ;} break; case 59: /* Line 1464 of yacc.c */ #line 179 "p.bison" { parser.action_keep_value (KEEP_VERSION); ;} break; case 60: /* Line 1464 of yacc.c */ #line 180 "p.bison" { parser.action_keep_value (KEEP_PACKAGE); ;} break; case 61: /* Line 1464 of yacc.c */ #line 181 "p.bison" { parser.action_keep_value (KEEP_FEATURE); ;} break; /* Line 1464 of yacc.c */ #line 1825 "p.tab.cc" default: break; } YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc); YYPOPSTACK (yylen); yylen = 0; YY_STACK_PRINT (yyss, yyssp); *++yyvsp = yyval; /* Now `shift' the result of the reduction. Determine what state that goes to, based on the state we popped back to and the rule number reduced by. */ yyn = yyr1[yyn]; yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) yystate = yytable[yystate]; else yystate = yydefgoto[yyn - YYNTOKENS]; goto yynewstate; /*------------------------------------. | yyerrlab -- here on detecting error | `------------------------------------*/ yyerrlab: /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { ++yynerrs; #if ! YYERROR_VERBOSE yyerror (YY_("syntax error")); #else { YYSIZE_T yysize = yysyntax_error (0, yystate, yychar); if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM) { YYSIZE_T yyalloc = 2 * yysize; if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM)) yyalloc = YYSTACK_ALLOC_MAXIMUM; if (yymsg != yymsgbuf) YYSTACK_FREE (yymsg); yymsg = (char *) YYSTACK_ALLOC (yyalloc); if (yymsg) yymsg_alloc = yyalloc; else { yymsg = yymsgbuf; yymsg_alloc = sizeof yymsgbuf; } } if (0 < yysize && yysize <= yymsg_alloc) { (void) yysyntax_error (yymsg, yystate, yychar); yyerror (yymsg); } else { yyerror (YY_("syntax error")); if (yysize != 0) goto yyexhaustedlab; } } #endif } if (yyerrstatus == 3) { /* If just tried and failed to reuse lookahead token after an error, discard it. */ if (yychar <= YYEOF) { /* Return failure if at end of input. */ if (yychar == YYEOF) YYABORT; } else { yydestruct ("Error: discarding", yytoken, &yylval); yychar = YYEMPTY; } } /* Else will try to reuse lookahead token after shifting the error token. */ goto yyerrlab1; /*---------------------------------------------------. | yyerrorlab -- error raised explicitly by YYERROR. | `---------------------------------------------------*/ yyerrorlab: /* Pacify compilers like GCC when the user code never invokes YYERROR and the label yyerrorlab therefore never appears in user code. */ if (/*CONSTCOND*/ 0) goto yyerrorlab; /* Do not reclaim the symbols of the rule which action triggered this YYERROR. */ YYPOPSTACK (yylen); yylen = 0; YY_STACK_PRINT (yyss, yyssp); yystate = *yyssp; goto yyerrlab1; /*-------------------------------------------------------------. | yyerrlab1 -- common code for both syntax error and YYERROR. | `-------------------------------------------------------------*/ yyerrlab1: yyerrstatus = 3; /* Each real token shifted decrements this. */ for (;;) { yyn = yypact[yystate]; if (yyn != YYPACT_NINF) { yyn += YYTERROR; if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) { yyn = yytable[yyn]; if (0 < yyn) break; } } /* Pop the current state because it cannot handle the error token. */ if (yyssp == yyss) YYABORT; yydestruct ("Error: popping", yystos[yystate], yyvsp); YYPOPSTACK (1); yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); } *++yyvsp = yylval; /* Shift the error token. */ YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp); yystate = yyn; goto yynewstate; /*-------------------------------------. | yyacceptlab -- YYACCEPT comes here. | `-------------------------------------*/ yyacceptlab: yyresult = 0; goto yyreturn; /*-----------------------------------. | yyabortlab -- YYABORT comes here. | `-----------------------------------*/ yyabortlab: yyresult = 1; goto yyreturn; #if !defined(yyoverflow) || YYERROR_VERBOSE /*-------------------------------------------------. | yyexhaustedlab -- memory exhaustion comes here. | `-------------------------------------------------*/ yyexhaustedlab: yyerror (YY_("memory exhausted")); yyresult = 2; /* Fall through. */ #endif yyreturn: if (yychar != YYEMPTY) yydestruct ("Cleanup: discarding lookahead", yytoken, &yylval); /* Do not reclaim the symbols of the rule which action triggered this YYABORT or YYACCEPT. */ YYPOPSTACK (yylen); YY_STACK_PRINT (yyss, yyssp); while (yyssp != yyss) { yydestruct ("Cleanup: popping", yystos[*yyssp], yyvsp); YYPOPSTACK (1); } #ifndef yyoverflow if (yyss != yyssa) YYSTACK_FREE (yyss); #endif #if YYERROR_VERBOSE if (yymsg != yymsgbuf) YYSTACK_FREE (yymsg); #endif /* Make sure YYID is used. */ return YYID (yyresult); } /* Line 1684 of yacc.c */ #line 190 "p.bison" packup-0.6/p.tab.hh0000644000175000010010000001030611573000736013276 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* A Bison parser, made by GNU Bison 2.4.2. */ /* Skeleton interface for Bison's Yacc-like parsers in C Copyright (C) 1984, 1989-1990, 2000-2006, 2009-2010 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ /* As a special exception, you may create a larger work that contains part or all of the Bison parser skeleton and distribute that work under terms of your choice, so long as that work isn't itself a parser generator using the skeleton or a modified version thereof as a parser skeleton. Alternatively, if you modify or redistribute the parser skeleton itself, you may (at your option) remove this special exception, which will cause the skeleton and the resulting Bison output files to be licensed under the GNU General Public License without this special exception. This special exception was added by the Free Software Foundation in version 2.2 of Bison. */ /* Tokens. */ #ifndef YYTOKENTYPE # define YYTOKENTYPE /* Put the tokens into the symbol table, so that GDB and other debuggers know about them. */ enum yytokentype { LEXER_END = 0, PACKAGE_NAME = 258, IDENTIFIER = 259, NUMBER = 260, PREAMBLE = 261, PACKAGE = 262, PROPERTY = 263, DEPENDS = 264, VERSION = 265, NEW_LINE = 266, COMMA = 267, EQUALS = 268, NOT_EQUALS = 269, GREATER_EQUALS = 270, GREATER = 271, LESS_EQUALS = 272, LESS = 273, KEEP = 274, REQUEST = 275, OPEN_SQUARE = 276, CLOSE_SQUARE = 277, COLON = 278, CONFLICTS = 279, INSTALLED = 280, PROVIDES = 281, INSTALL = 282, REMOVE = 283, UPGRADE = 284, PIPE = 285, KEEP_NONE_TOKEN = 286, KEEP_VERSION_TOKEN = 287, KEEP_PACKAGE_TOKEN = 288, KEEP_FEATURE_TOKEN = 289, TRUE_BANG = 290, FALSE_BANG = 291, BOOL_TRUE = 292, BOOL_FALSE = 293, RECOMMENDS = 294, STRING_VALUE = 295 }; #endif #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED typedef union YYSTYPE { /* Line 1685 of yacc.c */ #line 29 "p.bison" char* str; bool Boolean; /* Line 1685 of yacc.c */ #line 99 "p.tab.hh" } YYSTYPE; # define YYSTYPE_IS_TRIVIAL 1 # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 #endif extern YYSTYPE yylval; packup-0.6/PackageVersions.hh0000644000175000010010000000632311573000735015361 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: PackageVersions.h * Author: mikolas * * Created on August 27, 2010, 6:51 PM * Copyright (C) 2011, Mikolas Janota */ #ifndef PACKAGEVERSIONS_H #define PACKAGEVERSIONS_H #include #include #include #include #include "common_types.hh" using std::string; using std::stringstream; using std::cout; using std::cerr; using std::endl; using version_operators::Operator; using version_operators::VERSIONS_NONE; class PackageVersions { public: inline PackageVersions() : _op(VERSIONS_NONE), _version(0) {} inline PackageVersions(const PackageVersions& pvs) : _name(pvs._name), _op(pvs._op), _version(pvs._version) { assert ((op()!= VERSIONS_NONE) || version()==0); } inline PackageVersions(const string& pname,Operator pop,Version pversion) : _name(pname), _op(pop), _version(pversion) {} inline Version version() const {return _version;} inline Operator op() const {return _op;} inline string name() const {return _name;} void print (ostream& out=cerr) const { out<< name(); if (_op!=VERSIONS_NONE) out << version_operators::to_string(op()) << version(); } string to_string() const { stringstream strstr; print (strstr); return strstr.str(); } private: string _name; Operator _op; Version _version; }; struct eq_package_versions { bool operator()(const PackageVersions& pvs1, const PackageVersions& pvs2) const { if (pvs1.op() != pvs2.op()) return false; if ( (pvs1.op() != VERSIONS_NONE) && (pvs1.version() != pvs2.version()) ) return false; if (!SAME_PACKAGE_NAME(pvs1.name(),pvs2.name())) return false; return true; } }; struct hash_package_versions { size_t operator()(const PackageVersions& pvs) const { hash h1; return h1(pvs.name().data()) ^ ((size_t)pvs.op()) ^ ((size_t)pvs.version()); } }; #endif /* PACKAGEVERSIONS_H */ packup-0.6/PackageVersionVariables.cc0000644000175000010010000000345211573000735017015 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: PackageVersionVariables.cc * Author: mikolas * * Created on September 27, 2010, 2:19 PM * Copyright (C) 2011, Mikolas Janota */ #include "PackageVersionVariables.hh" PackageVersionVariables::PackageVersionVariables( IDManager& id_manager #ifdef MAPPING , unordered_map& variable_names , ofstream& mapping #endif ) : id_manager (id_manager) #ifdef MAPPING , variable_names (variable_names), mapping(mapping) #endif {} PackageVersionVariables::~PackageVersionVariables(){} packup-0.6/PackageVersionVariables.hh0000644000175000010010000000714211573000735017027 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: PackageVersionVariables.hh * Author: mikolas * * Created on September 27, 2010, 2:19 PM * Copyright (C) 2011, Mikolas Janota */ #ifndef PACKAGEVERSIONVARIABLES_HH #define PACKAGEVERSIONVARIABLES_HH #include "common_types.hh" #include "id_manager.hh" #include "collections.hh" class PackageVersionVariables { public: PackageVersionVariables(IDManager& id_manager #ifdef MAPPING , unordered_map& variable_names, ofstream& mapping #endif ); virtual ~PackageVersionVariables(); /** * Look for a variable in {@code variables}. * @param pv Feature or package version whose corresponding variable is searched for. * @param variable Is the search succeeds, the variable is placed in this variable, * otherwise it is unchanged. * @return True iff the search was successful. */ inline bool find_variable (CONSTANT PackageVersion &pv, Variable& variable) { PackageVersionMap::const_iterator i = variables.find(pv); if (i == variables.end ()) return false; variable = i->second; return true; } inline Variable add_variable_feature(CONSTANT PackageVersion& pv) { #ifdef MAPPING return add_variable (pv, "FV"); #else return add_variable (pv); #endif } inline Variable add_variable_package(CONSTANT PackageVersion& pv) { #ifdef MAPPING return add_variable (pv, "PV"); #else return add_variable (pv); #endif } inline bool has_variable (CONSTANT PackageVersion& pv) { return variables.find(pv) != variables.end(); } private: inline Variable add_variable (CONSTANT PackageVersion& pv #ifdef MAPPING ,CONSTANT string mn #endif ) { assert(!has_variable (pv)); CONSTANT Variable return_value = id_manager.new_id(); variables[pv]=return_value; #ifdef MAPPING string nm= mn + pv.to_string(); variable_names[return_value] = nm; mapping << return_value << "->" << nm << endl; #endif return return_value; } private: IDManager& id_manager; #ifdef MAPPING unordered_map& variable_names;// Names of variables for debugging purposes. ofstream& mapping; #endif PackageVersionMap variables; }; #endif /* PACKAGEVERSIONVARIABLES_HH */ packup-0.6/package_version.cc0000644000175000010010000000274411573000736015427 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: package_version.h * Author: mikolas * * Created on August 23, 2010, 5:29 PM * Copyright (C) 2011, Mikolas Janota */ #include "package_version.hh" hash h2; hash h1; packup-0.6/package_version.hh0000644000175000010010000000621011573000737015432 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: package_version.h * Author: mikolas * * Created on August 23, 2010, 5:29 PM * Copyright (C) 2011, Mikolas Janota */ #ifndef PACKAGE_VERSION_H #define PACKAGE_VERSION_H #include #include #include #include "common_types.hh" #include "PackageVersions.hh" using std::string; using std::cerr; using std::stringstream; extern hash h2; extern hash h1; class PackageVersion { public: PackageVersion() : _version(0) {}; PackageVersion(const PackageVersion& pv) : _name (pv._name), _version (pv._version), _hash_code(pv._hash_code) {} PackageVersion(const string& pname, Version pversion) : _name(pname), _version(pversion),_hash_code(h1(pname.data()) ^ h2(pversion)) {} void print () const {cerr << "[" << (name()) << "," << version() << "]";} string to_string() const { string return_value = string ("["); return_value+=name(); return_value+=string (","); stringstream ss; ss << version(); return_value+=ss.str(); return_value+=string("]"); return return_value; } size_t hash_code() const {return _hash_code;} Version version() const {return _version;} string name() const {return _name;} private: string _name; Version _version; size_t _hash_code; }; struct eq_package_version { bool operator()(const PackageVersion& pv1, const PackageVersion& pv2) const { //cout << "comparing "; pv1.print();pv2.print(); if (pv1.version() != pv2.version()) return false; if (!SAME_PACKAGE_NAME(pv1.name(),pv2.name())) return false; //bool rv=pv1.name.compare((pv2.name))==0; //cout << "true"; return true; } }; struct hash_package_version { size_t operator()(const PackageVersion& pv) const {return pv.hash_code();} }; #endif /* PACKAGE_VERSION_H */ packup-0.6/parser.cc0000644000175000010010000000502511573000737013557 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* Copyright (C) 2011, Mikolas Janota */ #include #include #include #include "parser.hh" using std::string; using std::cout; using std::cerr; using std::endl; void Parser::action_package_name(char* cname) { PDBG(cerr << "Package Name Token '" << (cname) << "'"<< endl;) //string name(cname); Str2Str::const_iterator index = package_names_set.find(cname); if (index != package_names_set.end()) { PDBG(cerr << "already there" << endl;) read_package_name = index->second; delete[] cname; } else { PDBG(cerr << "fstime" << endl;) read_package_name = cname; package_names_set[cname] = read_package_name; } } void Parser::action_first_disjunction () { read_CNF.clear(); read_CNF.push_back(read_clause); } void Parser::action_next_disjunction () { read_CNF.push_back(read_clause); } void Parser::action_first_literal() { read_clause= new VersionsList; read_clause->push_back(read_package_versions); } void Parser::action_next_literal() { read_clause->push_back(read_package_versions); } void Parser::action_CNF_true () { read_CNF.clear(); } void Parser::action_CNF_false () { read_CNF.clear(); read_CNF.push_back(new VersionsList()); } packup-0.6/parser.hh0000644000175000010010000001303011573000737013564 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: parser_functions.h * Author: mikolas * * Created on August 10, 2010, 6:12 PM * Copyright (C) 2011, Mikolas Janota */ #ifndef PARSER_FUNCTIONS_H #define PARSER_FUNCTIONS_H #ifdef PARS_DBG #define PDBG(t) t #else #define PDBG(t) #endif #include #include #include #include #include #include "common_types.hh" #include "collections.hh" #include "PackageVersions.hh" #include "package_version.hh" using namespace version_operators; using std::string; using std::vector; using std::cout; using std::cerr; using std::endl; using std::exception; class ReadException : public exception { public: ReadException(char* str) : s(str) {}; ~ReadException() throw() { delete[] s; } const char* what() const throw() { return s; } private: char* s; }; class Parser { public: virtual ~Parser() {}; /** Processing of a new package started.*/ virtual void start_package() = 0; /** Processing of a package stopped.*/ virtual void close_package() = 0; /**The version of currently processed package was read.*/ virtual void end_processed_package_version() = 0; /** The package universe has been fully read.*/ virtual void close_universe() = 0; /**The whole input was read.*/ virtual void close_input () = 0; //Package stanza virtual void package_provides() = 0; virtual void package_conflicts() = 0; // A list of conflicting versions was read. virtual void package_depends() = 0; virtual void package_recommends() = 0; virtual void package_keep() = 0; virtual void package_installed(bool installed_value) = 0; //Request stanzas virtual void request_install() = 0; virtual void request_remove() = 0; virtual void upgrade() = 0; void package_versions_list_empty() {read_package_versions_list.clear();} void package_versions_list_first() { read_package_versions_list.clear(); read_package_versions_list.push_back(read_package_versions); } void package_versions_list_next() {read_package_versions_list.push_back(read_package_versions);} void action_package_name(char* cname); void action_version_operator(Operator op) {read_operator=op;} Version action_version(char* version_string) { PDBG(cerr << "Version:" << (version_string) << endl;) const int r = sscanf(version_string, "%d", &read_version); if (r < 1) { static const char* ms = "Invalid version number: "; char* const message = new char [strlen(version_string)+strlen(ms)+1]; strcpy(message, ms); strcat(message, version_string); delete[] version_string; throw ReadException(message); } delete[] version_string; return read_version; } void action_package_versions() { read_package_versions = PackageVersions( read_package_name, read_operator, read_operator==VERSIONS_NONE? 0 : read_version); } void action_feature (){ assert (read_operator==VERSIONS_EQUALS ||read_operator==VERSIONS_NONE); read_feature = PackageVersion (read_package_name,read_operator==VERSIONS_NONE? 0 : read_version); }; void action_first_disjunction(); void action_next_disjunction(); void action_first_literal(); void action_next_literal(); void action_CNF_true(); void action_CNF_false(); void action_first_feature() { read_feature_list.clear (); read_feature_list.push_back(read_feature); } void action_next_feature(){ read_feature_list.push_back(read_feature); } void action_empty_feature_list() {read_feature_list.clear();} void action_keep_value (KeepValue value){read_keep_value = value;} protected: string read_package_name; Version read_version; Operator read_operator; KeepValue read_keep_value; vector package_names; vector feature_names; PackageVersions read_package_versions; PackageVersion read_feature; PackageVersionList read_feature_list; PackageVersionsCNF read_CNF; VersionsList* read_clause; VersionsList read_package_versions_list; Str2Str package_names_set; }; #endif /* PARSER_FUNCTIONS_H */ packup-0.6/Printer.cc0000644000175000010010000000565611573000735013716 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: Printer.cc * Author: mikolas * * Created on October 4, 2010, 2:04 PM * Copyright (C) 2011, Mikolas Janota */ #include "Printer.hh" Printer::Printer(CONSTANT VariableToName& variable_names) : variable_names (variable_names) {} Printer::~Printer() {} void Printer::print(BasicClause* cl, ostream& o, bool nice) const { Literator lpos = cl->begin(); Literator lend = cl->end(); for (; lpos != lend; ++lpos) { LINT l=*lpos; if (nice) o<< print_literal(l); else o << l; o << " "; } o << "0"; } void Printer::print(const LiteralVector& vs,ostream& o,bool nice/*=true*/) const { for (UINT i=0;i0) o<< " "; if (nice) o<< print_literal(vs[i]); else o << vs[i]; } } void Printer::print_solution(const LiteralVector& vs,ostream& o,bool nice/*=true*/) const { for (size_t i=1;i1) o<< " "; if (nice) o<< print_literal(literal); else o << literal; } } string Printer::print_literal (LINT literal) const { #ifdef CONV_DBG unordered_map::const_iterator i= variable_names.find(abs(literal)); if (i!=variable_names.end()) { if (literal>0) return i->second; else return "-" + i->second; } else { std::stringstream outs; // outs << "<<" << literal << ">>"; const bool sign = literal>0; outs << "<<" << (sign ? "+" : "-") << (sign ? literal : -literal) << ">>"; return outs.str(); } #else std::stringstream outs; outs << literal; return outs.str(); #endif } packup-0.6/Printer.hh0000644000175000010010000000370411573000735013720 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: Printer.hh * Author: mikolas * * Created on October 4, 2010, 2:04 PM * Copyright (C) 2011, Mikolas Janota */ #ifndef PRINTER_HH #define PRINTER_HH #include "collections.hh" #include "basic_clause.hh" class Printer { public: Printer(CONSTANT VariableToName& variable_names); virtual ~Printer(); void print (const LiteralVector& literals,ostream& o,bool nice=true) const; void print (BasicClause* cl,ostream& o,bool nice=true) const; void print_solution(const LiteralVector& vs,ostream& o,bool nice=true) const; string print_literal (LINT literal) const; private: CONSTANT VariableToName& variable_names; }; #endif /* PRINTER_HH */ packup-0.6/README.txt0000644000175000010010000000350411573000732013445 0ustar mikolasNonePackUP -- PACKage UPgradability with Boolean formulations ================================================================================= authors: Mikolas Janota, Joao Marques-Silva contributors: Ines Lynce, Vasco Manquinho email mikolas@sat.inesc-id.pt (C) 2011 Mikolas Janota Released under the GPL license. Overview -------------------------------------------------------------------------------- packup is a solver for the package upgradability problem specified in CUDF [TZ09]. It repeatedly invokes an optimization pseudo-Boolean solver in order to solve the problem. By default minisat+ [ES06] is used for that pusrpose but a different solver can be used by specifying the pertaining command line option. Usage -------------------------------------------------------------------------------- packup [OPTIONS] instance_file_name [output_file_name] -t trendy -p paranoid -u cs user criteria --external-solver command for the external solver default 'minisat+ -ansi' --multiplication-string string between coefficients and variables when communicating to the solver, default '*' --temporary-directory DIR where temporary files should be placed default if $TMPDIR if exists, '/tmp' otherwise --leave-temporary-files do not delete temporary files NOTE If the input file is '-', input is read from the standard input. If the output filename is omitted, output is produced to the standard output. References ------------------------------------------------------------------------------- [ES06] Niklas Een and Niklas Sorensson. Translating Pseudo-Boolean Constraints into SAT. SAT, 2006 [TZ09] Ralf Treinen and Stefano Zacchiroli. Common upgradeability description format (CUDF) 2.0. Technical Report 003, MANCOOSI, November 200 -- Mikolas Janota, May 2011 packup-0.6/rusage.hh0000644000175000010010000000631611573000737013567 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /*----------------------------------------------------------------------------*\ * Version: $Id: rusage.hh 73 2007-07-26 15:16:48Z jpms $ * * Author: jpms * * Description: Obtain time and memory resource usage stats. * Adapted from minisat and from MCSAT. * * Copyright (c) 2006, Joao Marques-Silva \*----------------------------------------------------------------------------*/ #ifndef _RUSAGE_HH_ #define _RUSAGE_HH_ 1 #include #include #include #include #include namespace RUSAGE { static inline double read_cpu_time(); static inline long read_mem_stats(int fields); static inline double read_mem_used(); static inline void print_cpu_time(const char* msg, ostream& outs=std::cout); static inline void print_mem_used(const char* msg, ostream& outs=std::cout); } static inline double RUSAGE::read_cpu_time() { struct rusage ru; getrusage(RUSAGE_SELF, &ru); return (double)ru.ru_utime.tv_sec + (double)ru.ru_utime.tv_usec / 1000000; } #define NSTRSZ 256 static inline long RUSAGE::read_mem_stats(int fields) { char name[NSTRSZ]; pid_t pid = getpid(); sprintf(name, "/proc/%d/statm", pid); FILE* finp = fopen(name, "rb"); if (finp == NULL) { /* assert(0); */ return 0; } int value; for (; fields >= 0; fields--) { fscanf(finp, "%d", &value); } fclose(finp); return value; } #define __1MBYTE__ 1048576 static inline double RUSAGE::read_mem_used() { return ((long)read_mem_stats(0) * (long)getpagesize() * 1.0) / __1MBYTE__; } static inline void RUSAGE::print_cpu_time(const char* msg, ostream& outs) { outs << msg << ": "<< RUSAGE::read_cpu_time() << endl; } static inline void RUSAGE::print_mem_used(const char* msg, ostream& outs) { outs << msg << ": " << RUSAGE::read_mem_used() << endl; } #endif /* _RUSAGE_HH_ */ /*----------------------------------------------------------------------------*/ packup-0.6/SolutionReader.cc0000644000175000010010000000776411573000735015234 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: SolutionReader.cc * Author: mikolas * * Created on September 19, 2010, 1:45 PM * Copyright (C) 2011, Mikolas Janota */ #include "SolutionReader.hh" #include #include #include #include "common_types.hh" #include "package_version.hh" using namespace std; inline bool begins_with (const string &s, const string & prefix) { if (s.length() < prefix.length ()) return false; return s.compare(0, prefix.length(), prefix)==0; } string remove_blank(const string &s, UINT pos1) { string return_value; UINT epos=s.length(); for (UINT i=pos1; i < epos; ++i) { char c=s[i]; if (c!= ' ') return_value+=c; } return return_value; } void SolutionReader::read (const char* file_name) { file.open(file_name); const string package="package: "; const string version="version: "; const string installed="installed: "; bool package_read=false, version_read=false, installed_read = false; string package_name; bool package_installed=false; UINT package_version=-1; while (file.good() && !file.eof()) { string line; getline(file, line); if (begins_with(line,package)) { package_read = true;version_read=false; installed_read = false; package_name=remove_blank(line, package.length()); #ifdef PARS_DBG cerr << "Package Name Token [" << package_name << "]"<< endl; #endif Str2Str::const_iterator index = _pns.find(package_name.c_str()); if (index != _pns.end()) { #ifdef PARS_DBG cerr << "already there" << endl; #endif package_name=index->second; } else { #ifdef PARS_DBG cerr << "fstime" << endl; #endif _pns[package_name.c_str()]=package_name; } } else if (begins_with(line,version)) { version_read = true; string version_str=remove_blank(line, version.length()); package_version=atoi(version_str.c_str()); } else if (begins_with(line,installed)) { installed_read = true; package_installed = line.find("true")!=line.npos; } if (package_read&&version_read&&installed_read) { package_read=false; version_read=false; installed_read = false; if (package_installed) { PackageVersion pv=PackageVersion(package_name, package_version); installed_package_versions.insert(pv); #ifdef PARS_DBG cerr << "sr: " << pv.to_string();// << endl; cerr << ( CONTAINS(installed_package_versions,pv) ? " inserted" : " not inserted" ) << endl; #endif } } } } packup-0.6/SolutionReader.hh0000644000175000010010000000346311573000735015236 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: SolutionReader.hh * Author: mikolas * * Created on September 19, 2010, 1:46 PM * Copyright (C) 2011, Mikolas Janota */ #ifndef SOLUTIONREADER_HH #define SOLUTIONREADER_HH #include #include "common_types.hh" #include "collections.hh" using std::ifstream; class SolutionReader { public: SolutionReader(Str2Str& pns) : _pns(pns) {} void read (const char* file_name); PackageVersionSet installed_package_versions; private: Str2Str& _pns; ifstream file; }; #endif /* SOLUTIONREADER_HH */ packup-0.6/SolverWrapper.hh0000644000175000010010000000620211573000735015104 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: SolverWrapper.hh * Author: mikolas * * Created on October 4, 2010, 1:32 PM * Copyright (C) 2011, Mikolas Janota */ #ifndef SOLVERWRAPPER_HH #define SOLVERWRAPPER_HH #include "collections.hh" #include "Printer.hh" template class SolverWrapper { public: virtual ~SolverWrapper() {} virtual void init () = 0; virtual void set_top(XLINT top)=0; virtual XLINT get_top()=0; virtual void output_clause (LiteralVector& literals) = 0; virtual ClausePtr record_clause (LiteralVector& literals) = 0; virtual void output_binary_clause (LINT l1, LINT l2) = 0; virtual void output_unary_clause (LINT l) = 0; virtual void output_weighted_clause(/*const*/ LiteralVector& literals,XLINT weight) = 0; virtual void output_unary_weighted_clause (LINT l, XLINT weight) = 0; virtual void output_binary_weighted_clause(LINT l1, LINT l2, XLINT weight) = 0; virtual void increase_weight(ClausePtr clause, XLINT weight) = 0; virtual bool solve() = 0; virtual IntVector& get_model() = 0; // Access computed model virtual bool has_solution() = 0; /** * This is used to produce single clauses from one clauses that resulted from summing up some of the weights. * This occurs when the same clause appears in multiple sometimes in the optimization function. * Summing the weights complicates the lexicographic algorithm for optimization. * @param weight this weight is being singled out. * @return weight was actually inserted */ virtual bool register_weight(XLINT weight) = 0; virtual UINT get_clause_count () =0; virtual XLINT get_soft_clauses_weight () =0; virtual XLINT get_min_unsat_cost() =0; virtual void dump(ostream& out) = 0; #ifdef CONV_DBG virtual void set_printer (Printer* clause_printer) = 0; #endif }; #endif /* SOLVERWRAPPER_HH */ packup-0.6/SolverWrapperBase.hh0000644000175000010010000001401111573000735015674 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: SolverWrapperBase.hh * Author: mikolas * * Created on October 4, 2010, 2:24 PM * Copyright (C) 2011, Mikolas Janota */ #ifndef SOLVERWRAPPERBASE_HH #define SOLVERWRAPPERBASE_HH #include "globals.hh" #include "common_types.hh" #include "Printer.hh" #include "SolverWrapper.hh" template class SolverWrapperBase : public SolverWrapper { public: SolverWrapperBase() : total_soft_weight(0), output_clause_count(0) {} virtual ~SolverWrapperBase() {}; #ifdef CONV_DBG void set_printer (Printer* clause_printer) {printer = clause_printer;} #endif void output_weighted_clause(LiteralVector& literals, XLINT weight) { unique_literals(literals); total_soft_weight+=weight; ++output_clause_count; OUT(cerr << weight << " "; printer->print (literals,cerr,true); cerr << " 0" << endl;) CNF_OUT(cout << weight << " "; printer->print (literals,cout,false); cout << " 0" << endl;) _output_weighted_clause (literals, weight); } void output_unary_weighted_clause(LINT l, XLINT weight) { total_soft_weight+=weight; ++output_clause_count; OUT (cerr << weight << " " << printer->print_literal(l) << " 0" << endl;) CNF_OUT (cout << weight << " " << l <<" 0" << endl;) _output_unary_weighted_clause (l, weight); } void output_binary_weighted_clause(LINT l1, LINT l2, XLINT weight) { if (l1==l2) output_unary_weighted_clause(l1, weight); total_soft_weight+=weight; ++output_clause_count; OUT (cerr << weight << " " << printer->print_literal (l1) << " " << printer->print_literal (l2) <<" 0" << endl;) CNF_OUT (cout << weight << " " << l1 << " " << l2 <<" 0" << endl;) _output_binary_weighted_clause (l1, l2, weight); } void output_unary_clause(LINT l) { ++output_clause_count; OUT (cerr << "T " <print_literal (l) <<" 0" << endl;) CNF_OUT (cout << "T " << l <<" 0" << endl;) _output_unary_clause (l); } void output_binary_clause(LINT l1, LINT l2) { if (l1==l2) output_unary_clause(l1); OUT (cerr << "T " << printer->print_literal (l1) <<" "<print_literal(l2) << " 0" << endl;) CNF_OUT (cout << "T " << l1 <<" "<print (literals,cerr,true); cerr << " 0" << endl;) CNF_OUT(cout << "T "; printer->print (literals,cout,false); cout << " 0" << endl;) ++output_clause_count; _output_clause (literals); } void increase_weight(BasicClause* clause, XLINT weight) { OUT(cerr << weight << " "; printer->print (clause,cerr,true); cerr << endl;) CNF_OUT(cout << weight << " "; printer->print (clause,cout,false); cout << endl;) ++output_clause_count; total_soft_weight+=weight; _increase_weight(clause, weight); } virtual ClausePointer record_clause (LiteralVector& literals) { unique_literals(literals); return _record_clause (literals); } virtual UINT get_clause_count () {return output_clause_count;} virtual XLINT get_soft_clauses_weight () {return total_soft_weight;} virtual void _output_clause (LiteralVector& literals) = 0; virtual ClausePointer _record_clause (LiteralVector& literals) = 0; virtual void _output_binary_clause (LINT l1, LINT l2) = 0; virtual void _output_unary_clause (LINT l) = 0; virtual void _output_weighted_clause(LiteralVector& literals,XLINT weight) = 0; virtual void _output_unary_weighted_clause (LINT l, XLINT weight) = 0; virtual void _output_binary_weighted_clause(LINT l1, LINT l2, XLINT weight) = 0; virtual void _increase_weight(ClausePointer clause, XLINT weight) = 0; protected: XLINT total_soft_weight; UINT output_clause_count; #ifdef CONV_DBG Printer* printer; #endif void unique_literals (LiteralVector& literals) { if (literals.empty()) return; sort(literals.begin(),literals.end(),AbsLitLess()); UINT insert_position = 1; UINT literal_position = 1; LINT last = literals[0]; while (literal_position . * \******************************************************************************/ /* * File: SolverWrapperTypes.hh * Author: mikolas * * Created on April 28, 2011, 4:38 PM * Copyright (C) 2011, Mikolas Janota */ #ifndef SOLVERWRAPPERTYPES_HH #define SOLVERWRAPPERTYPES_HH #ifdef EXTERNAL_SOLVER #include "basic_clause.hh" #include "ExternalWrapper.hh" typedef BasicClause* ClausePointer; typedef ExternalWrapper SolverType ; #endif #ifdef MULTI_LEVEL #include "basic_clause.hh" #include "xubmoWrapper.hh" typedef BasicClause* ClausePointer; typedef xubmoWrapper SolverType; #endif #ifdef SINGLE_LEVEL #include "msuncore.hh" #include "MSUnCoreWrapper.hh" typedef ClPtr ClausePointer; typedef MSUnCoreWrapper SolverType; #endif #endif /* SOLVERWRAPPERTYPES_HH */ packup-0.6/types.hh0000644000175000010010000002713111573000740013435 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /*----------------------------------------------------------------------------*\ * Version: $Id: types.hh 73 2007-07-26 15:16:48Z jpms $ * * Author: jpms * * Description: Type definitions used throughout. * * Copyright (c) 2005-2006, Joao Marques-Silva \*----------------------------------------------------------------------------*/ #ifndef _TYPES_HH_ #define _TYPES_HH_ 1 #include #include #include #include #include #include #include "basic_types.h" using namespace std; /*----------------------------------------------------------------------------*\ * Values besides 0 and 1 \*----------------------------------------------------------------------------*/ typedef enum logic_values { NoValue = 2 } LogicValues; #define NONE -1 /*----------------------------------------------------------------------------*\ * Functor utilities \*----------------------------------------------------------------------------*/ class AbsLitLess { public: bool operator()(LINT a, LINT b) const { return fabs(a) < fabs(b); } }; class AbsLitGreater { public: bool operator()(LINT a, LINT b) const { return fabs(a) > fabs(b); } }; class PtrLess { public: bool operator()(const void* pa, const void* pb) const { return (ULINT)pa < (ULINT)pb; } }; /*----------------------------------------------------------------------------*\ * Additional functors to be used in the definition of hash sets and maps \*----------------------------------------------------------------------------*/ class PtrHash { public: ULINT operator()(const void* ptr) const { return (ULINT)ptr; } }; class PtrEqual { public: bool operator()(const void* ptr1, const void* ptr2) const { return ptr1 == ptr2; } }; class IntHash { public: LINT operator()(LINT val) const { return val; } }; class IntEqual { public: bool operator()(LINT v1, LINT v2) const { return v1 == v2; } }; class ULIntHash { public: ULINT operator()(ULINT val) const { return val; } }; class ULIntEqual { public: bool operator()(ULINT v1, ULINT v2) const { return v1 == v2; } }; class XLIntHash { public: LINT operator()(XLINT val) const { return ToLint(val); } //#ifdef GMPDEF // return val.get_si(); //#else // return (LINT)val; //#endif // } }; class XLIntEqual { public: bool operator()(XLINT v1, XLINT v2) const { return v1 == v2; } }; class StrHash { public: ULINT operator()(string str) const { ULINT res = 0; string::const_iterator p = str.begin(); string::const_iterator end = str.end(); while (p!=end) { res = (res<<1) ^ *p++; } return res; } }; struct eqstr { bool operator()(const string s1, const string s2) const { return strcmp((char*)(s1.c_str()), (char*)(s2.c_str())) == 0; } }; struct eqint { bool operator()(int v1, int v2) const { return v1 == v2; } }; /*----------------------------------------------------------------------------*\ * Type definitions for maps and sets used throughout, most of which will be * based on int's and ptr's \*----------------------------------------------------------------------------*/ #include #include #include #include #include // Location of STL list extensions #include // Location of STL hash extensions #include // Location of STL hash extensions using namespace std; using namespace __gnu_cxx; // Required for STL hash extensions #ifdef USE_RBTREE_SETS template class StdSet : public set { public: void dump(ostream& outs=std::cout) { typename StdSet::iterator npos = this->begin(); typename StdSet::iterator nend = this->end(); for (; npos != nend; ++npos) { outs << *npos << " "; } } friend ostream & operator << (ostream& outs, StdSet& ss) { ss.dump(outs); return outs; } inline bool exists(T v) { return this->find(v) != this->end(); } }; typedef StdSet IntSet; template // K should be pointer type class RefSet : public StdSet { }; template class StdMap : public multimap { public: inline bool exists(TK k) { return this->find(k) != this->end(); } inline bool exists(TK k, TV v) { pair::iterator, typename StdMap::iterator> pp = equal_range(k); typename StdMap::iterator ppos = pp.first; typename StdMap::iterator pend = pp.second; for(; ppos != pend; ++ppos) { if (ppos->second == v) { return true; } } return false; } inline void insert(pair v) { multimap::insert(v); } inline void insert(TK v1,TV v2) { this->insert(make_pair(v1,v2)); } inline TV lookup(TK k) { assert(exists(k)); return this->find(k)->second; } void dump(ostream& outs=std::cout) { typename StdMap::iterator npos = this->begin(); typename StdMap::iterator nend = this->end(); for (; npos != nend; ++npos) { outs << npos->second << " "; } } friend ostream & operator << (ostream& outs, StdMap& sm) { sm.dump(outs); return outs; } }; template class IntKeyMap : public StdMap { }; template // K should be pointer type class RefKeyMap : public StdMap { }; #else template class StdSet : public hash_set { public: inline bool exists(T v) { return this->find(v) != this->end(); } inline void insert(T v) { unsigned int sz = this->size(); if (sz >= 2*this->bucket_count()) { // Optimizing # resizes //DBG( cout<<"Resizing a ""T"" set "<resize(8*(sz+(sz==0)?1:0)+1); } hash_set::insert(v); } void dump(ostream& outs=std::cout) { typename StdSet::iterator npos = this->begin(); typename StdSet::iterator nend = this->end(); for (; npos != nend; ++npos) { outs << *npos << " "; } } friend ostream & operator << (ostream& outs, StdSet& ss) { ss.dump(outs); return outs; } }; typedef StdSet IntSet; template // K should be pointer type class RefSet : public StdSet { }; template class StdMap : public hash_multimap { public: inline bool exists(TK k) { return this->find(k) != this->end(); } inline bool exists(TK k, TV v) { pair::iterator, typename StdMap::iterator> pp = this->equal_range(k); typename StdMap::iterator ppos = pp.first; typename StdMap::iterator pend = pp.second; for(; ppos != pend; ++ppos) { if (ppos->second == v) { return true; } } return false; } inline void insert(pair v) { unsigned int sz = this->size(); if (sz >= 2*this->bucket_count()) { // Optimizing # resizes //DBG( cout<<"Resizing a ""TK"" map "<resize(8*(sz+(sz==0)?1:0)+1); } hash_multimap::insert(v); } inline void insert(TK v1, TV v2) { this->insert(make_pair(v1,v2)); } inline TV lookup(TK k) { assert(exists(k)); return find(k)->second; } void dump(ostream& outs=std::cout) { typename StdMap::iterator npos = this->begin(); typename StdMap::iterator nend = this->end(); for (; npos != nend; ++npos) { outs << npos->first << "->" << npos->second << endl; } } friend ostream & operator << (ostream& outs, StdMap& sm) { sm.dump(outs); return outs; } }; template class IntKeyMap : public StdMap { }; template // K should be pointer type class RefKeyMap : public StdMap { }; #endif typedef vector BoolVector; //typedef IntKeyMap OptInt2IntMap; // Int 2 Int map //typedef IntKeyMap Int2RefMap; // Int 2 Ref map //template //class Ref2IntMap : public RefKeyMap { }; typedef hash_map Int2IntMap; typedef hash_map XLInt2XLIntMap; typedef hash_map XLInt2IntMap; //typedef map XLInt2IntMap; //typedef map XLStr2IntMap; typedef hash_set ULINTSet; typedef hash_set LINTSet; typedef vector UIntVector; typedef vector IntVector; typedef vector XLIntVector; typedef hash_map*,IntHash,IntEqual> Int2IntVMap; typedef hash_map Int2BoolMap; typedef Int2IntMap IDMap; // Std map of ID's typedef IntSet IDSet; // Std set of ID's template struct HashedSet { typedef hash_set Type; }; template struct Ref2RefPMap { typedef hash_map Type; }; template struct Ref2IntMap { typedef hash_map Type; }; template struct Ref2BoolMap { typedef hash_map Type; }; template struct Int2RefMap { typedef hash_map Type; }; //jpms:bc /*----------------------------------------------------------------------------*\ * Extras for using GMP \*----------------------------------------------------------------------------*/ //jpms:ec namespace gmpcmp { #ifdef GMPDEF #include template bool le(T a, U b) { return cmp(a, b) <= 0; } template bool lt(T a, U b) { return cmp(a, b) < 0; } template bool ge(T a, U b) { return cmp(a, b) >= 0; } template bool gt(T a, U b) { return cmp(a, b) > 0; } template bool eq(T a, U b) { return cmp(a, b) == 0; } template bool ne(T a, U b) { return cmp(a, b) != 0; } #else template bool le(T a, U b) { return a <= b; } template bool lt(T a, U b) { return a < b; } template bool ge(T a, U b) { return a >= b; } template bool gt(T a, U b) { return a > b; } template bool eq(T a, U b) { return a == b; } template bool ne(T a, U b) { return a != b; } #endif } #endif /* _TYPES_HH_ */ /*----------------------------------------------------------------------------*/ packup-0.6/VersionInstalled.hh0000644000175000010010000000416311573000736015563 0ustar mikolasNone/******************************************************************************\ * This file is part of packup. * * * * packup is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * packup is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with packup. If not, see . * \******************************************************************************/ /* * File: VesionInstalled.hh * Author: mikolas * * Created on September 16, 2010, 12:33 PM * Copyright (C) 2011, Mikolas Janota */ #ifndef VESIONINSTALLED_HH #define VESIONINSTALLED_HH #include "common_types.hh" class VersionInstalled { public: inline VersionInstalled(Version version,bool installed) : _version(version),_installed(installed) {} inline VersionInstalled(const VersionInstalled& orig) : _version(_version), _installed(orig._installed) {} inline Version version() const {return _version;} inline bool installed() const {return _installed;} private: Version _version; bool _installed; }; struct VersionInstalledCmp { inline bool operator()(const VersionInstalled& v1,const VersionInstalled& v2) const { return v1.version()