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/tendra5-amd64/src/utilities/sid/c-out-key.c – Rev 6

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
/*
6 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
6 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:-
6 7u83 42
 
2 7u83 43
        (1) Its Recipients shall ensure that this Notice is
44
        reproduced upon any copies or amended versions of it;
6 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;
6 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;
6 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
/*** c-out-key.c --- Output of key ADT objects.
62
 *
63
 ** Author: Steve Folkes <smf@hermes.mod.uk>
64
 *
65
 *** Commentary:
66
 *
67
 * This file implements the identifier key output routines used by SID.
68
 *
69
 *** Change Log:
70
 * $Log: c-out-key.c,v $
71
 * Revision 1.1.1.1  1998/01/17  15:57:43  release
72
 * First version to be checked into rolling release.
73
 *
74
 * Revision 1.2  1994/12/15  09:56:31  smf
75
 * Brought into line with OSSG C Coding Standards Document, as per
76
 * "CR94_178.sid+tld-update".
77
 *
78
 * Revision 1.1.1.1  1994/07/25  16:04:19  smf
79
 * Initial import of SID 1.8 non shared files.
80
 *
81
**/
82
 
83
/****************************************************************************/
84
 
85
#include "c-out-key.h"
86
#include "action.h"
87
#include "basic.h"
88
#include "name.h"
89
#include "rstack.h"
90
#include "rule.h"
91
#include "syntax.h"
92
#include "type.h"
93
 
94
/*--------------------------------------------------------------------------*/
95
 
96
static void
6 7u83 97
write_c_key(OStreamP ostream, CStringP contents, unsigned length)
2 7u83 98
{
99
    while (length --) {
100
	char c;
101
 
6 7u83 102
	switch (c = *contents++) {
2 7u83 103
	  case '-':
6 7u83 104
	    write_cstring(ostream, "_H");
2 7u83 105
	    break;
106
	  case '_':
6 7u83 107
	    write_cstring(ostream, "__");
2 7u83 108
	    break;
109
	  case ':':
6 7u83 110
	    write_cstring(ostream, "_C");
2 7u83 111
	    break;
112
	  default:
6 7u83 113
	    if ((syntax_is_letter(c)) || (syntax_is_digit(c))) {
114
		write_char(ostream, c);
2 7u83 115
	    } else {
6 7u83 116
		write_cstring(ostream, "_X");
117
		write_unsigned(ostream, (unsigned)(unsigned char)c);
118
		write_char(ostream, '_');
2 7u83 119
	    }
120
	    break;
121
	}
122
    }
123
}
124
 
125
/*--------------------------------------------------------------------------*/
126
 
127
void
6 7u83 128
c_output_mapped_key(COutputInfoP info, EntryP entry)
2 7u83 129
{
6 7u83 130
    OStreamP ostream = c_out_info_ostream(info);
131
    NStringP mapping = entry_get_mapping(entry);
132
    BoolT    strict  = c_out_info_get_numeric_ids(info);
2 7u83 133
 
134
    if (mapping) {
6 7u83 135
	write_nstring(ostream, mapping);
2 7u83 136
    } else {
6 7u83 137
	KeyP     key    = entry_key(entry);
2 7u83 138
	NStringP prefix;
139
 
6 7u83 140
	switch (entry_type(entry))EXHAUSTIVE {
2 7u83 141
	  case ET_TYPE:
6 7u83 142
	    prefix = c_out_info_type_prefix(info);
2 7u83 143
	    break;
144
	  case ET_RULE:
6 7u83 145
	    prefix = c_out_info_fn_prefix(info);
2 7u83 146
	    break;
147
	  case ET_BASIC:
6 7u83 148
	    prefix = c_out_info_terminal_prefix(info);
2 7u83 149
	    strict = FALSE;
150
	    break;
151
	  case ET_NON_LOCAL:
6 7u83 152
	    prefix = c_out_info_in_prefix(info);
2 7u83 153
	    break;
154
	  case ET_ACTION:
155
	  case ET_NAME:
156
	  case ET_RENAME:
157
	  case ET_PREDICATE:
158
	    UNREACHED;
159
	}
6 7u83 160
	write_nstring(ostream, prefix);
161
	if (key_is_string(key) && (!strict)) {
162
	    NStringP nstring = key_get_string(key);
2 7u83 163
 
6 7u83 164
	    write_c_key(ostream, nstring_contents(nstring),
165
			nstring_length(nstring));
2 7u83 166
	} else {
6 7u83 167
	    write_unsigned(ostream, key_get_number(key));
2 7u83 168
	}
169
    }
170
}
171
 
172
void
6 7u83 173
c_output_key(COutputInfoP info, KeyP key, NStringP prefix)
2 7u83 174
{
6 7u83 175
    OStreamP ostream = c_out_info_ostream(info);
176
    BoolT    strict  = c_out_info_get_numeric_ids(info);
2 7u83 177
 
6 7u83 178
    write_nstring(ostream, prefix);
179
    if (key_is_string(key) && (!strict)) {
180
	NStringP nstring = key_get_string(key);
2 7u83 181
 
6 7u83 182
	write_c_key(ostream, nstring_contents(nstring),
183
		    nstring_length(nstring));
2 7u83 184
    } else {
6 7u83 185
	write_unsigned(ostream, key_get_number(key));
2 7u83 186
    }
187
}
188
 
189
void
6 7u83 190
c_output_label_key(COutputInfoP info, KeyP key, unsigned label)
2 7u83 191
{
6 7u83 192
    OStreamP ostream = c_out_info_ostream(info);
193
    NStringP prefix  = c_out_info_label_prefix(info);
194
    BoolT    strict  = c_out_info_get_numeric_ids(info);
2 7u83 195
 
6 7u83 196
    write_nstring(ostream, prefix);
197
    write_unsigned(ostream, label);
198
    write_char(ostream, '_');
199
    if (key_is_string(key) && (!strict)) {
200
	NStringP nstring = key_get_string(key);
2 7u83 201
 
6 7u83 202
	write_c_key(ostream, nstring_contents(nstring),
203
		    nstring_length(nstring));
2 7u83 204
    } else {
6 7u83 205
	write_unsigned(ostream, key_get_number(key));
2 7u83 206
    }
207
}
208
 
209
/*
210
 * Local variables(smf):
211
 * eval: (include::add-path-entry "../os-interface" "../library")
212
 * eval: (include::add-path-entry "../transforms" "../output" "../generated")
213
 * end:
214
**/