Commit d092cfff authored by Niels Möller's avatar Niels Möller
Browse files

* src/command.c: Deleted file.

* src/command.h: Deleted file.
* src/exception.c: Deleted file.
* src/exception.h: Deleted file.

Rev: src/command.c:1.53(DEAD)
Rev: src/command.h:1.66(DEAD)
Rev: src/exception.c:1.20(DEAD)
Rev: src/exception.h:1.33(DEAD)
parent 7e5ee9bd
/* command.c
*
*/
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1998 Niels Möller
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <assert.h>
#include "command.h"
#include "io.h"
#include "werror.h"
#include "xalloc.h"
#define GABA_DEFINE
#include "command.h.x"
#undef GABA_DEFINE
#include "command.c.x"
static void
do_discard_continuation(struct command_continuation *ignored UNUSED,
struct lsh_object *x UNUSED)
{}
struct command_continuation discard_continuation =
{ STATIC_HEADER, do_discard_continuation};
struct command_context *
make_command_context(struct command_continuation *c,
struct exception_handler *e)
{
NEW(command_context, self);
self->c = c;
self->e = e;
return self;
}
/* A command taking 2 arguments */
/* GABA:
(class
(name command_2_invoke)
(super command)
(vars
(f object command_2)
(a1 object lsh_object)))
*/
static void
do_command_2_invoke(struct command *s, struct lsh_object *a2,
struct command_continuation *c,
struct exception_handler *e)
{
CAST(command_2_invoke, self, s);
self->f->invoke(self->a1, a2, c, e);
}
struct command *
make_command_2_invoke(struct command_2 *f,
struct lsh_object *a1)
{
NEW(command_2_invoke, self);
self->super.call = do_command_2_invoke;
self->f = f;
self->a1 = a1;
return &self->super;
}
void
do_command_2(struct command *s,
struct lsh_object *a1,
struct command_continuation *c,
struct exception_handler *e UNUSED)
{
CAST_SUBTYPE(command_2, self, s);
COMMAND_RETURN(c, make_command_2_invoke(self, a1));
}
/* A command taking 3 arguments */
/* GABA:
(class
(name command_3_invoke_2)
(super command)
(vars
(f object command_3)
(a1 object lsh_object)
(a2 object lsh_object)))
*/
static void
do_command_3_invoke_2(struct command *s,
struct lsh_object *a3,
struct command_continuation *c,
struct exception_handler *e)
{
CAST(command_3_invoke_2, self, s);
self->f->invoke(self->a1, self->a2, a3, c, e);
}
struct command *
make_command_3_invoke_2(struct command_3 *f,
struct lsh_object *a1,
struct lsh_object *a2)
{
NEW(command_3_invoke_2, self);
self->super.call = do_command_3_invoke_2;
self->f = f;
self->a1 = a1;
self->a2 = a2;
return &self->super;
}
/* GABA:
(class
(name command_3_invoke)
(super command)
(vars
(f object command_3)
(a1 object lsh_object)))
*/
static void
do_command_3_invoke(struct command *s,
struct lsh_object *a2,
struct command_continuation *c,
struct exception_handler *e UNUSED)
{
CAST(command_3_invoke, self, s);
COMMAND_RETURN(c, make_command_3_invoke_2(self->f, self->a1, a2));
}
struct command *
make_command_3_invoke(struct command_3 *f,
struct lsh_object *a1)
{
NEW(command_3_invoke, self);
self->super.call = do_command_3_invoke;
self->f = f;
self->a1 = a1;
return &self->super;
}
void
do_command_3(struct command *s,
struct lsh_object *a1,
struct command_continuation *c,
struct exception_handler *e UNUSED)
{
CAST_SUBTYPE(command_3, self, s);
COMMAND_RETURN(c, make_command_3_invoke(self, a1));
}
/* A command taking 4 arguments */
/* GABA:
(class
(name command_4_invoke_3)
(super command)
(vars
(f object command_4)
(a1 object lsh_object)
(a2 object lsh_object)
(a3 object lsh_object)))
*/
static void
do_command_4_invoke_3(struct command *s,
struct lsh_object *a4,
struct command_continuation *c,
struct exception_handler *e)
{
CAST(command_4_invoke_3, self, s);
self->f->invoke(self->a1, self->a2, self->a3, a4, c, e);
}
struct command *
make_command_4_invoke_3(struct command_4 *f,
struct lsh_object *a1,
struct lsh_object *a2,
struct lsh_object *a3)
{
NEW(command_4_invoke_3, self);
self->super.call = do_command_4_invoke_3;
self->f = f;
self->a1 = a1;
self->a2 = a2;
self->a3 = a3;
return &self->super;
}
/* GABA:
(class
(name command_4_invoke_2)
(super command)
(vars
(f object command_4)
(a1 object lsh_object)
(a2 object lsh_object)))
*/
static void
do_command_4_invoke_2(struct command *s,
struct lsh_object *a3,
struct command_continuation *c,
struct exception_handler *e UNUSED)
{
CAST(command_4_invoke_2, self, s);
COMMAND_RETURN(c, make_command_4_invoke_3(self->f, self->a1, self->a2, a3));
}
struct command *
make_command_4_invoke_2(struct command_4 *f,
struct lsh_object *a1,
struct lsh_object *a2)
{
NEW(command_4_invoke_2, self);
self->super.call = do_command_4_invoke_2;
self->f = f;
self->a1 = a1;
self->a2 = a2;
return &self->super;
}
/* GABA:
(class
(name command_4_invoke)
(super command)
(vars
(f object command_4)
(a1 object lsh_object)))
*/
static void
do_command_4_invoke(struct command *s,
struct lsh_object *a2,
struct command_continuation *c,
struct exception_handler *e UNUSED)
{
CAST(command_4_invoke, self, s);
COMMAND_RETURN(c, make_command_4_invoke_2(self->f, self->a1, a2));
}
struct command *
make_command_4_invoke(struct command_4 *f,
struct lsh_object *a1)
{
NEW(command_4_invoke, self);
self->super.call = do_command_4_invoke;
self->f = f;
self->a1 = a1;
return &self->super;
}
void
do_command_4(struct command *s,
struct lsh_object *a1,
struct command_continuation *c,
struct exception_handler *e UNUSED)
{
CAST_SUBTYPE(command_4, self, s);
COMMAND_RETURN(c, make_command_4_invoke(self, a1));
}
/* Tracing */
#if DEBUG_TRACE
/* GABA:
(class
(name trace_continuation)
(super command_continuation)
(vars
(name . "const char *")
(real object command_continuation)))
*/
static void
do_trace_continuation(struct command_continuation *s,
struct lsh_object *x)
{
CAST(trace_continuation, self, s);
trace("Leaving %z, value of type %t.\n",
self->name, x);
COMMAND_RETURN(self->real, x);
}
static struct command_continuation *
make_trace_continuation(const char *name,
struct command_continuation *real)
{
NEW(trace_continuation, self);
self->super.c = do_trace_continuation;
self->name = name;
self->real = real;
return &self->super;
}
/* GABA:
(class
(name trace_command)
(super command)
(vars
(name . "const char *")
(real object command)))
*/
static void
do_trace_command(struct command *s,
struct lsh_object *x,
struct command_continuation *c,
struct exception_handler *e)
{
CAST(trace_command, self, s);
trace("Entering %z\n", self->name);
#if 1
COMMAND_CALL(self->real, x,
make_trace_continuation(self->name, c),
e);
#else
COMMAND_CALL(self->real, x, c, e);
#endif
}
struct command *make_trace(const char *name, struct command *real)
{
NEW(trace_command, self);
self->super.call = do_trace_command;
self->name = name;
self->real = real;
return &self->super;
}
struct lsh_object *collect_trace(const char *name, struct lsh_object *c)
{
CAST_SUBTYPE(command, real, c);
return &make_trace(name, real)->super;
}
#endif /* DEBUG_TRACE */
/* command.h
*
*/
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1998 Niels Möller
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef LSH_COMMAND_H_INCLUDED
#define LSH_COMMAND_H_INCLUDED
#include <stdarg.h>
#include "lsh.h"
#include "exception.h"
#include "list.h"
#define GABA_DECLARE
#include "command.h.x"
#undef GABA_DECLARE
/* Continuation based command execution. A command can take one object
* as argument, and returns one object. */
/* GABA:
(class
(name command_continuation)
(vars
(c method void "struct lsh_object *result")))
*/
#define COMMAND_RETURN(r, v) ((r)->c((r), (struct lsh_object *) (v)))
/* GABA:
(class
(name command)
(vars
(call method void "struct lsh_object *arg"
"struct command_continuation *c"
"struct exception_handler *e")))
*/
#define COMMAND_CALL(f, a, c, e) \
((void)&(f), ((f)->call((f), (struct lsh_object *) (a), (c), (e))))
/* NOTE: Except when inheriting command, use DEFINE_COMMAND instead. */
#define STATIC_COMMAND(f) { STATIC_HEADER, f }
#define DEFINE_COMMAND(cname) \
static void \
do_##cname(struct command *, \
struct lsh_object *, \
struct command_continuation *, \
struct exception_handler *); \
\
struct command cname = \
STATIC_COMMAND(do_##cname); \
\
static void \
do_##cname
/* A command taking 2 arguments */
/* GABA:
(class
(name command_2)
(super command)
(vars
(invoke pointer
(function void "struct lsh_object *a1"
"struct lsh_object *a2"
"struct command_continuation *c"
"struct exception_handler *e"))))
*/
void
do_command_2(struct command *s,
struct lsh_object *a1,
struct command_continuation *c,
struct exception_handler *e);
struct command *
make_command_2_invoke(struct command_2 *f,
struct lsh_object *a1);
#define DEFINE_COMMAND2(cname) \
static void \
do_##cname(struct lsh_object *, \
struct lsh_object *, \
struct command_continuation *, \
struct exception_handler *); \
\
struct command_2 cname = \
{ { STATIC_HEADER, do_command_2 }, do_##cname }; \
\
static void \
do_##cname
/* A command taking 3 arguments */
/* GABA:
(class
(name command_3)
(super command)
(vars
(invoke pointer
(function void "struct lsh_object *a1"
"struct lsh_object *a2"
"struct lsh_object *a3"
"struct command_continuation *c"
"struct exception_handler *e"))))
*/
void
do_command_3(struct command *s,
struct lsh_object *a1,
struct command_continuation *c,
struct exception_handler *e);
struct command *
make_command_3_invoke(struct command_3 *f,
struct lsh_object *a1);
struct command *
make_command_3_invoke_2(struct command_3 *f,
struct lsh_object *a1,
struct lsh_object *a2);
#define DEFINE_COMMAND3(cname) \
static void \
do_##cname(struct lsh_object *, \
struct lsh_object *, \
struct lsh_object *, \
struct command_continuation *, \
struct exception_handler *); \
\
struct command_3 cname = \
{ { STATIC_HEADER, do_command_3 }, do_##cname }; \
\
static void \
do_##cname
/* A command taking 4 arguments */
/* GABA:
(class
(name command_4)
(super command)
(vars
(invoke pointer
(function void "struct lsh_object *a1"
"struct lsh_object *a2"
"struct lsh_object *a3"
"struct lsh_object *a4"
"struct command_continuation *c"
"struct exception_handler *e"))))
*/
void
do_command_4(struct command *s,
struct lsh_object *a1,
struct command_continuation *c,
struct exception_handler *e);
struct command *
make_command_4_invoke(struct command_4 *f,
struct lsh_object *a1);
struct command *
make_command_4_invoke_2(struct command_4 *f,
struct lsh_object *a1,
struct lsh_object *a2);
struct command *
make_command_4_invoke_3(struct command_4 *f,
struct lsh_object *a1,
struct lsh_object *a2,
struct lsh_object *a3);
#define DEFINE_COMMAND4(cname) \
static void \
do_##cname(struct lsh_object *, \
struct lsh_object *, \
struct lsh_object *, \
struct lsh_object *, \
struct command_continuation *, \
struct exception_handler *); \
\
struct command_4 cname = \
{ { STATIC_HEADER, do_command_4 }, do_##cname }; \
\
static void \
do_##cname
extern struct command_continuation discard_continuation;
/* GABA:
(class
(name command_frame)
(super command_continuation)
(vars
(up object command_continuation)
(e object exception_handler)))
*/
/* Used when the execution context must be saved for later use.
*
* Primarily used in channel.c.
*/
/* GABA:
(class
(name command_context)
(vars
(c object command_continuation)
(e object exception_handler)))
*/
struct command_context *
make_command_context(struct command_continuation *c,
struct exception_handler *e);
#if DEBUG_TRACE
struct command *make_trace(const char *name, struct command *real);
struct lsh_object *collect_trace(const char *name, struct lsh_object *real);
#define MAKE_TRACE collect_trace
#else /* !DEBUG_TRACE */
#define MAKE_TRACE(name, real) (real)
#endif /* !DEBUG_TRACE */
#endif /* LSH_COMMAND_H_INCLUDED */
/* exception.c
*
*/
/* lsh, an implementation of the ssh protocol
*
* Copyright (C) 1998 Niels Möller
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#if HAVE_CONFIG_H