summaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2019-01-08 10:05:37 +0100
committerLibravatar GitHub <noreply@github.com>2019-01-08 10:05:37 +0100
commit140bc2dd5b81205df58bf06e695788e689fae397 (patch)
tree6a88913630734736763b12ec0b10da68ef413256 /sway
parentMerge pull request #3337 from RedSoxFan/fix-seat-cmd-cursor (diff)
parentfixup! stringop.c: rewrite strip_whitespace (diff)
downloadsway-140bc2dd5b81205df58bf06e695788e689fae397.tar.gz
sway-140bc2dd5b81205df58bf06e695788e689fae397.tar.zst
sway-140bc2dd5b81205df58bf06e695788e689fae397.zip
Merge pull request #3275 from ianyfan/remove-readline
Rewrite strip_whitespace and remove readline.c
Diffstat (limited to 'sway')
-rw-r--r--sway/commands.c6
-rw-r--r--sway/config.c124
-rw-r--r--sway/input/input-manager.c2
-rw-r--r--sway/main.c68
4 files changed, 100 insertions, 100 deletions
diff --git a/sway/commands.c b/sway/commands.c
index 0883b57b..4e524a88 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -237,15 +237,15 @@ list_t *execute_command(char *_exec, struct sway_seat *seat,
237 criteria_destroy(criteria); 237 criteria_destroy(criteria);
238 config->handler_context.using_criteria = true; 238 config->handler_context.using_criteria = true;
239 // Skip leading whitespace 239 // Skip leading whitespace
240 head += strspn(head, whitespace); 240 for (; isspace(*head); ++head) {}
241 } 241 }
242 // Split command list 242 // Split command list
243 cmdlist = argsep(&head, ";"); 243 cmdlist = argsep(&head, ";");
244 cmdlist += strspn(cmdlist, whitespace); 244 for (; isspace(*cmdlist); ++cmdlist) {}
245 do { 245 do {
246 // Split commands 246 // Split commands
247 cmd = argsep(&cmdlist, ","); 247 cmd = argsep(&cmdlist, ",");
248 cmd += strspn(cmd, whitespace); 248 for (; isspace(*cmd); ++cmd) {}
249 if (strcmp(cmd, "") == 0) { 249 if (strcmp(cmd, "") == 0) {
250 wlr_log(WLR_INFO, "Ignoring empty command."); 250 wlr_log(WLR_INFO, "Ignoring empty command.");
251 continue; 251 continue;
diff --git a/sway/config.c b/sway/config.c
index 5d631b7e..8a0b293c 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -1,4 +1,4 @@
1#define _XOPEN_SOURCE 600 // for realpath 1#define _XOPEN_SOURCE 700 // for realpath
2#include <stdio.h> 2#include <stdio.h>
3#include <stdbool.h> 3#include <stdbool.h>
4#include <stdlib.h> 4#include <stdlib.h>
@@ -30,7 +30,6 @@
30#include "sway/tree/workspace.h" 30#include "sway/tree/workspace.h"
31#include "cairo.h" 31#include "cairo.h"
32#include "pango.h" 32#include "pango.h"
33#include "readline.h"
34#include "stringop.h" 33#include "stringop.h"
35#include "list.h" 34#include "list.h"
36#include "log.h" 35#include "log.h"
@@ -571,28 +570,49 @@ bool load_include_configs(const char *path, struct sway_config *config,
571 return true; 570 return true;
572} 571}
573 572
574static int detect_brace_on_following_line(FILE *file, char *line, 573// get line, with backslash continuation
575 int line_number) { 574static ssize_t getline_with_cont(char **lineptr, size_t *line_size, FILE *file) {
576 int lines = 0; 575 char *next_line = NULL;
577 if (line[strlen(line) - 1] != '{' && line[strlen(line) - 1] != '}') { 576 size_t next_line_size = 0;
578 char *peeked = NULL; 577 ssize_t nread = getline(lineptr, line_size, file);
579 long position = 0; 578 while (nread >= 2 && strcmp(&(*lineptr)[nread - 2], "\\\n") == 0) {
580 do { 579 ssize_t next_nread = getline(&next_line, &next_line_size, file);
581 free(peeked); 580 if (next_nread == -1) {
582 peeked = peek_line(file, lines, &position); 581 break;
583 if (peeked) { 582 }
584 peeked = strip_whitespace(peeked); 583
584 nread += next_nread - 2;
585 if ((ssize_t) *line_size < nread + 1) {
586 *line_size = nread + 1;
587 *lineptr = realloc(*lineptr, *line_size);
588 if (!*lineptr) {
589 nread = -1;
590 break;
585 } 591 }
586 lines++; 592 }
587 } while (peeked && strlen(peeked) == 0); 593 strcpy(&(*lineptr)[nread - next_nread], next_line);
594 }
595 free(next_line);
596 return nread;
597}
588 598
589 if (peeked && strlen(peeked) == 1 && peeked[0] == '{') { 599static int detect_brace(FILE *file) {
590 fseek(file, position, SEEK_SET); 600 int lines = 0;
591 } else { 601 long pos = ftell(file);
592 lines = 0; 602 char *line = NULL;
603 size_t line_size = 0;
604 while ((getline(&line, &line_size, file)) != -1) {
605 lines++;
606 strip_whitespace(line);
607 if (*line) {
608 if (strcmp(line, "{") != 0) {
609 fseek(file, pos, SEEK_SET);
610 lines = 0;
611 }
612 break;
593 } 613 }
594 free(peeked);
595 } 614 }
615 free(line);
596 return lines; 616 return lines;
597} 617}
598 618
@@ -635,55 +655,47 @@ bool read_config(FILE *file, struct sway_config *config,
635 655
636 bool success = true; 656 bool success = true;
637 int line_number = 0; 657 int line_number = 0;
638 char *line; 658 char *line = NULL;
659 size_t line_size = 0;
660 ssize_t nread;
639 list_t *stack = create_list(); 661 list_t *stack = create_list();
640 size_t read = 0; 662 size_t read = 0;
641 while (!feof(file)) { 663 while ((nread = getline_with_cont(&line, &line_size, file)) != -1) {
642 char *block = stack->length ? stack->items[0] : NULL;
643 line = read_line(file);
644 if (!line) {
645 continue;
646 }
647 line_number++;
648 wlr_log(WLR_DEBUG, "Read line %d: %s", line_number, line);
649
650 if (reading_main_config) { 664 if (reading_main_config) {
651 size_t length = strlen(line); 665 if (read + nread > config_size) {
652
653 if (read + length > config_size) {
654 wlr_log(WLR_ERROR, "Config file changed during reading"); 666 wlr_log(WLR_ERROR, "Config file changed during reading");
655 list_free_items_and_destroy(stack); 667 success = false;
656 free(line); 668 break;
657 return false;
658 } 669 }
659 670
660 strcpy(this_config + read, line); 671 strcpy(&this_config[read], line);
661 if (line_number != 1) { 672 read += nread;
662 this_config[read - 1] = '\n';
663 }
664 read += length + 1;
665 } 673 }
666 674
667 line = strip_whitespace(line); 675 if (line[nread - 1] == '\n') {
668 if (line[0] == '#') { 676 line[nread - 1] = '\0';
669 free(line);
670 continue;
671 } 677 }
672 if (strlen(line) == 0) { 678
673 free(line); 679 line_number++;
680 wlr_log(WLR_DEBUG, "Read line %d: %s", line_number, line);
681
682 strip_whitespace(line);
683 if (!*line || line[0] == '#') {
674 continue; 684 continue;
675 } 685 }
676 int brace_detected = detect_brace_on_following_line(file, line, 686 int brace_detected = 0;
677 line_number); 687 if (line[strlen(line) - 1] != '{' && line[strlen(line) - 1] != '}') {
678 if (brace_detected > 0) { 688 brace_detected = detect_brace(file);
679 line_number += brace_detected; 689 if (brace_detected > 0) {
680 wlr_log(WLR_DEBUG, "Detected open brace on line %d", line_number); 690 line_number += brace_detected;
691 wlr_log(WLR_DEBUG, "Detected open brace on line %d", line_number);
692 }
681 } 693 }
694 char *block = stack->length ? stack->items[0] : NULL;
682 char *expanded = expand_line(block, line, brace_detected > 0); 695 char *expanded = expand_line(block, line, brace_detected > 0);
683 if (!expanded) { 696 if (!expanded) {
684 list_free_items_and_destroy(stack); 697 success = false;
685 free(line); 698 break;
686 return false;
687 } 699 }
688 config->current_config_line_number = line_number; 700 config->current_config_line_number = line_number;
689 config->current_config_line = line; 701 config->current_config_line = line;
@@ -743,9 +755,9 @@ bool read_config(FILE *file, struct sway_config *config,
743 default:; 755 default:;
744 } 756 }
745 free(expanded); 757 free(expanded);
746 free(line);
747 free_cmd_results(res); 758 free_cmd_results(res);
748 } 759 }
760 free(line);
749 list_free_items_and_destroy(stack); 761 list_free_items_and_destroy(stack);
750 config->current_config_line_number = 0; 762 config->current_config_line_number = 0;
751 config->current_config_line = NULL; 763 config->current_config_line = NULL;
diff --git a/sway/input/input-manager.c b/sway/input/input-manager.c
index 61087733..04e14355 100644
--- a/sway/input/input-manager.c
+++ b/sway/input/input-manager.c
@@ -49,7 +49,7 @@ char *input_device_get_identifier(struct wlr_input_device *device) {
49 int vendor = device->vendor; 49 int vendor = device->vendor;
50 int product = device->product; 50 int product = device->product;
51 char *name = strdup(device->name); 51 char *name = strdup(device->name);
52 name = strip_whitespace(name); 52 strip_whitespace(name);
53 53
54 char *p = name; 54 char *p = name;
55 for (; *p; ++p) { 55 for (; *p; ++p) {
diff --git a/sway/main.c b/sway/main.c
index f70e751d..d08c0457 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -3,6 +3,7 @@
3#include <pango/pangocairo.h> 3#include <pango/pangocairo.h>
4#include <signal.h> 4#include <signal.h>
5#include <stdbool.h> 5#include <stdbool.h>
6#include <stdio.h>
6#include <stdlib.h> 7#include <stdlib.h>
7#include <stdio.h> 8#include <stdio.h>
8#include <string.h> 9#include <string.h>
@@ -22,7 +23,6 @@
22#include "sway/ipc-server.h" 23#include "sway/ipc-server.h"
23#include "ipc-client.h" 24#include "ipc-client.h"
24#include "log.h" 25#include "log.h"
25#include "readline.h"
26#include "stringop.h" 26#include "stringop.h"
27#include "util.h" 27#include "util.h"
28 28
@@ -47,31 +47,28 @@ void detect_raspi(void) {
47 if (!f) { 47 if (!f) {
48 return; 48 return;
49 } 49 }
50 char *line; 50 char *line = NULL;
51 while(!feof(f)) { 51 size_t line_size = 0;
52 if (!(line = read_line(f))) { 52 while (getline(&line, &line_size, f) != -1) {
53 break;
54 }
55 if (strstr(line, "Raspberry Pi")) { 53 if (strstr(line, "Raspberry Pi")) {
56 raspi = true; 54 raspi = true;
55 break;
57 } 56 }
58 free(line);
59 } 57 }
60 fclose(f); 58 fclose(f);
61 FILE *g = fopen("/proc/modules", "r"); 59 FILE *g = fopen("/proc/modules", "r");
62 if (!g) { 60 if (!g) {
61 free(line);
63 return; 62 return;
64 } 63 }
65 bool vc4 = false; 64 bool vc4 = false;
66 while (!feof(g)) { 65 while (getline(&line, &line_size, g) != -1) {
67 if (!(line = read_line(g))) {
68 break;
69 }
70 if (strstr(line, "vc4")) { 66 if (strstr(line, "vc4")) {
71 vc4 = true; 67 vc4 = true;
68 break;
72 } 69 }
73 free(line);
74 } 70 }
71 free(line);
75 fclose(g); 72 fclose(g);
76 if (!vc4 && raspi) { 73 if (!vc4 && raspi) {
77 fprintf(stderr, "\x1B[1;31mWarning: You have a " 74 fprintf(stderr, "\x1B[1;31mWarning: You have a "
@@ -86,13 +83,10 @@ void detect_proprietary(int allow_unsupported_gpu) {
86 if (!f) { 83 if (!f) {
87 return; 84 return;
88 } 85 }
89 while (!feof(f)) { 86 char *line = NULL;
90 char *line; 87 size_t line_size = 0;
91 if (!(line = read_line(f))) { 88 while (getline(&line, &line_size, f) != -1) {
92 break;
93 }
94 if (strstr(line, "nvidia")) { 89 if (strstr(line, "nvidia")) {
95 free(line);
96 if (allow_unsupported_gpu) { 90 if (allow_unsupported_gpu) {
97 wlr_log(WLR_ERROR, 91 wlr_log(WLR_ERROR,
98 "!!! Proprietary Nvidia drivers are in use !!!"); 92 "!!! Proprietary Nvidia drivers are in use !!!");
@@ -106,7 +100,6 @@ void detect_proprietary(int allow_unsupported_gpu) {
106 break; 100 break;
107 } 101 }
108 if (strstr(line, "fglrx")) { 102 if (strstr(line, "fglrx")) {
109 free(line);
110 if (allow_unsupported_gpu) { 103 if (allow_unsupported_gpu) {
111 wlr_log(WLR_ERROR, 104 wlr_log(WLR_ERROR,
112 "!!! Proprietary AMD drivers are in use !!!"); 105 "!!! Proprietary AMD drivers are in use !!!");
@@ -118,8 +111,8 @@ void detect_proprietary(int allow_unsupported_gpu) {
118 } 111 }
119 break; 112 break;
120 } 113 }
121 free(line);
122 } 114 }
115 free(line);
123 fclose(f); 116 fclose(f);
124} 117}
125 118
@@ -146,6 +139,19 @@ static void log_env(void) {
146 } 139 }
147} 140}
148 141
142static void log_file(FILE *f) {
143 char *line = NULL;
144 size_t line_size = 0;
145 ssize_t nread;
146 while ((nread = getline(&line, &line_size, f)) != -1) {
147 if (line[nread - 1] == '\n') {
148 line[nread - 1] = '\0';
149 }
150 wlr_log(WLR_INFO, "%s", line);
151 }
152 free(line);
153}
154
149static void log_distro(void) { 155static void log_distro(void) {
150 const char *paths[] = { 156 const char *paths[] = {
151 "/etc/lsb-release", 157 "/etc/lsb-release",
@@ -158,16 +164,7 @@ static void log_distro(void) {
158 FILE *f = fopen(paths[i], "r"); 164 FILE *f = fopen(paths[i], "r");
159 if (f) { 165 if (f) {
160 wlr_log(WLR_INFO, "Contents of %s:", paths[i]); 166 wlr_log(WLR_INFO, "Contents of %s:", paths[i]);
161 while (!feof(f)) { 167 log_file(f);
162 char *line;
163 if (!(line = read_line(f))) {
164 break;
165 }
166 if (*line) {
167 wlr_log(WLR_INFO, "%s", line);
168 }
169 free(line);
170 }
171 fclose(f); 168 fclose(f);
172 } 169 }
173 } 170 }
@@ -179,16 +176,7 @@ static void log_kernel(void) {
179 wlr_log(WLR_INFO, "Unable to determine kernel version"); 176 wlr_log(WLR_INFO, "Unable to determine kernel version");
180 return; 177 return;
181 } 178 }
182 while (!feof(f)) { 179 log_file(f);
183 char *line;
184 if (!(line = read_line(f))) {
185 break;
186 }
187 if (*line) {
188 wlr_log(WLR_INFO, "%s", line);
189 }
190 free(line);
191 }
192 pclose(f); 180 pclose(f);
193} 181}
194 182