tmux/cmd-source-file.c

74 lines
2.0 KiB
C
Raw Normal View History

2011-07-09 09:42:33 +00:00
/* $Id$ */
2008-12-15 21:21:56 +00:00
/*
* Copyright (c) 2008 Tiago Cunha <me@tiagocunha.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <sys/types.h>
#include <stdlib.h>
2008-12-15 21:21:56 +00:00
#include "tmux.h"
/*
* Sources a configuration file.
*/
enum cmd_retval cmd_source_file_exec(struct cmd *, struct cmd_ctx *);
2008-12-15 21:21:56 +00:00
const struct cmd_entry cmd_source_file_entry = {
"source-file", "source",
"", 1, 1,
2008-12-15 21:21:56 +00:00
"path",
0,
NULL,
NULL,
cmd_source_file_exec
2008-12-15 21:21:56 +00:00
};
enum cmd_retval
2008-12-15 21:21:56 +00:00
cmd_source_file_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct args *args = self->args;
int retval;
u_int i;
char *cause;
retval = load_cfg(args->argv[0], ctx, &cfg_causes);
/*
* If the context for the cmdclient came from tmux's configuration
* file, then return the status of this command now, regardless of the
* error condition. Any errors from parsing a configuration file at
* startup will be handled for us by the server.
*/
if (cfg_references > 0 ||
(ctx->curclient == NULL && ctx->cmdclient == NULL))
return (retval);
/*
* We were called from the command-line in which case print the errors
* gathered here directly.
*/
for (i = 0; i < ARRAY_LENGTH(&cfg_causes); i++) {
cause = ARRAY_ITEM(&cfg_causes, i);
ctx->print(ctx, "%s", cause);
free(cause);
2008-12-15 21:21:56 +00:00
}
ARRAY_FREE(&cfg_causes);
2008-12-15 21:21:56 +00:00
return (retval);
2008-12-15 21:21:56 +00:00
}