Compare commits

...

11 Commits

Author SHA1 Message Date
fe0381c762 Bump liberty and termo
All checks were successful
Alpine 3.21 Success
Arch Linux AUR Success
OpenBSD 7.6 Success
2025-06-04 22:09:41 +02:00
019c4302ad Handle tiny files gracefully
All checks were successful
Alpine 3.20 Success
Arch Linux AUR Success
OpenBSD 7.5 Success
Lua detection functions used to cause fatal errors on failure to read.

We could also reconsider treating detection errors as fatal.
2024-12-08 22:37:12 +01:00
189bf94034 Bump liberty
All checks were successful
Alpine 3.20 Success
Arch Linux AUR Success
OpenBSD 7.5 Success
2024-08-08 09:25:23 +02:00
3071db8e19 Be actually able to use a system Termo library
All checks were successful
Alpine 3.19 Success
Arch Linux AUR Success
OpenBSD 7.3 Success
2024-04-10 17:32:50 +02:00
0bbcbb7207 Fix build on Alpine
All checks were successful
Arch Linux AUR Success
Alpine 3.19 Success
2024-04-09 20:47:01 +02:00
d57db951aa Plugin load errors should not be fatal
All checks were successful
Arch Linux AUR Success
2024-02-26 23:54:05 +01:00
417115c3be Bump liberty 2024-02-10 12:51:05 +01:00
3c96448bcf Bump liberty, add an icon 2024-02-10 11:06:55 +01:00
92902a4f76 CMakeLists.txt: declare compatibility with 3.27
Sadly, the 3.5 deprecation warning doesn't go away after this.
2023-08-01 03:16:04 +02:00
43ef4805a5 Bump liberty 2023-07-04 06:55:15 +02:00
a29a785b20 README.adoc: update package information 2023-07-01 22:00:04 +02:00
13 changed files with 69 additions and 29 deletions

View File

@@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.0)
cmake_minimum_required (VERSION 3.0...3.27)
project (hex VERSION 0.1.0 LANGUAGES C)
# Moar warnings
@@ -40,7 +40,7 @@ else ()
endif ()
set (project_libraries ${Unistring_LIBRARIES}
${Ncursesw_LIBRARIES} termo-static)
${Ncursesw_LIBRARIES} ${Termo_LIBRARIES})
pkg_search_module (lua lua53 lua5.3 lua-5.3 lua54 lua5.4 lua-5.4 lua>=5.3)
option (WITH_LUA "Enable support for Lua plugins" ${lua_FOUND})
@@ -52,18 +52,9 @@ if (WITH_LUA)
list (APPEND project_libraries ${lua_LIBRARIES})
include_directories (${lua_INCLUDE_DIRS})
link_directories (${lua_LIBRARY_DIRS})
include (CheckTypeSize)
set (CMAKE_REQUIRED_LIBRARIES ${lua_LIBRARIES})
set (CMAKE_REQUIRED_INCLUDES ${lua_INCLUDE_DIRS})
set (CMAKE_EXTRA_INCLUDE_FILES "lua.h")
CHECK_TYPE_SIZE (lua_Integer LUA_INTEGER)
if (NOT HAVE_LUA_INTEGER OR LUA_INTEGER LESS 8)
message (FATAL_ERROR "Lua must have at least 64-bit integers")
endif ()
endif ()
pkg_check_modules (x11 x11 xrender xft fontconfig)
pkg_check_modules (x11 x11 xrender xft fontconfig libpng)
option (WITH_X11 "Build with X11 support" ${x11_FOUND})
if (WITH_X11)
if (NOT x11_FOUND)
@@ -110,6 +101,22 @@ if (WITH_LUA)
DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})
endif ()
if (WITH_X11)
include (IconUtils)
set (icon_base ${PROJECT_BINARY_DIR}/icons)
set (icon_png_list)
foreach (icon_size 16 32 48)
icon_to_png (${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/${PROJECT_NAME}.svg
${icon_size} ${icon_base} icon_png)
list (APPEND icon_png_list ${icon_png})
endforeach ()
add_custom_target (icons ALL DEPENDS ${icon_png_list})
install (FILES ${PROJECT_NAME}.svg
DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/scalable/apps)
install (DIRECTORY ${icon_base}
DESTINATION ${CMAKE_INSTALL_DATADIR})
install (FILES ${PROJECT_NAME}.desktop
DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
endif ()

View File

@@ -1,4 +1,4 @@
Copyright (c) 2016 - 2023, Přemysl Eric Janouch <p@janouch.name>
Copyright (c) 2016 - 2024, Přemysl Eric Janouch <p@janouch.name>
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.

View File

@@ -11,8 +11,10 @@ image::hex.png[align="center"]
Packages
--------
Regular releases are sporadic. git master should be stable enough. You can get
a package with the latest development version from Archlinux's AUR.
Regular releases are sporadic. git master should be stable enough.
You can get a package with the latest development version using Arch Linux's
https://aur.archlinux.org/packages/hex-git[AUR],
or as a https://git.janouch.name/p/nixexprs[Nix derivation].
Documentation
-------------
@@ -21,10 +23,11 @@ The rest of this README will concern itself with externalities.
Building and Running
--------------------
Build dependencies: CMake, pkg-config, awk, liberty (included),
termo (included), asciidoctor or asciidoc (recommended but optional) +
Build-only dependencies: CMake, pkg-config, awk, liberty (included),
termo (included), asciidoctor or asciidoc (recommended but optional),
rsvg-convert (X11) +
Runtime dependencies: ncursesw, libunistring, Lua >= 5.3 (for highlighting) +
Optional runtime dependencies: x11, xft
Optional runtime dependencies: x11 + xft + libpng (X11)
$ git clone --recursive https://git.janouch.name/p/hex.git
$ mkdir hex/build

19
hex.c
View File

@@ -1,7 +1,7 @@
/*
* hex -- hex viewer
*
* Copyright (c) 2016 - 2023, Přemysl Eric Janouch <p@janouch.name>
* Copyright (c) 2016 - 2024, Přemysl Eric Janouch <p@janouch.name>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted.
@@ -71,6 +71,12 @@ enum
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
// This test is too annoying to do in CMake due to CheckTypeSize() being unable
// to take link_directories(), and the Lua constant is documented.
#if LUA_MAXINTEGER < INT64_MAX
#error Lua must have at least 64-bit integers
#endif
#endif // WITH_LUA
#define APP_TITLE PROGRAM_NAME ///< Left top corner
@@ -164,7 +170,7 @@ g;
// --- Configuration -----------------------------------------------------------
static struct config_schema g_config_colors[] =
static const struct config_schema g_config_colors[] =
{
#define XX(name_, config, fg_, bg_, attrs_) \
{ .name = config, .type = CONFIG_ITEM_STRING },
@@ -1205,6 +1211,8 @@ app_lua_load_plugins (const char *plugin_dir)
return;
}
lua_pushcfunction (g.L, app_lua_error_handler);
struct dirent *iter;
while ((errno = 0, iter = readdir (dir)))
{
@@ -1213,16 +1221,19 @@ app_lua_load_plugins (const char *plugin_dir)
continue;
char *path = xstrdup_printf ("%s/%s", plugin_dir, iter->d_name);
lua_pushcfunction (g.L, app_lua_error_handler);
if (luaL_loadfile (g.L, path)
|| lua_pcall (g.L, 0, 0, -2))
exit_fatal ("Lua: %s", lua_tostring (g.L, -1));
{
print_error ("%s: %s", path, lua_tostring (g.L, -1));
lua_pop (g.L, 1);
}
free (path);
}
if (errno)
exit_fatal ("readdir: %s", strerror (errno));
closedir (dir);
lua_pop (g.L, 1);
}
static void

10
hex.svg Normal file
View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg version="1.0" width="48" height="48" viewBox="0 0 48 48"
xmlns="http://www.w3.org/2000/svg">
<g transform="translate(24 24) scale(2 2)">
<path d="M 0 0 -10 0 -10 -10 0 -10 Z" stroke-width="0" fill="#c6ffd6" />
<path d="M 0 0 10 0 10 -10 0 -10 Z" stroke-width="0" fill="#ffd8d8" />
<path d="M 0 0 -10 0 -10 10 0 10 Z" stroke-width="0" fill="#d8d8ff" />
<path d="M 0 0 10 0 10 10 0 10 Z" stroke-width="0" fill="#ffffac" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 524 B

Submodule liberty updated: 717c301207...d8f785eae5

View File

@@ -18,7 +18,7 @@
-- See man 5 elf, /usr/include/elf.h and /usr/include/llvm/Support/ELF.h
local detect = function (c)
return c:read (4) == "\x7FELF"
return #c >= 4 and c:read (4) == "\x7FELF"
end
local ph_type_table = {

View File

@@ -16,7 +16,7 @@
--
local detect = function (c)
return c:read (2) == "\x1f\x8b"
return #c >= 2 and c:read (2) == "\x1f\x8b"
end
local function latin1_to_utf8 (s)

View File

@@ -16,11 +16,17 @@
--
local detect = function (c)
if #c < 4 then
return false
end
local magic = c:u32 ()
return magic == 0xa1b2c3d4 or magic == 0xd4c3b2a1
end
local detect_ng = function (c)
if #c < 8 then
return false
end
local magic = c (9):u32 ()
return c:u32 () == 0x0a0d0d0a
and (magic == 0x1a2b3c4d or magic == 0x4d3c2b1a)

View File

@@ -335,7 +335,7 @@ end
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
local detect = function (c)
return c:read (5) == "%PDF-"
return #c >= 5 and c:read (5) == "%PDF-"
end
local decode_xref_subsection = function (lex, start, count, result)

View File

@@ -16,6 +16,9 @@
--
local detect = function (c)
if #c < 68 then
return false
end
c.position = 65
return c:read (4) == "\x7F\x10\xDA\xBE"
end

View File

@@ -16,7 +16,7 @@
--
local detect = function (c)
return c:read (4) == "Xcur"
return #c >= 4 and c:read (4) == "Xcur"
end
-- https://www.x.org/releases/current/doc/man/man3/Xcursor.3.xhtml

2
termo

Submodule termo updated: 8265f075b1...f9a102456f