Skip to content

Commit

Permalink
Generated JBWMKeys from keys.txt using keys.scm. Reformatted libconve…
Browse files Browse the repository at this point in the history
…rt.scm.

Added display-c-include.
  • Loading branch information
alisabedard committed Jul 7, 2017
1 parent e58a686 commit 14f3e89
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 76 deletions.
67 changes: 25 additions & 42 deletions JBWMKeys.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,30 @@
#define JBWM_JBWMKEYS_H
#include <X11/keysym.h>
enum JBWMKeys {
JBWM_KEY_NEXT=XK_Tab,
JBWM_KEY_NEW=XK_Return,
JBWM_KEY_QUIT=XK_Escape,
JBWM_KEY_TOPLEFT=XK_KP_Home,
JBWM_KEY_TOPRIGHT=XK_KP_Page_Up,
JBWM_KEY_BOTTOMLEFT=XK_KP_End,
JBWM_KEY_BOTTOMRIGHT=XK_KP_Page_Down,
JBWM_KEY_RAISE=XK_Up,
JBWM_KEY_LOWER=XK_Down,
JBWM_KEY_PREVDESK=XK_Left,
JBWM_KEY_NEXTDESK=XK_Right,
JBWM_KEY_UP=XK_k,
JBWM_KEY_DOWN=XK_j,
JBWM_KEY_LEFT=XK_h,
JBWM_KEY_RIGHT=XK_l,
JBWM_KEY_MAX_H=XK_x,
JBWM_KEY_MAX_V=XK_z,
JBWM_KEY_ALTLOWER=XK_minus,
JBWM_KEY_INFO=XK_F5,
JBWM_KEY_MAX=XK_space,
JBWM_KEY_STICK=XK_period,
JBWM_KEY_MOVE=XK_m,
JBWM_KEY_SHADE=XK_s,
JBWM_KEY_FS=XK_a
JBWM_KEY_ALTLOWER = XK_minus,
JBWM_KEY_BOTTOMLEFT = XK_KP_End,
JBWM_KEY_BOTTOMRIGHT = XK_KP_Page_Down,
JBWM_KEY_DOWN = XK_j,
JBWM_KEY_FS = XK_a,
JBWM_KEY_INFO = XK_F5,
JBWM_KEY_LEFT = XK_h,
JBWM_KEY_LOWER = XK_Down,
JBWM_KEY_MAX_H = XK_x,
JBWM_KEY_MAX = XK_space,
JBWM_KEY_MAX_V = XK_z,
JBWM_KEY_MOVE = XK_m,
JBWM_KEY_NEW = XK_Return,
JBWM_KEY_NEXTDESK = XK_Right,
JBWM_KEY_NEXT = XK_Tab,
JBWM_KEY_PREVDESK = XK_Left,
JBWM_KEY_QUIT = XK_Escape,
JBWM_KEY_RAISE = XK_Up,
JBWM_KEY_RIGHT = XK_l,
JBWM_KEY_SHADE = XK_s,
JBWM_KEY_STICK = XK_period,
JBWM_KEY_TOPLEFT = XK_KP_Home,
JBWM_KEY_TOPRIGHT = XK_KP_Page_Up,
JBWM_KEY_UP = XK_k,
};
/* Mixtures of Ctrl, Alt an Escape are used for things like VMWare and
* XFree86/Cygwin, so the KILL key is an option in the Makefile */
#ifndef JBWM_KEY_KILL
enum { JBWM_KEY_KILL = XK_q };
#endif
#define JBWM_NUM_KEYS XK_0, XK_1, XK_2, XK_3, XK_4, XK_5, XK_6, XK_7,\
XK_8, XK_9
#define JBWM_VWM_KEYS JBWM_KEY_PREVDESK, JBWM_KEY_NEXTDESK, \
JBWM_NUM_KEYS
#define JBWM_DIRECTION_KEYS JBWM_KEY_LEFT, JBWM_KEY_RIGHT, \
JBWM_KEY_DOWN, JBWM_KEY_UP
#define JBWM_KEYS_TO_GRAB JBWM_KEY_NEXT, JBWM_KEY_NEW, JBWM_KEY_QUIT,\
JBWM_KEY_KILL, JBWM_DIRECTION_KEYS, JBWM_KEY_LOWER,\
JBWM_KEY_ALTLOWER, JBWM_KEY_MAX, JBWM_KEY_STICK,\
JBWM_VWM_KEYS, JBWM_KEY_MOVE, JBWM_KEY_RAISE, JBWM_KEY_SHADE,\
JBWM_KEY_MAX_H, JBWM_KEY_MAX_V, JBWM_KEY_FS, 0
#define JBWM_ALT_KEYS_TO_GRAB JBWM_KEY_KILL, JBWM_DIRECTION_KEYS,\
JBWM_VWM_KEYS, 0
#include "key_combos.h"
#endif//!JBWM_JBWMKEYS_H
21 changes: 21 additions & 0 deletions key_combos.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Mixtures of Ctrl, Alt an Escape are used for things like VMWare and
* XFree86/Cygwin, so the KILL key is an option in the Makefile */
#ifndef JBWM_KEY_COMBOS_H
#define JBWM_KEY_COMBOS_H
#ifndef JBWM_KEY_KILL
enum { JBWM_KEY_KILL = XK_q };
#endif
#define JBWM_NUM_KEYS XK_0, XK_1, XK_2, XK_3, XK_4, XK_5, XK_6, XK_7,\
XK_8, XK_9
#define JBWM_VWM_KEYS JBWM_KEY_PREVDESK, JBWM_KEY_NEXTDESK, \
JBWM_NUM_KEYS
#define JBWM_DIRECTION_KEYS JBWM_KEY_LEFT, JBWM_KEY_RIGHT, \
JBWM_KEY_DOWN, JBWM_KEY_UP
#define JBWM_KEYS_TO_GRAB JBWM_KEY_NEXT, JBWM_KEY_NEW, JBWM_KEY_QUIT,\
JBWM_KEY_KILL, JBWM_DIRECTION_KEYS, JBWM_KEY_LOWER,\
JBWM_KEY_ALTLOWER, JBWM_KEY_MAX, JBWM_KEY_STICK,\
JBWM_VWM_KEYS, JBWM_KEY_MOVE, JBWM_KEY_RAISE, JBWM_KEY_SHADE,\
JBWM_KEY_MAX_H, JBWM_KEY_MAX_V, JBWM_KEY_FS, 0
#define JBWM_ALT_KEYS_TO_GRAB JBWM_KEY_KILL, JBWM_DIRECTION_KEYS,\
JBWM_VWM_KEYS, 0
#endif//!JBWM_KEY_COMBOS_H
27 changes: 27 additions & 0 deletions keys.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
; Copyright 2017, Jeffrey E. Bedard
; vim: sw=2
(load "libconvert.scm")
(define convert_keys
(lambda (in_filename out_filename)
(letrec ((i (open-input-file in_filename))
(o (open-output-file out_filename))
(guard "JBWM_JBWMKEYS")
(parse (lambda (i o)
(let ((line (read-line i)))
(if (and (not (eof-object? line))
(> (string-length line) 1))
(let ((key (string-car line))
(value (string-cdr line)))
(display (string-append "\tJBWM_KEY_" key
" = XK_" value ",\n") o)
(parse i o)))))))
(begin-include guard o)
(display-c-include "<X11/keysym.h>" o)
(display "enum JBWMKeys {\n" o)
(parse i o)
(display "};\n" o)
(display-c-include "\"key_combos.h\"" o)
(end-include guard o)
(close-port i)
(close-port o))))
(convert_keys "keys.txt" "JBWMKeys.h")
24 changes: 24 additions & 0 deletions keys.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ALTLOWER:minus
BOTTOMLEFT:KP_End
BOTTOMRIGHT:KP_Page_Down
DOWN:j
FS:a
INFO:F5
LEFT:h
LOWER:Down
MAX_H:x
MAX:space
MAX_V:z
MOVE:m
NEW:Return
NEXTDESK:Right
NEXT:Tab
PREVDESK:Left
QUIT:Escape
RAISE:Up
RIGHT:l
SHADE:s
STICK:period
TOPLEFT:KP_Home
TOPRIGHT:KP_Page_Up
UP:k
100 changes: 66 additions & 34 deletions libconvert.scm
Original file line number Diff line number Diff line change
@@ -1,41 +1,73 @@
; libconvert.scm
; Simple colon-separated database parsing library for header generation
; vim: sw=2
(define copyright "// Copyright 2017, Jeffrey E. Bedard\n")
; lisp-like operations on colon-separated strings:
(define get-string-divider (lambda (str)
(string-find-next-char str #\:)))
(define get-string-divider
(lambda (str) (string-find-next-char str #\:)))

; returns original string if not a list
(define string-car (lambda (str) (let ((i (get-string-divider str)))
(if i (string-head str i) str))))
(define string-car
(lambda (str)
(let ((i (get-string-divider str)))
(if i (string-head str i) str))))

; returns "" when list empty
(define string-cdr (lambda (str) (let ((i (get-string-divider str)))
(if i (string-tail str (+ 1 i)) ""))))
(define string-cdr
(lambda (str)
(let ((i (get-string-divider str)))
(if i (string-tail str (+ 1 i)) ""))))

; The following prefix is applied to each entry
(define master-prefix "_NET_")
(define begin-array-definition (lambda (type name out)
(display (string-append "static " type " " name " [] = {\n") out)))
(define begin-enum-definition (lambda (name out)
(display (string-append "enum " name " {\n") out)))

(define begin-array-definition
(lambda (type name out)
(display (string-append "static " type " " name " [] = {\n") out)))

(define begin-enum-definition
(lambda (name out)
(display (string-append "enum " name " {\n") out)))

(define end-c-definition (lambda (out) (display "};\n" out)))
(define get-array-line (lambda (prefix item)
(string-append "\t\"" master-prefix prefix item "\",\n")))
(define print-each-array-element (lambda (prefix elements out_port)
(map (lambda (item)
(display (get-array-line prefix item) out_port))
elements)))
(define get-enum-line (lambda (prefix item)
(string-append "\t" master-prefix prefix item ",\n")))
(define print-enum-line (lambda (prefix item out_port)
(display (get-enum-line prefix item) out_port)))
(define print-each-enum (lambda (prefix elements out_port)
(map (lambda (item) (print-enum-line prefix item out_port))
elements)))
(define get-guard (lambda (name)
(string-append name "_H\n")))
(define print-each (lambda (function data out_port)
(function (car data) (cdr data) out_port)))
(define add-c-include (lambda (name) (string-append "#include " name "\n")))
(define begin-include (lambda (guard_tag out)
(display (string-append copyright
"#ifndef " (get-guard guard_tag)
"#define " (get-guard guard_tag)) out)))
(define end-include (lambda (guard_tag out)
(display (string-append "#endif//!" (get-guard guard_tag)) out)))

(define get-array-line
(lambda (prefix item)
(string-append "\t\"" master-prefix prefix item "\",\n")))

(define print-each-array-element
(lambda (prefix elements out_port)
(map (lambda (item)
(display (get-array-line prefix item) out_port)) elements)))

(define get-enum-line
(lambda (prefix item) (string-append "\t" master-prefix prefix item ",\n")))

(define print-enum-line
(lambda (prefix item out_port)
(display (get-enum-line prefix item) out_port)))

(define print-each-enum
(lambda (prefix elements out_port)
(map (lambda (item) (print-enum-line prefix item out_port)) elements)))

(define get-guard (lambda (name) (string-append name "_H\n")))

(define print-each
(lambda (function data out_port)
(function (car data) (cdr data) out_port)))

(define add-c-include
(lambda (name) (string-append "#include " name "\n")))

(define display-c-include
(lambda (name out) (display (add-c-include name) out)))

(define begin-include
(lambda (guard_tag out)
(display (string-append copyright "#ifndef " (get-guard guard_tag)
"#define " (get-guard guard_tag)) out)))

(define end-include
(lambda (guard_tag out)
(display (string-append "#endif//!" (get-guard guard_tag)) out)))

0 comments on commit 14f3e89

Please sign in to comment.