Removing the json patch

Reasoning:
   - the patch is old and incompatible and conflicts with so many
     other patches
   - the functionality is rather limited especially considering that
     it is generally possible to convert json data to work with the
     TSV patch or the separator patch
   - the patch is for dmenu 4.9, which means that since February 2009
     nobody has bothered upgrading this patch to 5.0 or 5.1, which
     again implies that not many people actually use or rely on this
     patch

The json patch may be re-introduced into dmenu-flexipatch in the
future, but in that case it would be a bespoke version that is
designed around some of the other patches and takes more liberties
rather than trying to adhere to what is available at
https://tools.suckless.org/dmenu/patches/json/

Example using jq to convert json data to TSV format:

$ cat ~/.bookmarks
{
	"uggah": "buggah",
	"hello": "there",
	"bye": "tomorrow"
}

$ cat ~/.bookmarks | jq -r '. | to_entries | .[] | "\(.key)\t\(.value)"'
uggah	buggah
hello	there
bye	tomorrow
This commit is contained in:
bakkeby 2022-09-05 12:30:27 +02:00
parent 6f9bd28e6b
commit 036d2b0d08
8 changed files with 16 additions and 185 deletions

View File

@ -28,6 +28,8 @@ Browsing patches? There is a [map of patches](https://coggle.it/diagram/YjT2DD6j
### Changelog:
2022-09-05 - Removed the json patch due to maintenance and compatibility reasons
2022-09-04 - Added the fzfexpect patch
2022-06-21 - Adding barpadding patch and relative input width patch
@ -132,8 +134,8 @@ Browsing patches? There is a [map of patches](https://coggle.it/diagram/YjT2DD6j
- adds a flag that will cause dmenu to select an item immediately if there is only one
matching option left
- [json](https://tools.suckless.org/dmenu/patches/json/)
- adds basic support for json files
- [~json~](https://tools.suckless.org/dmenu/patches/json/)
- ~adds basic support for json files~
- [line-height](http://tools.suckless.org/dmenu/patches/line-height/)
- adds a `-h` option which sets the minimum height of a dmenu line

View File

@ -19,9 +19,6 @@ FREETYPEINC = /usr/include/freetype2
#FREETYPEINC = $(X11INC)/freetype2
#MANPREFIX = ${PREFIX}/man
# Uncomment this for the json patch / JSON_PATCH
#JANSSONINC = `pkg-config --cflags jansson`
#JANSSONLIBS = `pkg-config --libs jansson`
# uncomment on RHEL for strcasecmp
#EXTRAFLAGS=-D_GNU_SOURCE

92
dmenu.c
View File

@ -21,23 +21,14 @@
#if MULTI_SELECTION_PATCH
#undef NON_BLOCKING_STDIN_PATCH
#undef PIPEOUT_PATCH
#undef JSON_PATCH
#undef PRINTINPUTTEXT_PATCH
#endif // MULTI_SELECTION_PATCH
#if JSON_PATCH
#undef NON_BLOCKING_STDIN_PATCH
#undef PRINTINPUTTEXT_PATCH
#undef PIPEOUT_PATCH
#endif // JSON_PATCH
#include "drw.h"
#include "util.h"
#if GRIDNAV_PATCH
#include <stdbool.h>
#endif // GRIDNAV_PATCH
#if JSON_PATCH
#include <jansson.h>
#endif // JSON_PATCH
/* macros */
#define INTERSECT(x,y,w,h,r) (MAX(0, MIN((x)+(w),(r).x_org+(r).width) - MAX((x),(r).x_org)) \
@ -100,9 +91,6 @@ struct item {
#if HIGHPRIORITY_PATCH
int hp;
#endif // HIGHPRIORITY_PATCH
#if JSON_PATCH
json_t *json;
#endif // JSON_PATCH
#if FUZZYMATCH_PATCH
double distance;
#endif // FUZZYMATCH_PATCH
@ -572,12 +560,13 @@ drawmenu(void)
#endif // PANGO_PATCH
);
free(censort);
} else
} else {
drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0
#if PANGO_PATCH
, False
#endif // PANGO_PATCH
);
}
#else
drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0
#if PANGO_PATCH
@ -655,6 +644,7 @@ drawmenu(void)
#endif // PANGO_PATCH
);
}
fprintf(stderr, "bbbb\n" );
x += w;
for (item = curr; item != next; item = item->right) {
#if SYMBOLS_PATCH
@ -669,6 +659,7 @@ drawmenu(void)
#endif // PANGO_PATCH | TSV_PATCH
x = drawitem(item, x, 0, itw);
}
fprintf(stderr, "ajaj\n" );
if (next) {
#if SYMBOLS_PATCH
w = TEXTW(symbol_2);
@ -689,6 +680,7 @@ drawmenu(void)
);
}
}
#if NUMBERS_PATCH
drw_setscheme(drw, scheme[SchemeNorm]);
drw_text(drw, mw - rpad, 0, TEXTW(numbers), bh, lrpad / 2, numbers, 0);
@ -767,10 +759,6 @@ match(void)
#if NON_BLOCKING_STDIN_PATCH
int preserve = 0;
#endif // NON_BLOCKING_STDIN_PATCH
#if JSON_PATCH
if (json)
fstrstr = cistrstr;
#endif // JSON_PATCH
strcpy(buf, text);
/* separate input text into tokens to be matched individually */
@ -1214,10 +1202,7 @@ insert:
break;
#endif // RESTRICT_RETURN_PATCH
#if !MULTI_SELECTION_PATCH
#if JSON_PATCH
if (!printjsonssel(ev->state))
break;
#elif PIPEOUT_PATCH
#if PIPEOUT_PATCH
#if PRINTINPUTTEXT_PATCH
if (sel && (
(use_text_input && (ev->state & ShiftMask)) ||
@ -1417,15 +1402,11 @@ static void
readstdin(void)
{
char *line = NULL;
#if JSON_PATCH || TSV_PATCH
#if TSV_PATCH
char *buf, *p;
#endif // JSON_PATCH | TSV_PATCH
#endif // TSV_PATCH
#if JSON_PATCH
struct item *item;
#else
size_t size = 0;
#endif // JSON_PATCH
size_t i, junk;
ssize_t len;
@ -1438,20 +1419,12 @@ readstdin(void)
/* read each line from stdin and add it to the item list */
for (i = 0; (len = getline(&line, &junk, stdin)) != -1; i++, line = NULL) {
#if JSON_PATCH
item = itemnew();
#else
if (i + 1 >= size / sizeof *items)
if (!(items = realloc(items, (size += BUFSIZ))))
die("cannot realloc %zu bytes:", size);
#endif // JSON_PATCH
if (line[len - 1] == '\n')
line[len - 1] = '\0';
#if JSON_PATCH
if (!(item->text = strdup(line)))
die("cannot strdup %zu bytes:", strlen(line) + 1);
#endif // JSON_PATCH
items[i].text = line;
#if TSV_PATCH
buf = strdup(line);
@ -1465,33 +1438,19 @@ readstdin(void)
#if PRINTINDEX_PATCH
items[i].index = i;
#endif // PRINTINDEX_PATCH
#elif JSON_PATCH
item->json = NULL;
item->out = 0;
#if PRINTINDEX_PATCH
item->index = i;
#endif // PRINTINDEX_PATCH
#elif PRINTINDEX_PATCH
items[i].index = i;
#else
items[i].out = 0;
#endif // MULTI_SELECTION_PATCH | JSON_PATCH | PRINTINDEX_PATCH
#endif // MULTI_SELECTION_PATCH | PRINTINDEX_PATCH
#if HIGHPRIORITY_PATCH
items[i].hp = arrayhas(hpitems, hplength, items[i].text);
#endif // HIGHPRIORITY_PATCH
}
if (items)
#if JSON_PATCH
items[items_ln].text = NULL;
#else
items[i].text = NULL;
#endif // JSON_PATCH
#if JSON_PATCH
lines = MIN(lines, items_ln);
#else
lines = MIN(lines, i);
#endif // JSON_PATCH
}
#endif // NON_BLOCKING_STDIN_PATCH
@ -1856,12 +1815,9 @@ usage(void)
#endif // GRID_PATCH
"[-l lines] [-p prompt] [-fn font] [-m monitor]"
"\n [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]"
#if ALPHA_PATCH || BORDER_PATCH || HIGHPRIORITY_PATCH || INITIALTEXT_PATCH || LINE_HEIGHT_PATCH || NAVHISTORY_PATCH || XYW_PATCH || DYNAMIC_OPTIONS_PATCH || JSON_PATCH || FZFEXPECT_PATCH
#if ALPHA_PATCH || BORDER_PATCH || HIGHPRIORITY_PATCH || INITIALTEXT_PATCH || LINE_HEIGHT_PATCH || NAVHISTORY_PATCH || XYW_PATCH || DYNAMIC_OPTIONS_PATCH || FZFEXPECT_PATCH
"\n "
#endif
#if JSON_PATCH
" [-j json-file]"
#endif // JSON_PATCH
#if DYNAMIC_OPTIONS_PATCH
" [-dy command]"
#endif // DYNAMIC_OPTIONS_PATCH
@ -2017,10 +1973,6 @@ main(int argc, char *argv[])
lines = 1;
}
#endif // GRID_PATCH
#if JSON_PATCH
else if (!strcmp(argv[i], "-j"))
readjson(argv[++i]);
#endif // JSON_PATCH
else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */
lines = atoi(argv[++i]);
#if XYW_PATCH
@ -2170,39 +2122,19 @@ main(int argc, char *argv[])
#else
if (fast && !isatty(0)) {
grabkeyboard();
#if JSON_PATCH
if (json)
listjson(json);
#if DYNAMIC_OPTIONS_PATCH
else if (!(dynamic && *dynamic))
readstdin();
#else
else
readstdin();
#endif // DYNAMIC_OPTIONS_PATCH
#elif DYNAMIC_OPTIONS_PATCH
if (!(dynamic && *dynamic))
readstdin();
#else
readstdin();
#endif // JSON_PATCH | DYNAMIC_OPTIONS_PATCH
#endif // DYNAMIC_OPTIONS_PATCH
} else {
#if JSON_PATCH
if (json)
listjson(json);
#if DYNAMIC_OPTIONS_PATCH
else if (!(dynamic && *dynamic))
readstdin();
#else
else
readstdin();
#endif // DYNAMIC_OPTIONS_PATCH
#elif DYNAMIC_OPTIONS_PATCH
if (!(dynamic && *dynamic))
readstdin();
#else
readstdin();
#endif // JSON_PATCH | DYNAMIC_OPTIONS_PATCH
#endif // DYNAMIC_OPTIONS_PATCH
grabkeyboard();
}
#endif // NON_BLOCKING_STDIN_PATCH

View File

@ -21,9 +21,6 @@
#if MULTI_SELECTION_PATCH
#include "multiselect.c"
#endif
#if JSON_PATCH
#include "json.c"
#endif
#if MOUSE_SUPPORT_PATCH
#include "mousesupport.c"
#endif

View File

@ -4,9 +4,6 @@
#if FZFEXPECT_PATCH
#include "fzfexpect.h"
#endif
#if JSON_PATCH
#include "json.h"
#endif
#if NON_BLOCKING_STDIN_PATCH
#include "nonblockingstdin.h"
#endif

View File

@ -1,80 +0,0 @@
#include <jansson.h>
static size_t items_sz = 0;
static size_t items_ln = 0;
static json_t *json = NULL;
static struct item *
itemnew(void)
{
if (items_ln + 1 >= (items_sz / sizeof *items))
if (!(items = realloc(items, (items_sz += BUFSIZ))))
die("cannot realloc %u bytes:", items_sz);
return &items[items_ln++];
}
static void
readjson(const char *path)
{
json_error_t jerr;
if (!(json = json_load_file(path, 0, &jerr)))
die("%s @ line: %i - %s", jerr.text, jerr.line, path);
}
static void
listjson(json_t *obj)
{
void *iter;
unsigned imax = 0;
unsigned tmpmax = 0;
struct item *item;
items_ln = 0;
iter = json_object_iter(obj);
while (iter) {
item = itemnew();
item->text = (char*) json_object_iter_key(iter);
item->json = json_object_iter_value(iter);
#if !MULTI_SELECTION_PATCH
item->out = 0;
#endif // MULTI_SELECTION_PATCH
drw_font_getexts(drw->fonts, item->text, strlen(item->text),
&tmpmax, NULL);
if (tmpmax > inputw) {
inputw = tmpmax;
imax = items_ln - 1;
}
iter = json_object_iter_next(obj, iter);
}
if (items)
items[items_ln].text = NULL;
inputw = items ? TEXTW(items[imax].text) : 0;
lines = MIN(lines, items_ln - 1);
}
static int
printjsonssel(unsigned int state)
{
if (sel && sel->json) {
if (json_is_object(sel->json)) {
listjson(sel->json);
text[0] = '\0';
match();
drawmenu();
return 0;
} else {
puts(json_string_value(sel->json));
}
} else {
#if PRINTINDEX_PATCH
if (print_index)
printf("%d\n", (sel && !(state & ShiftMask)) ? sel->index : -1);
else
puts((sel && !(state & ShiftMask)) ? sel->text : text);
#else
puts((sel && !(state & ShiftMask)) ? sel->text : text);
#endif // PRINTINDEX_PATCH
}
return 1;
}

View File

@ -1 +0,0 @@
static void listjson(json_t *obj);

View File

@ -117,19 +117,6 @@
*/
#define INSTANT_PATCH 0
/* This patch adds basic support for json files.
* This patch depends on the jansson library. Uncomment the relevant line in config.mk when
* enabling this patch.
*
* This patch is not compatible with the multi-selection, printinputtext, pipeout and
* non-blocking stdin patches.
* The multi-selection patch takes precedence over this patch.
* This patch takes precedence over non-blocking stdin, pipeout and printintputtext patches.
*
* https://tools.suckless.org/dmenu/patches/json/
*/
#define JSON_PATCH 0
/* This patch adds a '-h' option which sets the minimum height of a dmenu line. This helps
* integrate dmenu with other UI elements that require a particular vertical size.
* http://tools.suckless.org/dmenu/patches/line-height/