<commit_before>/*
 * (C)opyright MMIV-MMVI <NAME> <<EMAIL>beam at gmail dot com>
 * (C)opyright MMVI      <NAME> <a dot h dot vandijk at gmail dot com>
 * See LICENSE file for license details.
 */

#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/cursorfont.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>

#include <blitz.h>
#include <cext.h>

VECTOR(ItemVector, char *);
static Bool done = False;
static int ret = 0;
static char text[4096];
static BlitzColor selcolor;
static BlitzColor normcolor;
static Display *dpy;
static Window win;
static XRectangle mrect;
static int screen;
static ItemVector allitem = {0};
static ItemVector item = {0};
static int sel = -1;
static unsigned int nextoff = 0;
static unsigned int prevoff = 0;
static unsigned int curroff = 0;
static unsigned int cmdw = 0;
static BlitzDraw draw = { 0 };
static const int seek = 30;		/* 30px */

static void draw_menu(void);
static void handle_kpress(XKeyEvent * e);

static char version[] = "wmiimenu - " VERSION ", (C)opyright MMIV-MMVI <NAME>\n";

static Vector *
item2vector(ItemVector *iv)
{
	return (Vector *) iv;
}

static void
usage()
{
	fprintf(stderr, "%s", "usage: wmiimenu [-v]\n");
	exit(1);
}

static void
update_offsets()
{
	unsigned int i;
	unsigned int tw, w = cmdw + 2 * seek;

	if(!item.size)
		return;

	for(i = curroff; i < item.size; i++) {
		tw = blitz_textwidth(dpy, &draw.font, item.data[i]);
		if(tw > mrect.width / 3)
			tw = mrect.width / 3;
		w += tw;
		if(w > mrect.width)
			break;
	}
	nextoff = i;

	w = cmdw + 2 * seek;
	for(i = curroff; i > 0; i--) {
		w += blitz_textwidth(dpy, &draw.font, item.data[i]) + mrect.height;
		if(w > mrect.width)
			break;
	}
	prevoff = i;
}

static unsigned int
update_items(char *pattern)
{
	unsigned int plen = strlen(pattern);
	int i;

	curroff = prevoff = nextoff = 0;
	sel = -1;

	while(item.size)
		cext_vdetach(item2vector(&item), item.data[0]);<commit_msg>fixed wmiimenu bug (also in wmii-3 repo)<commit_after>/*
 * (C)opyright MMIV-MMVI <NAME> <<EMAIL>beam at gmail dot com>
 * (C)opyright MMVI      <NAME> <a dot h dot vandijk at gmail dot com>
 * See LICENSE file for license details.
 */

#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/cursorfont.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>

#include <blitz.h>
#include <cext.h>

VECTOR(ItemVector, char *);
static Bool done = False;
static int ret = 0;
static char text[4096];
static BlitzColor selcolor;
static BlitzColor normcolor;
static Display *dpy;
static Window win;
static XRectangle mrect;
static int screen;
static ItemVector allitem = {0};
static ItemVector item = {0};
static int sel = -1;
static unsigned int nextoff = 0;
static unsigned int prevoff = 0;
static unsigned int curroff = 0;
static unsigned int cmdw = 0;
static BlitzDraw draw = { 0 };
static const int seek = 30;		/* 30px */

static void draw_menu(void);
static void handle_kpress(XKeyEvent * e);

static char version[] = "wmiimenu - " VERSION ", (C)opyright MMIV-MMVI <NAME>\n";

static Vector *
item2vector(ItemVector *iv)
{
	return (Vector *) iv;
}

static void
usage()
{
	fprintf(stderr, "%s", "usage: wmiimenu [-v]\n");
	exit(1);
}

static void
update_offsets()
{
	unsigned int i;
	unsigned int tw, w = cmdw + 2 * seek;

	if(!item.size)
		return;

	for(i = curroff; i < item.size; i++) {
		tw = blitz_textwidth(dpy, &draw.font, item.data[i]);
		if(tw > mrect.width / 3)
			tw = mrect.width / 3;
		w += tw + mrect.height;
		if(w > mrect.width)
			break;
	}
	nextoff = i;

	w = cmdw + 2 * seek;
	for(i = curroff; i > 0; i--) {
		w += blitz_textwidth(dpy, &draw.font, item.data[i]) + mrect.height;
		if(w > mrect.width)
			break;
	}
	prevoff = i;
}

static unsigned int
update_items(char *pattern)
{
	unsigned int plen = strlen(pattern);
	int i;

	curroff = prevoff = nextoff = 0;
	sel = -1;

	while(item.size)
		cext_vdetach(item2vector(&item), item.data[0]);
{'fraction_non_alphanumeric': 0.1513030888030888, 'fraction_numerical': 0.017615830115830115, 'mean_word_length': 3.9169632265717675, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '54737', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1623, 'n_words': 476}