<commit_before>// Copyright 2016, <NAME>
#include "xcb.h"
#include "log.h"
// Include here to check syntax:
#include "size.h"
#include "util.h"
#include <errno.h>
#include <string.h>
#include <sys/select.h>
bool jb_xcb_cookie_has_error(xcb_connection_t * x, const xcb_void_cookie_t c)
{
	xcb_generic_error_t * e = xcb_request_check(x, c);
	if (!e)
		return false;
	free(e);
	return true;
}
static void xerr(xcb_connection_t * x, const char * msg)
{
	xcb_disconnect(x);
	if (errno)
		perror(msg);
	else
		fprintf(stderr, "%s\n", msg);
	exit(1);
}
void jb_check_x(xcb_connection_t * x)
{
	switch(xcb_connection_has_error(x)) {
	case 0: // Success
		break;
	case XCB_CONN_ERROR:
		xerr(x, "X transport error, DISPLAY unavailable");
	case XCB_CONN_CLOSED_EXT_NOTSUPPORTED:
		xerr(x, "Extension not supported");
	case XCB_CONN_CLOSED_MEM_INSUFFICIENT:
		xerr(x, "Insufficient memory");
	case XCB_CONN_CLOSED_REQ_LEN_EXCEED:
		xerr(x, "Request length exceeded");
	case XCB_CONN_CLOSED_PARSE_ERR:
		xerr(x, "Invalid DISPLAY string");
	case XCB_CONN_CLOSED_INVALID_SCREEN:
		xerr(x, "Invalid screen");
	}
}
xcb_connection_t * jb_get_xcb_connection(const char * display, int * screen)
{
	xcb_connection_t * x = xcb_connect(display, screen);
	jb_check_x(x);
	return x;
}
xcb_screen_t * jb_get_xcb_screen(xcb_connection_t * x)
{
	return xcb_setup_roots_iterator(xcb_get_setup(x)).data;
}
pixel_t jb_get_pixel(xcb_connection_t * x, const xcb_colormap_t cmap,
	const char * color)
{
	xcb_alloc_named_color_cookie_t c = xcb_alloc_named_color(x,
		cmap, strlen(color), color);
	xcb_alloc_named_color_reply_t * r
		= xcb_alloc_named_color_reply(x, c, NULL);
	if (jb_check(r, "Could not allocate color"))
		return 0;
	pixel_t p = r->pixel;
	free(r);
	return p;
}
pixel_t jb_get_rgb_pixel(xcb_connection_t * x, const xcb_colormap_t cm,
	const int16_t r, const int16_t g, const int16_t b)
{<commit_msg>Set errno to zero.<commit_after>// Copyright 2016, <NAME>
#include "xcb.h"
#include "log.h"
// Include here to check syntax:
#include "size.h"
#include "util.h"
#include <errno.h>
#include <string.h>
#include <sys/select.h>
bool jb_xcb_cookie_has_error(xcb_connection_t * x, const xcb_void_cookie_t c)
{
	xcb_generic_error_t * e = xcb_request_check(x, c);
	if (!e)
		return false;
	free(e);
	return true;
}
static void xerr(xcb_connection_t * x, const char * msg)
{
	xcb_disconnect(x);
	if (errno)
		perror(msg);
	else
		fprintf(stderr, "%s\n", msg);
	exit(1);
}
void jb_check_x(xcb_connection_t * x)
{
	switch(xcb_connection_has_error(x)) {
	case 0: // Success
		break;
	case XCB_CONN_ERROR:
		xerr(x, "X transport error, DISPLAY unavailable");
	case XCB_CONN_CLOSED_EXT_NOTSUPPORTED:
		xerr(x, "Extension not supported");
	case XCB_CONN_CLOSED_MEM_INSUFFICIENT:
		xerr(x, "Insufficient memory");
	case XCB_CONN_CLOSED_REQ_LEN_EXCEED:
		xerr(x, "Request length exceeded");
	case XCB_CONN_CLOSED_PARSE_ERR:
		xerr(x, "Invalid DISPLAY string");
	case XCB_CONN_CLOSED_INVALID_SCREEN:
		xerr(x, "Invalid screen");
	}
}
xcb_connection_t * jb_get_xcb_connection(const char * display, int * screen)
{
	errno = 0;
	xcb_connection_t * x = xcb_connect(display, screen);
	jb_check_x(x);
	return x;
}
xcb_screen_t * jb_get_xcb_screen(xcb_connection_t * x)
{
	return xcb_setup_roots_iterator(xcb_get_setup(x)).data;
}
pixel_t jb_get_pixel(xcb_connection_t * x, const xcb_colormap_t cmap,
	const char * color)
{
	xcb_alloc_named_color_cookie_t c = xcb_alloc_named_color(x,
		cmap, strlen(color), color);
	xcb_alloc_named_color_reply_t * r
		= xcb_alloc_named_color_reply(x, c, NULL);
	if (jb_check(r, "Could not allocate color"))
		return 0;
	pixel_t p = r->pixel;
	free(r);
	return p;
}
pixel_t jb_get_rgb_pixel(xcb_connection_t * x, const xcb_colormap_t cm,
	const int16_t r, const int16_t g, const int16_t b)
{
{'fraction_non_alphanumeric': 0.11868887126619085, 'fraction_numerical': 0.007137192704203013, 'mean_word_length': 5.769230769230769, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '2504506', 'n_tokens_mistral': 1676, 'n_tokens_neox': 1631, 'n_words': 339}