command.h 5.86 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 Mller
 *
 * 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}

Niels Möller's avatar
Niels Möller committed
77
78
79
struct lsh_object *
do_collect_1(struct command_simple *s, struct lsh_object *a);

80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#define STATIC_COLLECT_1(next) \
{ { { STATIC_HEADER, do_call_simple_command }, do_collect_1}, \
  make_collect_state_1, next }

#if 0
#define STATIC_COLLECT_1_FINAL(f) \
{ { { STATIC_HEADER, do_call_simple_command }, do_collect_1}, \
  f, NULL }
#endif

#define STATIC_COLLECT_2(next) \
{ STATIC_HEADER, make_collect_state_2, next }

#define STATIC_COLLECT_2_FINAL(f) \
{ STATIC_HEADER, f, NULL }

#define STATIC_COLLECT_3(next) \
{ STATIC_HEADER, make_collect_state_3, next }

#define STATIC_COLLECT_3_FINAL(f) \
{ STATIC_HEADER, f, NULL }

102
/* GABA:
103
104
105
106
107
108
109
   (class
     (name command_frame)
     (super command_continuation)
     (vars
       (up object command_continuation)))
*/

110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/* Commands that need to collect some arguments before actually doing
 * anything. */

/* The collect_info_n classes keeps track about what to do whith the
 * next argument. As long as we collect arguments without doing
 * anything, the f field in collect_info_n will point to the
 * constructor make_collect_state_n. */
/* GABA:
   (class
     (name collect_info_4)
     (vars
       (f method "struct lsh_object *"
                 "struct lsh_object *" "struct lsh_object *"
		 "struct lsh_object *" "struct lsh_object *")
       ;; No next field
       ))
*/

/* GABA:
   (class
     (name collect_info_3)
     (vars
       (f method  "struct lsh_object *"
                  "struct lsh_object *" "struct lsh_object *"
		  "struct lsh_object *")
       (next object collect_info_4)))
*/

/* GABA:
   (class
     (name collect_info_2)
     (vars
       (f method  "struct lsh_object *"
                  "struct lsh_object *" "struct lsh_object *")
       (next object collect_info_3)))
*/

/* GABA:
   (class
     (name collect_info_1)
     (super command_simple)
     (vars
       (f method  "struct lsh_object *"
                  "struct lsh_object *")
       (next object collect_info_2)))
*/

struct lsh_object *
make_collect_state_1(struct collect_info_1 *info,
		     struct lsh_object *a);

struct lsh_object *
make_collect_state_2(struct collect_info_2 *info,
		     struct lsh_object *a,
		     struct lsh_object *b);

struct lsh_object *
make_collect_state_3(struct collect_info_3 *info,
		     struct lsh_object *a,
		     struct lsh_object *b,
		     struct lsh_object *c);

extern struct command_simple command_unimplemented;
#define COMMAND_UNIMPLEMENTED (&command_unimplemented.super.super)

175
176
struct command_continuation *
make_apply(struct command *f, struct command_continuation *c);  
Niels Möller's avatar
Niels Möller committed
177
178
struct lsh_object *gaba_apply(struct lsh_object *f,
			      struct lsh_object *x);
179

180
#define GABA_APPLY gaba_apply
181

182
183
184
extern struct command_simple command_I;
#define GABA_VALUE_I (&command_I.super.super)
#define GABA_APPLY_I_1(x) (x)
185

Niels Möller's avatar
Niels Möller committed
186
extern struct command_simple command_K;
187
188
189
190
191
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))

192
193
194
195
/* The macros are used by automatically generated evaluation code */
extern struct collect_info_1 command_S;
struct command *make_command_S_2(struct command *f,
				 struct command *g);
196

197
198
199
#define GABA_VALUE_S (&command_S.super.super)
#define GABA_APPLY_S_1(f) (make_collect_state_1(&collect_info_S_2, (f)))
#define GABA_APPLY_S_2(f, g) (make_collect_S_2(NULL, (f), (g)))
200

201
#if 0
202
203
extern struct command_simple command_B;

204
205
206
struct command *make_listen_command(struct io_backend *backend,
				    struct lsh_string *interface,
				    UINT32 port);
207
#endif
Niels Möller's avatar
Niels Möller committed
208

209
#if 0
Niels Möller's avatar
Niels Möller committed
210
211
212
213
214
215
216
217
/* (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);
218
#endif
219
220

#endif /* LSH_COMMAND_H_INCLUDED */