about summary refs log tree commit diff stats
path: root/config.default.h
blob: 85cc1353af28f64a35572ea073bbb660dfa1e392 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
 * See LICENSE file for license details.
 */

#define TAGS \
const char *tags[] = { "1", "2", "3", "4", "5", NULL };

#define DEFMODE			dotile /* dofloat */
#define FLOATSYMBOL		"><>"
#define TILESYMBOL		"[]="

#define FONT			"fixed"
#define NORMBGCOLOR		"#333366"
#define NORMFGCOLOR		"#cccccc"
#define SELBGCOLOR		"#666699"
#define SELFGCOLOR		"#eeeeee"
#define STATUSBGCOLOR		"#dddddd"
#define STATUSFGCOLOR		"#222222"

#define MASTER			600 /* per thousand */
#define MODKEY			Mod1Mask
#define SNAP			20 /* pixel */

#define KEYS \
static Key key[] = { \
	/* modifier			key		function	arguments */ \
	{ MODKEY|ShiftMask,		XK_Return,	spawn,		{ .cmd = "exec xterm" } }, \
	{ MODKEY,			XK_Tab,		focusnext,	{ 0 } }, \
	{ MODKEY|ShiftMask,		XK_Tab,		focusprev,	{ 0 } }, \
	{ MODKEY,			XK_Return,	zoom,		{ 0 } }, \
	{ MODKEY,			XK_g,		resizemaster,	{ .i = 15 } }, \
	{ MODKEY,			XK_s,		resizemaster,	{ .i = -15 } }, \
	{ MODKEY|ShiftMask,		XK_1,		tag,		{ .i = 0 } }, \
	{ MODKEY|ShiftMask,		XK_2,		tag,		{ .i = 1 } }, \
	{ MODKEY|ShiftMask,		XK_3,		tag,		{ .i = 2 } }, \
	{ MODKEY|ShiftMask,		XK_4,		tag,		{ .i = 3 } }, \
	{ MODKEY|ShiftMask,		XK_5,		tag,		{ .i = 4 } }, \
	{ MODKEY|ControlMask|ShiftMask,	XK_1,		toggletag,	{ .i = 0 } }, \
	{ MODKEY|ControlMask|ShiftMask,	XK_2,		toggletag,	{ .i = 1 } }, \
	{ MODKEY|ControlMask|ShiftMask,	XK_3,		toggletag,	{ .i = 2 } }, \
	{ MODKEY|ControlMask|ShiftMask,	XK_4,		toggletag,	{ .i = 3 } }, \
	{ MODKEY|ControlMask|ShiftMask,	XK_5,		toggletag,	{ .i = 4 } }, \
	{ MODKEY|ShiftMask,		XK_c,		killclient,	{ 0 } }, \
	{ MODKEY,			XK_space,	togglemode,	{ 0 } }, \
	{ MODKEY,			XK_0,		viewall,	{ 0 } }, \
	{ MODKEY,			XK_1,		view,		{ .i = 0 } }, \
	{ MODKEY,			XK_2,		view,		{ .i = 1 } }, \
	{ MODKEY,			XK_3,		view,		{ .i = 2 } }, \
	{ MODKEY,			XK_4,		view,		{ .i = 3 } }, \
	{ MODKEY,			XK_5,		view,		{ .i = 4 } }, \
	{ MODKEY|ControlMask,		XK_1,		toggleview,	{ .i = 0 } }, \
	{ MODKEY|ControlMask,		XK_2,		toggleview,	{ .i = 1 } }, \
	{ MODKEY|ControlMask,		XK_3,		toggleview,	{ .i = 2 } }, \
	{ MODKEY|ControlMask,		XK_4,		toggleview,	{ .i = 3 } }, \
	{ MODKEY|ControlMask,		XK_5,		toggleview,	{ .i = 4 } }, \
	{ MODKEY|ShiftMask,		XK_q,		quit,		{ 0 } }, \
};

/* Query class:instance:title for regex matching info with following command:
 * xprop | awk -F '"' '/^WM_CLASS/ { printf("%s:%s:",$4,$2) }; /^WM_NAME/ { printf("%s\n",$2) }' */
#define RULES \
static Rule rule[] = { \
	/* class:instance:title regex	tags regex	isfloat */ \
	{ "Firefox.*",			"2",		False }, \
	{ "Gimp.*",			NULL,		True }, \
};
color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#include <sys/types.h>
#include <sys/stat.h>

#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "gemtext.h"

static int
_case_text(struct gemtext *line, char **out, size_t *outlen)
{
	char *app;

	*outlen += gemtext_text_strlen(line);
	*outlen += 7; /* <p></p> */

	app = realloc(*out, (*outlen+1));
	if (app == NULL)
		return -1;
	*out = app;

	strlcat(*out, "<p>", (*outlen+1));
	strlcat(*out, gemtext_text_string(line), (*outlen)+1);
	strlcat(*out, "</p>", (*outlen)+1);

	return 0;
}

static int
_case_link(struct gemtext *line, char **out, size_t *outlen)
{
	char *app;

	*outlen += gemtext_link_link_strlen(line);
	*outlen += gemtext_link_label_strlen(line);
	*outlen += 22; /* <p><a href=""></a></p> */

	app = realloc(*out, (*outlen)+1);
	if (app == NULL)
		return -1;
	*out = app;

	strlcat(*out, "<p><a href=\"", (*outlen)+1);
	strlcat(*out, gemtext_link_link_string(line), (*outlen)+1);
	strlcat(*out, "\">", (*outlen)+1);
	if (gemtext_link_has_label(line))
		strlcat(*out, gemtext_link_label_string(line), (*outlen)+1);
	strlcat(*out, "</a></p>", (*outlen)+1);

	return 0;
}

static int
_case_pre(struct gemtext *line, char **out, size_t *outlen)
{
	char *app;

	*outlen += gemtext_pre_strlen(line);
	*outlen += 18; /* <p><pre></pre></p> */

	app = realloc(*out, (*outlen)+1);
	if (app == NULL)
		return -1;
	*out = app;

	strlcat(*out, "<p><pre>", (*outlen)+1);
	strlcat(*out, gemtext_pre_string(line), (*outlen)+1);
	strlcat(*out, "</pre></p>", (*outlen)+1);

	return 0;
}

static int
_case_h1(struct gemtext *line, char **out, size_t *outlen)
{
	char *app;

	*outlen += gemtext_h1_strlen(line);
	*outlen += 9; /* <h1></h1> */

	app = realloc(*out, (*outlen)+1);
	if (app == NULL)
		return -1;
	*out = app;

	strlcat(*out, "<h1>", (*outlen)+1);
	strlcat(*out, gemtext_h1_string(line), (*outlen)+1);
	strlcat(*out, "</h1>", (*outlen)+1);

	return 0;
}

static int
_case_h2(struct gemtext *line, char **out, size_t *outlen)
{
	char *app;

	*outlen += gemtext_h2_strlen(line);
	*outlen += 9; /* <h2></h2> */

	app = realloc(*out, (*outlen)+1);
	if (app == NULL)
		return -1;
	*out = app;

	strlcat(*out, "<h2>", (*outlen)+1);
	strlcat(*out, gemtext_h2_string(line), (*outlen)+1);
	strlcat(*out, "</h2>", (*outlen)+1);

	return 0;
}

static int
_case_h3(struct gemtext *line, char **out, size_t *outlen)
{
	char *app;

	*outlen += gemtext_h3_strlen(line);
	*outlen += 9; /* <h3></h3> */

	app = realloc(*out, (*outlen)+1);
	if (app == NULL)
		return -1;
	*out = app;

	strlcat(*out, "<h3>", (*outlen)+1);
	strlcat(*out, gemtext_h3_string(line), (*outlen)+1);
	strlcat(*out, "</h3>", (*outlen)+1);

	return 0;
}

static int
_case_ul(struct gemtext *line, char **out, size_t *outlen)
{
	char *app;

	*outlen += gemtext_ul_strlen(line);
	*outlen += 9; /* <li></li> */

	app = realloc(*out, (*outlen)+1);
	if (app == NULL)
		return -1;
	*out = app;

	strlcat(*out, "<li>", (*outlen)+1);
	strlcat(*out, gemtext_ul_string(line), (*outlen)+1);
	strlcat(*out, "</li>", (*outlen)+1);

	return 0;
}

static int
_case_qt(struct gemtext *line, char **out, size_t *outlen)
{
	char *app;

	*outlen += gemtext_qt_strlen(line);
	*outlen += 25; /* <blockquote></blockquote> */

	app = realloc(*out, (*outlen)+1);
	if (app == NULL)
		return -1;
	*out = app;

	strlcat(*out, "<blockquote>", (*outlen)+1);
	strlcat(*out, gemtext_qt_string(line), (*outlen)+1);
	strlcat(*out, "</blockquote>", (*outlen)+1);

	return 0;
}

int
gemtext_list_encode_to_html(struct gemtext **list, char **out, size_t *outlen)
{
	char *app;
	int i;
	int ulindic;

	*out = NULL;
	*outlen = 0;
	ulindic = 0;

	*out = malloc(1);
	if (*out == NULL)
		return -1;
	*out[0] = '\0'; /* for strlcat() */

	for (i = 0; list[i] != NULL; i++) {
		if (gemtext_type(list[i]) != GEMTEXT_UL && ulindic) {
			*outlen += 5; /* </ul> */
			app = realloc(*out, (*outlen)+1);
			if (app == NULL) {
				free(*out);
				return -1;
			}
			*out = app;
			strlcat(*out, "</ul>", (*outlen)+1);
			ulindic = 0;
		}
		switch (gemtext_type(list[i])) {
		case GEMTEXT_TEXT:
			if (_case_text(list[i], out, outlen) == -1) {
				free(*out);
				return -1;
			}
			break;
		case GEMTEXT_LINK:
			if (_case_link(list[i], out, outlen) == -1) {
				free(*out);
				return -1;
			}
			break;
		case GEMTEXT_PRE:
			if (_case_pre(list[i], out, outlen) == -1) {
				free(*out);
				return -1;
			}
			break;
		case GEMTEXT_H1:
			if (_case_h1(list[i], out, outlen) == -1) {
				free(*out);
				return -1;
			}
			break;
		case GEMTEXT_H2:
			if (_case_h2(list[i], out, outlen) == -1) {
				free(*out);
				return -1;
			}
			break;
		case GEMTEXT_H3:
			if (_case_h3(list[i], out, outlen) == -1) {
				free(*out);
				return -1;
			}
			break;
		case GEMTEXT_UL:
			if (!ulindic) {
				*outlen += 4; /* <ul> */
				app = realloc(*out, (*outlen)+1);
				if (app == NULL) {
					free(*out);
					return -1;
				}
				*out = app;
				strlcat(*out, "<ul>", (*outlen)+1);
				ulindic = 1;
			}
			if (_case_ul(list[i], out, outlen) == -1) {
				free(*out);
				return -1;
			}
			break;
		case GEMTEXT_QT:
			if (_case_qt(list[i], out, outlen) == -1) {
				free(*out);
				return -1;
			}
			break;
		}
	}

	return 0;
}

int
gemtext_list_encode_to_html_fd(struct gemtext **list, int fd)
{
	char *out;
	size_t len;

	if (gemtext_list_encode_to_html(list, &out, &len) == -1)
		return -1;
	if (write(fd, out, len) == -1) {
		free(out);
		return -1;
	}
	free(out);

	return 0;
}

int
gemtext_list_encode_to_html_file(struct gemtext **list, const char *file)
{
	int fd;

	fd = open(file, O_WRONLY|O_TRUNC|O_CREAT);
	if (fd == -1)
		return -1;
	/* file does not have to be owned by user, so errors are expected */
	fchmod(fd, 0644);
	if (gemtext_list_encode_to_html_fd(list, fd) == -1) {
		close(fd);
		return -1;
	}
	close(fd);

	return 0;
}