command.h 3.81 KB
Newer Older
1
2
/* command.h
 *
Niels Möller's avatar
Niels Möller committed
3
 * $Id$ */
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

/* 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
Niels Möller's avatar
Niels Möller committed
21
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
23
24
25
26
 */

#ifndef LSH_COMMAND_H_INCLUDED
#define LSH_COMMAND_H_INCLUDED

27
#include "lsh.h"
28

Niels Möller's avatar
Niels Möller committed
29
#include "list.h"
30
#include "io.h"
Niels Möller's avatar
Niels Möller committed
31
32
33

#include <stdarg.h>

34
#define GABA_DECLARE
35
#include "command.h.x"
36
#undef GABA_DECLARE
37
38
39
40

/* Continuation based command execution. A command can take one object
 * as argument, and returns one object. */

41
/* GABA:
42
43
44
45
46
47
   (class
     (name command_continuation)
     (vars
       (c method int "struct lsh_object *result")))
*/

48
/* GABA:
49
50
51
   (class
     (name command)
     (vars
52
53
       (call method int "struct lsh_object *arg"
                        "struct command_continuation *c")))
54
55
*/

56
/* GABA:
57
58
59
60
61
62
63
64
65
   (class
     (name command_simple)
     (super command)
     (vars
       ;; Like call, but returns the value immediately rather than
       ;; using a continuation function
       (call_simple method "struct lsh_object *" "struct lsh_object *")))
*/

66
67
#define COMMAND_CALL(f, a, c) ((f)->call((f), (a), (c)))
#define COMMAND_RETURN(r, v) ((r)->c((r), (struct lsh_object *) (v))) 
68
#define COMMAND_SIMPLE(f, a) ((f)->call_simple((f), (a)))
69

Niels Möller's avatar
Niels Möller committed
70
int do_call_simple_command(struct command *s,
71
72
73
74
75
76
			   struct lsh_object *arg,
			   struct command_continuation *c);

#define STATIC_COMMAND_SIMPLE(f) \
{ { STATIC_HEADER, do_call_simple_command }, f}

77
/* GABA:
78
79
80
81
82
83
84
85
86
   (class
     (name command_frame)
     (super command_continuation)
     (vars
       (up object command_continuation)))
*/

struct command_continuation *
make_apply(struct command *f, struct command_continuation *c);  
Niels Möller's avatar
Niels Möller committed
87
88
struct lsh_object *gaba_apply(struct lsh_object *f,
			      struct lsh_object *x);
89

90
/* The macros are used by automatically generated evaluation code */
Niels Möller's avatar
Niels Möller committed
91
extern struct command_simple command_S;
92
93
94
95
96
struct command *make_command_S_2(struct command *f,
				 struct command *g);

struct command *make_command_S_1(struct command *f);

Niels Möller's avatar
Niels Möller committed
97
98
struct lsh_object *gaba_apply_S_1(struct lsh_object *f);
struct lsh_object *gaba_apply_S_2(struct lsh_object *f,
99
100
101
102
103
104
				  struct lsh_object *g);

#define GABA_VALUE_S (&command_S.super.super)
#define GABA_APPLY_S_1 gaba_apply_S_1
#define GABA_APPLY_S_2 gaba_apply_S_2

Niels Möller's avatar
Niels Möller committed
105
extern struct command_simple command_K;
106
107
108
109
110
111
112
113
114
115
116
struct command *make_command_K_1(struct lsh_object *x);

#define GABA_VALUE_K (&command_K.super.super)
#define GABA_APPLY_K_1(x) ((struct lsh_object *) make_command_K_1(x))

#define GABA_APPLY gaba_apply

extern struct command_simple command_I;
#define GABA_VALUE_I (&command_I.super.super)
#define GABA_APPLY_I_1(x) (x)

117
118
119
120
extern struct command_simple command_B;

extern struct command_simple command_unimplemented;
#define COMMAND_UNIMPLEMENTED (&command_unimplemented.super.super)
121
122
123
124

struct command *make_listen_command(struct io_backend *backend,
				    struct lsh_string *interface,
				    UINT32 port);
Niels Möller's avatar
Niels Möller committed
125

126
#if 0
Niels Möller's avatar
Niels Möller committed
127
128
129
130
131
132
133
134
/* (lambda (x) (f (g x))) */
struct command *command_compose(struct command *f, struct command *g);

/* (lambda (x) (and (f1 x) (f2 x) ...)) */
struct command *command_andl(struct object_list *args);

/* (lambda (x) (or (f1 x) (f2 x) ...)) */
struct command *command_orl(struct object_list *args);
135
#endif
136
137

#endif /* LSH_COMMAND_H_INCLUDED */