<commit_before>/*
 * Yabar - A modern and lightweight status bar for X window managers.
 *
 * Copyright (c) 2016, <NAME>
 * See LICENSE for more information.
 *
 */

#include "yabar.h"

char conf_file[CFILELEN]; 
static const char * const yashell = "/bin/sh";

#ifdef YA_INTERNAL_EWMH
inline static void ya_exec_intern_ewmh_blk(ya_block_t *blk) {
	switch(blk->internal->index) {
		case YA_INT_TITLE: {
			ya_get_cur_window_title(blk);
			ya_draw_pango_text(blk);
			break;
		}
		case YA_INT_WORKSPACE: {
			uint32_t current_desktop;
			xcb_get_property_cookie_t ck = xcb_ewmh_get_current_desktop(ya.ewmh, 0);
			xcb_ewmh_get_current_desktop_reply(ya.ewmh, ck, &current_desktop, NULL);
			sprintf(blk->buf, "%u", current_desktop);
			ya_draw_pango_text(blk);
			break;
		}
	}

}
#endif //YA_INTERNAL_EWMH

static void ya_exec_redir_once(ya_block_t *blk) {
	int opipe[2];
	if(pipe(opipe)==-1) {
		fprintf(stderr, "Error opening pipe for block %s.%s. Terminating block's thread...\n", blk->bar->name, blk->name);
		pthread_detach(blk->thread);
		pthread_exit(NULL);
	}
	if (fork() == 0) {
		dup2(opipe[1], STDOUT_FILENO);
		close(opipe[1]);
		setvbuf(stdout,NULL,_IONBF,0);

		execl(yashell, yashell, "-c", blk->cmd, (char *) NULL);
		_exit(EXIT_SUCCESS);
	}
	<commit_msg>Support print custom workspace names to ws intern blk.<commit_after>/*
 * Yabar - A modern and lightweight status bar for X window managers.
 *
 * Copyright (c) 2016, <NAME>
 * See LICENSE for more information.
 *
 */

#include "yabar.h"

char conf_file[CFILELEN]; 
static const char * const yashell = "/bin/sh";

#ifdef YA_INTERNAL_EWMH
inline static void ya_copy_buf_from_index(ya_block_t *blk, uint32_t cur_desktop) {
	char *cur = blk->internal->option[0];
	uint32_t index =0;
	for(;*cur!= '\0' && *cur == ' ';cur++);
	for(;*cur != '\0'; cur++) {
		int offset = 0;
		if(*cur==' ')
			continue;
		if(index==cur_desktop) {
			for(;*cur != '\0' && *cur != ' '; cur++, offset++) {
				blk->buf[offset] = *cur;
			}
			blk->buf[offset] = '\0';
			return;
		}
		else {
			for(;*cur != '\0' && *cur != ' '; cur++);
			index++;
		}
	}
	//Corresponding string not found, must be a higher desktop number
	//than number of available strings. So print current desktop number.
	sprintf(blk->buf, "%u", cur_desktop+1);
}

inline static void ya_exec_intern_ewmh_blk(ya_block_t *blk) {
	switch(blk->internal->index) {
		case YA_INT_TITLE: {
			ya_get_cur_window_title(blk);
			ya_draw_pango_text(blk);
			break;
		}
		case YA_INT_WORKSPACE: {
			uint32_t current_desktop;
			xcb_get_property_cookie_t ck = xcb_ewmh_get_current_desktop(ya.ewmh, 0);
			xcb_ewmh_get_current_desktop_reply(ya.ewmh, ck, &current_desktop, NULL);
			if(blk->internal->option[0]==NULL)
				sprintf(blk->buf, "%u", current_desktop+1);
			else {
				ya_copy_buf_from_index(blk, current_desktop);
			}
			ya_draw_pango_text(blk);
			break;
		}
	}

}
#endif //YA_INTERNAL_EWMH

static void ya_exec_redir_once(ya_block_t *blk) {
	int opipe[2];
	if(pipe(opipe)==-1) {
		fprintf(stderr, "Error opening pipe for block %s.%s. Terminating block's thread...\n", blk->bar->name, blk->name);
		pthread_detach(blk->thread);
		pthread_exit(NULL);
	}
	if (fork() == 0) {
		dup2(opipe[1], STDOUT_FILENO);
		close(opipe[1]);
		setvbuf(stdout,NULL,_IONBF,0);

		execl(yashell, yashell, "-c", blk->cmd, (char *) NULL);
		_exit(EXIT_SUCCESS);
	}
	
{'fraction_non_alphanumeric': 0.1593210244192972, 'fraction_numerical': 0.012805241215008934, 'mean_word_length': 4.298107255520505, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, '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': '3164040', 'n_tokens_mistral': 1508, 'n_tokens_neox': 1355, 'n_words': 273}