Skip to content
Snippets Groups Projects
Select Git revision
  • b9bdac02514b305f7fb25d810054c99fa332f4a0
  • max32xxx default protected
  • dw-cmsisdap-path
3 results

command.c

Blame
  • command.c 13.89 KiB
    /***************************************************************************
     *   Copyright (C) 2005 by Dominic Rath                                    *
     *   Dominic.Rath@gmx.de                                                   *
     *                                                                         *
     *   part of this file is taken from libcli (libcli.sourceforge.net)       *
     *   Copyright (C) David Parrish (david@dparrish.com)                      *
     *                                                                         *
     *   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 Free Software Foundation; either version 2 of the License, or     *
     *   (at your option) any later version.                                   *
     *                                                                         *
     *   This program is distributed in the hope that it will be useful,       *
     *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
     *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
     *   GNU General Public License for more details.                          *
     *                                                                         *
     *   You should have received a copy of the GNU General Public License     *
     *   along with this program; if not, write to the                         *
     *   Free Software Foundation, Inc.,                                       *
     *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
     ***************************************************************************/
    #ifdef HAVE_CONFIG_H
    #include "config.h"
    #endif
    
    #include "replacements.h"
    
    #include "command.h"
    
    #include "log.h"
    #include "time_support.h"
    
    #include <stdlib.h>
    #include <string.h>
    #include <ctype.h>
    #include <stdarg.h>
    #include <stdio.h>
    #include <unistd.h>
    
    void command_print_help_line(command_context_t* context, struct command_s *command, int indent);
    
    int handle_sleep_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
    int handle_time_command(struct command_context_s *cmd_ctx, char *cmd, char **args, int argc);
    
    int build_unique_lengths(command_context_t *context, command_t *commands)
    {
    	command_t *c, *p;
    
    	/* iterate through all commands */
    	for (c = commands; c; c = c->next)
    	{
    		/* find out how many characters are required to uniquely identify a command */
    		for (c->unique_len = 1; c->unique_len <= strlen(c->name); c->unique_len++)
    		{
    			int foundmatch = 0;
    			
    			/* for every command, see if the current length is enough */
    			for (p = commands; p; p = p->next)
    			{
    				/* ignore the command itself */
    				if (c == p)
    					continue;
    				
    				/* compare commands up to the current length */
    				if (strncmp(p->name, c->name, c->unique_len) == 0)
    					foundmatch++;
    			}
    			
    			/* when none of the commands matched, we've found the minimum length required */