From 7c6d4f60f30085919c1e2ecc6d3b9e85702247ca Mon Sep 17 00:00:00 2001 From: Ashik K Date: Tue, 4 Apr 2023 14:10:13 +0200 Subject: [PATCH] add getopt() parsing to parser.cc --- parser.cc | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/parser.cc b/parser.cc index da8860f..4b03085 100644 --- a/parser.cc +++ b/parser.cc @@ -1,6 +1,9 @@ #include #include +#include +#include + #include #include #include @@ -14,17 +17,28 @@ std::string yearstr(int year) { int main(int argc, char **argv) { + int c; bool download_mode =false; - if (argc == 2) { - std::string arg1 = argv[1]; - download_mode = arg1=="--download"; - } + int numfiles = 0; + while ((c = getopt (argc, argv, "d:n:")) != -1) + switch(c) + { + case 'd': // download mode + download_mode = true; + break; + case 'n': // number of records + numfiles = atoi(optarg); + break; + default: + break; + } + char filename[64]; snprintf(filename, sizeof filename, "out.csv"); std::ofstream out_file1; out_file1.open(filename); out_file1<<"id, Caption/title, production start year, end year, Description, Item url, Image Source, image_filename, subjects, date published, collection name, museum name, exif_model, exif_iso, exif_focallength, exif_exposuretime, exif_aperture, exif_datetimeoriginal, liceses\n"; - for (auto i = 0; i<4; i++) { + for (auto i = 0; i