* Pointer to underlying string buffer. If alloc != 0, then
* this was allocated via malloc().
*/
- char *buf;
+ char *data;
/**
- * Allocated length of buf. If zero, buf was not allocated
+ * Allocated length of buf. If zero, data was not allocated
* (either NULL or literal empty string).
*/
int alloc;
};
/** Value used to initialize a struct buf to an empty string */
-#define BUF_INIT ((struct buf){.buf = ""})
+#define BUF_INIT ((struct buf){.data = ""})
/**
* buf_expand_tilde - expand ~ in buffer
struct buf cmd = BUF_INIT;
buf_add(&cmd, action_get_str(action, "command", NULL));
buf_expand_tilde(&cmd);
- spawn_async_no_shell(cmd.buf);
+ spawn_async_no_shell(cmd.data);
buf_reset(&cmd);
}
break;
button_filename(button_name, filename, sizeof(filename));
struct buf token_buf = grab_file(filename);
if (token_buf.len) {
- struct token *tokens = tokenize_xbm(token_buf.buf);
+ struct token *tokens = tokenize_xbm(token_buf.data);
pixmap = parse_xbm_tokens(tokens);
if (tokens) {
free(tokens);
{
struct buf new = BUF_INIT;
for (int i = 0 ; i < s->len ; i++) {
- if (s->buf[i] == '~') {
+ if (s->data[i] == '~') {
buf_add(&new, getenv("HOME"));
} else {
- buf_add_char(&new, s->buf[i]);
+ buf_add_char(&new, s->data[i]);
}
}
buf_move(s, &new);
struct buf environment_variable = BUF_INIT;
for (int i = 0 ; i < s->len ; i++) {
- if (s->buf[i] == '$' && isvalid(s->buf[i+1])) {
+ if (s->data[i] == '$' && isvalid(s->data[i+1])) {
/* expand environment variable */
buf_clear(&environment_variable);
- buf_add(&environment_variable, s->buf + i + 1);
- char *p = environment_variable.buf;
+ buf_add(&environment_variable, s->data + i + 1);
+ char *p = environment_variable.data;
while (isvalid(*p)) {
++p;
}
*p = '\0';
- i += strlen(environment_variable.buf);
- strip_curly_braces(environment_variable.buf);
- p = getenv(environment_variable.buf);
+ i += strlen(environment_variable.data);
+ strip_curly_braces(environment_variable.data);
+ p = getenv(environment_variable.data);
if (p) {
buf_add(&new, p);
}
} else {
- buf_add_char(&new, s->buf[i]);
+ buf_add_char(&new, s->data[i]);
}
}
buf_reset(&environment_variable);
new_alloc = MAX(new_alloc, 256);
new_alloc = MAX(new_alloc, s->alloc * 3 / 2);
if (s->alloc) {
- assert(s->buf);
- s->buf = xrealloc(s->buf, new_alloc);
+ assert(s->data);
+ s->data = xrealloc(s->data, new_alloc);
} else {
assert(!s->len);
- s->buf = xmalloc(new_alloc);
- s->buf[0] = '\0';
+ s->data = xmalloc(new_alloc);
+ s->data[0] = '\0';
}
s->alloc = new_alloc;
}
}
int len = strlen(data);
buf_expand(s, s->len + len + 1);
- memcpy(s->buf + s->len, data, len);
+ memcpy(s->data + s->len, data, len);
s->len += len;
- s->buf[s->len] = 0;
+ s->data[s->len] = 0;
}
void
buf_add_char(struct buf *s, char ch)
{
buf_expand(s, s->len + 1);
- s->buf[s->len++] = ch;
- s->buf[s->len] = '\0';
+ s->data[s->len++] = ch;
+ s->data[s->len] = '\0';
}
void
buf_clear(struct buf *s)
{
if (s->alloc) {
- assert(s->buf);
+ assert(s->data);
s->len = 0;
- s->buf[0] = '\0';
+ s->data[0] = '\0';
} else {
*s = BUF_INIT;
}
buf_reset(struct buf *s)
{
if (s->alloc) {
- free(s->buf);
+ free(s->data);
}
*s = BUF_INIT;
}
buf_move(struct buf *dst, struct buf *src)
{
if (dst->alloc) {
- free(dst->buf);
+ free(dst->data);
}
*dst = *src;
*src = BUF_INIT;
* .default_prefix in the same way.
*/
gchar * *prefixes;
- prefixes = g_strsplit(prefix.buf, ":", -1);
+ prefixes = g_strsplit(prefix.data, ":", -1);
for (gchar * *p = prefixes; *p; p++) {
ctx->build_path_fn(ctx, *p, d.path);
if (debug) {
void
rcxml_parse_xml(struct buf *b)
{
- xmlDoc *d = xmlParseMemory(b->buf, b->len);
+ xmlDoc *d = xmlParseMemory(b->data, b->len);
if (!d) {
wlr_log(WLR_ERROR, "error parsing config file");
return;
buf_add(&value, string_strip(++p));
buf_expand_shell_variables(&value);
buf_expand_tilde(&value);
- setenv(key, value.buf, 1);
+ setenv(key, value.data, 1);
buf_reset(&value);
}
static bool
parse_buf(struct server *server, struct buf *buf)
{
- xmlDoc *d = xmlParseMemory(buf->buf, buf->len);
+ xmlDoc *d = xmlParseMemory(buf->data, buf->len);
if (!d) {
wlr_log(WLR_ERROR, "xmlParseMemory()");
return false;
}
/* Guard against badly formed data such as binary input */
- if (!starts_with_less_than(ctx->buf.buf)) {
+ if (!starts_with_less_than(ctx->buf.data)) {
wlr_log(WLR_ERROR, "expect xml data to start with '<'; abort pipemenu");
goto clean_up;
}
* theme->osd_window_switcher_item_padding_x)
* field->width / 100.0;
pango_layout_set_width(layout, field_width * PANGO_SCALE);
- pango_layout_set_text(layout, buf.buf, -1);
+ pango_layout_set_text(layout, buf.data, -1);
pango_cairo_show_layout(cairo, layout);
x += field_width + theme->osd_window_switcher_item_padding_x;
}
fmt[fmt_position++] = 's';
fmt[fmt_position++] = '\0';
snprintf(converted_field, sizeof(converted_field),
- fmt, field_result.buf);
+ fmt, field_result.data);
/* And finally write it to the output buffer */
buf_add(buf, converted_field);