return 0;
}
+/*!
+ * Create a command syntax.
+ *
+ * \note Use cmd_AddParm() or cmd_AddParmAtOffset() to set the
+ * parameters for the new command.
+ *
+ * \param[in] aname name used to invoke the command
+ * \param[in] aproc procedure to be called when command is invoked
+ * \param[in] arock opaque data pointer to be passed to aproc
+ * \param[in] aflags command option flags (CMD_HIDDEN)
+ * \param[in] ahelp help string to display for this command
+ *
+ * \return a pointer to the cmd_syndesc or NULL if error.
+ */
struct cmd_syndesc *
cmd_CreateSyntax(char *aname,
int (*aproc) (struct cmd_syndesc * ts, void *arock),
- void *arock, char *ahelp)
+ void *arock, afs_uint32 aflags, char *ahelp)
{
struct cmd_syndesc *td;
if (noOpcodes)
return NULL;
+ /* Allow only valid cmd flags. */
+ if (aflags & ~CMD_HIDDEN) {
+ return NULL;
+ }
+
td = calloc(1, sizeof(struct cmd_syndesc));
assert(td);
td->aliasOf = td; /* treat aliasOf as pointer to real command, no matter what */
+ td->flags = aflags;
/* copy in name, etc */
if (aname) {
noOpcodes = 1;
}
if (ahelp) {
- /* Piggy-back the hidden option onto the help string */
- if (ahelp == (char *)CMD_HIDDEN) {
- td->flags |= CMD_HIDDEN;
- } else {
- td->help = strdup(ahelp);
- assert(td->help);
- }
+ td->help = strdup(ahelp);
+ assert(td->help);
} else
td->help = NULL;
td->proc = aproc;
}
int
-cmd_IsAdministratorCommand(struct cmd_syndesc *as)
-{
- as->flags |= CMD_ADMIN;
- return 0;
-}
-
-int
cmd_Seek(struct cmd_syndesc *as, int apos)
{
if (apos >= CMD_MAXPARMS)
struct cmd_syndesc *ts;
if (!noOpcodes) {
- ts = cmd_CreateSyntax("help", HelpProc, NULL,
+ ts = cmd_CreateSyntax("help", HelpProc, NULL, 0,
"get help on commands");
cmd_AddParm(ts, "-topic", CMD_LIST, CMD_OPTIONAL, "help string");
- cmd_AddParm(ts, "-admin", CMD_FLAG, CMD_OPTIONAL, NULL);
- ts = cmd_CreateSyntax("apropos", AproposProc, NULL,
+ ts = cmd_CreateSyntax("apropos", AproposProc, NULL, 0,
"search by help text");
cmd_AddParm(ts, "-topic", CMD_SINGLE, CMD_REQUIRED, "help string");
- cmd_CreateSyntax("version", VersionProc, NULL,
- (char *)CMD_HIDDEN);
- cmd_CreateSyntax("-version", VersionProc, NULL,
- (char *)CMD_HIDDEN);
- cmd_CreateSyntax("-help", HelpProc, NULL,
- (char *)CMD_HIDDEN);
- cmd_CreateSyntax("--version", VersionProc, NULL,
- (char *)CMD_HIDDEN);
- cmd_CreateSyntax("--help", HelpProc, NULL,
- (char *)CMD_HIDDEN);
+ cmd_CreateSyntax("version", VersionProc, NULL, 0,
+ "show version");
+ cmd_CreateSyntax("-version", VersionProc, NULL, CMD_HIDDEN, NULL);
+ cmd_CreateSyntax("-help", HelpProc, NULL, CMD_HIDDEN, NULL);
+ cmd_CreateSyntax("--version", VersionProc, NULL, CMD_HIDDEN, NULL);
+ cmd_CreateSyntax("--help", HelpProc, NULL, CMD_HIDDEN, NULL);
}
}
const char *str;
struct cmd_item *item, **last;
const char *start, *end;
+ size_t len;
int code;
if (pos > syn->nParms)
start = str;
while ((end = strchr(start, ' '))) {
item = calloc(1, sizeof(struct cmd_item));
- item->data = malloc(end - start + 1);
- strlcpy(item->data, start, end - start + 1);
+ len = end - start + 1;
+ item->data = malloc(len);
+ strlcpy(item->data, start, len);
*last = item;
last = &item->next;
for (start = end; *start == ' '; start++); /* skip any whitespace */
/* Catch the final element */
if (*start != '\0') {
item = calloc(1, sizeof(struct cmd_item));
- item->data = malloc(strlen(start) + 1);
- strlcpy(item->data, start, strlen(start) + 1);
+ len = strlen(start) + 1;
+ item->data = malloc(len);
+ strlcpy(item->data, start, len);
*last = item;
}