I see nothing related to libcod, all of this can be done in vanilla cod(2).

Also I am missing completion, this is just a code snippet (part).
You cannot start a script with a 'case' statement.