mirror of
https://github.com/NixOS/nix
synced 2025-06-27 08:31:16 +02:00
* Don't use the ATerm library for parsing/printing .drv files.
This commit is contained in:
parent
55b5ddd3ca
commit
efc7a579e8
14 changed files with 174 additions and 330 deletions
|
@ -1,16 +1,16 @@
|
|||
pkglib_LTLIBRARIES = libutil.la
|
||||
|
||||
libutil_la_SOURCES = util.cc hash.cc serialise.cc \
|
||||
archive.cc aterm.cc xml-writer.cc
|
||||
archive.cc xml-writer.cc
|
||||
|
||||
libutil_la_LIBADD = ../boost/format/libformat.la
|
||||
|
||||
pkginclude_HEADERS = util.hh hash.hh serialise.hh \
|
||||
archive.hh aterm.hh xml-writer.hh types.hh
|
||||
archive.hh xml-writer.hh types.hh
|
||||
|
||||
if !HAVE_OPENSSL
|
||||
libutil_la_SOURCES += \
|
||||
md5.c md5.h sha1.c sha1.h sha256.c sha256.h md32_common.h
|
||||
endif
|
||||
|
||||
AM_CXXFLAGS = -Wall -I$(srcdir)/.. ${aterm_include}
|
||||
AM_CXXFLAGS = -Wall -I$(srcdir)/..
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
#include "aterm.hh"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
using std::string;
|
||||
|
||||
|
||||
string nix::atPrint(ATerm t)
|
||||
{
|
||||
if (!t) throw Error("attempt to print null aterm");
|
||||
char * s = ATwriteToString(t);
|
||||
if (!s) throw Error("cannot print term");
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
std::ostream & operator << (std::ostream & stream, ATerm e)
|
||||
{
|
||||
return stream << nix::atPrint(e);
|
||||
}
|
||||
|
||||
|
||||
nix::Error nix::badTerm(const format & f, ATerm t)
|
||||
{
|
||||
char * s = ATwriteToString(t);
|
||||
if (!s) throw Error("cannot print term");
|
||||
if (strlen(s) > 1000) {
|
||||
int len;
|
||||
s = ATwriteToSharedString(t, &len);
|
||||
if (!s) throw Error("cannot print term");
|
||||
}
|
||||
return Error(format("%1%, in `%2%'") % f.str() % (string) s);
|
||||
}
|
||||
|
||||
|
||||
ATerm nix::toATerm(const char * s)
|
||||
{
|
||||
return (ATerm) ATmakeAppl0(ATmakeAFun((char *) s, 0, ATtrue));
|
||||
}
|
||||
|
||||
|
||||
ATerm nix::toATerm(const string & s)
|
||||
{
|
||||
return toATerm(s.c_str());
|
||||
}
|
||||
|
||||
|
||||
ATermList nix::toATermList(const StringSet & ss)
|
||||
{
|
||||
ATermList l = ATempty;
|
||||
for (StringSet::const_reverse_iterator i = ss.rbegin();
|
||||
i != ss.rend(); ++i)
|
||||
l = ATinsert(l, toATerm(*i));
|
||||
return l;
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
#ifndef __ATERM_H
|
||||
#define __ATERM_H
|
||||
|
||||
#include <aterm2.h>
|
||||
|
||||
#include "types.hh"
|
||||
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
||||
/* Print an ATerm. */
|
||||
string atPrint(ATerm t);
|
||||
|
||||
class ATermIterator
|
||||
{
|
||||
ATermList t;
|
||||
|
||||
public:
|
||||
ATermIterator(ATermList _t) : t(_t) { }
|
||||
ATermIterator & operator ++ ()
|
||||
{
|
||||
t = ATgetNext(t);
|
||||
return *this;
|
||||
}
|
||||
ATerm operator * ()
|
||||
{
|
||||
return ATgetFirst(t);
|
||||
}
|
||||
operator bool ()
|
||||
{
|
||||
return t != ATempty;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/* Throw an exception with an error message containing the given
|
||||
aterm. */
|
||||
Error badTerm(const format & f, ATerm t);
|
||||
|
||||
|
||||
/* Convert strings to ATerms. */
|
||||
ATerm toATerm(const char * s);
|
||||
ATerm toATerm(const string & s);
|
||||
|
||||
ATermList toATermList(const StringSet & ss);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Write an ATerm to an output stream. */
|
||||
std::ostream & operator << (std::ostream & stream, ATerm e);
|
||||
|
||||
|
||||
#endif /* !__ATERM_H */
|
|
@ -1006,6 +1006,47 @@ bool hasSuffix(const string & s, const string & suffix)
|
|||
}
|
||||
|
||||
|
||||
void expect(std::istream & str, const string & s)
|
||||
{
|
||||
char s2[s.size()];
|
||||
str.read(s2, s.size());
|
||||
if (string(s2, s.size()) != s)
|
||||
throw Error(format("expected string `%1%'") % s);
|
||||
}
|
||||
|
||||
|
||||
string parseString(std::istream & str)
|
||||
{
|
||||
string res;
|
||||
expect(str, "\"");
|
||||
int c;
|
||||
while ((c = str.get()) != '"')
|
||||
if (c == '\\') {
|
||||
c = str.get();
|
||||
if (c == 'n') res += '\n';
|
||||
else if (c == 'r') res += '\r';
|
||||
else if (c == 't') res += '\t';
|
||||
else res += c;
|
||||
}
|
||||
else res += c;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
bool endOfList(std::istream & str)
|
||||
{
|
||||
if (str.peek() == ',') {
|
||||
str.get();
|
||||
return false;
|
||||
}
|
||||
if (str.peek() == ']') {
|
||||
str.get();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void ignoreException()
|
||||
{
|
||||
try {
|
||||
|
|
|
@ -302,34 +302,23 @@ string int2String(int n);
|
|||
bool hasSuffix(const string & s, const string & suffix);
|
||||
|
||||
|
||||
/* Read string `s' from stream `str'. */
|
||||
void expect(std::istream & str, const string & s);
|
||||
|
||||
|
||||
/* Read a C-style string from stream `str'. */
|
||||
string parseString(std::istream & str);
|
||||
|
||||
|
||||
/* Utility function used to parse legacy ATerms. */
|
||||
bool endOfList(std::istream & str);
|
||||
|
||||
|
||||
/* Exception handling in destructors: print an error message, then
|
||||
ignore the exception. */
|
||||
void ignoreException();
|
||||
|
||||
|
||||
/* STL functions such as sort() pass a binary function object around
|
||||
by value, so it gets cloned a lot. This is bad if the function
|
||||
object has state or is simply large. This adapter wraps the
|
||||
function object to simulate passing by reference. */
|
||||
template<class F>
|
||||
struct binary_function_ref_adapter
|
||||
{
|
||||
F * p;
|
||||
|
||||
binary_function_ref_adapter(F * _p)
|
||||
{
|
||||
p = _p;
|
||||
}
|
||||
|
||||
typename F::result_type operator () (
|
||||
const typename F::first_argument_type & x,
|
||||
const typename F::second_argument_type & y)
|
||||
{
|
||||
return (*p)(x, y);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue