diff options
-rw-r--r-- | config | 11 | ||||
-rw-r--r-- | include/stringop.h | 4 | ||||
-rw-r--r-- | sway.1.txt | 2 | ||||
-rw-r--r-- | sway/commands.c | 6 | ||||
-rw-r--r-- | sway/config.c | 5 | ||||
-rw-r--r-- | sway/readline.c | 13 | ||||
-rw-r--r-- | sway/stringop.c | 52 |
7 files changed, 48 insertions, 45 deletions
@@ -9,10 +9,13 @@ | |||
9 | 9 | ||
10 | 10 | ||
11 | ### Variables | 11 | ### Variables |
12 | 12 | # | |
13 | set $mod Mod4 # Logo key. Use Mod1 for Alt. | 13 | # Logo key. Use Mod1 for Alt. |
14 | set $term urxvt # Your preferred terminal emulator | 14 | set $mod Mod4 |
15 | set $menu dmenu_run # Your preferred application launcher | 15 | # Your preferred terminal emulator |
16 | set $term urxvt | ||
17 | # Your preferred application launcher | ||
18 | set $menu dmenu_run | ||
16 | 19 | ||
17 | ### Key bindings | 20 | ### Key bindings |
18 | # | 21 | # |
diff --git a/include/stringop.h b/include/stringop.h index a5346829..03387345 100644 --- a/include/stringop.h +++ b/include/stringop.h | |||
@@ -2,8 +2,8 @@ | |||
2 | #define _SWAY_STRINGOP_H | 2 | #define _SWAY_STRINGOP_H |
3 | #include "list.h" | 3 | #include "list.h" |
4 | 4 | ||
5 | char *strip_whitespace(char *str, int *trimmed_start); | 5 | void strip_whitespace(char *str); |
6 | char *strip_comments(char *str); | 6 | void strip_comments(char *str); |
7 | list_t *split_string(const char *str, const char *delims); | 7 | list_t *split_string(const char *str, const char *delims); |
8 | void free_flat_list(list_t *list); | 8 | void free_flat_list(list_t *list); |
9 | char *code_strchr(const char *string, char delimiter); | 9 | char *code_strchr(const char *string, char delimiter); |
@@ -1,6 +1,8 @@ | |||
1 | ///// | 1 | ///// |
2 | vim:set ts=4 sw=4 tw=82 noet: | 2 | vim:set ts=4 sw=4 tw=82 noet: |
3 | ///// | 3 | ///// |
4 | :quotes.~: | ||
5 | |||
4 | sway (1) | 6 | sway (1) |
5 | ======== | 7 | ======== |
6 | 8 | ||
diff --git a/sway/commands.c b/sway/commands.c index 444e6159..642fa3ce 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -490,7 +490,7 @@ static char **split_directive(char *line, int *argc) { | |||
490 | if (!*line) return parts; | 490 | if (!*line) return parts; |
491 | 491 | ||
492 | int in_string = 0, in_character = 0; | 492 | int in_string = 0, in_character = 0; |
493 | int i, j, _; | 493 | int i, j; |
494 | for (i = 0, j = 0; line[i]; ++i) { | 494 | for (i = 0, j = 0; line[i]; ++i) { |
495 | if (line[i] == '\\') { | 495 | if (line[i] == '\\') { |
496 | ++i; | 496 | ++i; |
@@ -503,7 +503,7 @@ static char **split_directive(char *line, int *argc) { | |||
503 | char *item = malloc(i - j + 1); | 503 | char *item = malloc(i - j + 1); |
504 | strncpy(item, line + j, i - j); | 504 | strncpy(item, line + j, i - j); |
505 | item[i - j] = '\0'; | 505 | item[i - j] = '\0'; |
506 | item = strip_whitespace(item, &_); | 506 | strip_whitespace(item); |
507 | if (item[0] == '\0') { | 507 | if (item[0] == '\0') { |
508 | free(item); | 508 | free(item); |
509 | } else { | 509 | } else { |
@@ -521,7 +521,7 @@ static char **split_directive(char *line, int *argc) { | |||
521 | char *item = malloc(i - j + 1); | 521 | char *item = malloc(i - j + 1); |
522 | strncpy(item, line + j, i - j); | 522 | strncpy(item, line + j, i - j); |
523 | item[i - j] = '\0'; | 523 | item[i - j] = '\0'; |
524 | item = strip_whitespace(item, &_); | 524 | strip_whitespace(item); |
525 | if (*argc == capacity) { | 525 | if (*argc == capacity) { |
526 | capacity++; | 526 | capacity++; |
527 | parts = realloc(parts, sizeof(char *) * capacity); | 527 | parts = realloc(parts, sizeof(char *) * capacity); |
diff --git a/sway/config.c b/sway/config.c index f06d55f8..bde65614 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -186,10 +186,9 @@ bool read_config(FILE *file, bool is_active) { | |||
186 | int temp_depth = 0; // Temporary: skip all config sections with depth | 186 | int temp_depth = 0; // Temporary: skip all config sections with depth |
187 | 187 | ||
188 | while (!feof(file)) { | 188 | while (!feof(file)) { |
189 | int _; | ||
190 | char *line = read_line(file); | 189 | char *line = read_line(file); |
191 | line = strip_whitespace(line, &_); | 190 | strip_comments(line); |
192 | line = strip_comments(line); | 191 | strip_whitespace(line); |
193 | if (!line[0]) { | 192 | if (!line[0]) { |
194 | goto _continue; | 193 | goto _continue; |
195 | } | 194 | } |
diff --git a/sway/readline.c b/sway/readline.c index be8c35cc..dfdc3fe8 100644 --- a/sway/readline.c +++ b/sway/readline.c | |||
@@ -3,7 +3,7 @@ | |||
3 | #include <stdio.h> | 3 | #include <stdio.h> |
4 | 4 | ||
5 | char *read_line(FILE *file) { | 5 | char *read_line(FILE *file) { |
6 | int i = 0, length = 0, size = 128; | 6 | int length = 0, size = 128; |
7 | char *string = malloc(size); | 7 | char *string = malloc(size); |
8 | if (!string) { | 8 | if (!string) { |
9 | return NULL; | 9 | return NULL; |
@@ -16,21 +16,20 @@ char *read_line(FILE *file) { | |||
16 | if (c == '\r') { | 16 | if (c == '\r') { |
17 | continue; | 17 | continue; |
18 | } | 18 | } |
19 | if (i == size) { | 19 | if (length == size) { |
20 | string = realloc(string, length *= 2); | 20 | string = realloc(string, size *= 2); |
21 | if (!string) { | 21 | if (!string) { |
22 | return NULL; | 22 | return NULL; |
23 | } | 23 | } |
24 | } | 24 | } |
25 | string[i++] = (char)c; | 25 | string[length++] = c; |
26 | length++; | ||
27 | } | 26 | } |
28 | if (i + 1 != size) { | 27 | if (length + 1 == size) { |
29 | string = realloc(string, length + 1); | 28 | string = realloc(string, length + 1); |
30 | if (!string) { | 29 | if (!string) { |
31 | return NULL; | 30 | return NULL; |
32 | } | 31 | } |
33 | } | 32 | } |
34 | string[i] = '\0'; | 33 | string[length] = '\0'; |
35 | return string; | 34 | return string; |
36 | } | 35 | } |
diff --git a/sway/stringop.c b/sway/stringop.c index 1dff97bf..00cc32b8 100644 --- a/sway/stringop.c +++ b/sway/stringop.c | |||
@@ -1,37 +1,38 @@ | |||
1 | #include "stringop.h" | ||
2 | #include <stdlib.h> | 1 | #include <stdlib.h> |
3 | #include <stdio.h> | 2 | #include <stdio.h> |
3 | #include <strings.h> | ||
4 | #include <ctype.h> | ||
5 | #include "stringop.h" | ||
4 | #include "string.h" | 6 | #include "string.h" |
5 | #include "list.h" | 7 | #include "list.h" |
6 | #include <strings.h> | ||
7 | 8 | ||
8 | /* Note: This returns 8 characters for trimmed_start per tab character. */ | 9 | /* Note: This returns 8 characters for trimmed_start per tab character. */ |
9 | char *strip_whitespace(char *_str, int *trimmed_start) { | 10 | void strip_whitespace(char *str) { |
10 | *trimmed_start = 0; | 11 | int shift = 0; |
11 | if (*_str == '\0') | 12 | int bpair = 1; |
12 | return _str; | 13 | int in_str = 0, in_ch = 0; |
13 | char *strold = _str; | 14 | while (*str) { |
14 | while (*_str == ' ' || *_str == '\t') { | 15 | str[-shift] = str[0]; |
15 | if (*_str == '\t') { | 16 | if (*str == '"' && !in_ch) { |
16 | *trimmed_start += 8; | 17 | in_str = !in_str; |
17 | } else { | 18 | } else if (*str == '\'' && !in_str) { |
18 | *trimmed_start += 1; | 19 | in_ch = !in_ch; |
20 | } else if (!in_ch && !in_str) { | ||
21 | if (isblank(*str)) { | ||
22 | if (bpair) { | ||
23 | ++shift; | ||
24 | } | ||
25 | bpair=1; | ||
26 | } else { | ||
27 | bpair = 0; | ||
28 | } | ||
19 | } | 29 | } |
20 | _str++; | 30 | ++str; |
21 | } | 31 | } |
22 | char *str = malloc(strlen(_str) + 1); | 32 | str[-shift-bpair] = 0; |
23 | strcpy(str, _str); | ||
24 | free(strold); | ||
25 | int i; | ||
26 | for (i = 0; str[i] != '\0'; ++i); | ||
27 | do { | ||
28 | i--; | ||
29 | } while (i >= 0 && (str[i] == ' ' || str[i] == '\t')); | ||
30 | str[i + 1] = '\0'; | ||
31 | return str; | ||
32 | } | 33 | } |
33 | 34 | ||
34 | char *strip_comments(char *str) { | 35 | void strip_comments(char *str) { |
35 | int in_string = 0, in_character = 0; | 36 | int in_string = 0, in_character = 0; |
36 | int i = 0; | 37 | int i = 0; |
37 | while (str[i] != '\0') { | 38 | while (str[i] != '\0') { |
@@ -40,14 +41,13 @@ char *strip_comments(char *str) { | |||
40 | } else if (str[i] == '\'' && !in_string) { | 41 | } else if (str[i] == '\'' && !in_string) { |
41 | in_character = !in_character; | 42 | in_character = !in_character; |
42 | } else if (!in_character && !in_string) { | 43 | } else if (!in_character && !in_string) { |
43 | if (str[i] == '#' && i == 0) { | 44 | if (str[i] == '#') { |
44 | str[i] = '\0'; | 45 | str[i] = '\0'; |
45 | break; | 46 | break; |
46 | } | 47 | } |
47 | } | 48 | } |
48 | ++i; | 49 | ++i; |
49 | } | 50 | } |
50 | return str; | ||
51 | } | 51 | } |
52 | 52 | ||
53 | list_t *split_string(const char *str, const char *delims) { | 53 | list_t *split_string(const char *str, const char *delims) { |