~sircmpwn/public-inbox

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
4

[PATCH fdicons 1/4] Fix unaligned SIZE column

Tom Lebreux
Details
Message ID
<20200222201025.1709165-1-tomlebreux@cock.li>
DKIM signature
pass
Download raw message
Patch: +1 -1
Before:
TYPE       SIZE  SCALE THEME
----       ----  ----- -----
Fixed         16     1 (Victory Icon Theme)

After:
TYPE        SIZE SCALE THEME
----        ---- ----- -----
Fixed         16     1 (Victory Icon Theme
---
 fdicons.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fdicons.c b/fdicons.c
index 8fc17f40f6ee..cf1ec7546365 100644
--- a/fdicons.c
+++ b/fdicons.c
@@ -71,7 +71,7 @@ list_icon_dirs(struct fd_icon_database *database, int argc, char *argv[])
{
	/* TODO: Check argc for a specific theme name */
	struct fd_icon_theme *theme = fd_icon_database_get_themes(database);
	const char *fmt = "%-30s %-20s %-10s %-5d %-5d (%s)\n";
	const char *fmt = "%-30s %-20s %-10s %5d %5d (%s)\n";
	if (isatty(STDOUT_FILENO)) {
		const char *table_fmt = "%-30s %-20s %-10s %5s %5s %s\n";
		printf(table_fmt, "NAME", "CONTEXT", "TYPE",
-- 
2.25.0

[PATCH fdicons 2/4] Implement theme name argument for list-icon-dirs

Tom Lebreux
Details
Message ID
<20200222201025.1709165-2-tomlebreux@cock.li>
In-Reply-To
<20200222201025.1709165-1-tomlebreux@cock.li> (view parent)
DKIM signature
pass
Download raw message
Patch: +11 -2
---
 fdicons.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/fdicons.c b/fdicons.c
index cf1ec7546365..ffb045c3bd1a 100644
--- a/fdicons.c
+++ b/fdicons.c
@@ -69,8 +69,14 @@ typestr(enum fd_icon_type type)
static int
list_icon_dirs(struct fd_icon_database *database, int argc, char *argv[])
{
	/* TODO: Check argc for a specific theme name */
	struct fd_icon_theme *theme = fd_icon_database_get_themes(database);
	struct fd_icon_theme *theme;
	char *theme_name = argc > 2 ? argv[2] : NULL;
	if (theme_name) {
		theme = fd_icon_database_get_theme(database, theme_name);
	} else {
		theme = fd_icon_database_get_themes(database);
	}

	const char *fmt = "%-30s %-20s %-10s %5d %5d (%s)\n";
	if (isatty(STDOUT_FILENO)) {
		const char *table_fmt = "%-30s %-20s %-10s %5s %5s %s\n";
@@ -88,6 +94,9 @@ list_icon_dirs(struct fd_icon_database *database, int argc, char *argv[])
			dir = dir->next;
		}

		if (theme_name) {
			break;
		}
		theme = theme->next;
	}
	return 0;
-- 
2.25.0

[PATCH fdicons 3/4] Implement list-icons

Tom Lebreux
Details
Message ID
<20200222201025.1709165-3-tomlebreux@cock.li>
In-Reply-To
<20200222201025.1709165-1-tomlebreux@cock.li> (view parent)
DKIM signature
pass
Download raw message
Patch: +84 -0
---
I was not sure whether we want to have something like `fd_icon_get_icons()`
in the library itself that lists all the icons, so I implemented with what the
library had already.
 fdicons.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)

diff --git a/fdicons.c b/fdicons.c
index ffb045c3bd1a..d3f4da5c8829 100644
--- a/fdicons.c
+++ b/fdicons.c
@@ -1,4 +1,6 @@
#include <dirent.h>
#include <fdicons.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -50,6 +52,27 @@ next:
	return 0;
}

static char *
split_extension(char *name)
{
	char *ext = strrchr(name, '.');
	*ext = '\0';
	ext++;
	return ext;
}

static bool
is_icon(const char *ext)
{
	const char *default_exts[] = { "png", "svg", "xpm", NULL };
	for (int i = 0; default_exts[i]; ++i) {
		if (strcmp(ext, default_exts[i]) == 0) {
			return true;
		}
	}
	return false;
}

static const char *
typestr(enum fd_icon_type type)
{
@@ -102,6 +125,66 @@ list_icon_dirs(struct fd_icon_database *database, int argc, char *argv[])
	return 0;
}

static void
list_icons_in_dir(struct fd_icon_theme_dir *theme_dir, const char *path)
{
	DIR *dir = opendir(path);
	if (!dir) {
		return;
	}

	struct dirent *d;
	while ((d = readdir(dir))) {
		char *name = strdup(d->d_name);
		char *ext = split_extension(name);
		if (!is_icon(ext)) {
			free(name);
			continue;
		}

		printf("%-40s %-20s %-10s %5d %5d %-20s %s/%s\n",
				name, theme_dir->context,
				typestr(theme_dir->type), theme_dir->size,
				theme_dir->scale, theme_dir->theme->name,
				path, d->d_name);
		free(name);
	}
}

static int
list_icons(struct fd_icon_database *database, int argc, char *argv[])
{
	/* TODO: Check argc for a specific theme name and directory */
	struct fd_icon_theme *theme = fd_icon_database_get_themes(database);

	if (true || isatty(STDOUT_FILENO)) {
		const char *table_fmt = "%-40s %-20s %-10s %5s %5s %-20s %s\n";
		printf(table_fmt, "NAME", "CONTEXT", "TYPE",
				"SIZE", "SCALE", "THEME", "PATH");
		printf(table_fmt, "----", "-------", "----",
				"----", "-----", "-----", "----");
	}

	while (theme) {
		struct fd_icon_theme_dir *dir = theme->directories;
		char path[PATH_MAX + 1];
		while (dir) {
			int n = snprintf(path, sizeof(path), "%s/%s",
					theme->path, dir->name);
			if (n < 0 || n >= PATH_MAX) {
				dir = dir->next;
				continue;
			}

			list_icons_in_dir(dir, path);
			dir = dir->next;
		}
		theme = theme->next;
	}

	return 0;
}

static int
get_icon(struct fd_icon_database *database, int argc, char **argv)
{
@@ -201,6 +284,7 @@ main(int argc, char *argv[])
	} programs[] = {
		{ "list-themes", list_themes },
		{ "list-icon-dirs", list_icon_dirs },
		{ "list-icons", list_icons },
		{ "get-icon", get_icon },
	};

-- 
2.25.0

[PATCH fdicons 4/4] Implement theme argument for list-icons

Tom Lebreux
Details
Message ID
<20200222201025.1709165-4-tomlebreux@cock.li>
In-Reply-To
<20200222201025.1709165-1-tomlebreux@cock.li> (view parent)
DKIM signature
pass
Download raw message
Patch: +12 -2
---
 fdicons.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/fdicons.c b/fdicons.c
index d3f4da5c8829..f502666b3f40 100644
--- a/fdicons.c
+++ b/fdicons.c
@@ -154,8 +154,14 @@ list_icons_in_dir(struct fd_icon_theme_dir *theme_dir, const char *path)
static int
list_icons(struct fd_icon_database *database, int argc, char *argv[])
{
	/* TODO: Check argc for a specific theme name and directory */
	struct fd_icon_theme *theme = fd_icon_database_get_themes(database);
	/* TODO: Check argc for a specific directory */
	struct fd_icon_theme *theme;
	char *theme_name = argc > 2 ? argv[2] : NULL;
	if (theme_name) {
		theme = fd_icon_database_get_theme(database, theme_name);
	} else {
		theme = fd_icon_database_get_themes(database);
	}

	if (true || isatty(STDOUT_FILENO)) {
		const char *table_fmt = "%-40s %-20s %-10s %5s %5s %-20s %s\n";
@@ -179,6 +185,10 @@ list_icons(struct fd_icon_database *database, int argc, char *argv[])
			list_icons_in_dir(dir, path);
			dir = dir->next;
		}

		if (theme_name) {
			break;
		}
		theme = theme->next;
	}

-- 
2.25.0

Re: [PATCH fdicons 3/4] Implement list-icons

Tom Lebreux
Details
Message ID
<d62a1bdf-1258-9f10-1e50-ebe76ec263a6@cock.li>
In-Reply-To
<20200222201025.1709165-3-tomlebreux@cock.li> (view parent)
DKIM signature
pass
Download raw message
Hi,

This patch SEGFAULT when there is a file without any extension in an icon directory.

I will publish a v2 of this patch with a fix.
Review patch Export thread (mbox)