common/buf: rename buf->buf to buf->data

This commit is contained in:
John Lindgren 2024-04-16 23:36:32 -04:00 committed by Johan Malm
parent fccc6a2922
commit a8f98cb90b
10 changed files with 33 additions and 33 deletions

View file

@ -13,9 +13,9 @@ struct buf {
* 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;
@ -28,7 +28,7 @@ struct buf {
};
/** 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

View file

@ -709,7 +709,7 @@ actions_run(struct view *activator, struct server *server,
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;

View file

@ -290,7 +290,7 @@ button_xbm_load(const char *button_name, struct lab_data_buffer **buffer,
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);

View file

@ -13,10 +13,10 @@ buf_expand_tilde(struct buf *s)
{
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);
@ -47,23 +47,23 @@ buf_expand_shell_variables(struct buf *s)
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);
@ -85,12 +85,12 @@ buf_expand(struct buf *s, int new_alloc)
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;
}
@ -103,26 +103,26 @@ buf_add(struct buf *s, const char *data)
}
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;
}
@ -132,7 +132,7 @@ void
buf_reset(struct buf *s)
{
if (s->alloc) {
free(s->buf);
free(s->data);
}
*s = BUF_INIT;
}
@ -141,7 +141,7 @@ void
buf_move(struct buf *dst, struct buf *src)
{
if (dst->alloc) {
free(dst->buf);
free(dst->data);
}
*dst = *src;
*src = BUF_INIT;

View file

@ -112,7 +112,7 @@ find_dir(struct ctx *ctx)
* .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) {

View file

@ -1107,7 +1107,7 @@ xml_tree_walk(xmlNode *node)
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;

View file

@ -53,7 +53,7 @@ process_line(char *line)
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);
}

View file

@ -617,7 +617,7 @@ xml_tree_walk(xmlNode *node, struct server *server)
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;
@ -1195,7 +1195,7 @@ handle_pipemenu_readable(int fd, uint32_t mask, void *_ctx)
}
/* 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;
}

View file

@ -296,7 +296,7 @@ render_osd(struct server *server, cairo_t *cairo, int w, int h,
* 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;
}

View file

@ -237,7 +237,7 @@ field_set_custom(struct buf *buf, struct view *view, const char *format)
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);