--- /dev/null
+/*
+ * Read file into memory
+ *
+ * Copyright Johan Malm 2020
+ */
+
+#ifndef __LABWC_GRAB_FILE_H
+#define __LABWC_GRAB_FILE_H
+
+/**
+ * grab_file - read file into memory buffer
+ * @filename: file to read
+ * Returns pointer to buffer. Free with free().
+ */
+char *grab_file(const char *filename);
+
+#endif /* __LABWC_GRAB_FILE_H */
--- /dev/null
+/*
+ * Read file into memory
+ *
+ * Copyright Johan Malm 2020
+ */
+
+#define _POSIX_C_SOURCE 200809L
+#include "common/grab-file.h"
+#include "common/buf.h"
+
+#include <stdio.h>
+
+char *grab_file(const char *filename)
+{
+ char *line = NULL;
+ size_t len = 0;
+ FILE *stream = fopen(filename, "r");
+ if (!stream)
+ return NULL;
+ struct buf buffer;
+ buf_init(&buffer);
+ while ((getline(&line, &len, stream) != -1)) {
+ char *p = strrchr(line, '\n');
+ if (p)
+ *p = '\0';
+ buf_add(&buffer, line);
+ }
+ free(line);
+ fclose(stream);
+ return (buffer.buf);
+}
labwc_sources += files(
'buf.c',
'font.c',
+ 'grab-file.c',
'spawn.c',
)
#include <stdint.h>
#include <stdbool.h>
-#include "common/buf.h"
#include "theme/xbm/parse.h"
/* TODO: should be window.active.button.unpressed.image.color */
process_bytes(&pixmap, t);
return pixmap;
}
-
-char *xbm_read_file(const char *filename)
-{
- char *line = NULL;
- size_t len = 0;
- FILE *stream = fopen(filename, "r");
- if (!stream)
- return NULL;
- struct buf buffer;
- buf_init(&buffer);
- while ((getline(&line, &len, stream) != -1)) {
- char *p = strrchr(line, '\n');
- if (p)
- *p = '\0';
- buf_add(&buffer, line);
- }
- free(line);
- fclose(stream);
- return (buffer.buf);
-}
#include "theme/xbm/parse.h"
#include "theme/theme-dir.h"
#include "config/rcxml.h"
+#include "common/grab-file.h"
/* built-in 6x6 buttons */
char close_button_normal[] = { 0x33, 0x3f, 0x1e, 0x1e, 0x3f, 0x33 };
static void load_button(struct wlr_renderer *renderer, const char *filename,
struct wlr_texture **texture, char *button)
{
- char *buffer = xbm_read_file(xbm_path(filename));
+ char *buffer = grab_file(xbm_path(filename));
if (!buffer)
goto out;
fprintf(stderr, "loading %s\n", filename);