]> git.mdlowis.com Git - proto/labwc.git/commitdiff
common/buf: rename buf->buf to buf->data
authorJohn Lindgren <john@jlindgren.net>
Wed, 17 Apr 2024 03:36:32 +0000 (23:36 -0400)
committerJohan Malm <johanmalm@users.noreply.github.com>
Thu, 18 Apr 2024 06:00:23 +0000 (07:00 +0100)
include/common/buf.h
src/action.c
src/button/button-xbm.c
src/common/buf.c
src/common/dir.c
src/config/rcxml.c
src/config/session.c
src/menu/menu.c
src/osd.c
src/osd_field.c

index df009edb15cdaeccef912946cf30f15e54a88576..bcbc8301ab4ad4273b87c8527d6731916a5e2ccd 100644 (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
index 2ba1c53165af738b03770df04fe3b05c6cfb55e8..7cc4bc56bcea19c8bd9788e6a8041bf0ed84360f 100644 (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;
index 0133a052700a28c19b7f5be49b554dde19c18c7b..94ad238a3fe5cea24d09ee689d5359ed1fc4754c 100644 (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);
index 78d48d150514aaadd25603d934acebab823dd06b..ecdddc6e8cd7e079156cd62c3e33d1faae0d21a7 100644 (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;
index 4f173e94134db7ce5fad1789cad4b3281e2f4333..201c9b0339825e988801cf7b53737299c96d4916 100644 (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) {
index ded8b646f383a23b8f931d832b6faabc97c972ed..1b14c0a2a80245b9e02c65f7515d6dcb4782466a 100644 (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;
index 2bf4693b69ec858868815d9228c239b354daf0b5..db5894343f479f68cf39ff71848691498e2bef72 100644 (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);
 }
 
index 7130b21387c1b1e22b839db0eb8f5a820afc0d53..84b8679353554b21c0beb6e7fda389f3e3ae3864 100644 (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;
        }
index 4bd57a6ddf5c25f25390239bb4eafc4ceff16f7a..9555d913239be4f1c531e5a3d6f7a8ef60c0c796 100644 (file)
--- a/src/osd.c
+++ b/src/osd.c
@@ -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;
                }
index 7728297d77890633d13f9c2a264e8b6581568f82..b97418b2a25bdebd21f3ccde667ab96d636b8e21 100644 (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);