plugins/keyboard/keysrc.yacc (raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
%{ #include "keyboard.h" #include "../../kernel/action.h" #include <glib.h> #ifdef HAVE_STDIO_H # include <stdio.h> #endif extern int kparselex(); extern int kparselineno; extern FILE *kparsein; /* lexer input */ void kparseerror(char *s); static void addbinding(GList *keylist, char *action, char *path, int num); static char *path; %} %union { char *string; int integer; GList *list; } %token <integer> INTEGER %token <string> STRING %token <string> FIELD %token <string> DESKTOP %type <list> fields %% config: | config '\n' | config fields FIELD '\n' { addbinding($2, $3, NULL, 0); } | config fields FIELD INTEGER '\n' { addbinding($2, $3, NULL, $4); } | config fields FIELD STRING '\n' { addbinding($2, $3, $4, 0); } ; fields: FIELD { $$ = g_list_append(NULL, $1); } | fields FIELD { $$ = g_list_append($1, $2); } ; %% void kparseerror(char *s) { g_warning("Parser error in '%s' on line %d", path, kparselineno); } void keysrc_parse() { path = g_build_filename(g_get_home_dir(), ".openbox", "keysrc", NULL); if ((kparsein = fopen(path, "r")) == NULL) { g_free(path); path = g_build_filename(RCDIR, "keysrc", NULL); if ((kparsein = fopen(path, "r")) == NULL) { g_warning("No keysrc file found!"); g_free(path); return; } } kparselineno = 1; kparseparse(); } static void addbinding(GList *keylist, char *action, char *apath, int num) { Action *a; a = action_from_string(action); /* no move/resize with the keyboard */ if (a && (a->func == action_move || a->func == action_resize)) { action_free(a); a = NULL; } if (a == NULL) { g_warning("Invalid action '%s' in '%s' on line %d", action, apath, kparselineno - 1); return; } /* these have extra data! */ if (a->func == action_execute || a->func == action_restart) a->data.execute.path = apath; else g_free(apath); if (a->func == action_desktop || a->func == action_send_to_desktop) a->data.desktop.desk = (unsigned) num - 1; if (a->func == action_move_relative_horz || a->func == action_move_relative_vert || a->func == action_resize_relative_horz || a->func == action_resize_relative_vert) a->data.relative.delta = num; if (!kbind(keylist, a)) { action_free(a); g_warning("Unable to add binding in '%s' on line %d", path, kparselineno - 1); } } |