/*
* Copyright (C) 2009 Martin Willi
- * Hochschule fuer Technik Rapperswil
+ * HSR Hochschule fuer Technik Rapperswil
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
memset(command_optstring, 0, sizeof(command_optstring));
if (active == help_idx)
{
- for (i = 0; cmds[i].cmd; i++)
+ for (i = 0; i < MAX_COMMANDS && cmds[i].cmd; i++)
{
command_opts[i].name = cmds[i].cmd;
command_opts[i].val = cmds[i].op;
"options", '+', 1, "read command line options from file"
};
}
+ for (i = 0; cmds[registered].line[i]; i++)
+ {
+ if (i == MAX_LINES - 1)
+ {
+ fprintf(stderr, "command '%s' specifies too many usage summary "
+ "lines, please increase MAX_LINES\n", command.cmd);
+ break;
+ }
+ }
}
registered++;
}
int command_usage(char *error)
{
FILE *out = stdout;
- int i;
+ int i, indent = 0;
if (error)
{
}
else
{
- for (i = 0; cmds[active].line[i]; i++)
+ for (i = 0; i < MAX_LINES && cmds[active].line[i]; i++)
{
if (i == 0)
{
- fprintf(out, " pki --%s %s\n",
- cmds[active].cmd, cmds[active].line[i]);
+ indent = fprintf(out, " pki --%s ", cmds[active].cmd);
+ fprintf(out, "%s\n", cmds[active].line[i]);
}
else
{
- fprintf(out, " %s\n", cmds[active].line[i]);
+ fprintf(out, "%*s%s\n", indent, "", cmds[active].line[i]);
}
}
for (i = 0; cmds[active].options[i].name; i++)
build_opts();
op = getopt_long(c, v, command_optstring, command_opts, NULL);
- for (i = 0; cmds[i].cmd; i++)
+ for (i = 0; i < MAX_COMMANDS && cmds[i].cmd; i++)
{
if (cmds[i].op == op)
{