Skip to content

Commit

Permalink
Move version printing into separate file.
Browse files Browse the repository at this point in the history
All the #ifdef stuff for printing version numbers is getting
a bit into the way in main timg.cc
  • Loading branch information
hzeller committed Jan 4, 2025
1 parent b2698a7 commit 52d47bb
Show file tree
Hide file tree
Showing 8 changed files with 182 additions and 107 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ target_sources(timg PRIVATE
timg-base64.h
timg-png.h timg-png.cc
timg-time.h
timg-print-version.h timg-print-version.cc
timg-help.h timg-help.cc
unicode-block-canvas.h unicode-block-canvas.cc
)
Expand Down
1 change: 1 addition & 0 deletions src/graphics-magick-source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <cstring>
#include <exception>
#include <string>
#include <vector>

#include "buffered-write-sequencer.h"
#include "display-options.h"
Expand Down
2 changes: 2 additions & 0 deletions src/pdf-image-source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#include <algorithm>
#include <csignal>
#include <filesystem>
#include <memory>
#include <string>
#include <utility>

#include "display-options.h"
#include "framebuffer.h"
Expand Down
2 changes: 2 additions & 0 deletions src/stb-image-source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
#include "stb-image-source.h"

#define STB_IMAGE_IMPLEMENTATION
#include <algorithm>
#include <csignal>
#include <cstdint>
#include <cstdio>
#include <string>
#include <utility>

#include "buffered-write-sequencer.h"
#include "display-options.h"
Expand Down
4 changes: 2 additions & 2 deletions src/term-query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ static const char *QueryTerminal(const char *query, char *const buffer,
if (s_log_terminal_queries) {
debug_data(stderr, "Query: ", query, query_len);
debug_data(stderr, " Response: ", buffer, pos - buffer);
fprintf(stderr, " (%ldms)\n",
(timg::Time() - start).nanoseconds() / 1'000'000);
fprintf(stderr, " (%dms)\n",
(int)((timg::Time() - start).nanoseconds() / 1'000'000));
}
return found_pos;
}
Expand Down
124 changes: 124 additions & 0 deletions src/timg-print-version.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
// -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; -*-
// (c) 2025 Henner Zeller <[email protected]>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation version 2.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://gnu.org/licenses/gpl-2.0.txt>

#include "timg-print-version.h"

#include <cstdio>

// Includes to display version numbers
#ifdef WITH_TIMG_OPENSLIDE_SUPPORT
#include "openslide-source.h"
#endif
#ifdef WITH_TIMG_VIDEO
#include "video-source.h"
#endif
#ifdef WITH_TIMG_GRPAPHICSMAGICK
#include "graphics-magick-source.h"
#endif
#ifdef WITH_TIMG_SIXEL
#include <sixel.h>
#endif
#ifdef WITH_TIMG_RSVG
#include <cairo-version.h>
#include <librsvg/rsvg.h>
#endif
#ifdef WITH_TIMG_POPPLER
#include <cairo-version.h>
#include <poppler.h>
#endif

#ifdef WITH_TIMG_JPEG
#include <jconfig.h>
#endif
#include <libdeflate.h>
#include <libswscale/swscale.h> // NOLINT used for version.

#include "timg-version.h" // generated.
#ifndef TIMG_VERSION
#define TIMG_VERSION "(unknown)"
#endif

namespace timg {
const char *timgVersion() { return TIMG_VERSION; }

int PrintComponentVersions(FILE *stream) {
// Print our version and various version numbers from our dependencies.
fprintf(stream, "timg " TIMG_VERSION
" <https://timg.sh/>\n"
"Copyright (c) 2016..2024 Henner Zeller. "
"This program is free software; license GPL 2.0.\n\n");
#ifdef WITH_TIMG_GRPAPHICSMAGICK
fprintf(stream, "Image decoding %s\n",
timg::GraphicsMagickSource::VersionInfo());
#endif
#ifdef WITH_TIMG_OPENSLIDE_SUPPORT
fprintf(stream, "Openslide %s\n", timg::OpenSlideSource::VersionInfo());
#endif
#ifdef WITH_TIMG_JPEG
fprintf(stream, "Turbo JPEG ");
#ifdef LIBJPEG_TURBO_VERSION
#define jpeg_xstr(s) jpeg_str(s)
#define jpeg_str(s) #s
fprintf(stream, "%s", jpeg_xstr(LIBJPEG_TURBO_VERSION));
#endif
fprintf(stream, "\n");
#endif
#ifdef WITH_TIMG_RSVG
fprintf(stream, "librsvg %d.%d.%d + cairo %d.%d.%d\n",
LIBRSVG_MAJOR_VERSION, LIBRSVG_MINOR_VERSION, LIBRSVG_MICRO_VERSION,
CAIRO_VERSION_MAJOR, CAIRO_VERSION_MINOR, CAIRO_VERSION_MICRO);
#endif
#ifdef WITH_TIMG_POPPLER
fprintf(stream, "PDF rendering with poppler %s + cairo %d.%d.%d",
poppler_get_version(), CAIRO_VERSION_MAJOR, CAIRO_VERSION_MINOR,
CAIRO_VERSION_MICRO);
#if not POPPLER_CHECK_VERSION(0, 88, 0)
// Too old versions of poppler don't have a bounding-box function
fprintf(stream, " (no --auto-crop)");
#endif
fprintf(stream, "\n");
#endif
#ifdef WITH_TIMG_QOI
fprintf(stream, "QOI image loading\n");
#endif
#ifdef WITH_TIMG_STB
fprintf(stream,
"STB image loading; STB resize v"
#ifdef STB_RESIZE_VERSION2
"2"
#else
"1"
#endif
#ifdef WITH_TIMG_GRPAPHICSMAGICK
// If we have graphics magic, that will take images first,
// so STB will only really be called as fallback.
" (fallback)"
#endif
"\n");
#endif
fprintf(stream, "swscale %s\n", AV_STRINGIFY(LIBSWSCALE_VERSION));
#ifdef WITH_TIMG_VIDEO
fprintf(stream, "Video decoding %s\n", timg::VideoSource::VersionInfo());
#endif
#ifdef WITH_TIMG_SIXEL
fprintf(stream, "Libsixel version %s\n", LIBSIXEL_VERSION);
#endif
fprintf(stream, "libdeflate %s\n", LIBDEFLATE_VERSION_STRING);
fprintf(stream,
"Half, quarter, iterm2, and kitty graphics output: "
"timg builtin.\n");
return 0;
}
} // namespace timg
29 changes: 29 additions & 0 deletions src/timg-print-version.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; -*-
// (c) 2025 Henner Zeller <[email protected]>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation version 2.
//
// This program 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 General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://gnu.org/licenses/gpl-2.0.txt>

#ifndef TIMG_VERSION_H
#define TIMG_VERSION_H

#include <cstdio>

namespace timg {
// Return timg version.
const char *timgVersion();

// Print versions timg and all components to stream. Always return 0.
int PrintComponentVersions(FILE *stream);
} // namespace timg

#endif // TIMG_VERSION_H
Loading

0 comments on commit 52d47bb

Please sign in to comment.