aboutsummaryrefslogtreecommitdiff
path: root/src/eclat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/eclat.c')
-rw-r--r--src/eclat.c75
1 files changed, 25 insertions, 50 deletions
diff --git a/src/eclat.c b/src/eclat.c
index a93c7ae..df35e86 100644
--- a/src/eclat.c
+++ b/src/eclat.c
@@ -210,7 +210,6 @@ node_ident_cmp(struct grecs_node const *a, struct grecs_node const *b)
struct command {
const char *ident;
- size_t match_len;
const char *tag;
eclat_command_handler_t handler;
char *fmt;
@@ -218,11 +217,13 @@ struct command {
};
struct command cmdtab[] = {
- { "start-instances", 1, "StartInstances", eclat_start_instance },
- { "stop-instances", 1, "StopInstances", eclat_stop_instance },
- { "describe-tags", 1, "DescribeTags", eclat_describe_tags },
- { "describe-instance-status", 1, "DescribeInstanceStatus",
- eclat_describe_instance_status }
+ { "start-instances", "StartInstances", eclat_start_instance },
+ { "stop-instances", "StopInstances", eclat_stop_instance },
+ { "describe-tags", "DescribeTags", eclat_describe_tags },
+ { "describe-instance-status", "DescribeInstanceStatus",
+ eclat_describe_instance_status },
+ { "describe-instances", "DescribeInstances",
+ eclat_describe_instances },
};
size_t cmdcnt = sizeof(cmdtab) / sizeof(cmdtab[0]);
@@ -234,43 +235,6 @@ cmdcmp(const void *a, const void *b)
}
void
-init_cmdtab()
-{
- size_t i;
-
- /* Sort commands alphabetically */
- qsort(cmdtab, cmdcnt, sizeof(cmdtab[0]), cmdcmp);
- /* Determine minimum abbreviations */
- for (i = 0; i < cmdcnt; i++) {
- const char *sample = cmdtab[i].ident;
- size_t sample_len = strlen(sample);
- size_t minlen = cmdtab[i].match_len;
- size_t j;
-
- for (j = i + 1; j < cmdcnt; j++) {
- size_t len = strlen(cmdtab[j].ident);
- if (len >= minlen && memcmp(cmdtab[j].ident, sample,
- minlen) == 0)
- do {
- minlen++;
- if (minlen <= strlen(cmdtab[j].ident))
- cmdtab[j].match_len = minlen;
- if (minlen == sample_len)
- break;
- } while (len >= minlen &&
- memcmp(cmdtab[j].ident,
- sample, minlen) == 0);
- else if (cmdtab[j].ident[0] == sample[0])
- cmdtab[j].match_len = minlen;
- else
- break;
- }
- if (minlen <= sample_len)
- cmdtab[i].match_len = minlen;
- }
-}
-
-void
listcmd()
{
struct command *cp;
@@ -288,15 +252,28 @@ listcmd()
struct command *
find_command_name(const char *name)
{
- struct command *cp;
+ struct command *cp, *match = NULL;
size_t namelen = strlen(name);
for (cp = cmdtab; cp < cmdtab + cmdcnt; cp++) {
- if (cp->match_len <= namelen &&
- memcmp(name, cp->ident, namelen) == 0)
- return cp;
+ if (!strncmp(cp->ident, name, namelen)) {
+ if (strlen(cp->ident) == namelen)
+ return cp;
+ else if (!match)
+ match = cp;
+ else {
+ /* Second match */
+ err("ambiguous command %s:");
+ err(" %s", match->ident);
+ err(" %s", cp->ident);
+ while (++cp < cmdtab + cmdcnt)
+ if (!strncmp(cp->ident, name, namelen))
+ err(" %s", cp->ident);
+ exit(EX_USAGE);
+ }
+ }
}
- return NULL;
+ return match;
}
struct command *
@@ -417,7 +394,6 @@ list_filters(FILE *fp)
fputc('\n', fp);
}
-
int
main(int argc, char **argv)
@@ -432,7 +408,6 @@ main(int argc, char **argv)
struct command *command = NULL;
set_program_name(argv[0]);
- init_cmdtab();
proginfo.print_help_hook = listcmd;
debug_init();
forlan_init();

Return to:

Send suggestions and report system problems to the System administrator.