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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
/**
* VOTAPP_SPP.C -- SPP Interface routines to applications code.
*
* @file votApp_spp.c
* @author Mike Fitzpatrick
* @date 6/03/11
*
* @brief SPP Interface routines to applications code.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
#include <ctype.h>
#include <errno.h>
/*
#include "votParseP.h"
*/
#include "votParse.h"
/* SPP Type definitions.
*/
#define XCHAR short
#define PKCHAR char
#define XINT int
#define XEOS 0
/* SPP Interface Definitions.
*
* SPP compilers on various platforms may append one or more trailing
* underscores to symbol names, we'll use macros for the interface names
* and use defines to see what the symbol name is.
*/
#ifdef _NO_US_
#define VX_VODATA vxvoda
#define VX_VODIRECTORY vxvody
#define VX_VOSESAME vxvose
#define VX_VOCOPY vxvocy
#define VX_VOGET vxvogt
#define VX_VOINFO vxvoio
#else
#define VX_VODATA vxvoda_
#define VX_VODIRECTORY vxvody_
#define VX_VOSESAME vxvose_
#define VX_VOCOPY vxvocy_
#define VX_VOGET vxvogt_
#define VX_VOINFO vxvoio_
#endif
typedef void (*PFV)();
typedef int (*PFI)();
/**
* Local interface declarations.
*/
static PKCHAR *spp2c (XCHAR *instr, int maxch);
static int spplen (XCHAR *str);
static void func_exec (PFV func, char *name, int *argc, XCHAR *firstArg,
va_list argp);
/*****************************************************************************
* Application Interfaces
****************************************************************************/
#define MAX_ARGS 64
void vodata (int argc, char **argv);
void voregistry (int argc, char **argv);
void vosesame (int argc, char **argv);
void votcnv (int argc, char **argv);
void votget (int argc, char **argv);
void votinfo (int argc, char **argv);
void voc_debug (void);
/**
* FUNC_EXEC -- Execute a VOClient function from the SPP binding.
*/
static void
func_exec (PFV func, char *name, int *argc, XCHAR *firstArg, va_list argp)
{
int i, _argc = *argc;
char *_argv[MAX_ARGS];
XCHAR *arg;
if (firstArg == NULL) /* must pass in at least one arg */
return;
/* Process the argument list.
*/
_argc = *argc + 1;
_argv[0] = strdup (name);
_argv[1] = spp2c (firstArg, spplen (firstArg));
for (i=2; i < _argc && (arg=(XCHAR *)va_arg(argp,XCHAR *)) != NULL; i++)
if (arg)
_argv[i] = spp2c (arg, spplen (arg));
/* Debug output.
*/
if (access ("/tmp/VOC_DEBUG", F_OK) == 0) {
for (i=0; i < _argc; i++)
fprintf (stderr, "%s ", _argv[i]);
fprintf (stderr, "\n");
}
(*func) (_argc, _argv); /* call the task */
for (i=0; i < *argc; i++) /* free the arg pointers */
if (_argv[i])
free ((char *) _argv[i]);
return;
}
/****************************************************************************
* Task wrappers
****************************************************************************/
/**
* VX_VOCOPY -- Application interface to the VOCOPY task.
*/
void VX_VOCOPY (int *argc, XCHAR *firstArg, ...)
{
va_list argp;
va_start (argp, firstArg);
func_exec (votcnv, "votcopy", argc, firstArg, argp);
va_end (argp);
}
/**
* VX_VODATA -- Application interface to the VODATA task.
*/
void VX_VODATA (int *argc, XCHAR *firstArg, ...)
{
va_list argp;
va_start (argp, firstArg);
func_exec (vodata, "vodata", argc, firstArg, argp);
va_end (argp);
}
/**
* VX_VODIRECTORY -- Application interface to the VODIRECTORY task.
*/
void VX_VODIRECTORY (int *argc, XCHAR *firstArg, ...)
{
va_list argp;
va_start (argp, firstArg);
func_exec (voregistry, "vodirectory", argc, firstArg, argp);
va_end (argp);
}
/**
* VX_VOGET -- Application interface to the VOGET task.
*/
void VX_VOGET (int *argc, XCHAR *firstArg, ...)
{
va_list argp;
va_start (argp, firstArg);
func_exec (votget, "votget", argc, firstArg, argp);
va_end (argp);
}
/**
* VX_VOINFO -- Application interface to the VOTINFO task.
*/
void VX_VOINFO (int *argc, XCHAR *firstArg, ...)
{
va_list argp;
va_start (argp, firstArg);
func_exec (votinfo, "votinfo", argc, firstArg, argp);
va_end (argp);
}
/**
* VX_VOSESAME -- Application interface to the VOSESAME task.
*/
void VX_VOSESAME (int *argc, XCHAR *firstArg, ...)
{
va_list argp;
va_start (argp, firstArg);
func_exec (vosesame, "vosesame", argc, firstArg, argp);
va_end (argp);
}
/****************************************************************************
* Private utility procedures
****************************************************************************/
/**
* SPP2C -- Convert an SPP string to a host C string.
*/
static char *
spp2c (XCHAR *instr, int maxch)
{
XCHAR *ip = instr;
char *outstr = (char *) calloc (1, maxch+1);
char *op = (char *) outstr;
int n = maxch;
while ((*op++ = (char)*ip++) != (char)XEOS && --n >= 0)
;
*--op = (char) XEOS;
return (outstr);
}
/**
* SPPLEN -- Get the length of an SPP string.
*/
static int
spplen (XCHAR *str)
{
int len = 0;
for (len=0; str[len] != (XCHAR) XEOS; len++)
;
return (len);
}
void voc_debug () { int junk; junk = 1; }
|