:(before "End Types") struct socket_t { int fd; sockaddr_in addr; bool polled; socket_t() { fd = 0; polled = false; bzero(&addr, sizeof(addr)); } }; :(before "End Primitive Recipe Declarations") _OPEN_CLIENT_SOCKET, :(before "End Primitive Recipe Numbers") put(Recipe_ordinal, "$open-client-socket", _OPEN_CLIENT_SOCKET); :(before "End Primitive Recipe Checks") case _OPEN_CLIENT_SOCKET: { if (SIZE(inst.ingredients) != 2) { raise << maybe(get(Recipe, r).name) << "'$open-client-socket' requires exactly two ingredients, but got '" << to_original_string(inst) << "'\n" << end(); break; } if (!is_mu_text(inst.ingredients.at(0))) { raise << maybe(get(Recipe, r).name) << "first ingredient of '$open-client-socket' should be text (the hostname), but got '" << to_string(inst.ingredients.at(0)) << "'\n" << end(); break; } if (!is_mu_number(inst.ingredients.at(1))) { raise << maybe(get(Recipe, r).name) << "second ingredient of '$open-client-socket' should be a number (the port of the hostname to connect to), but got '" << to_string(inst.ingredients.at(1)) << "'\n" << end(); break; } if (SIZE(inst.products) != 1) { raise << maybe(get(Recipe, r).name) << "'$open-client-socket' requires exactly one product, but got '" << to_original_string(inst) << "'\n" << end(); break; } if (!is_mu_number(inst.products.at(0))) { raise << maybe(get(Recipe, r).name) << "first product of '$open-client-socket' should be a number (socket handle), but got '" << to_string(inst.products.at(0)) << "'\n" << end(); break; } break; } :(before "End Primitive Recipe Implementations") case _OPEN_CLIENT_SOCKET: { string host = read_mu_text(ingredients.at(0).at(/*skip alloc id*/1)); int port = ingredients.at(1).at(0); socket_t* client = client_socket(host, port); products.resize(1); if (client->fd < 0) { // error delete client; products.at(0).push_back(0); break; } long long int result = reinterpret_cast(client); products.at(0).push_back(static_cast(result)); break; } :(code) socket_t* client_socket(const string& host, int port) { socket_t* result = new socket_t; result->fd = socket(AF_INET, SOCK_STREAM, 0); if (result->fd < 0) { raise << "Failed to create socket.\n" << end(); return result; } result->addr.sin_family = AF_INET; hostent* tmp = gethostbyname(host.c_str()); bcopy(tmp->h_addr, reinterpret_cast(&result->addr.sin_addr.s_addr), tmp->h_length); result->addr.sin_port = htons(port); if (connect(result->fd, reinterpret_cast(&result->addr), sizeof(result->addr)) < 0) { close(result->fd); result->fd = -1; raise << "Failed to connect to " << host << ':' << port << '\n' << end(); } return result; } :(before "End Primitive Recipe Declarations") _OPEN_SERVER_SOCKET, :(before "End Primitive Recipe Numbers") put(Recipe_ordinal, "$open-server-socket", _OPEN_SERVER_SOCKET); :(before "End Primitive Recipe Checks") case _OPEN_SERVER_SOCKET: { if (SIZE(inst.ingredients) != 1) { raise << maybe(get(Recipe, r).name) << "'$open-server-socket' requires exactly one ingredient (the port to listen for requests on), but got '" << to_original_string(inst) << "'\n" << end(); break; } if (!is_mu_number(inst.ingredients.at(0))) { raise << maybe(get(Recipe, r).name) << "first ingredient of '$open-server-socket' should be a number, but got '" << to_string(inst.ingredients.at(0)) << "'\n" << end(); break; } if (SIZE(inst.products) != 1) { raise << maybe(get(Recipe, r).name) << "'$open-server-socket' requires exactly one product, but got '" << to_original_string(inst) << "'\n" << end(); break; } if (!is_mu_number(inst.products.at(0))) { raise << maybe(get(Recipe, r).name) << "first product of '$open-server-soc
/*
 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
 * See LICENSE file for license details.
 */

#include "wm.h"

static const char *status[] = {
	"sh", "-c", "echo -n `date` `uptime | sed 's/.*://; s/,//g'`"
		" `acpi | awk '{print $4}' | sed 's/,//'`", 0 \
};

void
draw_bar()
{
	static char buf[1024];

	buf[0] = 0;
	pipe_spawn(buf, sizeof(buf), dpy, (char **)status);

	brush.rect = barrect;
	brush.rect.x = brush.rect.y = 0;
	draw(dpy, &brush, False, buf);

	XCopyArea(dpy, brush.drawable, barwin, brush.gc, 0, 0, barrect.width,
			barrect.height, 0, 0);
	XFlush(dpy);
}