]> git.sur5r.net Git - i3/i3/commitdiff
Finish configfile parsing with lexer, implement -l to use the lexer.
authorMichael Stapelberg <michael@stapelberg.de>
Sat, 19 Sep 2009 17:05:15 +0000 (19:05 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Sat, 19 Sep 2009 17:05:15 +0000 (19:05 +0200)
Every user is encouraged to use -l to switch to the new lexer and
see if there are any problems.

include/config.h
src/cfgparse.l
src/cfgparse.y
src/config.c
src/mainx.c

index f94d9a40e908773176e41d89cbf6025fef1a272a..c0105cee4507292bcc0384909074c39b671d8920 100644 (file)
@@ -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,
index ac2a71b0e2b98ec4cbd6cdd6b7d42e1c531e7345..2332055abfcdee5271ba98aecf4bde9d8cc07f39 100644 (file)
@@ -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; }
index f3c552f9ddbb270f8f3246d67ca9340b1550df37..4b7224b51ae1a8fc31e4a3c2edc17854314520da 100644 (file)
@@ -152,6 +152,7 @@ void parse_file(const char *f) {
         int number;
         char *string;
         struct Colortriple *color;
+       struct Assignment *assignment;
 }
 
 %token <number>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", $<string>3, $<number>6);
+
+               struct Assignment *new = $<assignment>6;
+               new->windowclass_title = strdup($<string>3);
+               TAILQ_INSERT_TAIL(&assignments, new, assignments);
         }
         ;
 
+assign_target:
+       NUMBER
+       {
+               struct Assignment *new = scalloc(sizeof(struct Assignment));
+               new->workspace = $<number>1;
+               new->floating = ASSIGN_FLOATING_NO;
+               $<assignment>$ = new;
+       }
+       | '~'
+       {
+               struct Assignment *new = scalloc(sizeof(struct Assignment));
+               new->floating = ASSIGN_FLOATING_ONLY;
+               $<assignment>$ = new;
+       }
+       | '~' NUMBER
+       {
+               struct Assignment *new = scalloc(sizeof(struct Assignment));
+               new->workspace = $<number>2;
+               new->floating = ASSIGN_FLOATING;
+               $<assignment>$ = new;
+       }
+       ;
+
 window_class:
         QUOTEDSTRING
         | STR_NG
index dd2f70c1ef7057cb31c9c4f304c1fd3da2020262..ffc8b7ed6c7e0a0941527314153ae2cbd17ead2a 100644 (file)
@@ -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++) {
index cb385c89badad71286fe37aedc23b155a6fdcae6..329aae2920e3ec4a2defdb17522ec86736191de3 100644 (file)
@@ -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");