cmd_key: refactor to free memory on the end

Fixes memleak when `--window` is given multiple times.
xdo_search: fix memleaks, pre-compile regexes optimization

If no regex is given, a default one matching none would be used. This
memory was not freed. Now it is freed and besides that, all regexes
are now pre-compiled before iterating through all windows.

(as a side-effect of the optimization: return early when a regex fails
to compile).

Other changes: constantify regex_t* where applicable, whitespace
cleanup.
cmd_type: respect window stack

If `--window` is omitted, it should select the window(s) from the
window stack (as selected by `search --name Firefox` for example).

The following command should type "foo" in the Firefox window(s) instead
of the current window.

    xdotool search --name Firefox type foo

Suggested by @jordansissel in #35.