Skip to content

Commit

Permalink
* newline fixes (dos2unix)
Browse files Browse the repository at this point in the history
* add support to use curl_formadd (deprecated) instead of curl_mime_* for older distributions
* a few versioning and packaging fixes
  • Loading branch information
cr-marcstevens committed May 2, 2019
1 parent ff2aae6 commit 2acf15b
Show file tree
Hide file tree
Showing 8 changed files with 1,027 additions and 986 deletions.
19 changes: 18 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
AC_PREREQ([2.68])
AC_INIT([dblpbibtex], [2.0.0], [[email protected]],[dblpbibtex2],[https://github.com/cr-marcstevens/dblpbibtex2])
# Important: DBLPBIBTEX version needs to match with: ./version src/core.hpp
AC_INIT([dblpbibtex], [2.0a], [[email protected]],[dblpbibtex],[https://github.com/cr-marcstevens/dblpbibtex])
AC_CONFIG_SRCDIR([README.md])
AC_CONFIG_HEADERS([src/config.h])
AC_CONFIG_AUX_DIR([build-aux])
Expand Down Expand Up @@ -88,6 +89,22 @@ LIBS="$PTHREAD_LIBS $LIBS $LIBCURL"
CPPFLAGS="$CPPFLAGS $LIBCURL_CPPFLAGS"
CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS"

AC_MSG_CHECKING([if curl_mime_* is available])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <curl/curl.h>]],[[
/* test for curl_mime, otherwise use curl_formadd */
curl_global_init(CURL_GLOBAL_DEFAULT);
CURL* curl = curl_easy_init();
curl_mime* mime = nullptr;
curl_mimepart* part = nullptr;
mime = curl_mime_init(curl);
part = curl_mime_addpart(mime);
curl_mime_name(part, "test");
return 0;
]])],AC_MSG_RESULT([yes]),[
AC_MSG_RESULT([using curl_formadd instead])
AC_DEFINE([USE_CURL_FORM],[1],[Define if curl_mime_* is not available])
])

AC_CONFIG_FILES([
Makefile
])
Expand Down
168 changes: 84 additions & 84 deletions src/bib_get.hpp
Original file line number Diff line number Diff line change
@@ -1,84 +1,84 @@
// Copyright Marc Stevens 2010 - 2019.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include "core.hpp"
#include "network.hpp"

#include <contrib/string_algo.hpp>
namespace sa = string_algo;

/*** download citations ***/
bool download_dblp_citation(const std::string& key, bool prepend = true)
{
auto hdr_html = url_get("https://dblp.org/rec/bib2/" + key.substr(5));
auto& html = hdr_html.second;
if (html.empty())
return false;

auto it = sa::find(html, '@');
if (it == html.end())
return false;
auto it2 = sa::find(html, '@', it+1);
html.erase(it2, html.end());

if (html.empty())
return false;
std::cout << "Downloaded bibtex entry:" << std::endl << html << std::endl;
add_entry_to_mainbibfile(html, prepend);
return true;
}

bool download_cryptoeprint_citation(const std::string& key, bool prepend = true)
{
std::string year = std::string(key.begin()+key.find(':')+1, key.begin()+key.find_last_of(':'));
std::string paper = key.substr(key.find_last_of(':')+1);
auto hdr_html = url_get("https://eprint.iacr.org/eprint-bin/cite.pl?entry=" + year + "/" + paper);
auto& html = hdr_html.second;
if (html.empty())
return false;

html.erase(html.begin(), sa::ifind(html,"<pre>")+5);
html.erase(sa::ifind(html,"</pre>"), html.end());

if (html.empty())
return false;
std::cout << "Downloaded bibtex entry:" << std::endl << html << std::endl;
add_entry_to_mainbibfile(html, prepend);
return true;
}

bool download_citation(const std::string& key, bool prepend = true)
{
if (mainbibfile.empty()) {
std::cout << "No main bib file found!" << std::endl;
return false;
}

// download actual citation from DBLP or IACR ePrint
if (!params.nodblp && sa::istarts_with(key, "dblp:"))
return download_dblp_citation(key, prepend);
if (!params.nocryptoeprint && sa::istarts_with(key, "cryptoeprint:"))
return download_cryptoeprint_citation(key, prepend);

// process search citation and replace with results
if (key.find(':') == std::string::npos)
return false;
if (params.enablesearch && sa::istarts_with(key, "search:")) {
if (search_citation_bib(key))
return true;
if (search_citation_dblp(key))
return true;
if (search_citation_cryptoeprint(key))
return true;
return false;
}
if (params.enablesearch && sa::istarts_with(key, "search-dblp:"))
return search_citation_dblp(key);
if (params.enablesearch && sa::istarts_with(key, "search-cryptoeprint:"))
return search_citation_cryptoeprint(key);
if (params.enablesearch && sa::istarts_with(key, "search-bib:"))
return search_citation_bib(key);
return false;
}
// Copyright Marc Stevens 2010 - 2019.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include "core.hpp"
#include "network.hpp"

#include <contrib/string_algo.hpp>
namespace sa = string_algo;

/*** download citations ***/
bool download_dblp_citation(const std::string& key, bool prepend = true)
{
auto hdr_html = url_get("https://dblp.org/rec/bib2/" + key.substr(5));
auto& html = hdr_html.second;
if (html.empty())
return false;

auto it = sa::find(html, '@');
if (it == html.end())
return false;
auto it2 = sa::find(html, '@', it+1);
html.erase(it2, html.end());

if (html.empty())
return false;
std::cout << "Downloaded bibtex entry:" << std::endl << html << std::endl;
add_entry_to_mainbibfile(html, prepend);
return true;
}

bool download_cryptoeprint_citation(const std::string& key, bool prepend = true)
{
std::string year = std::string(key.begin()+key.find(':')+1, key.begin()+key.find_last_of(':'));
std::string paper = key.substr(key.find_last_of(':')+1);
auto hdr_html = url_get("https://eprint.iacr.org/eprint-bin/cite.pl?entry=" + year + "/" + paper);
auto& html = hdr_html.second;
if (html.empty())
return false;

html.erase(html.begin(), sa::ifind(html,"<pre>")+5);
html.erase(sa::ifind(html,"</pre>"), html.end());

if (html.empty())
return false;
std::cout << "Downloaded bibtex entry:" << std::endl << html << std::endl;
add_entry_to_mainbibfile(html, prepend);
return true;
}

bool download_citation(const std::string& key, bool prepend = true)
{
if (mainbibfile.empty()) {
std::cout << "No main bib file found!" << std::endl;
return false;
}

// download actual citation from DBLP or IACR ePrint
if (!params.nodblp && sa::istarts_with(key, "dblp:"))
return download_dblp_citation(key, prepend);
if (!params.nocryptoeprint && sa::istarts_with(key, "cryptoeprint:"))
return download_cryptoeprint_citation(key, prepend);

// process search citation and replace with results
if (key.find(':') == std::string::npos)
return false;
if (params.enablesearch && sa::istarts_with(key, "search:")) {
if (search_citation_bib(key))
return true;
if (search_citation_dblp(key))
return true;
if (search_citation_cryptoeprint(key))
return true;
return false;
}
if (params.enablesearch && sa::istarts_with(key, "search-dblp:"))
return search_citation_dblp(key);
if (params.enablesearch && sa::istarts_with(key, "search-cryptoeprint:"))
return search_citation_cryptoeprint(key);
if (params.enablesearch && sa::istarts_with(key, "search-bib:"))
return search_citation_bib(key);
return false;
}
Loading

0 comments on commit 2acf15b

Please sign in to comment.