]> icculus.org git repositories - mikachu/openbox.git/blob - plugins/keyboard/keyparse.c
remove debug print
[mikachu/openbox.git] / plugins / keyboard / keyparse.c
1 #include "kernel/parse.h"
2 #include "keyboard.h"
3
4 void keyparse(ParseToken *token)
5 {
6     static char *top = NULL;
7     static Action *action = NULL;
8     static GList *chain = NULL;
9     static gboolean err = FALSE;
10     static char *arg_str = NULL;
11     static int arg_int = 0;
12     GList *it;
13
14     if (err) {
15         if (token->type == TOKEN_NEWLINE)
16             err = FALSE;
17         /* just fall through and free the token */
18     } else if (top == NULL) {
19         if (token->type == TOKEN_IDENTIFIER &&
20             !g_ascii_strcasecmp("key", token->data.identifier)) {
21             top = token->data.identifier;
22             return;
23         } else {
24             yyerror("syntax error (expected Key)");
25             err = TRUE;
26         }
27     } else if (chain == NULL) {
28         if (token->type == TOKEN_LIST) {
29             for (it = token->data.list; it; it = it->next)
30                 if (((ParseToken*)it->data)->type != TOKEN_IDENTIFIER) break;
31             if (it == NULL) {
32                 chain = token->data.list;
33                 return;
34             } else {
35                 yyerror("invalid element in key chain");
36                 err = TRUE;
37             }
38         } else {
39             yyerror("syntax error (expected key chain)");
40             err = TRUE;
41         }
42     } else if (action == NULL) {
43         if (token->type == TOKEN_IDENTIFIER) {
44             action = action_from_string(token->data.identifier);
45
46             /* no move/resize with the keyboard */
47             if (action &&
48                 (action->func == action_move ||
49                  action->func == action_resize)) {
50                 action_free(action);
51                 action = NULL;
52             }
53
54             if (action != NULL) {
55                 parse_free_token(token); /* its data isnt saved */
56                 return;
57             } else {
58                 yyerror("invalid action");
59                 err = TRUE;
60             }
61         } else {
62             yyerror("syntax error (expected action)");
63             err = TRUE;
64         }
65     } else if (token->type == TOKEN_STRING) { /* string argument */
66         arg_str = token->data.string;
67         return;
68     } else if (token->type == TOKEN_INTEGER) { /* number argument */
69         arg_int = token->data.integer;
70         return;
71     } else if (token->type != TOKEN_NEWLINE) {
72         yyerror("syntax error (unexpected trailing token)");
73         err = TRUE;
74     } else {
75         GList *strchain = NULL;
76
77         /* build a list of just char*'s */
78         for (it = chain; it; it = it->next)
79             strchain = g_list_append(strchain,
80                                      ((ParseToken*)it->data)->data.identifier);
81
82         /* these use the argument */
83         if (action->func == action_execute || action->func == action_restart)
84             action->data.execute.path = g_strdup(arg_str);
85         if ((action->func == action_desktop ||
86              action->func == action_send_to_desktop) &&
87             arg_int)
88             action->data.desktop.desk = (unsigned) arg_int - 1;
89         if (action->func == action_move_relative_horz ||
90             action->func == action_move_relative_vert ||
91             action->func == action_resize_relative_horz ||
92             action->func == action_resize_relative_vert)
93             action->data.relative.delta = arg_int;
94
95         if (kbind(strchain, action))
96             action = NULL; /* don't free this if kbind succeeds */
97         else
98             yyerror("failed to add binding");
99         /* free the char*'s */
100         g_list_free(strchain);
101
102         err = FALSE;
103     }    
104
105     g_free(top); top = NULL;
106     action_free(action); action = NULL;
107     g_free(arg_str); arg_str = NULL;
108     arg_int = 0;
109     for (it = chain; it; it = it->next) {
110         parse_free_token(it->data);
111         g_free(it->data);
112     }
113     g_list_free(chain); chain = NULL;
114     parse_free_token(token);
115 }