Skip to content
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

Merged
merged 5 commits into from
Jan 8, 2019

Conversation

ianyfan
Copy link
Contributor

@ianyfan ianyfan commented Dec 9, 2018

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 into detect_brace.


if (!*str) return;

while (isspace(str[--len])) {}
Copy link
Member

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) {}
Copy link
Member

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
Copy link
Member

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

Copy link
Contributor Author

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 Show resolved Hide resolved
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') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: missing space

Copy link
Member

@RedSoxFan RedSoxFan left a 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.

@ianyfan ianyfan changed the title Rewrite strip_whitespace and remove readline.c [DO NOT MERGE] Rewrite strip_whitespace and remove readline.c Dec 11, 2018
@ianyfan
Copy link
Contributor Author

ianyfan commented Dec 11, 2018

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.

@emersion
Copy link
Member

I'd still like to see readline.c go away

@ianyfan ianyfan changed the title [DO NOT MERGE] Rewrite strip_whitespace and remove readline.c Rewrite strip_whitespace and remove readline.c Dec 31, 2018
@ianyfan
Copy link
Contributor Author

ianyfan commented Dec 31, 2018

I've added a commit to address the backslash continuation issue, hopefully this works? It's not the prettiest though...

size_t start = strspn(str, whitespace);
memmove(str, &str[start], len + 1 - start);

if (!*str) return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: missing brackets

Copy link
Member

@emersion emersion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM and works

@emersion emersion merged commit 140bc2d into swaywm:master Jan 8, 2019
@emersion
Copy link
Member

emersion commented Jan 8, 2019

Thanks!

@ianyfan
Copy link
Contributor Author

ianyfan commented Jan 8, 2019

Oh, I was going to squash the commits, but forgot, sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants