File: stub.c

package info (click to toggle)
oleo 1.6-16
  • links: PTS
  • area: main
  • in suites: potato
  • size: 2,640 kB
  • ctags: 3,139
  • sloc: ansic: 39,221; yacc: 1,737; sh: 362; makefile: 88
file content (212 lines) | stat: -rw-r--r-- 5,296 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*	Copyright (C) 1993 Free Software Foundation, Inc.

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, 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 software; see the file COPYING.  If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */



/* This is a collection of stubs that are used to call interactive functions.
 * Their responsability is to extract arguments from a command_frame as
 * constructed by the function COMMAND_LOOP.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "global.h"
#include "cmd.h"
#include "stub.h"




static void
find_args (struct command_arg ** argv_out, int argc, struct command_frame * frame)
{
  int found = 0;
  int pos = 0;
  while (found < argc)
    {
      if (frame->argv[pos].style->representation != cmd_none)
	argv_out[found++] = &frame->argv[pos];
      ++pos;
    }
}


/* These macros are invoked in stubs.h and are used to define
 * the stub functions.  Later, these macros will be redifined 
 * an used to build a table of stub functions.
 */

#define STUB1(STR,NAME, PRE, VAL, TYPE) \
static void \
NAME (frame) \
     struct command_frame * frame; \
{ \
  struct command_arg * argv; \
  find_args (&argv, 1, frame); \
  ((void (*) (TYPE)) frame->cmd->func_func) (PRE argv->val.VAL); \
}

#define STUB2(STR,NAME,PRE1,VAL1,TYPE1,PRE2,VAL2,TYPE2) \
static void \
NAME (frame) \
     struct command_frame * frame; \
{ \
  struct command_arg * argv[2]; \
  find_args (argv, 2, frame); \
  ((void (*) (TYPE1, TYPE2)) frame->cmd->func_func) \
    (PRE1 argv[0]->val.VAL1,  \
     PRE2 argv[1]->val.VAL2); \
}


#define STUB3(STR,NAME,PRE1,VAL1,TYPE1,PRE2,VAL2,TYPE2,PRE3,VAL3,TYPE3) \
static void \
NAME (frame) \
     struct command_frame * frame; \
{ \
  struct command_arg * argv[3]; \
  find_args (argv, 3, frame); \
  frame->cmd->func_func \
    (PRE1 argv[0]->val.VAL1, \
     PRE2 argv[1]->val.VAL2, \
     PRE3 argv[2]->val.VAL3); \
}

#define STUB4(STR,NAME,PRE1,VAL1,TYPE1,PRE2,VAL2,TYPE2,PRE3,VAL3,TYPE3,PRE4,VAL4,TYPE4) \
static void \
NAME (frame) \
     struct command_frame * frame; \
{ \
  struct command_arg * argv[4]; \
  find_args (argv, 4, frame); \
  frame->cmd->func_func \
    (PRE1 argv[0]->val.VAL1, \
     PRE2 argv[1]->val.VAL2, \
     PRE3 argv[2]->val.VAL3, \
     PRE4 argv[3]->val.VAL4); \
}

#define STUB5(STR,NAME,PRE1,VAL1,TYPE1,PRE2,VAL2,TYPE2,PRE3,VAL3,TYPE3,PRE4,VAL4,TYPE4,PRE5,VAL5,TYPE5) \
static void \
NAME (frame) \
     struct command_frame * frame; \
{ \
  struct command_arg * argv[5]; \
  find_args (argv, 5, frame); \
  frame->cmd->func_func \
    (PRE1 argv[0]->val.VAL1, \
     PRE2 argv[1]->val.VAL2, \
     PRE3 argv[2]->val.VAL3, \
     PRE4 argv[3]->val.VAL4, \
     PRE5 argv[4]->val.VAL5); \
}

/* This contains the list of stub functions. */

#include "stubs.h"

/* There is only one `STUB0' so we needn't bother with a macro. */

static void
stub_void (struct command_frame * frame)
{
  frame->cmd->func_func ();
}

/* For define_usr_fmt */
static void
stub_isssssssss (struct command_frame *frame)
{
  struct command_arg * argv[10];
  find_args (argv, 10, frame);
  frame->cmd->func_func (argv[0]->val.integer,
			 argv[1]->val.string,
			 argv[2]->val.string,
			 argv[3]->val.string,
			 argv[4]->val.string,
			 argv[5]->val.string,
			 argv[6]->val.string,
			 argv[7]->val.string,
			 argv[8]->val.string,
			 argv[9]->val.string);
}





/* Single character type-codes denote the types of arguments.  A string
 * of type-codes maps to a stub function (hopefully).
 */
struct cmd_stub
{
  char * type;
  cmd_invoker stub;
};

#undef STUB1
#undef STUB2
#undef STUB3
#undef STUB4
#undef STUB5

#define STUB1(STR,NAME,PRE1,VAL1,TYPE1) { STR, NAME },
#define STUB2(STR,NAME,PRE1,VAL1,TYPE1,PRE2,VAL2,TYPE2)  { STR, NAME },
#define STUB3(STR,NAME,PRE1,VAL1,TYPE1,PRE2,VAL2,TYPE2,PRE3,VAL3,TYPE3) \
	{ STR, NAME },
#define STUB4(STR,NAME,PRE1,VAL1,TYPE1,PRE2,VAL2,TYPE2,PRE3,VAL3,TYPE3,PRE4,VAL4,TYPE4) \
	{ STR, NAME },
#define STUB5(STR,NAME,PRE1,VAL1,TYPE1,PRE2,VAL2,TYPE2,PRE3,VAL3,TYPE3,PRE4,VAL4,TYPE4,PRE5,VAL5,TYPE5) \
	{ STR, NAME },

static struct cmd_stub the_stubs[] =
{
  { "", stub_void },
#include "stubs.h"
  { "isssssssss", stub_isssssssss },
  { 0, 0 }
};



/* This looks at the arguments built for the current command and 
 * finds the right stub.
 */
cmd_invoker
find_stub (void)
{
  char type_buf[100];

  /* Figure out a name for the stub we want. */
  {
    int x, bufpos;
    for (x = 0, bufpos = 0; x < cmd_argc; ++x)
      if (the_cmd_frame->argv[x].style->representation != cmd_none)
	type_buf[bufpos++] = the_cmd_frame->argv[x].style->representation;
    type_buf[bufpos] = '\0';
  }

  /* Look for the stub. */
  {
    int x;
    for (x = 0; the_stubs[x].type; ++x)
      if (!stricmp (the_stubs[x].type, type_buf))
	break;
    return the_stubs[x].stub;
  }
}