Diff for /libaitcli/src/aitcli.c between versions 1.16 and 1.17

version 1.16, 2019/02/04 21:22:31 version 1.17, 2020/09/01 23:19:55
Line 12  terms: Line 12  terms:
 All of the documentation and software included in the ELWIX and AITNET  All of the documentation and software included in the ELWIX and AITNET
 Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>  Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
   
Copyright 2004 - 2019Copyright 2004 - 2020
         by Michael Pounov <misho@elwix.org>.  All rights reserved.          by Michael Pounov <misho@elwix.org>.  All rights reserved.
   
 Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
Line 1463  cliNetLoop(linebuffer_t * __restrict cli_buffer, const Line 1463  cliNetLoop(linebuffer_t * __restrict cli_buffer, const
 }  }
   
 /*  /*
    * cliRun() - CLI run command line
    *
    * @cli_buffer = CLI buffer
    * @psInput = Input command line
    * @prompt = Display prompt after command
    * return: RETCODE_ERR error, RETCODE_OK ok
   */
   int
   cliRun(linebuffer_t * __restrict cli_buffer, char *psInput, int prompt)
   {
           char *line, *s, *t, **app, *items[MAX_PROMPT_ITEMS];
           register int i;
           int ret = RETCODE_OK;
           struct tagCommand *cmd;
   
           if (!psInput)
                   return RETCODE_ERR;
           else
                   line = psInput;
   
           // clear whitespaces
           for (s = line; isspace((int) *s); s++);
           if (*s) {
                   for (t = s + strlen(s) - 1; t > s && isspace((int) *t); t--);
                   *++t = 0;
           }
   
           if (*s) {
                   memset(items, 0, sizeof(char*) * MAX_PROMPT_ITEMS);
                   for (app = items; app < items + MAX_PROMPT_ITEMS - 1 && 
                                   (*app = strsep(&s, " \t")); *app ? app++ : app);
   
                   // exec_cmd ...
                   i = 0;
                   SLIST_FOREACH(cmd, &cli_buffer->line_cmds, cmd_next) {
                           if (!(cmd->cmd_level & (1 << cli_buffer->line_level)))
                                   continue;
                           if (*items[0] && !strncmp(cmd->cmd_name, items[0], strlen(items[0])))
                                   break;
                           else
                                   i++;
                   }
   
                   if (!cmd) {
                           cli_Printf(cli_buffer, "%sCommand '%s' not found!\n", 
                                           cli_buffer->line_prompt ? "\n" : "", items[0]);
                           ret = RETCODE_ERR;
                   } else
                           if (cmd->cmd_func) {
                                   if (prompt && cli_buffer->line_prompt)
                                           cli_Printf(cli_buffer, "\n");
                                   ret = cmd->cmd_func(cli_buffer, 
                                                   cli_buffer->line_level, items);
                           } else if (prompt) {
                                   clrscrEOL(cli_buffer);
                                   printfCR(cli_buffer, 1);
                           }
           }
   
           return ret;
   }
   
   /*
  * cliLoop() - CLI main loop   * cliLoop() - CLI main loop
  *   *
  * @cli_buffer = CLI buffer   * @cli_buffer = CLI buffer
Line 1473  cliNetLoop(linebuffer_t * __restrict cli_buffer, const Line 1536  cliNetLoop(linebuffer_t * __restrict cli_buffer, const
 int  int
 cliLoop(linebuffer_t * __restrict cli_buffer, const char *csHistFile, int timeout)  cliLoop(linebuffer_t * __restrict cli_buffer, const char *csHistFile, int timeout)
 {  {
        char *line, *s, *t, **app, *items[MAX_PROMPT_ITEMS];        char *line;
        register int i; 
         int ret = RETCODE_OK;          int ret = RETCODE_OK;
         struct tagCommand *cmd;  
   
         /* --- main body of CLI --- */          /* --- main body of CLI --- */
         cliInitLine(cli_buffer);          cliInitLine(cli_buffer);
Line 1491  cliLoop(linebuffer_t * __restrict cli_buffer, const ch Line 1552  cliLoop(linebuffer_t * __restrict cli_buffer, const ch
                         break;                          break;
                 } else                  } else
                         cli_addHistory(cli_buffer, NULL);                          cli_addHistory(cli_buffer, NULL);
                 // clear whitespaces  
                 for (s = line; isspace((int) *s); s++);  
                 if (*s) {  
                         for (t = s + strlen(s) - 1; t > s && isspace((int) *t); t--);  
                         *++t = 0;  
                 }  
   
                if (*s) {                ret = cliRun(cli_buffer, line, 42);
                        memset(items, 0, sizeof(char*) * MAX_PROMPT_ITEMS); 
                        for (app = items; app < items + MAX_PROMPT_ITEMS - 1 &&  
                                        (*app = strsep(&s, " \t")); *app ? app++ : app); 
 
                        // exec_cmd ... 
                        i = 0; 
                        SLIST_FOREACH(cmd, &cli_buffer->line_cmds, cmd_next) { 
                                if (!(cmd->cmd_level & (1 << cli_buffer->line_level))) 
                                        continue; 
                                if (*items[0] && !strncmp(cmd->cmd_name, items[0], strlen(items[0]))) 
                                        break; 
                                else 
                                        i++; 
                        } 
 
                        if (!cmd) { 
                                cli_Printf(cli_buffer, "%sCommand '%s' not found!\n",  
                                                cli_buffer->line_prompt ? "\n" : "", items[0]); 
                                ret = -1; 
                        } else 
                                if (cmd->cmd_func) { 
                                        if (cli_buffer->line_prompt) 
                                                cli_Printf(cli_buffer, "\n"); 
                                        ret = cmd->cmd_func(cli_buffer,  
                                                        cli_buffer->line_level, items); 
                                } else { 
                                        clrscrEOL(cli_buffer); 
                                        printfCR(cli_buffer, 1); 
                                } 
                } 
   
                 cli_freeLine(cli_buffer);                  cli_freeLine(cli_buffer);
                 cli_resetHistory(cli_buffer);                  cli_resetHistory(cli_buffer);

Removed from v.1.16  
changed lines
  Added in v.1.17


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