[BACK]Return to cmd-set-environment.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tmux

Diff for /src/usr.bin/tmux/cmd-set-environment.c between version 1.3 and 1.4

version 1.3, 2009/11/13 19:53:29 version 1.4, 2011/01/04 00:42:47
Line 31 
Line 31 
   
 const struct cmd_entry cmd_set_environment_entry = {  const struct cmd_entry cmd_set_environment_entry = {
         "set-environment", "setenv",          "set-environment", "setenv",
           "grt:u", 1, 2,
         "[-gru] " CMD_TARGET_SESSION_USAGE " name [value]",          "[-gru] " CMD_TARGET_SESSION_USAGE " name [value]",
         CMD_ARG12, "gru",          0,
         NULL,          NULL,
         cmd_target_parse,          NULL,
         cmd_set_environment_exec,          cmd_set_environment_exec
         cmd_target_free,  
         cmd_target_print  
 };  };
   
 int  int
 cmd_set_environment_exec(struct cmd *self, struct cmd_ctx *ctx)  cmd_set_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
 {  {
         struct cmd_target_data  *data = self->data;          struct args     *args = self->args;
         struct session          *s;          struct session  *s;
         struct environ          *env;          struct environ  *env;
           const char      *name, *value;
   
         if (*data->arg == '\0') {          name = args->argv[0];
           if (*name == '\0') {
                 ctx->error(ctx, "empty variable name");                  ctx->error(ctx, "empty variable name");
                 return (-1);                  return (-1);
         }          }
         if (strchr(data->arg, '=') != NULL) {          if (strchr(name, '=') != NULL) {
                 ctx->error(ctx, "variable name contains =");                  ctx->error(ctx, "variable name contains =");
                 return (-1);                  return (-1);
         }          }
   
         if (cmd_check_flag(data->chflags, 'g'))          if (args->argc < 1)
                   value = NULL;
           else
                   value = args->argv[1];
   
           if (args_has(self->args, 'g'))
                 env = &global_environ;                  env = &global_environ;
         else {          else {
                 if ((s = cmd_find_session(ctx, data->target)) == NULL)                  if ((s = cmd_find_session(ctx, args_get(args, 't'))) == NULL)
                         return (-1);                          return (-1);
                 env = &s->environ;                  env = &s->environ;
         }          }
   
         if (cmd_check_flag(data->chflags, 'u')) {          if (args_has(self->args, 'u')) {
                 if (data->arg2 != NULL) {                  if (value != NULL) {
                         ctx->error(ctx, "can't specify a value with -u");                          ctx->error(ctx, "can't specify a value with -u");
                         return (-1);                          return (-1);
                 }                  }
                 environ_unset(env, data->arg);                  environ_unset(env, name);
         } else if (cmd_check_flag(data->chflags, 'r')) {          } else if (args_has(self->args, 'r')) {
                 if (data->arg2 != NULL) {                  if (value != NULL) {
                         ctx->error(ctx, "can't specify a value with -r");                          ctx->error(ctx, "can't specify a value with -r");
                         return (-1);                          return (-1);
                 }                  }
                 environ_set(env, data->arg, NULL);                  environ_set(env, name, NULL);
         } else {          } else {
                 if (data->arg2 == NULL) {                  if (value == NULL) {
                         ctx->error(ctx, "no value specified");                          ctx->error(ctx, "no value specified");
                         return (-1);                          return (-1);
                 }                  }
                 environ_set(env, data->arg, data->arg2);                  environ_set(env, name, value);
         }          }
   
         return (0);          return (0);

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4