Compare commits
15 Commits
f6d552766b
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
fe0381c762
|
|||
|
019c4302ad
|
|||
|
189bf94034
|
|||
|
3071db8e19
|
|||
|
0bbcbb7207
|
|||
|
d57db951aa
|
|||
|
417115c3be
|
|||
|
3c96448bcf
|
|||
|
92902a4f76
|
|||
|
43ef4805a5
|
|||
|
a29a785b20
|
|||
|
accc095403
|
|||
|
b15ec36e38
|
|||
|
b000f5eca7
|
|||
|
35cbb8647d
|
@@ -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)
|
project (hex VERSION 0.1.0 LANGUAGES C)
|
||||||
|
|
||||||
# Moar warnings
|
# Moar warnings
|
||||||
@@ -40,9 +40,9 @@ else ()
|
|||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
set (project_libraries ${Unistring_LIBRARIES}
|
set (project_libraries ${Unistring_LIBRARIES}
|
||||||
${Ncursesw_LIBRARIES} termo-static)
|
${Ncursesw_LIBRARIES} ${Termo_LIBRARIES})
|
||||||
|
|
||||||
pkg_search_module (lua lua53 lua5.3 lua-5.3 lua>=5.3)
|
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})
|
option (WITH_LUA "Enable support for Lua plugins" ${lua_FOUND})
|
||||||
if (WITH_LUA)
|
if (WITH_LUA)
|
||||||
if (NOT lua_FOUND)
|
if (NOT lua_FOUND)
|
||||||
@@ -52,18 +52,9 @@ if (WITH_LUA)
|
|||||||
list (APPEND project_libraries ${lua_LIBRARIES})
|
list (APPEND project_libraries ${lua_LIBRARIES})
|
||||||
include_directories (${lua_INCLUDE_DIRS})
|
include_directories (${lua_INCLUDE_DIRS})
|
||||||
link_directories (${lua_LIBRARY_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 ()
|
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})
|
option (WITH_X11 "Build with X11 support" ${x11_FOUND})
|
||||||
if (WITH_X11)
|
if (WITH_X11)
|
||||||
if (NOT x11_FOUND)
|
if (NOT x11_FOUND)
|
||||||
@@ -79,6 +70,14 @@ include_directories (${Unistring_INCLUDE_DIRS}
|
|||||||
${Ncursesw_INCLUDE_DIRS} ${Termo_INCLUDE_DIRS})
|
${Ncursesw_INCLUDE_DIRS} ${Termo_INCLUDE_DIRS})
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
|
if ("${CMAKE_SYSTEM_NAME}" MATCHES "BSD")
|
||||||
|
# Need this for SIGWINCH in FreeBSD and OpenBSD respectively;
|
||||||
|
# our POSIX version macros make it undefined
|
||||||
|
add_definitions (-D__BSD_VISIBLE=1 -D_BSD_SOURCE=1)
|
||||||
|
elseif (APPLE)
|
||||||
|
add_definitions (-D_DARWIN_C_SOURCE)
|
||||||
|
endif ()
|
||||||
|
|
||||||
include (CheckFunctionExists)
|
include (CheckFunctionExists)
|
||||||
set (CMAKE_REQUIRED_LIBRARIES ${Ncursesw_LIBRARIES})
|
set (CMAKE_REQUIRED_LIBRARIES ${Ncursesw_LIBRARIES})
|
||||||
CHECK_FUNCTION_EXISTS ("resizeterm" HAVE_RESIZETERM)
|
CHECK_FUNCTION_EXISTS ("resizeterm" HAVE_RESIZETERM)
|
||||||
@@ -97,7 +96,27 @@ add_threads (${PROJECT_NAME})
|
|||||||
include (GNUInstallDirs)
|
include (GNUInstallDirs)
|
||||||
install (TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
|
install (TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||||
install (FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})
|
install (FILES LICENSE DESTINATION ${CMAKE_INSTALL_DOCDIR})
|
||||||
|
if (WITH_LUA)
|
||||||
|
install (DIRECTORY plugins
|
||||||
|
DESTINATION ${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME})
|
||||||
|
endif ()
|
||||||
if (WITH_X11)
|
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
|
install (FILES ${PROJECT_NAME}.desktop
|
||||||
DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
|
DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
|
||||||
endif ()
|
endif ()
|
||||||
@@ -149,7 +168,7 @@ foreach (page ${project_MAN_PAGES})
|
|||||||
endforeach ()
|
endforeach ()
|
||||||
|
|
||||||
# CPack
|
# CPack
|
||||||
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Hex viewer")
|
set (CPACK_PACKAGE_DESCRIPTION_SUMMARY "Interpreting hex viewer")
|
||||||
set (CPACK_PACKAGE_VENDOR "Premysl Eric Janouch")
|
set (CPACK_PACKAGE_VENDOR "Premysl Eric Janouch")
|
||||||
set (CPACK_PACKAGE_CONTACT "Přemysl Eric Janouch <p@janouch.name>")
|
set (CPACK_PACKAGE_CONTACT "Přemysl Eric Janouch <p@janouch.name>")
|
||||||
set (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
|
set (CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
|
||||||
|
|||||||
2
LICENSE
2
LICENSE
@@ -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
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
purpose with or without fee is hereby granted.
|
purpose with or without fee is hereby granted.
|
||||||
|
|||||||
15
README.adoc
15
README.adoc
@@ -11,8 +11,10 @@ image::hex.png[align="center"]
|
|||||||
|
|
||||||
Packages
|
Packages
|
||||||
--------
|
--------
|
||||||
Regular releases are sporadic. git master should be stable enough. You can get
|
Regular releases are sporadic. git master should be stable enough.
|
||||||
a package with the latest development version from Archlinux's AUR.
|
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
|
Documentation
|
||||||
-------------
|
-------------
|
||||||
@@ -21,10 +23,11 @@ The rest of this README will concern itself with externalities.
|
|||||||
|
|
||||||
Building and Running
|
Building and Running
|
||||||
--------------------
|
--------------------
|
||||||
Build dependencies: CMake, pkg-config, awk, liberty (included),
|
Build-only dependencies: CMake, pkg-config, awk, liberty (included),
|
||||||
termo (included), asciidoctor or asciidoc (recommended but optional) +
|
termo (included), asciidoctor or asciidoc (recommended but optional),
|
||||||
Runtime dependencies: ncursesw, libunistring, Lua >= 5.3 (for highlighting)
|
rsvg-convert (X11) +
|
||||||
Optional runtime dependencies: x11, xft
|
Runtime dependencies: ncursesw, libunistring, Lua >= 5.3 (for highlighting) +
|
||||||
|
Optional runtime dependencies: x11 + xft + libpng (X11)
|
||||||
|
|
||||||
$ git clone --recursive https://git.janouch.name/p/hex.git
|
$ git clone --recursive https://git.janouch.name/p/hex.git
|
||||||
$ mkdir hex/build
|
$ mkdir hex/build
|
||||||
|
|||||||
21
hex.c
21
hex.c
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* hex -- hex viewer
|
* 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
|
* Permission to use, copy, modify, and/or distribute this software for any
|
||||||
* purpose with or without fee is hereby granted.
|
* purpose with or without fee is hereby granted.
|
||||||
@@ -71,6 +71,12 @@ enum
|
|||||||
#include <lua.h>
|
#include <lua.h>
|
||||||
#include <lualib.h>
|
#include <lualib.h>
|
||||||
#include <lauxlib.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
|
#endif // WITH_LUA
|
||||||
|
|
||||||
#define APP_TITLE PROGRAM_NAME ///< Left top corner
|
#define APP_TITLE PROGRAM_NAME ///< Left top corner
|
||||||
@@ -164,7 +170,7 @@ g;
|
|||||||
|
|
||||||
// --- Configuration -----------------------------------------------------------
|
// --- Configuration -----------------------------------------------------------
|
||||||
|
|
||||||
static struct config_schema g_config_colors[] =
|
static const struct config_schema g_config_colors[] =
|
||||||
{
|
{
|
||||||
#define XX(name_, config, fg_, bg_, attrs_) \
|
#define XX(name_, config, fg_, bg_, attrs_) \
|
||||||
{ .name = config, .type = CONFIG_ITEM_STRING },
|
{ .name = config, .type = CONFIG_ITEM_STRING },
|
||||||
@@ -1205,6 +1211,8 @@ app_lua_load_plugins (const char *plugin_dir)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lua_pushcfunction (g.L, app_lua_error_handler);
|
||||||
|
|
||||||
struct dirent *iter;
|
struct dirent *iter;
|
||||||
while ((errno = 0, iter = readdir (dir)))
|
while ((errno = 0, iter = readdir (dir)))
|
||||||
{
|
{
|
||||||
@@ -1213,16 +1221,19 @@ app_lua_load_plugins (const char *plugin_dir)
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
char *path = xstrdup_printf ("%s/%s", plugin_dir, iter->d_name);
|
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)
|
if (luaL_loadfile (g.L, path)
|
||||||
|| lua_pcall (g.L, 0, 0, -2))
|
|| lua_pcall (g.L, 0, 0, -2))
|
||||||
exit_fatal ("Lua: %s", lua_tostring (g.L, -1));
|
{
|
||||||
lua_pop (g.L, 1);
|
print_error ("%s: %s", path, lua_tostring (g.L, -1));
|
||||||
|
lua_pop (g.L, 1);
|
||||||
|
}
|
||||||
free (path);
|
free (path);
|
||||||
}
|
}
|
||||||
if (errno)
|
if (errno)
|
||||||
exit_fatal ("readdir: %s", strerror (errno));
|
exit_fatal ("readdir: %s", strerror (errno));
|
||||||
closedir (dir);
|
closedir (dir);
|
||||||
|
|
||||||
|
lua_pop (g.L, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|||||||
10
hex.svg
Normal file
10
hex.svg
Normal 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 |
2
liberty
2
liberty
Submodule liberty updated: d01a1ff034...d8f785eae5
@@ -18,7 +18,7 @@
|
|||||||
-- See man 5 elf, /usr/include/elf.h and /usr/include/llvm/Support/ELF.h
|
-- See man 5 elf, /usr/include/elf.h and /usr/include/llvm/Support/ELF.h
|
||||||
|
|
||||||
local detect = function (c)
|
local detect = function (c)
|
||||||
return c:read (4) == "\x7FELF"
|
return #c >= 4 and c:read (4) == "\x7FELF"
|
||||||
end
|
end
|
||||||
|
|
||||||
local ph_type_table = {
|
local ph_type_table = {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
--
|
--
|
||||||
|
|
||||||
local detect = function (c)
|
local detect = function (c)
|
||||||
return c:read (2) == "\x1f\x8b"
|
return #c >= 2 and c:read (2) == "\x1f\x8b"
|
||||||
end
|
end
|
||||||
|
|
||||||
local function latin1_to_utf8 (s)
|
local function latin1_to_utf8 (s)
|
||||||
|
|||||||
@@ -16,11 +16,17 @@
|
|||||||
--
|
--
|
||||||
|
|
||||||
local detect = function (c)
|
local detect = function (c)
|
||||||
|
if #c < 4 then
|
||||||
|
return false
|
||||||
|
end
|
||||||
local magic = c:u32 ()
|
local magic = c:u32 ()
|
||||||
return magic == 0xa1b2c3d4 or magic == 0xd4c3b2a1
|
return magic == 0xa1b2c3d4 or magic == 0xd4c3b2a1
|
||||||
end
|
end
|
||||||
|
|
||||||
local detect_ng = function (c)
|
local detect_ng = function (c)
|
||||||
|
if #c < 8 then
|
||||||
|
return false
|
||||||
|
end
|
||||||
local magic = c (9):u32 ()
|
local magic = c (9):u32 ()
|
||||||
return c:u32 () == 0x0a0d0d0a
|
return c:u32 () == 0x0a0d0d0a
|
||||||
and (magic == 0x1a2b3c4d or magic == 0x4d3c2b1a)
|
and (magic == 0x1a2b3c4d or magic == 0x4d3c2b1a)
|
||||||
|
|||||||
@@ -335,7 +335,7 @@ end
|
|||||||
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||||
|
|
||||||
local detect = function (c)
|
local detect = function (c)
|
||||||
return c:read (5) == "%PDF-"
|
return #c >= 5 and c:read (5) == "%PDF-"
|
||||||
end
|
end
|
||||||
|
|
||||||
local decode_xref_subsection = function (lex, start, count, result)
|
local decode_xref_subsection = function (lex, start, count, result)
|
||||||
|
|||||||
@@ -16,6 +16,9 @@
|
|||||||
--
|
--
|
||||||
|
|
||||||
local detect = function (c)
|
local detect = function (c)
|
||||||
|
if #c < 68 then
|
||||||
|
return false
|
||||||
|
end
|
||||||
c.position = 65
|
c.position = 65
|
||||||
return c:read (4) == "\x7F\x10\xDA\xBE"
|
return c:read (4) == "\x7F\x10\xDA\xBE"
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
--
|
--
|
||||||
|
|
||||||
local detect = function (c)
|
local detect = function (c)
|
||||||
return c:read (4) == "Xcur"
|
return #c >= 4 and c:read (4) == "Xcur"
|
||||||
end
|
end
|
||||||
|
|
||||||
-- https://www.x.org/releases/current/doc/man/man3/Xcursor.3.xhtml
|
-- https://www.x.org/releases/current/doc/man/man3/Xcursor.3.xhtml
|
||||||
|
|||||||
2
termo
2
termo
Submodule termo updated: 8265f075b1...f9a102456f
Reference in New Issue
Block a user