Compare commits

..

5 Commits

Author SHA1 Message Date
969a4cfc3e liberty-xui: clip terminal drawing 2024-02-27 00:27:54 +01:00
ad5b2fb8cd asciiman: mildly improve compatibility
git manual pages render a little bit more sensibly now.
2024-02-12 10:57:23 +01:00
2a1f17a8f7 liberty-xdg: add desktop entry parser tests
And fix a discovered bug.
2024-02-10 12:49:01 +01:00
8d56fae41b liberty-xdg: actually make libpng optional 2024-02-10 12:20:44 +01:00
0239a4242a liberty-xdg: fix usage of volatile 2024-02-10 10:16:27 +01:00
5 changed files with 98 additions and 9 deletions

View File

@@ -36,7 +36,7 @@ endforeach ()
# Build some unit tests
include_directories (${PROJECT_SOURCE_DIR})
enable_testing ()
set (tests liberty proto)
set (tests liberty proto xdg)
pkg_check_modules (libpulse libpulse)
if (libpulse_FOUND)

View File

@@ -21,9 +21,11 @@
#ifdef LIBERTY_XDG_WANT_X11
#include <X11/Xatom.h>
#include <X11/Xlib.h>
#endif
#ifdef LIBERTY_XDG_WANT_ICONS
#include <png.h>
#endif // LIBERTY_XDG_WANT_X11
#endif
// --- XSettings ---------------------------------------------------------------
@@ -200,7 +202,7 @@ fail:
// --- Desktop file parser -----------------------------------------------------
// Useful for parsing desktop-file-spec, icon-theme-spec, trash-spec,
// Useful for parsing desktop-entry-spec, icon-theme-spec, trash-spec,
// mime-apps-spec. This code is not designed for making changes to the files.
struct desktop_file
@@ -349,6 +351,7 @@ desktop_file_unescape (const char *value, bool is_list)
break; case 'r': str_append_c (&s, '\r');
break; default: str_append_c (&s, *p);
}
escape = false;
}
else if (*p == '\\' && p[1])
escape = true;
@@ -434,6 +437,8 @@ desktop_file_get_integer (struct desktop_file *self,
// This implements part of the Icon Theme Specification.
#ifdef LIBERTY_XDG_WANT_ICONS
struct icon_theme_icon
{
uint32_t width; ///< Width of argb in pixels
@@ -462,7 +467,7 @@ icon_theme_open (const char *path)
{
volatile png_bytep buffer = NULL;
volatile png_bytepp row_pointers = NULL;
volatile struct icon_theme_icon *result = NULL;
struct icon_theme_icon *volatile result = NULL;
FILE *fp = fopen (path, "rb");
if (!fp)
{
@@ -535,7 +540,7 @@ fail:
free (row_pointers);
png_destroy_read_struct (&pngp, &infop, NULL);
fclose (fp);
return (struct icon_theme_icon *) result;
return result;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -764,3 +769,4 @@ icon_theme_set_window_icon (Display *dpy,
}
#endif // LIBERTY_XDG_WANT_X11
#endif // LIBERTY_XDG_WANT_ICONS

View File

@@ -69,6 +69,7 @@ enum { XUI_KEYMOD_DOUBLE_CLICK = 1 << 15 };
#include <X11/Xft/Xft.h>
#define LIBERTY_XDG_WANT_X11
#define LIBERTY_XDG_WANT_ICONS
#include "liberty-xdg.c"
#endif // LIBERTY_XUI_WANT_X11
@@ -727,9 +728,12 @@ tui_flush_buffer (struct widget *self, struct row_buffer *buf)
{
move (self->y, self->x);
if (self->y >= 0 && self->y < g_xui.height)
{
int space = MIN (self->width, g_xui.width - self->x);
row_buffer_align (buf, space, self->attrs);
row_buffer_flush (buf);
}
row_buffer_free (buf);
}

67
tests/xdg.c Normal file
View File

@@ -0,0 +1,67 @@
/*
* tests/xdg.c
*
* Copyright (c) 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.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
#define PROGRAM_NAME "test"
#define PROGRAM_VERSION "0"
#include "../liberty.c"
#include "../liberty-xdg.c"
static const char file[] =
"# This only tests the happy paths\n"
"[Desktop Entry]\n"
"Version = 1.0\n"
"Name=\\s\\n\\t\\r\\\\\n"
"Name[fr]=Nom\n"
"Hidden=true\n"
"Categories=Utility;TextEditor;\n"
"Number=42";
static void
test_desktop_file (void)
{
struct desktop_file entry = desktop_file_make (file, sizeof file - 1);
const char *group = "Desktop Entry";
char *value = desktop_file_get_string (&entry, group, "Version");
hard_assert (!strcmp (value, "1.0"));
cstr_set (&value, desktop_file_get_string (&entry, group, "Name"));
hard_assert (!strcmp (value, " \n\t\r\\"));
free (value);
hard_assert (desktop_file_get_bool (&entry, group, "Hidden"));
struct strv values = desktop_file_get_stringv (&entry, group, "Categories");
hard_assert (values.len == 2);
hard_assert (!strcmp (values.vector[0], "Utility"));
hard_assert (!strcmp (values.vector[1], "TextEditor"));
strv_free (&values);
hard_assert (desktop_file_get_integer (&entry, group, "Number") == 42);
desktop_file_free (&entry);
}
int
main (int argc, char *argv[])
{
struct test test;
test_init (&test, argc, argv);
test_add_simple (&test, "/desktop-file", NULL, test_desktop_file);
return test_run (&test);
}

View File

@@ -1,6 +1,6 @@
# asciiman.awk: simplified AsciiDoc to manual page converter
#
# Copyright (c) 2022 - 2023, Přemysl Eric Janouch <p@janouch.name>
# Copyright (c) 2022 - 2024, Přemysl Eric Janouch <p@janouch.name>
# SPDX-License-Identifier: 0BSD
#
# This is not intended to produce great output, merely useful output.
@@ -149,6 +149,11 @@ function format(line, v) {
} else if (match(line, /^[*][^*]+[*]/) &&
substr(line, RSTART + RLENGTH) !~ /^[[:alnum:]]/) {
v = v "\\fB" substr(line, RSTART + 1, RLENGTH - 2) "\\fP"
} else if (match(line, /^`[^`]+`/) &&
substr(line, RSTART + RLENGTH) !~ /^[[:alnum:]]/) {
# Manual pages are usually already rendered in monospace;
# follow others, and render this in boldface.
v = v "\\fB" substr(line, RSTART + 1, RLENGTH - 2) "\\fP"
} else {
v = v substr(line, 1, 1)
line = substr(line, 2)
@@ -226,6 +231,13 @@ function process(firstline, posattrs, namedattrs) {
return 0
}
if (firstline ~ /^--$/) {
flushspace()
# For now, recognize, but do not process open block delimiters.
InOpenBlock = !InOpenBlock
return 1
}
if (firstline ~ /^(-{4,}|[.]{4,})$/) {
flushspace()