<commit_before>// Copyright 2016, <NAME>
#include "status_file.h"
#include "config.h"
#include "font.h"
#include "libjb/file.h"
#include "libjb/util.h"
#include "util.h"
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
static ssize_t poll_status_file(const char * restrict filename,
	char * restrict buf)
{
	fd_t fd = jb_open(filename, O_RDONLY | O_CREAT);
	if (fd < 0)
		return -1;
	fchmod(fd, 0600);
	ssize_t r = read(fd, buf, XSTATUS_CONST_BUFFER_SIZE);
	jb_check(r != -1, "Could not read status file");
	close(fd);
	return r;
}
static void warn_no_data(const char * restrict fn)
{
	static bool warned;
	if (warned)
		return;
	fprintf(stderr, "No data in status file: %s\n", fn);
	warned = true;
}
// Returns offset for next widget
uint16_t draw_status_file(xcb_connection_t * xc,
	const uint16_t x_offset,
	const char * restrict filename)
{
	char buf[XSTATUS_CONST_BUFFER_SIZE];
	const ssize_t s = poll_status_file(filename, buf) - 1;
	if (s <= 0) { // empty or error
		warn_no_data(filename);
		return x_offset;
	}
	xcb_image_text_8(xc, s, xstatus_get_window(xc),
		xstatus_get_gc(xc), x_offset + XSTATUS_CONST_WIDE_PAD,
		xstatus_get_font_size().h, buf);
	return xstatus_get_font_size().w * s + x_offset
		+ XSTATUS_CONST_WIDE_PAD + XSTATUS_CONST_WIDE_PAD;
}<commit_msg>Split out draw_text().<commit_after>// Copyright 2016, <NAME>
#include "status_file.h"
#include "config.h"
#include "font.h"
#include "libjb/file.h"
#include "libjb/util.h"
#include "xdata.h"
#include <stdio.h>
#include <sys/stat.h>
static ssize_t poll_status_file(const char * restrict filename,
	char * restrict buf)
{
	fd_t fd = jb_open(filename, O_RDONLY | O_CREAT);
	if (fd < 0)
		return -1;
	fchmod(fd, 0600);
	ssize_t r = read(fd, buf, XSTATUS_CONST_BUFFER_SIZE);
	jb_check(r != -1, "Could not read status file");
	close(fd);
	return r;
}
static void warn_no_data(const char * restrict fn)
{
	static bool warned;
	if (warned)
		return;
	fprintf(stderr, "No data in status file: %s\n", fn);
	warned = true;
}
static void draw_text(xcb_connection_t * restrict xc, const int16_t x,
	const int8_t len, char * buf)
{
	xcb_image_text_8(xc, len, xstatus_get_window(xc),
		xstatus_get_gc(xc), x + XSTATUS_CONST_WIDE_PAD,
		xstatus_get_font_size().h, buf);
}
// Returns offset for next widget
uint16_t draw_status_file(xcb_connection_t * xc,
	const uint16_t x_offset,
	const char * restrict filename)
{
	char buf[XSTATUS_CONST_BUFFER_SIZE];
	const ssize_t s = poll_status_file(filename, buf) - 1;
	if (s <= 0) { // empty or error
		warn_no_data(filename);
		return x_offset;
	}
	draw_text(xc, x_offset, s, buf);
	return xstatus_get_font_size().w * s + x_offset
		+ XSTATUS_CONST_WIDE_PAD + XSTATUS_CONST_WIDE_PAD;
}
{'fraction_non_alphanumeric': 0.12794117647058822, 'fraction_numerical': 0.014338235294117646, 'mean_word_length': 5.033259423503326, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, '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': '174794', 'n_tokens_mistral': 1152, 'n_tokens_neox': 1099, 'n_words': 271}