Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "date" on null in /usr/local/www/websvn.planix.org/blame.php on line 247

Warning: Attempt to read property "msg" on null in /usr/local/www/websvn.planix.org/blame.php on line 247
WebSVN – tendra.SVN – Blame – //branches/algol60/src/tools/tspec/name.c – Rev 7

Subversion Repositories tendra.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 7u83 1
/*
7 7u83 2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions are met:
7
 *
8
 * 1. Redistributions of source code must retain the above copyright notice,
9
 *    this list of conditions and the following disclaimer.
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
11
 *    this list of conditions and the following disclaimer in the documentation
12
 *    and/or other materials provided with the distribution.
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
14
 *    may be used to endorse or promote products derived from this software
15
 *    without specific, prior written permission.
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 *
29
 * $Id$
30
 */
31
/*
2 7u83 32
    		 Crown Copyright (c) 1997
7 7u83 33
 
2 7u83 34
    This TenDRA(r) Computer Program is subject to Copyright
35
    owned by the United Kingdom Secretary of State for Defence
36
    acting through the Defence Evaluation and Research Agency
37
    (DERA).  It is made available to Recipients with a
38
    royalty-free licence for its use, reproduction, transfer
39
    to other parties and amendment for any purpose not excluding
40
    product development provided that any such use et cetera
41
    shall be deemed to be acceptance of the following conditions:-
7 7u83 42
 
2 7u83 43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
7 7u83 45
 
2 7u83 46
        (2) Any amended version of it shall be clearly marked to
47
        show both the nature of and the organisation responsible
48
        for the relevant amendment or amendments;
7 7u83 49
 
2 7u83 50
        (3) Its onward transfer from a recipient to another
51
        party shall be deemed to be that party's acceptance of
52
        these conditions;
7 7u83 53
 
2 7u83 54
        (4) DERA gives no warranty or assurance as to its
55
        quality or suitability for any purpose and DERA accepts
56
        no liability whatsoever in relation to any use to which
57
        it may be put.
58
*/
59
 
60
 
61
#include "config.h"
62
#include <ctype.h>
63
#include "object.h"
64
#include "hash.h"
65
#include "name.h"
66
#include "type.h"
67
#include "utility.h"
68
#include "variable.h"
69
 
70
 
71
/*
72
    STANDARD FLAGS
73
 
74
    These flags are set by the command-line options and determine the
75
    action of the program.
76
*/
77
 
7 7u83 78
boolean allow_long_long = 0;
79
boolean force_output = 0;
80
boolean local_input = 0;
81
boolean restrict_depth = 1;
82
boolean restrict_use = 0;
83
boolean unique_names = 0;
84
int verbose = 0;
2 7u83 85
 
86
 
87
/*
88
    FIND THE BASENAME OF A FILE NAME
89
 
90
    This routine returns the basename (i.e. just the final component) of
91
    the filename nm.
92
*/
93
 
7 7u83 94
char *
95
basename(char *nm)
2 7u83 96
{
7 7u83 97
    char *b = nm;
98
    for (; *nm; nm++) {
99
	if (*nm == '/')b = nm + 1;
2 7u83 100
    }
7 7u83 101
    return(b);
2 7u83 102
}
103
 
104
 
105
/*
106
    FIND THE DIRECTORY COMPONENT OF A FILE NAME
107
 
108
    This routine returns a copy of the directory component of the filename
109
    nm.
110
*/
111
 
7 7u83 112
char *
113
dirname(char *nm)
2 7u83 114
{
7 7u83 115
    char *p, *end = null;
116
    char *dir = string_copy(nm);
117
    for (p = dir; *p; p++) {
118
	if (*p == '/')end = p;
2 7u83 119
    }
7 7u83 120
    if (end == null || end == dir) return(null);
121
    *end = 0;
122
    return(dir);
2 7u83 123
}
124
 
125
 
126
/*
127
    FIND A RELATIVE PATHNAME
128
 
129
    This routine prints the relative pathname from the file from to the
130
    file to, ignoring the first n characters.
131
*/
132
 
7 7u83 133
char *
134
relative(char *from, char *to, int n)
2 7u83 135
{
7 7u83 136
    char *s = buffer;
137
    if (from == null) return(to);
138
    if (to == null) return(from);
139
    for (from = from + n; *from; from++) {
140
	if (*from == '/') {
141
	    IGNORE strcpy(s, "../");
142
	    s += 3;
2 7u83 143
	}
144
    }
7 7u83 145
    IGNORE strcpy(s, to + n);
146
    return(buffer);
2 7u83 147
}
148
 
149
 
150
/*
151
    HACK A NAME
152
 
153
    This routine hacks the name nm according to the given key.
154
*/
155
 
7 7u83 156
char *
157
hack_name(char *nm, char *key)
2 7u83 158
{
7 7u83 159
    char *p = string_copy(nm), *q;
160
    for (q = p; *q; q++) {
161
	char c = *q;
162
	if (isalpha(c) && isupper(c)) {
2 7u83 163
	    /* The second letter of key maps upper case letters */
7 7u83 164
	    if (key [1] == 'a')*q = (char)tolower(c);
165
	} else if (isalpha(c) && islower(c)) {
2 7u83 166
	    /* The third letter of key maps lower case letters */
7 7u83 167
	    if (key [2] == 'A')*q = (char)toupper(c);
168
	} else if (isdigit(c)) {
2 7u83 169
	    /* The fourth letter of key maps digits */
7 7u83 170
	    *q = (char)(c - '0' + key [3]);
171
	} else if (strchr(key + 4, c)) {
2 7u83 172
	    /* The rest of key gives special characters */
173
	} else {
174
	    /* The first letter of key is the default */
7 7u83 175
	    *q = key [0];
2 7u83 176
	}
177
    }
7 7u83 178
    return(p);
2 7u83 179
}
180
 
181
 
182
/*
183
    FIND A TOKEN NAME
184
 
185
    This routine makes up a token name for an object named nm.  If
186
    unique_names is false this is just nm, otherwise it is prefixed by
187
    a string depending on the current input file.
188
*/
189
 
7 7u83 190
char *
191
token_name(char *nm)
2 7u83 192
{
7 7u83 193
    if (strneq(nm, HIDDEN_NAME, HIDDEN_LEN)) {
194
	nm = string_concat("~", nm + HIDDEN_LEN);
2 7u83 195
    }
7 7u83 196
    if (unique_names && crt_object) {
197
	info *i = crt_object->u.u_info;
198
	char *pfx = i->prefix;
199
	if (pfx == null) {
200
	    pfx = token_prefix(i->api, i->file, i->subset);
201
	    i->prefix = pfx;
2 7u83 202
	}
7 7u83 203
	if (*pfx) return(string_printf("%s.%s", pfx, nm));
2 7u83 204
    }
7 7u83 205
    return(nm);
2 7u83 206
}
207
 
208
 
209
/*
210
    FIND TOKEN PREFIX
211
 
212
    This routine finds the token prefix for the API subset api:file:subset.
213
*/
214
 
7 7u83 215
char *
216
token_prefix(char *api, char *file, char *subset)
2 7u83 217
{
7 7u83 218
    UNUSED(subset);
219
    if (unique_names) {
220
	int n;
221
	if (file == null) return(api);
222
	IGNORE sprintf(buffer, "%s.%s", api, basename(file));
223
	n = (int)strlen(buffer) - 2;
224
	if (n >= 0 && buffer [n] == '.')buffer [n] = 0;
225
	return(hack_name(buffer, "_Aa0."));
2 7u83 226
    }
7 7u83 227
    return(null);
2 7u83 228
}
229
 
230
 
231
/*
232
    FIND A SUBSET NAME
233
 
234
    This routine finds the name associated with the API subset with API
235
    api, header file and subset subset.
236
*/
237
 
7 7u83 238
char *
239
subset_name(char *api, char *file, char *subset)
2 7u83 240
{
7 7u83 241
    char *sn;
242
    if (subset) {
243
	char *f = (file ? file : "");
244
	sn = string_printf("%s:%s:%s", api, f, subset);
245
    } else if (file) {
246
	sn = string_printf("%s:%s", api, file);
2 7u83 247
    } else {
7 7u83 248
	sn = string_printf("%s", api);
2 7u83 249
    }
7 7u83 250
    return(sn);
2 7u83 251
}
252
 
253
 
254
/*
255
    FIND AN INCLUDE OUTPUT FILE NAME
256
 
257
    This routine finds the include output file name for the API subset
258
    api:file:subset using the directory dir as a base.
259
*/
260
 
7 7u83 261
char *
262
include_name(char *dir, char *api, char *file, char *subset)
2 7u83 263
{
7 7u83 264
    char *nm;
265
    if (subset) {
266
	char s [20];
267
	IGNORE strncpy(s, subset, 18);
268
	s [ OUTPUT_LENGTH ] = 0;
269
	nm = string_printf(OUTPUT_SUBSET, dir, api, s);
270
    } else if (file) {
271
	nm = string_printf(OUTPUT_FILE, dir, api, file);
2 7u83 272
    } else {
7 7u83 273
	nm = string_printf(OUTPUT_API, dir, api);
2 7u83 274
    }
7 7u83 275
    return(nm);
2 7u83 276
}
277
 
278
 
279
/*
280
    FIND A SOURCE OUTPUT FILE NAME
281
 
282
    This routine finds the source output file name for the API subset
283
    api:file:subset using the directory dir as a base.
284
*/
285
 
7 7u83 286
char *
287
src_name(char *dir, char *api, char *file, char *subset)
2 7u83 288
{
7 7u83 289
    char *nm;
290
    if (subset) {
291
	char s [20];
292
	IGNORE strncpy(s, subset, 18);
293
	s [ OUTPUT_LENGTH ] = 0;
294
	nm = string_printf(SOURCE_SUBSET, dir, api, s);
295
    } else if (file) {
296
	int n;
297
	nm = string_printf(SOURCE_FILE, dir, api, basename(file));
298
	n = (int)strlen(nm) - 4;
299
	if (n >= 0 && streq(nm + n, ".h.c")) {
300
	    IGNORE strcpy(nm + n, ".c");
2 7u83 301
	}
302
    } else {
7 7u83 303
	nm = string_printf(SOURCE_API, dir, api);
2 7u83 304
    }
7 7u83 305
    return(nm);
2 7u83 306
}
307
 
308
 
309
/*
310
    FIND A MACRO NAME
311
 
312
    This routine finds the protection (or other) macro for the API subset
313
    api:file:subset using the macro prefix pfx.
314
*/
315
 
7 7u83 316
char *
317
macro_name(char *pfx, char *api, char *file, char *subset)
2 7u83 318
{
7 7u83 319
    if (subset) {
320
	char *f = (file ? file : "");
321
	IGNORE sprintf(buffer, "%s_%s_%s_%s", pfx, api, f, subset);
322
    } else if (file) {
323
	IGNORE sprintf(buffer, "%s_%s_%s", pfx, api, file);
2 7u83 324
    } else {
7 7u83 325
	IGNORE sprintf(buffer, "%s_%s", pfx, api);
2 7u83 326
    }
7 7u83 327
    return(hack_name(buffer, "_AA0"));
2 7u83 328
}
329
 
330
 
331
/*
332
    FIND A DECLARATION BLOCK NAME
333
 
334
    This routine finds the declaration block name for the API subset
335
    api:file:subset.
336
*/
337
 
7 7u83 338
char *
339
block_name(char *api, char *file, char *subset)
2 7u83 340
{
7 7u83 341
    char * pfx = (subset ? "subset" : "api");
342
    if (file) {
2 7u83 343
	int len;
7 7u83 344
	IGNORE sprintf(buffer, "%s__%s__%s", pfx, api, file);
2 7u83 345
	/* remove any trailing ".h" */
7 7u83 346
	len = (int)strlen(buffer);
347
	if (streq(buffer + len - 2, ".h"))
348
	    buffer [ len - 2 ] = '\0';
2 7u83 349
    } else {
7 7u83 350
	IGNORE sprintf(buffer, "%s__%s", pfx, api);
2 7u83 351
    }
7 7u83 352
    return(hack_name(buffer, "_Aa0"));
2 7u83 353
}