version 1.6, 2012/07/11 07:10:15 |
version 1.7, 2013/03/24 09:54:10 |
|
|
* Show environment. |
* Show environment. |
*/ |
*/ |
|
|
enum cmd_retval cmd_show_environment_exec(struct cmd *, struct cmd_ctx *); |
enum cmd_retval cmd_show_environment_exec(struct cmd *, struct cmd_q *); |
|
|
const struct cmd_entry cmd_show_environment_entry = { |
const struct cmd_entry cmd_show_environment_entry = { |
"show-environment", "showenv", |
"show-environment", "showenv", |
|
|
}; |
}; |
|
|
enum cmd_retval |
enum cmd_retval |
cmd_show_environment_exec(struct cmd *self, struct cmd_ctx *ctx) |
cmd_show_environment_exec(struct cmd *self, struct cmd_q *cmdq) |
{ |
{ |
struct args *args = self->args; |
struct args *args = self->args; |
struct session *s; |
struct session *s; |
|
|
if (args_has(self->args, 'g')) |
if (args_has(self->args, 'g')) |
env = &global_environ; |
env = &global_environ; |
else { |
else { |
if ((s = cmd_find_session(ctx, args_get(args, 't'), 0)) == NULL) |
if ((s = cmd_find_session(cmdq, args_get(args, 't'), 0)) == NULL) |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
env = &s->environ; |
env = &s->environ; |
} |
} |
|
|
if (args->argc != 0) { |
if (args->argc != 0) { |
envent = environ_find(env, args->argv[0]); |
envent = environ_find(env, args->argv[0]); |
if (envent == NULL) { |
if (envent == NULL) { |
ctx->error(ctx, "unknown variable: %s", args->argv[0]); |
cmdq_error(cmdq, "unknown variable: %s", args->argv[0]); |
return (CMD_RETURN_ERROR); |
return (CMD_RETURN_ERROR); |
} |
} |
if (envent->value != NULL) |
if (envent->value != NULL) |
ctx->print(ctx, "%s=%s", envent->name, envent->value); |
cmdq_print(cmdq, "%s=%s", envent->name, envent->value); |
else |
else |
ctx->print(ctx, "-%s", envent->name); |
cmdq_print(cmdq, "-%s", envent->name); |
return (CMD_RETURN_NORMAL); |
return (CMD_RETURN_NORMAL); |
} |
} |
|
|
RB_FOREACH(envent, environ, env) { |
RB_FOREACH(envent, environ, env) { |
if (envent->value != NULL) |
if (envent->value != NULL) |
ctx->print(ctx, "%s=%s", envent->name, envent->value); |
cmdq_print(cmdq, "%s=%s", envent->name, envent->value); |
else |
else |
ctx->print(ctx, "-%s", envent->name); |
cmdq_print(cmdq, "-%s", envent->name); |
} |
} |
|
|
return (CMD_RETURN_NORMAL); |
return (CMD_RETURN_NORMAL); |