From: Michael Stapelberg Date: Sat, 19 Sep 2009 17:05:15 +0000 (+0200) Subject: Finish configfile parsing with lexer, implement -l to use the lexer. X-Git-Tag: 3.d~90^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ca472559b93213b3330a16c674333dc441f01911;p=i3%2Fi3 Finish configfile parsing with lexer, implement -l to use the lexer. Every user is encouraged to use -l to switch to the new lexer and see if there are any problems. --- diff --git a/include/config.h b/include/config.h index f94d9a40..c0105cee 100644 --- a/include/config.h +++ b/include/config.h @@ -20,6 +20,7 @@ typedef struct Config Config; extern Config config; +extern bool config_use_lexer; /** * Part of the struct Config. It makes sense to group colors for background, diff --git a/src/cfgparse.l b/src/cfgparse.l index ac2a71b0..2332055a 100644 --- a/src/cfgparse.l +++ b/src/cfgparse.l @@ -43,6 +43,7 @@ Mod2 { yylval.number = BIND_MOD2; return MODIFIER; } Mod3 { yylval.number = BIND_MOD3; return MODIFIER; } Mod4 { yylval.number = BIND_MOD4; return MODIFIER; } Mod5 { yylval.number = BIND_MOD5; return MODIFIER; } +Mode_switch { yylval.number = BIND_MODE_SWITCH; return MODIFIER; } control { return TOKCONTROL; } shift { return TOKSHIFT; } → { return TOKARROW; } diff --git a/src/cfgparse.y b/src/cfgparse.y index f3c552f9..4b7224b5 100644 --- a/src/cfgparse.y +++ b/src/cfgparse.y @@ -152,6 +152,7 @@ void parse_file(const char *f) { int number; char *string; struct Colortriple *color; + struct Assignment *assignment; } %token NUMBER @@ -272,13 +273,39 @@ screen: ; assign: - TOKASSIGN WHITESPACE window_class WHITESPACE optional_arrow NUMBER + TOKASSIGN WHITESPACE window_class WHITESPACE optional_arrow assign_target { - /* TODO */ printf("assignment of %s to %d\n", $3, $6); + + struct Assignment *new = $6; + new->windowclass_title = strdup($3); + TAILQ_INSERT_TAIL(&assignments, new, assignments); } ; +assign_target: + NUMBER + { + struct Assignment *new = scalloc(sizeof(struct Assignment)); + new->workspace = $1; + new->floating = ASSIGN_FLOATING_NO; + $$ = new; + } + | '~' + { + struct Assignment *new = scalloc(sizeof(struct Assignment)); + new->floating = ASSIGN_FLOATING_ONLY; + $$ = new; + } + | '~' NUMBER + { + struct Assignment *new = scalloc(sizeof(struct Assignment)); + new->workspace = $2; + new->floating = ASSIGN_FLOATING; + $$ = new; + } + ; + window_class: QUOTEDSTRING | STR_NG diff --git a/src/config.c b/src/config.c index dd2f70c1..ffc8b7ed 100644 --- a/src/config.c +++ b/src/config.c @@ -28,6 +28,8 @@ Config config; +bool config_use_lexer = false; + /* * This function resolves ~ in pathnames. * @@ -226,6 +228,25 @@ void load_configuration(xcb_connection_t *conn, const char *override_configpath, config.bar.urgent.background = get_colorpixel(conn, "#900000"); config.bar.urgent.text = get_colorpixel(conn, "#ffffff"); + if (config_use_lexer) { + /* Yes, this will be cleaned up soon. */ + if (override_configpath != NULL) { + parse_file(override_configpath); + } else { + FILE *handle; + char *globbed = glob_path("~/.i3/config"); + if ((handle = fopen(globbed, "r")) == NULL) { + if ((handle = fopen("/etc/i3/config", "r")) == NULL) { + die("Neither \"%s\" nor /etc/i3/config could be opened\n", globbed); + } else { + parse_file("/etc/i3/config"); + } + } else { + parse_file(globbed); + } + } + } else { + FILE *handle; if (override_configpath != NULL) { if ((handle = fopen(override_configpath, "r")) == NULL) @@ -508,9 +529,6 @@ void load_configuration(xcb_connection_t *conn, const char *override_configpath, grab_all_keys(conn); fclose(handle); - REQUIRED_OPTION(terminal); - REQUIRED_OPTION(font); - while (!SLIST_EMPTY(&variables)) { struct Variable *v = SLIST_FIRST(&variables); SLIST_REMOVE_HEAD(&variables, variables); @@ -518,6 +536,10 @@ void load_configuration(xcb_connection_t *conn, const char *override_configpath, free(v->value); free(v); } + } + + REQUIRED_OPTION(terminal); + REQUIRED_OPTION(font); /* Set an empty name for every workspace which got no name */ for (int i = 0; i < 10; i++) { diff --git a/src/mainx.c b/src/mainx.c index cb385c89..329aae29 100644 --- a/src/mainx.c +++ b/src/mainx.c @@ -165,7 +165,7 @@ int main(int argc, char *argv[], char *env[]) { start_argv = argv; - while ((opt = getopt_long(argc, argv, "c:vahp", long_options, &option_index)) != -1) { + while ((opt = getopt_long(argc, argv, "c:vahl", long_options, &option_index)) != -1) { switch (opt) { case 'a': LOG("Autostart disabled using -a\n"); @@ -177,12 +177,9 @@ int main(int argc, char *argv[], char *env[]) { case 'v': printf("i3 version " I3_VERSION " © 2009 Michael Stapelberg and contributors\n"); exit(EXIT_SUCCESS); - case 'p': - { - printf("parsing\n"); - parse_file(override_configpath); - exit(0); - } + case 'l': + config_use_lexer = true; + break; default: fprintf(stderr, "Usage: %s [-c configfile] [-a] [-v]\n", argv[0]); fprintf(stderr, "\n");