Skip to content

Commit

Permalink
add PKGDATADIR macro and fix makefile bug
Browse files Browse the repository at this point in the history
  • Loading branch information
odashi committed Mar 17, 2015
1 parent a116e62 commit 628c4e3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
3 changes: 1 addition & 2 deletions data/Makefile.am
@@ -1,4 +1,3 @@
dist_pkgdata_DATA = \
wsj.words.gz wsj.splits.gz wsj.lexicon.gz wsj.grammar.gz \
jdc.words.gz jdc.splits.gz jdc.lexicon.gz jdc.grammar.gz \
;
jdc.words.gz jdc.splits.gz jdc.lexicon.gz jdc.grammar.gz
2 changes: 1 addition & 1 deletion src/lib/Makefile.am
@@ -1,6 +1,6 @@
lib_LTLIBRARIES = libckylark.la

AM_CXXFLAGS = -I$(srcdir)/../include $(BOOST_CPPFLAGS)
AM_CXXFLAGS = -I$(srcdir)/../include $(BOOST_CPPFLAGS) -DPKGDATADIR='"$(pkgdatadir)"'

libckylark_la_SOURCES = \
BerkeleySignatureEstimator.cc \
Expand Down
17 changes: 17 additions & 0 deletions src/lib/StreamFactory.cc
Expand Up @@ -36,6 +36,23 @@ shared_ptr<InputStream> StreamFactory::createInputStream(const string & path) {
} catch (exception & ex) {
}

// try loading basic text stream from shared directory
string path2 = string(PKGDATADIR) + "/" + path;
try {
InputStream * stream = new TextInputStream(path2);
Tracer::println(1, "input path: " + path2 + " (mode=text)");
return shared_ptr<InputStream>(stream);
} catch (...) {
}

// try loading gzip stream from shared directory
string path2_gz = path2 + ".gz";
try {
InputStream * stream = new GZipInputStream(path2_gz);
Tracer::println(1, "input path: " + path2_gz + " (mode=gzip)");
return shared_ptr<InputStream>(stream);
} catch (exception & ex) {
}
// all cases are failed
throw runtime_error("StreamFactory::createInputStream: cannot open file: " + path);
}
Expand Down

0 comments on commit 628c4e3

Please sign in to comment.