Initialise event queues before calling termcapinit()

- Move queue initialization out of event_init() into
  new function event_early_init()
- event_early_init() must be called before termcapinit(), and
  event_init() can only be called afterwards
- Add unit tests to check termcapinit with valid and invalid
  term types