mirror of
https://github.com/swaywm/sway.git
synced 2024-11-26 01:41:30 +00:00
Only strip comments at the start of a line
This is necessary because i3 config files use CSS notation for colors (i.e. #rrggbb).
This commit is contained in:
parent
ef91764bc7
commit
5a369b3132
|
@ -10,7 +10,6 @@
|
||||||
|
|
||||||
const char whitespace[] = " \f\n\r\t\v";
|
const char whitespace[] = " \f\n\r\t\v";
|
||||||
|
|
||||||
/* Note: This returns 8 characters for trimmed_start per tab character. */
|
|
||||||
char *strip_whitespace(char *_str) {
|
char *strip_whitespace(char *_str) {
|
||||||
if (*_str == '\0')
|
if (*_str == '\0')
|
||||||
return _str;
|
return _str;
|
||||||
|
@ -29,25 +28,6 @@ char *strip_whitespace(char *_str) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *strip_comments(char *str) {
|
|
||||||
int in_string = 0, in_character = 0;
|
|
||||||
int i = 0;
|
|
||||||
while (str[i] != '\0') {
|
|
||||||
if (str[i] == '"' && !in_character) {
|
|
||||||
in_string = !in_string;
|
|
||||||
} else if (str[i] == '\'' && !in_string) {
|
|
||||||
in_character = !in_character;
|
|
||||||
} else if (!in_character && !in_string) {
|
|
||||||
if (str[i] == '#') {
|
|
||||||
str[i] = '\0';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
++i;
|
|
||||||
}
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
|
|
||||||
void strip_quotes(char *str) {
|
void strip_quotes(char *str) {
|
||||||
bool in_str = false;
|
bool in_str = false;
|
||||||
bool in_chr = false;
|
bool in_chr = false;
|
||||||
|
|
|
@ -207,7 +207,10 @@ bool read_config(FILE *file, bool is_active) {
|
||||||
while (!feof(file)) {
|
while (!feof(file)) {
|
||||||
line = read_line(file);
|
line = read_line(file);
|
||||||
line_number++;
|
line_number++;
|
||||||
line = strip_comments(line);
|
line = strip_whitespace(line);
|
||||||
|
if (line[0] == '#') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
struct cmd_results *res = config_command(line);
|
struct cmd_results *res = config_command(line);
|
||||||
switch(res->status) {
|
switch(res->status) {
|
||||||
case CMD_FAILURE:
|
case CMD_FAILURE:
|
||||||
|
@ -261,8 +264,7 @@ bool read_config(FILE *file, bool is_active) {
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
int output_name_cmp(const void *item, const void *data)
|
int output_name_cmp(const void *item, const void *data) {
|
||||||
{
|
|
||||||
const struct output_config *output = item;
|
const struct output_config *output = item;
|
||||||
const char *name = data;
|
const char *name = data;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue