<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <err.h>
#include <xcb/xcb.h>

#include "arg.h"
#include "util.h"

char *argv0;
static xcb_connection_t *conn;
static xcb_screen_t *scrn;

static void usage(void);
static int should_list(xcb_window_t, int);
static void list_windows(xcb_window_t, int);

enum {
	LIST_HIDDEN = 1 << 0,
	LIST_IGNORE = 1 << 1
};

static void
usage(void)
{
	fprintf(stderr, "usage: %s [-hiar] [wid...]\n", argv0);
	exit(1);
}

static int
should_list(xcb_window_t w, int mask)
{
	if (ignore(conn, w) && !(mask & LIST_IGNORE))
		return 0;

	if (!mapped(conn, w) && !(mask & LIST_HIDDEN))
		 return 0;

	return 1;
}

static void
list_windows(xcb_window_t w, int listmask)
{
	int i;
	xcb_window_t *wc;
	xcb_query_tree_cookie_t c;
	xcb_query_tree_reply_t *r;

	c = xcb_query_tree(conn, w);
	r = xcb_query_tree_reply(conn, c, NULL);
	if (r == NULL)
		errx(1, "0x%08x: no such window", w);

	wc = xcb_query_tree_children(r);
	if (wc == NULL)
		errx(1, "0x%08x: unable to retrieve children", w);

	for (i=0; i<r->children_len; i++) {
		if (should_list(wc[i], listmask))
			printf("0x%08x\n", wc[i]);
	}

	free(r);
}

int
main(int argc, char **argv)
{
	int listmask = 0, rootflag = 0;

	ARGBEGIN {
		case 'a': listmask |= LIST_HIDDEN; break;
		case 'i': listmask |= LIST_IGNORE; break;
		case 'r': rootflag = 1; break;
		default : usage();
	} ARGEND;

	init_xcb(&conn);
	get_screen(conn, &scrn);

	if (rootflag == 1) {
		printf("0x%08x\n", scrn->root);
		return 0;
	}

	if (argc == 0)
		list_windows(scrn->root, listmask);

	while (*argv)
		list_windows(strtoul(*argv++, NULL, 16), listmask);

	kill_xcb(&conn);
<commit_msg>lsw: reworked flags, watch out !<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <err.h>
#include <xcb/xcb.h>

#include "arg.h"
#include "util.h"

char *argv0;
static xcb_connection_t *conn;
static xcb_screen_t *scrn;

static void usage(void);
static int should_list(xcb_window_t, int);
static void list_windows(xcb_window_t, int);

enum {
	LIST_HIDDEN = 1 << 0,
	LIST_IGNORE = 1 << 1,
	LIST_ALL    = 1 << 2
};

static void
usage(void)
{
	fprintf(stderr, "usage: %s [-houra] [wid...]\n", argv0);
	exit(1);
}

static int
should_list(xcb_window_t w, int mask)
{
	if ((mask & LIST_ALL)
		|| (!mapped(conn, w) && mask & LIST_HIDDEN)
		|| (ignore(conn, w) && mask & LIST_IGNORE)
		|| (mapped(conn, w)
			&& !ignore(conn, w)
			&& mask == 0))
		return 1;

	return 0;
}

static void
list_windows(xcb_window_t w, int listmask)
{
	int i;
	xcb_window_t *wc;
	xcb_query_tree_cookie_t c;
	xcb_query_tree_reply_t *r;

	c = xcb_query_tree(conn, w);
	r = xcb_query_tree_reply(conn, c, NULL);
	if (r == NULL)
		errx(1, "0x%08x: no such window", w);

	wc = xcb_query_tree_children(r);
	if (wc == NULL)
		errx(1, "0x%08x: unable to retrieve children", w);

	for (i=0; i<r->children_len; i++) {
		if (should_list(wc[i], listmask))
			printf("0x%08x\n", wc[i]);
	}

	free(r);
}

int
main(int argc, char **argv)
{
	int listmask = 0, rootflag = 0;

	ARGBEGIN {
		case 'a': listmask |= LIST_ALL; break;
		case 'u': listmask |= LIST_HIDDEN; break;
		case 'o': listmask |= LIST_IGNORE; break;
		case 'r': rootflag = 1; break;
		default : usage();
	} ARGEND;

	init_xcb(&conn);
	get_screen(conn, &scrn);

	if (rootflag == 1) {
		printf("0x%08x\n", scrn->root);
		return 0;
	}

	if (argc == 0)
		list_windows(scrn->root, listmask);

	while (*argv)
		list_windows(strtoul(*argv++, NULL, 16), listmask);

	kill_xcb(&conn);

{'fraction_non_alphanumeric': 0.17475447718082032, 'fraction_numerical': 0.019641825534373193, 'mean_word_length': 4.311349693251533, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 17, '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': '6822918', 'n_tokens_mistral': 1642, 'n_tokens_neox': 1527, 'n_words': 364}