diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | include/stringop.h | 7 | ||||
-rw-r--r-- | sway/commands.c | 4 | ||||
-rw-r--r-- | sway/container.c | 2 | ||||
-rw-r--r-- | sway/log.c | 4 | ||||
-rw-r--r-- | sway/main.c | 2 | ||||
-rw-r--r-- | sway/stringop.c | 29 | ||||
-rw-r--r-- | sway/workspace.c | 1 |
8 files changed, 37 insertions, 13 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index afad8123..09f37d6d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt | |||
@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 2.8.5) | |||
2 | project(sway C) | 2 | project(sway C) |
3 | set(CMAKE_C_FLAGS "-g") | 3 | set(CMAKE_C_FLAGS "-g") |
4 | set(CMAKE_C_STANDARD 99) | 4 | set(CMAKE_C_STANDARD 99) |
5 | SET(CMAKE_C_EXTENSIONS OFF) | ||
5 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin/") | 6 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin/") |
6 | add_definitions("-Wall -Wextra -Wno-unused-parameter") | 7 | add_definitions("-Wall -Wextra -Wno-unused-parameter") |
7 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMake) | 8 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMake) |
diff --git a/include/stringop.h b/include/stringop.h index dc81cdae..49bfa771 100644 --- a/include/stringop.h +++ b/include/stringop.h | |||
@@ -2,8 +2,13 @@ | |||
2 | #define _SWAY_STRINGOP_H | 2 | #define _SWAY_STRINGOP_H |
3 | #include "list.h" | 3 | #include "list.h" |
4 | 4 | ||
5 | #if !HAVE_DECL_SETENV | ||
6 | // Not sure why we need to provide this | ||
7 | extern int setenv(const char *, const char *, int); | ||
8 | #endif | ||
9 | |||
5 | // array of whitespace characters to use for delims | 10 | // array of whitespace characters to use for delims |
6 | extern const char *whitespace; | 11 | extern const char whitespace[]; |
7 | 12 | ||
8 | char *strip_whitespace(char *str); | 13 | char *strip_whitespace(char *str); |
9 | char *strip_comments(char *str); | 14 | char *strip_comments(char *str); |
diff --git a/sway/commands.c b/sway/commands.c index f2ee0184..80770e87 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -5,8 +5,10 @@ | |||
5 | #include <stdlib.h> | 5 | #include <stdlib.h> |
6 | #include <errno.h> | 6 | #include <errno.h> |
7 | #include <string.h> | 7 | #include <string.h> |
8 | #include <strings.h> | ||
8 | #include <unistd.h> | 9 | #include <unistd.h> |
9 | #include <ctype.h> | 10 | #include <ctype.h> |
11 | #include <sys/types.h> | ||
10 | #include "stringop.h" | 12 | #include "stringop.h" |
11 | #include "layout.h" | 13 | #include "layout.h" |
12 | #include "focus.h" | 14 | #include "focus.h" |
@@ -193,7 +195,7 @@ static enum cmd_status cmd_exec_always(int argc, char **argv) { | |||
193 | sway_log(L_DEBUG, "Executing %s", cmd); | 195 | sway_log(L_DEBUG, "Executing %s", cmd); |
194 | 196 | ||
195 | pid_t pid; | 197 | pid_t pid; |
196 | if ((pid = vfork()) == 0) { | 198 | if ((pid = fork()) == 0) { |
197 | execv("/bin/sh", args); | 199 | execv("/bin/sh", args); |
198 | _exit(-1); | 200 | _exit(-1); |
199 | } else if (pid < 0) { | 201 | } else if (pid < 0) { |
diff --git a/sway/container.c b/sway/container.c index d6bcc4c2..4c523827 100644 --- a/sway/container.c +++ b/sway/container.c | |||
@@ -1,7 +1,9 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <stdbool.h> | 2 | #include <stdbool.h> |
3 | #include <strings.h> | 3 | #include <strings.h> |
4 | #include <string.h> | ||
4 | #include "config.h" | 5 | #include "config.h" |
6 | #include "stringop.h" | ||
5 | #include "container.h" | 7 | #include "container.h" |
6 | #include "workspace.h" | 8 | #include "workspace.h" |
7 | #include "focus.h" | 9 | #include "focus.h" |
@@ -80,9 +80,7 @@ void sway_log_errno(log_importance_t verbosity, char* format, ...) { | |||
80 | va_end(args); | 80 | va_end(args); |
81 | 81 | ||
82 | fprintf(stderr, ": "); | 82 | fprintf(stderr, ": "); |
83 | char error[256]; | 83 | fprintf(stderr, "%s", strerror(errno)); |
84 | strerror_r(errno, error, sizeof(error)); | ||
85 | fprintf(stderr, "%s", error); | ||
86 | 84 | ||
87 | if (colored && isatty(STDERR_FILENO)) { | 85 | if (colored && isatty(STDERR_FILENO)) { |
88 | fprintf(stderr, "\x1B[0m"); | 86 | fprintf(stderr, "\x1B[0m"); |
diff --git a/sway/main.c b/sway/main.c index e03588ea..66921184 100644 --- a/sway/main.c +++ b/sway/main.c | |||
@@ -3,9 +3,11 @@ | |||
3 | #include <stdbool.h> | 3 | #include <stdbool.h> |
4 | #include <wlc/wlc.h> | 4 | #include <wlc/wlc.h> |
5 | #include <sys/wait.h> | 5 | #include <sys/wait.h> |
6 | #include <sys/types.h> | ||
6 | #include <signal.h> | 7 | #include <signal.h> |
7 | #include <getopt.h> | 8 | #include <getopt.h> |
8 | #include "layout.h" | 9 | #include "layout.h" |
10 | #include "stringop.h" | ||
9 | #include "config.h" | 11 | #include "config.h" |
10 | #include "log.h" | 12 | #include "log.h" |
11 | #include "readline.h" | 13 | #include "readline.h" |
diff --git a/sway/stringop.c b/sway/stringop.c index 90f963d6..31a036c3 100644 --- a/sway/stringop.c +++ b/sway/stringop.c | |||
@@ -1,5 +1,6 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <stdio.h> | 2 | #include <stdio.h> |
3 | #include <string.h> | ||
3 | #include <strings.h> | 4 | #include <strings.h> |
4 | #include <ctype.h> | 5 | #include <ctype.h> |
5 | #include "stringop.h" | 6 | #include "stringop.h" |
@@ -7,7 +8,7 @@ | |||
7 | #include "string.h" | 8 | #include "string.h" |
8 | #include "list.h" | 9 | #include "list.h" |
9 | 10 | ||
10 | const char *whitespace = " \f\n\r\t\v"; | 11 | const char whitespace[] = " \f\n\r\t\v"; |
11 | 12 | ||
12 | /* Note: This returns 8 characters for trimmed_start per tab character. */ | 13 | /* Note: This returns 8 characters for trimmed_start per tab character. */ |
13 | char *strip_whitespace(char *_str) { | 14 | char *strip_whitespace(char *_str) { |
@@ -313,13 +314,16 @@ char *join_list(list_t *list, char *separator) { | |||
313 | } | 314 | } |
314 | 315 | ||
315 | char *cmdsep(char **stringp, const char *delim) { | 316 | char *cmdsep(char **stringp, const char *delim) { |
316 | char *head = strsep(stringp, delim); | 317 | // skip over leading delims |
317 | // But skip over trailing delims. '3 tokens here' -> '3' 'tokens here' | 318 | char *head = *stringp + strspn(*stringp, delim); |
318 | if (*stringp) { | 319 | // Find end token |
319 | *stringp += strspn(*stringp, delim); | 320 | char *tail = *stringp += strcspn(*stringp, delim); |
320 | // If skiping over delims brings us to the end of string, set to NULL | 321 | // Set stringp to begining of next token |
321 | if (!**stringp) *stringp = NULL; | 322 | *stringp += strspn(*stringp, delim); |
322 | } | 323 | // Set stringp to null if last token |
324 | if (!**stringp) *stringp = NULL; | ||
325 | // Nullify end of first token | ||
326 | *tail = 0; | ||
323 | return head; | 327 | return head; |
324 | } | 328 | } |
325 | 329 | ||
@@ -358,3 +362,12 @@ char *argsep(char **stringp, const char *delim) { | |||
358 | found: | 362 | found: |
359 | return start; | 363 | return start; |
360 | } | 364 | } |
365 | |||
366 | char *strdup(const char *str) { | ||
367 | char *dup = malloc(strlen(str) + 1); | ||
368 | if (dup) { | ||
369 | strcpy(dup, str); | ||
370 | } | ||
371 | return dup; | ||
372 | } | ||
373 | |||
diff --git a/sway/workspace.c b/sway/workspace.c index 658f79bc..c169c1cb 100644 --- a/sway/workspace.c +++ b/sway/workspace.c | |||
@@ -2,6 +2,7 @@ | |||
2 | #include <stdbool.h> | 2 | #include <stdbool.h> |
3 | #include <wlc/wlc.h> | 3 | #include <wlc/wlc.h> |
4 | #include <string.h> | 4 | #include <string.h> |
5 | #include <strings.h> | ||
5 | #include "workspace.h" | 6 | #include "workspace.h" |
6 | #include "layout.h" | 7 | #include "layout.h" |
7 | #include "list.h" | 8 | #include "list.h" |