Skip to content

Commit

Permalink
Add key lock check in command module
Browse files Browse the repository at this point in the history
  • Loading branch information
coditva committed Nov 23, 2017
1 parent e29652e commit c9a34f4
Showing 1 changed file with 29 additions and 15 deletions.
44 changes: 29 additions & 15 deletions src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "command.h"
#include "interface.h"
#include "map.h"
#include "key.h"


void increment_cursor(const map_t *map, point_t *point)
Expand Down Expand Up @@ -71,11 +72,13 @@ int get_count()
int get_oper()
{
input_key_t key = interface_input_key();

switch (key) {
case 'd':
case 'c':
case 'y':
return key;
if (key_unlocked(key)) return key;
else return 0;
default:
interface_input_key_undo(key);
return 0;
Expand All @@ -85,6 +88,10 @@ int get_oper()
int get_motion()
{
input_key_t key = interface_input_key();

while (!key_unlocked(key)) {
return 0;
}
return key;
}

Expand Down Expand Up @@ -190,22 +197,29 @@ command_t * command_get()
{
command_t *command;

/* check if it's a command line */
if ((command = get_command_line()) != NULL)
return command;
while (1) {
/* check if it's a command line */
if ((command = get_command_line()) != NULL)
return command;

/* else build the command */
command = (command_t *) malloc(sizeof(command_t));
command -> type = COMMAND_OTHER;
command -> count = get_count();
command -> oper = get_oper();
if (command -> oper == 0) {
command -> motion.count = command -> count;
command -> count = 1;
} else {
command -> motion.count = get_count();
}
command -> motion.value = get_motion();

/* else build the command */
command = (command_t *) malloc(sizeof(command_t));
command -> type = COMMAND_OTHER;
command -> count = get_count();
command -> oper = get_oper();
if (command -> oper == 0) {
command -> motion.count = command -> count;
command -> count = 1;
} else {
command -> motion.count = get_count();
/* we could not form any command */
if (command -> motion.value == 0) {
continue;
}
}
command -> motion.value = get_motion();

return command;
}
Expand Down

0 comments on commit c9a34f4

Please sign in to comment.