1 #include "kernel/parse.h"
4 void keyparse(ParseToken
*token
)
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;
15 if (token
->type
== TOKEN_NEWLINE
)
17 /* just fall through and free the token */
18 } else if (top
== NULL
) {
19 if (token
->type
== TOKEN_IDENTIFIER
&&
20 !g_ascii_strcasecmp("kbind", token
->data
.identifier
)) {
21 top
= token
->data
.identifier
;
24 yyerror("syntax error (expected kbind)");
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;
32 chain
= token
->data
.list
;
35 yyerror("invalid element in key chain");
39 yyerror("syntax error (expected key chain)");
42 } else if (action
== NULL
) {
43 if (token
->type
== TOKEN_IDENTIFIER
) {
44 action
= action_from_string(token
->data
.identifier
);
46 /* no move/resize with the keyboard */
48 (action
->func
== action_move
||
49 action
->func
== action_resize
)) {
55 parse_free_token(token
); /* its data isnt saved */
58 yyerror("invalid action");
62 yyerror("syntax error (expected action)");
65 } else if (token
->type
== TOKEN_STRING
) { /* string argument */
66 arg_str
= token
->data
.string
;
68 } else if (token
->type
== TOKEN_INTEGER
) { /* number argument */
69 arg_int
= token
->data
.integer
;
71 } else if (token
->type
!= TOKEN_NEWLINE
) {
72 yyerror("syntax error (unexpected trailing token)");
75 GList
*strchain
= NULL
;
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
);
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
) &&
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
;
95 if (kbind(strchain
, action
))
96 action
= NULL
; /* don't free this if kbind succeeds */
98 yyerror("failed to add key binding");
99 /* free the char*'s */
100 g_list_free(strchain
);
105 g_free(top
); top
= NULL
;
106 action_free(action
); action
= NULL
;
107 g_free(arg_str
); arg_str
= NULL
;
109 for (it
= chain
; it
; it
= it
->next
) {
110 parse_free_token(it
->data
);
113 g_list_free(chain
); chain
= NULL
;
114 parse_free_token(token
);