-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite strip_whitespace and remove readline.c #3275
Conversation
common/stringop.c
Outdated
|
||
if (!*str) return; | ||
|
||
while (isspace(str[--len])) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you need to subtract start
from len
before doing this? len
is still the original length of the string.
sway/commands.c
Outdated
} | ||
// Split command list | ||
cmdlist = argsep(&head, ";"); | ||
cmdlist += strspn(cmdlist, whitespace); | ||
for (; isspace(*cmdlist); ++head) {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++cmdlist
?
sway/config.c
Outdated
@@ -1,4 +1,5 @@ | |||
#define _XOPEN_SOURCE 600 // for realpath | |||
#define _POSIX_C_SOURCE 200809L | |||
#define _XOPEN_SOURCE 500 // for realpath |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't define both, they'll cause issues because _XOPEN_SOURCE
defines implicitly _POSIX_C_SOURCE
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not know that, thanks
sway/main.c
Outdated
size_t line_size = 0; | ||
ssize_t nread; | ||
while ((nread = getline(&line, &line_size, f)) != -1) { | ||
if (line[nread -1] == '\n') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: missing space
be708de
to
b1e90e5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not allow for lines to be continued on to the next when a backslash is the last character of the line.
Ah, that's a good point. And since that functionality is needed in quite a few places, maybe this isn't a change worth doing. |
I'd still like to see readline.c go away |
b1e90e5
to
b56edaf
Compare
I've added a commit to address the backslash continuation issue, hopefully this works? It's not the prettiest though... |
All occurrences of read_line have been replaced by getline. peek_line has been absorbed into detect_brace.
b56edaf
to
bd35879
Compare
common/stringop.c
Outdated
size_t start = strspn(str, whitespace); | ||
memmove(str, &str[start], len + 1 - start); | ||
|
||
if (!*str) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: missing brackets
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM and works
Thanks! |
Oh, I was going to squash the commits, but forgot, sorry. |
strip_whitespace
was pretty awfully written.read_line
has been replaced by getline, hopefully I've rewritten everything correctly.peek_line
was only used once, and the way it was being used was quite inefficient, so I just absorbed it intodetect_brace
.