/*
 *===========================================================================
 *                    ipcom_shell_cmd_help
 *===========================================================================
 * Description:     Shell command: Get help on command or display all commands
 * Parameters:      argc - number of arguments
 *                  argv - pointer to pointer to the arguments
 * Returns:         0
 *
 */
IP_STATIC int
ipcom_shell_cmd_help(int argc, char **argv)
{
    Ipcom_shell_cmd *cmd;
    Ipcom_shell_intcmd *intcmd;

    Ip_s32 i = 0;

    /* Check if argument is supplied */
    if (argc > 1)
    {
        intcmd = IP_NULL;

        /* Find shell internal command */
        while(shell_intcmd[i].name[0] != 0)
        {
            intcmd = (Ipcom_shell_intcmd *)&shell_intcmd[i];
            if (ipcom_strcmp(intcmd->name, argv[1]) == 0)
                break;

            intcmd = IP_NULL;
            i++;
        }
        if (intcmd)
        {
            ipcom_printf("Usage: %s\n", intcmd->usage);
            return 0;
        }

        /* Find shell command */
        cmd = ipcom_shell_find_cmd(argv[1]);
        if (cmd)
        {
            ipcom_printf("Usage: %s\n", cmd->usage);
            return 0;
        }

        /* Command not found */
        ipcom_printf("help: Unknown command '%s'\n", argv[1]);
    }
    else
    {
        /* List all shell internal commands */
        while(shell_intcmd[i].name[0] != 0)
        {
            ipcom_printf("%-32s %s\n", shell_intcmd[i].name, shell_intcmd[i].description);
            i++;
        }

        /* List all shell commands */
        for (cmd = IPCOM_LIST_FIRST(&ipcom_shell_cmd_head); cmd; cmd = IPCOM_LIST_NEXT(&cmd->cmd_list))
        {
            ipcom_printf("%-32s %s\n", cmd->name, cmd->description);
        }
        ipcom_printf("\n");
    }

    return 0;
}
Esempio n. 2
0
/*
 *===========================================================================
 *                    ipcom_shell_add_cmd
 *===========================================================================
 * Description:     Add a command to the list of available ipcom_shell commands
 * Parameters:      name : command's name
 *                  usage : usage string
 *                  description : description of command
 *                  hook : function to that executes the command
 *                  priority : na
 *                  stack_size : the stack to be used by the process that
 *                               executes the hook.
 *
 * Returns:         IPCOM_SUCCESS : ok
 *                  IPCOM_ERR_DUPLICATE : command already exists
 *                  IPCOM_ERR_NO_MEMORY : out of memory
 *
 *
 */
IP_PUBLIC Ip_err
ipcom_shell_add_cmd(const char *name, const char *usage,
                    const char *description, Ipcom_shell_cmd_type hook,
                    Ip_s32 priority, Ip_s32 stack_size)
{
    Ipcom_shell_cmd *cmd;
    static Ipcom_once_t  once = IPCOM_ONCE_INIT;
    Ip_err  err;

    err = ipcom_once(&once, ipcom_shellcmd_init, IP_NULL);
    if (err != IPCOM_SUCCESS)
        return err;

    /* First check if present */
    cmd = ipcom_shell_find_cmd(name);
    if (cmd != IP_NULL)
        return IPCOM_ERR_DUPLICATE;      /*!!allow duplicates for overlay. */

    /* Add a new entry to the list */
    cmd = (Ipcom_shell_cmd *)ipcom_malloc(sizeof(Ipcom_shell_cmd));
    if (cmd == IP_NULL)
        return IPCOM_ERR_NO_MEMORY;

    ipcom_memset(cmd, 0, sizeof(Ipcom_shell_cmd));

    ipcom_strncpy(cmd->name, name, sizeof(cmd->name)-1);
    ipcom_strncpy(cmd->usage, usage, sizeof(cmd->usage)-1);
    ipcom_strncpy(cmd->description, description, sizeof(cmd->description)-1);

    cmd->hook = hook;
    if (priority == 0 || priority == IPCOM_SHELL_PRIO_SAME)
       cmd->priority = ipcom_proc_getprio(ipcom_getpid());
    else
       cmd->priority = priority;
    cmd->stack_size = stack_size;

    ipcom_list_insert_last(&ipcom_shell_cmd_head, &cmd->cmd_list);

#if defined(WRS_IPNET) && defined(IP_PORT_VXWORKS) && (IP_PORT_VXWORKS >= 65)
    (void)ipcom_vxshell_add_cmd(name,
                                usage,
                                description,
                                hook,
                                priority,
                                stack_size);
#endif

    return IPCOM_SUCCESS;
}
Esempio n. 3
0
/*
 *===========================================================================
 *                    ipcom_shell_remove_cmd
 *===========================================================================
 * Description:     Remove a command from the list of available ipcom_shell commands
 * Parameters:      name : the command to remove
 * Returns:         IPCOM_SUCCESS : ok
 *                  IPCOM_ERR_NOT_FOUND : the command does not exist
 *
 */
IP_PUBLIC Ip_err
ipcom_shell_remove_cmd(const char *name, Ipcom_shell_cmd_type hook)
{
    Ipcom_shell_cmd *cmd;

    (void)hook;

    /* First check if present */
    cmd = ipcom_shell_find_cmd(name);
    if (cmd == IP_NULL)
        return IPCOM_ERR_NOT_FOUND;

    ipcom_list_remove(&cmd->cmd_list);
    ipcom_free(cmd);

    return IPCOM_SUCCESS;
}