summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4085b6e)
raw | patch | inline | side by side (parent: 4085b6e)
author | Jonathan Neuschäfer <j.neuschaefer@gmx.net> | |
Wed, 21 Dec 2011 20:40:52 +0000 (21:40 +0100) | ||
committer | Jonathan Neuschäfer <j.neuschaefer@gmx.net> | |
Wed, 21 Dec 2011 20:40:52 +0000 (21:40 +0100) |
src/command.c | patch | blob | history |
diff --git a/src/command.c b/src/command.c
index 6d06368123e47918c02dcd083eae8e0b7a124cbe..af6afd15a01ee7e93ab01a31e72cfa6a4f301e2d 100644 (file)
--- a/src/command.c
+++ b/src/command.c
void
command_dump_keys(void)
{
- int i = 0;
-
- while (cmds[i].description) {
+ for (int i = 0; cmds[i].description; i++)
if (cmds[i].command != CMD_NONE)
printf(" %20s : %s\n", get_key_names(cmds[i].command,1),cmds[i].name);
- i++;
- }
}
#ifndef NCMPC_MINI
static int
set_key_flags(command_definition_t *cp, command_t command, int flags)
{
- int i = 0;
-
- while (cp[i].name) {
+ for (int i = 0; cp[i].name; i++) {
if (cp[i].command == command) {
cp[i].flags |= flags;
return 0;
}
- i++;
}
return 1;
const char *
get_key_names(command_t command, int all)
{
- int i = 0;
-
- while (cmds[i].description) {
+ for (int i = 0; cmds[i].description; i++) {
if (cmds[i].command == command) {
- int j;
static char keystr[80];
g_strlcpy(keystr, key2str(cmds[i].keys[0]), sizeof(keystr));
if (!all)
return keystr;
- j=1;
- while (j < MAX_COMMAND_KEYS && cmds[i].keys[j] > 0) {
+
+ for (int j = 1; j < MAX_COMMAND_KEYS &&
+ cmds[i].keys[j] > 0; j++) {
g_strlcat(keystr, " ", sizeof(keystr));
g_strlcat(keystr, key2str(cmds[i].keys[j]), sizeof(keystr));
- j++;
}
return keystr;
}
- i++;
}
return NULL;
}
const char *
get_key_description(command_t command)
{
- int i = 0;
-
- while (cmds[i].description) {
+ for (int i = 0; cmds[i].description; i++)
if (cmds[i].command == command)
return _(cmds[i].description);
- i++;
- }
return NULL;
}
const char *
get_key_command_name(command_t command)
{
- int i = 0;
-
- while (cmds[i].name) {
+ for (int i = 0; cmds[i].name; i++)
if (cmds[i].command == command)
return cmds[i].name;
- i++;
- }
+
return NULL;
}
command_t
get_key_command_from_name(char *name)
{
- int i = 0;
-
- while (cmds[i].name) {
+ for (int i = 0; cmds[i].name; i++)
if (strcmp(name, cmds[i].name) == 0)
return cmds[i].command;
- i++;
- }
return CMD_NONE;
}
command_t
find_key_command(int key, command_definition_t *c)
{
- int i = 0;
-
assert(key != 0);
assert(c != NULL);
- while (c[i].name) {
+ for (int i = 0; c[i].name; i++) {
if (c[i].keys[0] == key ||
c[i].keys[1] == key ||
c[i].keys[2] == key)
return c[i].command;
- i++;
}
return CMD_NONE;
int
assign_keys(command_t command, int keys[MAX_COMMAND_KEYS])
{
- int i = 0;
-
- while (cmds[i].name) {
+ for (int i = 0; cmds[i].name; i++) {
if (cmds[i].command == command) {
memcpy(cmds[i].keys, keys, sizeof(int)*MAX_COMMAND_KEYS);
#ifndef NCMPC_MINI
#endif
return 0;
}
- i++;
}
+
return -1;
}
int
write_key_bindings(FILE *f, int flags)
{
- int i = 0, j;
-
if (flags & KEYDEF_WRITE_HEADER)
fprintf(f, "## Key bindings for ncmpc (generated by ncmpc)\n\n");
- while (cmds[i].name && !ferror(f)) {
+ for (int i = 0; cmds[i].name && !ferror(f); i++) {
if (cmds[i].flags & COMMAND_KEY_MODIFIED ||
flags & KEYDEF_WRITE_ALL) {
fprintf(f, "## %s\n", cmds[i].description);
if (flags & KEYDEF_COMMENT_ALL)
fprintf(f, "#");
fprintf(f, "key %s = ", cmds[i].name);
- for (j = 0; j < MAX_COMMAND_KEYS; j++) {
+ for (int j = 0; j < MAX_COMMAND_KEYS; j++) {
if (j && cmds[i].keys[j])
fprintf(f, ", ");
if (!j || cmds[i].keys[j]) {
}
fprintf(f,"\n\n");
}
- i++;
}
return ferror(f);