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
256
257
258
259
260
261
|
/*
* SCCS: @(#)tcconf.c 1.8 (98/09/01)
*
* UniSoft Ltd., London, England
*
* (C) Copyright 1992 X/Open Company Limited
*
* All rights reserved. No part of this source code may be reproduced,
* stored in a retrieval system, or transmitted, in any form or by any
* means, electronic, mechanical, photocopying, recording or otherwise,
* except as stated in the end-user licence agreement, without the prior
* permission of the copyright owners.
*
* X/Open and the 'X' symbol are trademarks of X/Open Company Limited in
* the UK and other countries.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
/************************************************************************
SCCS: @(#)tcconf.c 1.8 98/09/01 TETware release 3.3
NAME: tcconf.c
PRODUCT: TETware
AUTHOR: Andrew Dingwall, UniSoft Ltd.
DATE CREATED: May 1992
DESCRIPTION:
functions to send config variables to/from TCCD
MODIFICATIONS:
Andrew Dingwall, UniSoft Ltd., August 1996
added support for per-mode tccd configuration
************************************************************************/
#include <stdio.h>
#include "dtmac.h"
#include "dtmsg.h"
#include "avmsg.h"
#include "valmsg.h"
#include "tet3_config.h"
#include "error.h"
#include "servlib.h"
#include "dtetlib.h"
/* static function declarations */
static int tc_cs PROTOLIST((int, int, char **, int, int));
static int tc_cs2 PROTOLIST((int, int, char **, int, int, int));
static char *tc_csr PROTOLIST((int, int));
/*
** tet_tcconfigv() - send OP_CONFIG messages to TCCD and receive replies
**
** return 0 if successful or -1 on error
*/
int tet_tcconfigv(sysid, lines, nline, mode)
int sysid, nline, mode;
char **lines;
{
return(tc_cs(sysid, OP_CONFIG, lines, nline, mode));
}
/*
** tet_tcsetconf() - send an OP_SETCONF message to TCCD and receive a reply
**
** return 0 if successful or -1 on error
*/
int tet_tcsetconf(sysid, mode)
int sysid, mode;
{
register struct valmsg *mp;
/* ensure that mode is valid */
switch (mode) {
case TC_CONF_BUILD:
case TC_CONF_EXEC:
case TC_CONF_CLEAN:
break;
default:
tet_tcerrno = ER_INVAL;
return(-1);
}
/* get the TCCD message buffer */
if ((mp = (struct valmsg *) tet_tcmsgbuf(sysid, valmsgsz(OP_SETCONF_NVALUE))) == (struct valmsg *) 0) {
tet_tcerrno = ER_ERR;
return(-1);
}
/* construct the message */
mp->vm_nvalue = OP_SETCONF_NVALUE;
VM_MODE(mp) = mode;
return(tc_csr(sysid, OP_SETCONF) == (char *) 0 ? -1 : 0);
}
/*
** tet_tcsndconfv() - send OP_SNDCONF messages to TCCD and receive replies
**
** return 0 if successful or -1 on error
*/
int tet_tcsndconfv(sysid, lines, nline)
int sysid, nline;
char **lines;
{
return(tc_cs(sysid, OP_SNDCONF, lines, nline, 0));
}
/*
** tc_cs() - common function for OP_SNDCONF and OP_CONFIG
*/
static int tc_cs(sysid, request, lines, nline, mode)
int sysid, request, mode;
register char **lines;
register int nline;
{
/* make sure that lines is non-zero and that nline is +ve */
if (!lines || nline <= 0) {
tet_tcerrno = ER_INVAL;
return(-1);
}
/* make sure that OP_CONFIG has a valid mode */
if (request == OP_CONFIG)
switch (mode) {
case TC_CONF_BUILD:
case TC_CONF_EXEC:
case TC_CONF_CLEAN:
break;
default:
tet_tcerrno = ER_INVAL;
return(-1);
}
/* send as many messages as necessary */
while (nline > 0) {
if (tc_cs2(sysid, request, lines, TET_MIN(nline, AV_NLINE),
mode, nline > AV_NLINE ? 0 : 1) < 0)
return(-1);
nline -= AV_NLINE;
lines += AV_NLINE;
}
return(0);
}
/*
** tc_cs2() - send a single OP_CONFIG or OP_SNDCONF message
** and receive a reply
**
** return 0 if successful or -1 on error
*/
static int tc_cs2(sysid, request, lines, nline, mode, done)
int sysid, request, mode, done;
register int nline;
register char **lines;
{
register struct avmsg *mp;
register int n;
/* get the TCCD message buffer */
if ((mp = (struct avmsg *) tet_tcmsgbuf(sysid, avmsgsz(OP_CONF_ARGC(nline)))) == (struct avmsg *) 0) {
tet_tcerrno = ER_ERR;
return(-1);
}
/* set up the request message */
mp->av_argc = OP_CONF_ARGC(nline);
AV_FLAG(mp) = done ? AV_DONE : AV_MORE;
AV_MODE(mp) = mode;
for (n = 0; n < nline; n++)
AV_CLINE(mp, n) = *lines++;
return(tc_csr(sysid, request) == (char *) 0 ? -1 : 0);
}
/*
** tet_tcrcvconfv() - send an OP_RCVCONF message to TCCD and receive a
** reply
**
** return a pointer to the first in a list of received config lines if
** successful, or (char **) 0 on error
**
** if successful, the number of lines in the list is returned indirectly
** through *nlines and *done is set to 0 or 1 depending on whether or not
** there are any more lines to come
**
** the lines and their pointers are held in memory owned by the
** tet_tctalk() subsystem, so they must be copied if required before
** another TCCD request to the same sysid is issued
*/
char **tet_tcrcvconfv(sysid, nlines, done)
int sysid, *nlines, *done;
{
register struct avmsg *rp;
/* make sure that nlines and done are non-zero */
if (!nlines || !done) {
tet_tcerrno = ER_INVAL;
return((char **) 0);
}
if ((rp = (struct avmsg *) tc_csr(sysid, OP_RCVCONF)) == (struct avmsg
*) 0)
return((char **) 0);
/* all ok so return all the return values */
*nlines = (int) OP_CONF_NLINE(rp);
*done = AV_FLAG(rp) == AV_DONE ? 1 : 0;
return(&AV_CLINE(rp, 0));
}
/*
** tc_csr() - common tet_tctalk() interface used by several functions
**
** return pointer to TCCD reply buffer if successful
** or (char *) 0 on error
*/
static char *tc_csr(sysid, request)
int sysid, request;
{
register char *dp;
extern char tet_tcerrmsg[];
/* send the request and receive the reply */
dp = tet_tctalk(sysid, request, TALK_DELAY);
/* handle the return codes */
switch (tet_tcerrno) {
case ER_OK:
return(dp);
case ER_INVAL:
case ER_CONTEXT:
case ER_INPROGRESS:
case ER_DONE:
break;
case ER_ERR:
if (!dp)
break;
/* else fall through */
default:
error(0, tet_tcerrmsg, tet_ptrepcode(tet_tcerrno));
break;
}
/* here for server error return */
return((char *) 0);
}
|