diff options
author | Hubert Figuière <hub@figuiere.net> | 2022-03-31 23:01:57 -0400 |
---|---|---|
committer | Hubert Figuière <hub@figuiere.net> | 2022-03-31 23:01:57 -0400 |
commit | f159a0909ecf02c02e4a917d601b83cf523c2ebb (patch) | |
tree | f19611f085638bc2689d40d712d307568823fa5c /tools | |
parent | 50939af1be302e3a0e674a4c2a8e2658ab4eb72e (diff) |
Added tools/identify
- a quick command line tool to determine if a file can be read
Diffstat (limited to 'tools')
-rw-r--r-- | tools/Makefile.am | 5 | ||||
-rw-r--r-- | tools/identify.cpp | 111 |
2 files changed, 115 insertions, 1 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am index fcccf3b..273f5e9 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -2,10 +2,13 @@ AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/lib @BOOST_CPPFLAGS@ -noinst_PROGRAMS = ordiag exifdump +noinst_PROGRAMS = ordiag exifdump identify ordiag_SOURCES = ordiag.cpp dumputils.cpp dumputils.hpp ordiag_LDADD = $(top_builddir)/lib/libopenraw.la -ljpeg exifdump_SOURCES = exifdump.cpp dumputils.cpp dumputils.hpp exifdump_LDADD = $(top_builddir)/lib/libopenraw.la -ljpeg + +identify_SOURCES = identify.cpp +identify_LDADD = $(top_builddir)/lib/libopenraw.la -ljpeg diff --git a/tools/identify.cpp b/tools/identify.cpp new file mode 100644 index 0000000..7434606 --- /dev/null +++ b/tools/identify.cpp @@ -0,0 +1,111 @@ +/* + * libopenraw - identify.cpp + * + * Copyright (C) 2022 Hubert Figuière + * + * This library is free software: you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + */ + + +#include <iostream> +#include <string> +#include <vector> + +#include <libopenraw/libopenraw.h> + +void print_help() +{ + std::cerr << "identify [-h] [-d 0-9] [files...]\n"; + std::cerr << "Print libopenraw diagnostics\n"; + std::cerr << "\t-h: show this help\n"; + std::cerr << "\t-d level: set debug / verbosity to level\n"; + std::cerr << "\tfiles: the files to diagnose\n"; +} + +void print_version() +{ + std::cerr << "identify version 0.1 - (c) 2022 Hubert Figuiere\n"; +} + +int main(int argc, char **argv) +{ + int done = 0; + int dbl = 0; + std::string extract_thumbs; + std::vector<std::string> files; + + int o; + while((o = getopt(argc, argv, "hvdDt:")) != -1) { + switch (o) { + case 'h': + print_help(); + done = 1; + break; + case 'd': + dbl++; + break; + case '?': + break; + default: + break; + } + } + if (done) { + return 1; + } + for ( ; optind < argc; optind++) { + files.push_back(argv[optind]); + } + + if (files.empty()) { + std::cerr << "missing file name.\n"; + if (dbl) { + print_version(); + } + print_help(); + return 1; + } + + if (dbl >=2) { + or_debug_set_level(DEBUG2); + } + // do the business. + for_each(files.begin(), files.end(), [dbl] (const std::string& file) { + if (dbl) { + printf("Processing %s\n", file.c_str()); + } + ORRawFileRef rf = or_rawfile_new(file.c_str(), OR_RAWFILE_TYPE_UNKNOWN); + if (rf != nullptr) { + auto id = or_rawfile_get_typeid(rf); + printf("%s %u\n", file.c_str(), id); + or_rawfile_release(rf); + } else { + printf("Unrecognized: %s\n", file.c_str()); + } + }); + + return 0; +} +/* + Local Variables: + mode:c++ + c-basic-offset:4 + tab-width:4 + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)) + indent-tabs-mode:nil + fill-column:80 + End: +*/ |