aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerlaender2017-10-06 16:56:32 +0200
committerAdrian Kummerlaender2017-10-06 16:56:32 +0200
commit7f0c89c1890c662904bc6aa740a4515c2d5b595e (patch)
treedf269d3bf6b2e9a1323ab410d5827d6b35c64d50
parentb93f4fea59dfab2c8cb06d00b32a567838982bdf (diff)
downloadDictzipQuery-7f0c89c1890c662904bc6aa740a4515c2d5b595e.tar
DictzipQuery-7f0c89c1890c662904bc6aa740a4515c2d5b595e.tar.gz
DictzipQuery-7f0c89c1890c662904bc6aa740a4515c2d5b595e.tar.bz2
DictzipQuery-7f0c89c1890c662904bc6aa740a4515c2d5b595e.tar.lz
DictzipQuery-7f0c89c1890c662904bc6aa740a4515c2d5b595e.tar.xz
DictzipQuery-7f0c89c1890c662904bc6aa740a4515c2d5b595e.tar.zst
DictzipQuery-7f0c89c1890c662904bc6aa740a4515c2d5b595e.zip
Add support for arbitrary queries to example
-rw-r--r--example.cc25
1 files changed, 14 insertions, 11 deletions
diff --git a/example.cc b/example.cc
index f1fbc8c..af91d93 100644
--- a/example.cc
+++ b/example.cc
@@ -17,15 +17,18 @@ std::string get(const std::string& path, std::size_t offset, std::size_t length)
return result;
}
-int main() {
- // Get location of _Accession_
- const std::string line = dictzip::get_line_starting_with("gcide.index", "Accession");
-
- // Decode location of _Accession_
- // `gcide.index[1089]: "Accession 8Aw Wt"
- const std::size_t offset = dictzip::base64_decode(dictzip::get_encoded_offset(line));
- const std::size_t length = dictzip::base64_decode(dictzip::get_encoded_length(line));
-
- // Print the GCIDE definition of _Accession_
- std::cout << get("gcide.dict.dz", offset, length) << std::endl;
+int main(int argc, char** argv) {
+ if ( argc != 2 ) {
+ std::cerr << "Empty query." << std::endl;
+ } else {
+ // Get index entry of requested word definition
+ const std::string line = dictzip::get_line_starting_with("gcide.index", argv[1]);
+
+ // Decode location in compressed archive
+ const std::size_t offset = dictzip::base64_decode(dictzip::get_encoded_offset(line));
+ const std::size_t length = dictzip::base64_decode(dictzip::get_encoded_length(line));
+
+ // Print the GCIDE definition of _Accession_
+ std::cout << get("gcide.dict.dz", offset, length) << std::endl;
+ }
}