Move -s and -c down a level so handling them is the responsibility of the command (with some helper functions), rather than the top-level. This changes the action command syntax so that -s and -c must be after the command rather than before.

This commit is contained in:
Nicholas Marriott
2008-06-02 18:08:17 +00:00
parent 11ee55e755
commit c7243b73cb
42 changed files with 1086 additions and 437 deletions

View File

@ -1,4 +1,4 @@
/* $Id: server-fn.c,v 1.36 2007-12-06 09:46:23 nicm Exp $ */
/* $Id: server-fn.c,v 1.37 2008-06-02 18:08:17 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@ -23,57 +23,6 @@
#include "tmux.h"
/* Find session from command message. */
struct session *
server_extract_session(struct msg_command_data *data, char *name, char **cause)
{
struct session *s;
u_int i, n;
if (name != NULL) {
if ((s = session_find(name)) == NULL) {
xasprintf(cause, "session not found: %s", name);
return (NULL);
}
return (s);
}
if (data->pid != -1) {
if (data->pid != getpid()) {
xasprintf(cause, "wrong server: %lld", data->pid);
return (NULL);
}
if (data->idx > ARRAY_LENGTH(&sessions)) {
xasprintf(cause, "index out of range: %d", data->idx);
return (NULL);
}
if ((s = ARRAY_ITEM(&sessions, data->idx)) == NULL) {
xasprintf(
cause, "session doesn't exist: %u", data->idx);
return (NULL);
}
return (s);
}
s = NULL;
n = 0;
for (i = 0; i < ARRAY_LENGTH(&sessions); i++) {
if (ARRAY_ITEM(&sessions, i) != NULL) {
s = ARRAY_ITEM(&sessions, i);
n++;
}
}
if (s == NULL) {
xasprintf(cause, "no sessions found");
return (NULL);
}
if (n != 1) {
xasprintf(cause, "multiple sessions and session not specified");
return (NULL);
}
return (s);
}
void
server_write_client(
struct client *c, enum hdrtype type, const void *buf, size_t len)