Diff for /libaitcli/src/aitcli.c between versions 1.2.2.4 and 1.2.2.6

version 1.2.2.4, 2010/06/04 16:16:17 version 1.2.2.6, 2010/06/07 11:32:50
Line 440  cli_BindKey(bindkey_t * __restrict key, linebuffer_t * Line 440  cli_BindKey(bindkey_t * __restrict key, linebuffer_t *
   
   
 /*  /*
    * cli_addCommand() Add command to CLI session
    * @buffer = CLI buffer
    * @csCmd = Command name
    * @cliLevel = Level in CLI, -1 unprivi(view from all), 0 main config, 1 sub config ...
    * @funcCmd = Callback function when user call command
    * @csInfo = Inline information for command
    * @csHelp = Help line when call help
    * return: RETCODE_ERR error, RETCODE_OK ok
   */
   int
   cli_addCommand(linebuffer_t * __restrict buffer, const char *csCmd, int cliLevel, cmd_func_t funcCmd, 
                   const char *csInfo, const char *csHelp)
   {
           struct tagCommand *cmd;
   
           if (!buffer || !csCmd || !funcCmd) {
                   cli_SetErr(EINVAL, "Error:: invalid input parameters ...");
                   return RETCODE_ERR;
           }
   
           cmd = malloc(sizeof(struct tagCommand));
           if (!cmd) {
                   LOGERR;
                   return RETCODE_ERR;
           } else
                   memset(cmd, 0, sizeof(struct tagCommand));
   
           cmd->cmd_level = cliLevel;
           cmd->cmd_func = funcCmd;
           cmd->cmd_len = strlcpy(cmd->cmd_name, csCmd, STRSIZ);
           if (csInfo)
                   strlcpy(cmd->cmd_info, csInfo, STRSIZ);
           if (csHelp)
                   strlcpy(cmd->cmd_help, csHelp, STRSIZ);
           SLIST_INSERT_HEAD(&buffer->line_cmds, cmd, cmd_next);
           return RETCODE_OK;
   }
   
   /*
    * cli_delCommand() Delete command from CLI session
    * @buffer = CLI buffer
    * @csCmd = Command name
    * @cliLevel = Level in CLI, -1 unprivi(view from all), 0 main config, 1 sub config ...
    * return: RETCODE_ERR error, RETCODE_OK ok
   */
   int
   cli_delCommand(linebuffer_t * __restrict buffer, const char *csCmd, int cliLevel)
   {
           struct tagCommand *cmd;
           int ret = RETCODE_OK;
   
           if (!buffer || !csCmd) {
                   cli_SetErr(EINVAL, "Error:: invalid input parameters ...");
                   return RETCODE_ERR;
           }
   
           SLIST_FOREACH(cmd, &buffer->line_cmds, cmd_next) 
                   if (cmd->cmd_level == cliLevel && !strcmp(cmd->cmd_name, csCmd)) {
                           ret = 1;
                           SLIST_REMOVE(&buffer->line_cmds, cmd, tagCommand, cmd_next);
                           free(cmd);
                           break;
                   }
   
           return ret;
   }
   
   /*
    * cli_updCommand() Update command in CLI session
    * @buffer = CLI buffer
    * @csCmd = Command name
    * @cliLevel = Level in CLI, -1 unprivi(view from all), 0 main config, 1 sub config ...
    * @funcCmd = Callback function when user call command
    * @csInfo = Inline information for command
    * @csHelp = Help line when call help
    * return: RETCODE_ERR error, RETCODE_OK ok
   */
   int
   cli_updCommand(linebuffer_t * __restrict buffer, const char *csCmd, int cliLevel, cmd_func_t funcCmd, 
                   const char *csInfo, const char *csHelp)
   {
           struct tagCommand *cmd;
           int ret = RETCODE_OK;
   
           if (!buffer || !csCmd) {
                   cli_SetErr(EINVAL, "Error:: invalid input parameters ...");
                   return RETCODE_ERR;
           }
   
           SLIST_FOREACH(cmd, &buffer->line_cmds, cmd_next) 
                   if (cmd->cmd_level == cliLevel && !strcmp(cmd->cmd_name, csCmd)) {
                           ret = 1;
   
                           if (funcCmd)
                                   cmd->cmd_func = funcCmd;
                           if (csInfo)
                                   strlcpy(cmd->cmd_info, csInfo, STRSIZ);
                           if (csHelp)
                                   strlcpy(cmd->cmd_help, csHelp, STRSIZ);
   
                           break;
                   }
   
           return ret;
   }
   
   
   /*
  * cli_addHistory() Add line to history   * cli_addHistory() Add line to history
  * @buffer = CLI buffer   * @buffer = CLI buffer
  * @str = Add custom text or if NULL use readed line from CLI buffer   * @str = Add custom text or if NULL use readed line from CLI buffer
Line 1008  recheck: Line 1116  recheck:
                         break;                          break;
         }          }
   
        if (code != RETCODE_ERR && buffer->line_buf)        if (code != RETCODE_ERR && code != RETCODE_EOF && buffer->line_buf)
                 str = strdup(buffer->line_buf);                  str = strdup(buffer->line_buf);
         return str;          return str;
 }  }
Line 1190  cliLoop(linebuffer_t * __restrict buffer, const char * Line 1298  cliLoop(linebuffer_t * __restrict buffer, const char *
   
         do {          do {
                 line = cliReadLine(buffer);                  line = cliReadLine(buffer);
                if (!line)                if (!line) {
                         printfNL(buffer, 0);
                         break;                          break;
                else                } else
                         cli_addHistory(buffer, NULL);                          cli_addHistory(buffer, NULL);
                 // clear whitespaces                  // clear whitespaces
                 for (s = line; isspace(*s); s++);                  for (s = line; isspace(*s); s++);
Line 1214  cliLoop(linebuffer_t * __restrict buffer, const char * Line 1323  cliLoop(linebuffer_t * __restrict buffer, const char *
                                 else                                  else
                                         i++;                                          i++;
                         }                          }
   
                         if (!cmd) {                          if (!cmd) {
                                cli_Printf(buffer, "Command '%s' not found!\n", items[0]);                                cli_Printf(buffer, "\nCommand '%s' not found!\n", items[0]);
                                 ret = -1;                                  ret = -1;
                         } else                          } else
                                 ret = cmd->cmd_func(buffer, i, items);                                  ret = cmd->cmd_func(buffer, i, items);

Removed from v.1.2.2.4  
changed lines
  Added in v.1.2.2.6


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>