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
|
/*
* SCCS: @(#)ynstr.c 1.2 (96/11/04)
*
* UniSoft Ltd., London, England
*
* (C) Copyright 1996 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.
* A copy of the end-user licence agreement is contained in the file
* Licence which accompanies this distribution.
*
* 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: @(#)ynstr.c 1.2 96/11/04 TETware release 3.3
NAME: ynstr.c
PRODUCT: TETware
AUTHOR: Andrew Dingwall, UniSoft Ltd.
DATE CREATED: August 1996
DESCRIPTION:
functions associated with tcc's -y and -n command-line options
MODIFICATIONS:
Aaron Plattner, April 2010
Fixed warnings when compiled with GCC's -Wall option.
************************************************************************/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>
#include "dtmac.h"
#include "error.h"
#include "ltoa.h"
#include "dtetlib.h"
#include "tcc.h"
/* the lists of -y and -n strings from the command line */
static char **ylcmd, **nlcmd;
static int Nylcmd, Nnlcmd;
/* the lists of -y and -n strings from the old journal file */
static char **ylojf, **nlojf;
static int Nylojf, Nnlojf;
/* static function declarations */
static void addstr PROTOLIST((char *, char ***, int *));
static char *findstr PROTOLIST((char *, char **, int));
static int instring PROTOLIST((char *, char *));
static void ynstr2 PROTOLIST((char *, char ***, int *));
/*
** yesstr() - store a -y argument from the tcc command line
*/
void yesstr(s, flag)
char *s;
int flag;
{
register char ***spp;
register int *nspp;
/* determine which list to use */
switch (flag) {
case YN_CMDLINE:
spp = &ylcmd;
nspp = &Nylcmd;
break;
case YN_OJFILE:
spp = &ylojf;
nspp = &Nylojf;
break;
default:
/* this "can't happen" */
fatal(0, "unexpected flag value:", tet_i2a(flag));
/* NOTREACHED */
}
ynstr2(s, spp, nspp);
}
/*
** nostr() - store a -n argument from the tcc command line
*/
void nostr(s, flag)
char *s;
{
register char ***spp;
register int *nspp;
/* determine which list to use */
switch (flag) {
case YN_CMDLINE:
spp = &nlcmd;
nspp = &Nnlcmd;
break;
case YN_OJFILE:
spp = &nlojf;
nspp = &Nnlojf;
break;
default:
/* this "can't happen" */
fatal(0, "unexpected flag value:", tet_i2a(flag));
/* NOTREACHED */
}
ynstr2(s, spp, nspp);
}
/*
** ynstr2() - common subroutine for yesstr() and nostr()
*/
static void ynstr2(s, spp, nspp)
char *s, ***spp;
int *nspp;
{
if (s && *s && findstr(s, *spp, *nspp) == (char *) 0)
addstr(s, spp, nspp);
}
/*
** okstr() - see if it OK to process this test case
**
** return 1 if it is or 0 if it isn't
*/
int okstr(s, flag)
char *s;
int flag;
{
register char **sp;
register char **yeslist, **nolist;
register int Nyeslist, Nnolist;
/* determine which lists to use */
switch (flag) {
case YN_CMDLINE:
yeslist = ylcmd;
Nyeslist = Nylcmd;
nolist = nlcmd;
Nnolist = Nnlcmd;
break;
case YN_OJFILE:
yeslist = ylojf;
Nyeslist = Nylojf;
nolist = nlojf;
Nnolist = Nnlojf;
break;
default:
/* this "can't happen" */
fatal(0, "unexpected flag value:", tet_i2a(flag));
/* NOTREACHED */
}
/*
** if no strings have been specified and the string contains one
** of the no strings, don't process the test case
*/
if (Nnolist) {
for (sp = nolist + Nnolist - 1; sp >= nolist; sp--)
if (instring(s, *sp))
break;
if (sp >= nolist)
return(0);
}
/*
** if yes strings have been specified, only process the
** test case if the string contains one of the yes strings
*/
if (Nyeslist) {
for (sp = yeslist + Nyeslist - 1; sp >= yeslist; sp--)
if (instring(s, *sp))
break;
return(sp >= yeslist ? 1 : 0);
}
/*
** here if -y was not specified, and either -n was not specified
** or string did not match any of the no strings
*/
return(1);
}
/*
** instring() - see if s2 appears anywhere within s1
**
** return 1 if it does or 0 if it doesn't
*/
static int instring(s1, s2)
char *s1, *s2;
{
register char *p1, *p2, *p3;
for (p1 = s1; *p1; p1++) {
for (p2 = s2, p3 = p1; *p2 && *p3; p2++, p3++)
if (*p2 != *p3)
break;
if (!*p2)
return(1);
}
return(0);
}
/*
** findstr() - find a string in a string list and return a
** pointer thereto
**
** return (char *) 0 if the string is not in the list
*/
static char *findstr(s, sp, nsp)
char *s;
register char **sp;
register int nsp;
{
while (--nsp >= 0)
if (!strcmp(s, *sp))
return(*sp);
else
sp++;
return((char *) 0);
}
/*
** addstr() - add a string to the end of a string list
*/
static void addstr(s, spp, nspp)
char *s, ***spp;
int *nspp;
{
int len = *nspp * sizeof **spp;
RBUFCHK((char **) spp, &len, (*nspp + 1) * (int) sizeof **spp);
*(*spp + (*nspp)++) = rstrstore(s);
}
|