Subversion Repositories tendra.SVN

Rev

Rev 2 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
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
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 62... Line 92...
62
#include "type.h"
92
#include "type.h"
63
 
93
 
64
/*--------------------------------------------------------------------------*/
94
/*--------------------------------------------------------------------------*/
65
 
95
 
66
static void
96
static void
67
write_c_key PROTO_N ((ostream, contents, length))
97
write_c_key(OStreamP ostream, CStringP contents, unsigned length)
68
	    PROTO_T (OStreamP ostream X
-
 
69
		     CStringP contents X
-
 
70
		     unsigned length)
-
 
71
{
98
{
72
    while (length --) {
99
    while (length --) {
73
	char c;
100
	char c;
74
 
101
 
75
	switch (c = *contents ++) {
102
	switch (c = *contents++) {
76
	  case '-':
103
	  case '-':
77
	    write_cstring (ostream, "_H");
104
	    write_cstring(ostream, "_H");
78
	    break;
105
	    break;
79
	  case '_':
106
	  case '_':
80
	    write_cstring (ostream, "__");
107
	    write_cstring(ostream, "__");
81
	    break;
108
	    break;
82
	  case ':':
109
	  case ':':
83
	    write_cstring (ostream, "_C");
110
	    write_cstring(ostream, "_C");
84
	    break;
111
	    break;
85
	  default:
112
	  default:
86
	    if ((syntax_is_letter (c)) || (syntax_is_digit (c))) {
113
	    if ((syntax_is_letter(c)) || (syntax_is_digit(c))) {
87
		write_char (ostream, c);
114
		write_char(ostream, c);
88
	    } else {
115
	    } else {
89
		write_cstring (ostream, "_X");
116
		write_cstring(ostream, "_X");
90
		write_unsigned (ostream, (unsigned) (unsigned char) c);
117
		write_unsigned(ostream, (unsigned)(unsigned char)c);
91
		write_char (ostream, '_');
118
		write_char(ostream, '_');
92
	    }
119
	    }
93
	    break;
120
	    break;
94
	}
121
	}
95
    }
122
    }
96
}
123
}
97
 
124
 
98
/*--------------------------------------------------------------------------*/
125
/*--------------------------------------------------------------------------*/
99
 
126
 
100
void
127
void
101
c_output_mapped_key PROTO_N ((info, entry))
128
c_output_mapped_key(COutputInfoP info, EntryP entry)
102
		    PROTO_T (COutputInfoP info X
-
 
103
			     EntryP       entry)
-
 
104
{
129
{
105
    OStreamP ostream = c_out_info_ostream (info);
130
    OStreamP ostream = c_out_info_ostream(info);
106
    NStringP mapping = entry_get_mapping (entry);
131
    NStringP mapping = entry_get_mapping(entry);
107
    BoolT    strict  = c_out_info_get_numeric_ids (info);
132
    BoolT    strict  = c_out_info_get_numeric_ids(info);
108
 
133
 
109
    if (mapping) {
134
    if (mapping) {
110
	write_nstring (ostream, mapping);
135
	write_nstring(ostream, mapping);
111
    } else {
136
    } else {
112
	KeyP     key    = entry_key (entry);
137
	KeyP     key    = entry_key(entry);
113
	NStringP prefix;
138
	NStringP prefix;
114
 
139
 
115
	switch (entry_type (entry)) EXHAUSTIVE {
140
	switch (entry_type(entry))EXHAUSTIVE {
116
	  case ET_TYPE:
141
	  case ET_TYPE:
117
	    prefix = c_out_info_type_prefix (info);
142
	    prefix = c_out_info_type_prefix(info);
118
	    break;
143
	    break;
119
	  case ET_RULE:
144
	  case ET_RULE:
120
	    prefix = c_out_info_fn_prefix (info);
145
	    prefix = c_out_info_fn_prefix(info);
121
	    break;
146
	    break;
122
	  case ET_BASIC:
147
	  case ET_BASIC:
123
	    prefix = c_out_info_terminal_prefix (info);
148
	    prefix = c_out_info_terminal_prefix(info);
124
	    strict = FALSE;
149
	    strict = FALSE;
125
	    break;
150
	    break;
126
	  case ET_NON_LOCAL:
151
	  case ET_NON_LOCAL:
127
	    prefix = c_out_info_in_prefix (info);
152
	    prefix = c_out_info_in_prefix(info);
128
	    break;
153
	    break;
129
	  case ET_ACTION:
154
	  case ET_ACTION:
130
	  case ET_NAME:
155
	  case ET_NAME:
131
	  case ET_RENAME:
156
	  case ET_RENAME:
132
	  case ET_PREDICATE:
157
	  case ET_PREDICATE:
133
	    UNREACHED;
158
	    UNREACHED;
134
	}
159
	}
135
	write_nstring (ostream, prefix);
160
	write_nstring(ostream, prefix);
136
	if (key_is_string (key) && (!strict)) {
161
	if (key_is_string(key) && (!strict)) {
137
	    NStringP nstring = key_get_string (key);
162
	    NStringP nstring = key_get_string(key);
138
 
163
 
139
	    write_c_key (ostream, nstring_contents (nstring),
164
	    write_c_key(ostream, nstring_contents(nstring),
140
			 nstring_length (nstring));
165
			nstring_length(nstring));
141
	} else {
166
	} else {
142
	    write_unsigned (ostream, key_get_number (key));
167
	    write_unsigned(ostream, key_get_number(key));
143
	}
168
	}
144
    }
169
    }
145
}
170
}
146
 
171
 
147
void
172
void
148
c_output_key PROTO_N ((info, key, prefix))
173
c_output_key(COutputInfoP info, KeyP key, NStringP prefix)
149
	     PROTO_T (COutputInfoP info X
-
 
150
		      KeyP         key X
-
 
151
		      NStringP     prefix)
-
 
152
{
174
{
153
    OStreamP ostream = c_out_info_ostream (info);
175
    OStreamP ostream = c_out_info_ostream(info);
154
    BoolT    strict  = c_out_info_get_numeric_ids (info);
176
    BoolT    strict  = c_out_info_get_numeric_ids(info);
155
 
177
 
156
    write_nstring (ostream, prefix);
178
    write_nstring(ostream, prefix);
157
    if (key_is_string (key) && (!strict)) {
179
    if (key_is_string(key) && (!strict)) {
158
	NStringP nstring = key_get_string (key);
180
	NStringP nstring = key_get_string(key);
159
 
181
 
160
	write_c_key (ostream, nstring_contents (nstring),
182
	write_c_key(ostream, nstring_contents(nstring),
161
		     nstring_length (nstring));
183
		    nstring_length(nstring));
162
    } else {
184
    } else {
163
	write_unsigned (ostream, key_get_number (key));
185
	write_unsigned(ostream, key_get_number(key));
164
    }
186
    }
165
}
187
}
166
 
188
 
167
void
189
void
168
c_output_label_key PROTO_N ((info, key, label))
190
c_output_label_key(COutputInfoP info, KeyP key, unsigned label)
169
		   PROTO_T (COutputInfoP info X
-
 
170
			    KeyP         key X
-
 
171
			    unsigned     label)
-
 
172
{
191
{
173
    OStreamP ostream = c_out_info_ostream (info);
192
    OStreamP ostream = c_out_info_ostream(info);
174
    NStringP prefix  = c_out_info_label_prefix (info);
193
    NStringP prefix  = c_out_info_label_prefix(info);
175
    BoolT    strict  = c_out_info_get_numeric_ids (info);
194
    BoolT    strict  = c_out_info_get_numeric_ids(info);
176
 
195
 
177
    write_nstring (ostream, prefix);
196
    write_nstring(ostream, prefix);
178
    write_unsigned (ostream, label);
197
    write_unsigned(ostream, label);
179
    write_char (ostream, '_');
198
    write_char(ostream, '_');
180
    if (key_is_string (key) && (!strict)) {
199
    if (key_is_string(key) && (!strict)) {
181
	NStringP nstring = key_get_string (key);
200
	NStringP nstring = key_get_string(key);
182
 
201
 
183
	write_c_key (ostream, nstring_contents (nstring),
202
	write_c_key(ostream, nstring_contents(nstring),
184
		     nstring_length (nstring));
203
		    nstring_length(nstring));
185
    } else {
204
    } else {
186
	write_unsigned (ostream, key_get_number (key));
205
	write_unsigned(ostream, key_get_number(key));
187
    }
206
    }
188
}
207
}
189

208

190
/*
209
/*
191
 * Local variables(smf):
210
 * Local variables(smf):