aboutsummaryrefslogtreecommitdiff
path: root/sway
diff options
context:
space:
mode:
authorIan Fan <ianfan0@gmail.com>2018-12-31 23:00:49 +0000
committerIan Fan <ianfan0@gmail.com>2019-01-01 09:01:25 +0000
commita9c5158a77cc53a526ea0b16d99e476bd960e4a5 (patch)
tree7c67e55278820a2d8c0032f49403044a3c87349a /sway
parenta82b8a3c14e45697708e57f8cb27a8fc6cf31839 (diff)
config.c: re-enable backslash continuation in config file
Diffstat (limited to 'sway')
-rw-r--r--sway/config.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/sway/config.c b/sway/config.c
index 4afa09b3..4177ea10 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -569,6 +569,36 @@ bool load_include_configs(const char *path, struct sway_config *config,
return true;
}
+// get line, with backslash continuation
+static ssize_t getline_with_cont(char **lineptr, size_t *line_size, FILE *file) {
+ char *next_line = NULL;
+ size_t next_line_size = 0;
+ ssize_t nread = getline(lineptr, line_size, file);
+ while (nread >= 2) {
+ if (strcmp(&(*lineptr)[nread - 2], "\\\n") != 0) {
+ break;
+ }
+
+ ssize_t next_nread = getline(&next_line, &next_line_size, file);
+ if (next_nread == -1) {
+ break;
+ }
+
+ nread += next_nread - 2;
+ if ((ssize_t) *line_size < nread + 1) {
+ *line_size = nread + 1;
+ *lineptr = realloc(*lineptr, *line_size);
+ if (!lineptr) {
+ nread = -1;
+ break;
+ }
+ }
+ strcpy(&(*lineptr)[nread - next_nread], next_line);
+ }
+ free(next_line);
+ return nread;
+}
+
static int detect_brace(FILE *file) {
int lines = 0;
long pos = ftell(file);
@@ -633,7 +663,7 @@ bool read_config(FILE *file, struct sway_config *config,
ssize_t nread;
list_t *stack = create_list();
size_t read = 0;
- while ((nread = getline(&line, &line_size, file)) != -1) {
+ while ((nread = getline_with_cont(&line, &line_size, file)) != -1) {
if (reading_main_config) {
if (read + nread > config_size) {
wlr_log(WLR_ERROR, "Config file changed during reading");