Changeset c4ba74d for cmd.c


Ignore:
Timestamp:
Aug 21, 2008, 12:52:04 AM (13 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, debian, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
38a7f22
Parents:
aef51f8
Message:
Make BarnOwl::command() accept a pre-tokenized command.

If given more than one argument, BarnOwl::command now treats the
arguments as an argv list to execute the command with. Previously it
only accepted a single argument, so this should not change the
behavior of any existing code.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • cmd.c

    r34509d5 rc4ba74d  
    6767}
    6868
     69char *_owl_cmddict_execute(owl_cmddict *cd, owl_context *ctx, char **argv, int argc, char *buff) {
     70  char *retval = NULL;
     71  owl_cmd *cmd;
     72
     73  if (!strcmp(argv[0], "")) {
     74  } else if (NULL != (cmd = (owl_cmd*)owl_dict_find_element(cd, argv[0]))) {
     75    retval = owl_cmd_execute(cmd, cd, ctx, argc, argv, buff);
     76  } else {
     77    owl_function_makemsg("Unknown command '%s'.", buff);
     78  }
     79  return retval;
     80}
     81
    6982char *owl_cmddict_execute(owl_cmddict *cd, owl_context *ctx, char *cmdbuff) {
    7083  char **argv;
     
    7285  char *tmpbuff;
    7386  char *retval = NULL;
    74   owl_cmd *cmd;
    7587
    7688  tmpbuff=owl_strdup(cmdbuff);
     
    8597  if (argc < 1) return(NULL);
    8698
    87   if (!strcmp(argv[0], "")) {
    88   } else if (NULL != (cmd = (owl_cmd*)owl_dict_find_element(cd, argv[0]))) {
    89     retval = owl_cmd_execute(cmd, cd, ctx, argc, argv, cmdbuff);
    90   } else {
    91     owl_function_makemsg("Unknown command '%s'.", cmdbuff);
    92   }
     99  retval = _owl_cmddict_execute(cd, ctx, argv, argc, cmdbuff);
     100
    93101  owl_parsefree(argv, argc);
    94102  owl_free(tmpbuff);
    95103  sepbar(NULL);
     104  return retval;
     105}
     106
     107char *owl_cmddict_execute_argv(owl_cmddict *cd, owl_context *ctx, char **argv, int argc) {
     108  char *buff, *ptr;
     109  int len = 0, i;
     110  char *retval = NULL;
     111
     112  for(i = 0; i < argc; i++) {
     113    len += strlen(argv[i]) + 1;
     114  }
     115
     116  ptr = buff = owl_malloc(len);
     117
     118  for(i = 0; i < argc; i++) {
     119    strcpy(ptr, argv[i]);
     120    ptr += strlen(argv[i]);
     121    *(ptr++) = ' ';
     122  }
     123  *(ptr - 1) = 0;
     124
     125  retval = _owl_cmddict_execute(cd, ctx, argv, argc, buff);
     126
     127  owl_free(buff);
    96128  return retval;
    97129}
Note: See TracChangeset for help on using the changeset viewer.