Changeset c4ba74d


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.
Files:
4 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}
  • functions.c

    r0504f63 rc4ba74d  
    2525  return owl_cmddict_execute(owl_global_get_cmddict(&g),
    2626                             owl_global_get_context(&g), cmdbuff);
     27}
     28
     29char *owl_function_command_argv(char **argv, int argc)
     30{
     31  return owl_cmddict_execute_argv(owl_global_get_cmddict(&g),
     32                                  owl_global_get_context(&g),
     33                                  argv, argc);
    2734}
    2835
  • perlconfig.c

    r0f9eca7 rc4ba74d  
    181181{
    182182  dSP ;
    183   int count, len;
     183  int count;
     184  unsigned int len;
    184185  SV *msgref, *srv;
    185186  char *out, *preout;
     
    457458  if(SvTRUE(ERRSV)) {
    458459    owl_function_error("%s", SvPV(ERRSV, n_a));
    459     POPs;
     460    (void)POPs;
    460461  } else {
    461462    if(count != 1)
  • perlglue.xs

    racb13bb rc4ba74d  
    1717         *************************************************************
    1818         * These functions, when they are intended to be user-visible,
    19          * are document in perlwrap.pm. If you add functions to this
     19         * are documented in perlwrap.pm. If you add functions to this
    2020         * file, add the appropriate documentation there!
    2121         *
     
    3333
    3434char *
    35 command(cmd)
     35command(cmd, ...)
    3636        char *cmd
    3737        PREINIT:
    3838                char *rv = NULL;
    39         CODE:
    40                 rv = owl_function_command(cmd);
    41                 RETVAL = rv;   
     39                char **argv;
     40                int i;
     41        CODE:
     42        {
     43                if (items == 1) {
     44                        rv = owl_function_command(cmd);
     45                } else {
     46                        argv = owl_malloc((items + 1) * sizeof *argv);
     47                        argv[0] = cmd;
     48                        for(i = 1; i < items; i++) {
     49                                argv[i] = SvPV_nolen(ST(i));
     50                        }
     51                        rv = owl_function_command_argv(argv, items);
     52                        owl_free(argv);
     53                }
     54                RETVAL = rv;
     55        }
    4256        OUTPUT:
    4357                RETVAL
Note: See TracChangeset for help on using the changeset viewer.