<commit_before>/*
 * (C)opyright MMIV-MMVI <NAME> <<EMAIL>>
 * See LICENSE file for license details.
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

#include "wmii.h"

static void
spawn_ixp_write(char *cmd)
{
	IXPClient c;
	char *file = cmd;
	char *data = strchr(cmd, ' ');
	char *address = strdup(getenv("WMII_ADDRESS"));
    unsigned int fid = c.root_fid << 2;
	size_t len;

	if(!data || !cmd || !address)
		return;
	*data = 0;
	data++;
	len = strlen(data);
	fprintf(stderr, "spawn_ixp_write write file=%s data=%s address=%s\n", file, data, address);

    if(ixp_client_init(&c, address, getpid()) == -1) {
		free(address);
        fprintf(stderr, "libwmii: %s\n", c.errstr);
		return;
    }
	free(address);
    /* open */
    if(ixp_client_open(&c, fid, file, IXP_OWRITE) == -1) {
        fprintf(stderr, "libwmii: cannot open file '%s': %s\n", file, c.errstr);
        return;
    }
    if(ixp_client_write(&c, fid, 0, len, (void *)data) != len) {
    	fprintf(stderr, "libwmii: cannot write file: %s\n", c.errstr);
		return; 
	}
    ixp_client_close(&c, fid);
    ixp_client_deinit(&c);
}

void
wmii_spawn(void *dpy, char *cmd)
{
	static char *ixpcmd = nil;
	static size_t ixpcmdsz = 0;
	size_t len;

	if(!cmd)
		return;
	if(!strncmp(cmd, "#write ", 7)) {
	    if(!(len = strlen(&cmd[7]) + 1))
			return;
		if(len > ixpcmdsz) {
			ixpcmdsz = len + 1;
			if(ixpcmd)
				free(ixpcmd);
			ixpcmd = cext_emallocz(ixpcmdsz);
		}
		cext_strlcpy(ixpcmd, &cmd[7], len);
		spawn_ixp_write(ixpcmd);
		return;
	}
<commit_msg>removed crap from spawn.c<commit_after>/*
 * (C)opyright MMIV-MMVI <NAME> <<EMAIL>beam at gmail dot com>
 * See LICENSE file for license details.
 */

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

#include "wmii.h"

void
wmii_spawn(void *dpy, char *cmd)
{
	if(!cmd)
		return;
{'fraction_non_alphanumeric': 0.179539641943734, 'fraction_numerical': 0.005626598465473146, 'mean_word_length': 3.7132530120481926, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 22, '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': 1, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3776259', 'n_tokens_mistral': 868, 'n_tokens_neox': 834, 'n_words': 189}