Subversion Repositories tendra.SVN

Rev

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

Rev 5 Rev 6
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 30... Line 60...
30
 
60
 
31
#include "config.h"
61
#include "config.h"
32
#include "types.h"
62
#include "types.h"
33
#include "read_types.h"
63
#include "read_types.h"
34
#include "analyser.h"
64
#include "analyser.h"
-
 
65
#include "help.h"
35
#include "node.h"
66
#include "node.h"
36
#include "table.h"
67
#include "table.h"
37
#include "tdf.h"
68
#include "tdf.h"
38
#include "utility.h"
69
#include "utility.h"
39
 
70
 
Line 42... Line 73...
42
    FLAG
73
    FLAG
43
 
74
 
44
    Should help information be printed in functional form?
75
    Should help information be printed in functional form?
45
*/
76
*/
46
 
77
 
47
boolean func_help = 0 ;
78
boolean func_help = 0;
48
 
79
 
49
 
80
 
50
/*
81
/*
51
    PRINT A LIST OF ARGUMENTS
82
    PRINT A LIST OF ARGUMENTS
52
 
83
 
53
    This routine prints the arguments corresponding to the argument
84
    This routine prints the arguments corresponding to the argument
54
    string str.  The flag num is true to indicate an actual TDF
85
    string str.  The flag num is true to indicate an actual TDF
55
    integer, rather than the identifier for a tag, token etc.
86
    integer, rather than the identifier for a tag, token etc.
56
*/
87
*/
57
 
88
 
58
static void help_args
89
static void
59
    PROTO_N ( ( str, num ) )
-
 
60
    PROTO_T ( char *str X boolean num )
90
help_args(char *str, boolean num)
61
{
91
{
62
    char c ;
92
    char c;
63
    boolean started = 0 ;
93
    boolean started = 0;
64
    while ( c = *str, c != 0 && c != ']' ) {
94
    while (c = *str, c != 0 && c != ']') {
65
	if ( func_help && started ) IGNORE putchar ( ',' ) ;
95
	if (func_help && started)IGNORE putchar(',');
66
	switch ( c ) {
96
	switch (c) {
67
 
97
 
68
	    case '[' :
98
	    case '[':
69
	    case '{' :
99
	    case '{':
70
	    case '}' :
100
	    case '}':
71
	    case '&' :
101
	    case '&':
72
	    case '^' :
102
	    case '^':
73
	    case '|' : {
103
	    case '|': {
74
		/* Ignore these cases */
104
		/* Ignore these cases */
75
		break ;
105
		break;
76
	    }
106
	    }
77
 
107
 
78
	    case 'i' : {
108
	    case 'i': {
79
		/* Numbers or identifiers */
109
		/* Numbers or identifiers */
80
		if ( num ) {
110
		if (num) {
81
		    IGNORE printf ( " number" ) ;
111
		    IGNORE printf(" number");
82
		} else {
112
		} else {
83
		    IGNORE printf ( " identifier" ) ;
113
		    IGNORE printf(" identifier");
84
		}
114
		}
85
		break ;
115
		break;
86
	    }
116
	    }
87
 
117
 
88
	    case 'j' : {
118
	    case 'j': {
89
		/* Ignore bits */
119
		/* Ignore bits */
90
		break ;
120
		break;
91
	    }
121
	    }
92
 
122
 
93
	    case '$' : {
123
	    case '$': {
94
		/* Strings */
124
		/* Strings */
95
		IGNORE printf ( " tdfstring" ) ;
125
		IGNORE printf(" tdfstring");
96
		break ;
126
		break;
97
	    }
127
	    }
98
 
128
 
99
	    case '*' : {
129
	    case '*': {
100
		/* Repeated arguments */
130
		/* Repeated arguments */
101
		str += 2 ;
131
		str += 2;
102
		help_args ( str, 0 ) ;
132
		help_args(str, 0);
103
		if ( func_help ) {
133
		if (func_help) {
104
		    IGNORE printf ( ", ...," ) ;
134
		    IGNORE printf(", ...,");
105
		} else {
135
		} else {
106
		    IGNORE printf ( " ..." ) ;
136
		    IGNORE printf(" ...");
107
		}
137
		}
108
		help_args ( str, 0 ) ;
138
		help_args(str, 0);
109
		str = skip_text ( str ) ;
139
		str = skip_text(str);
110
		break ;
140
		break;
111
	    }
141
	    }
112
 
142
 
113
	    case '?' : {
143
	    case '?': {
114
		/* Optional arguments */
144
		/* Optional arguments */
115
		str += 2 ;
145
		str += 2;
116
		IGNORE printf ( " [" ) ;
146
		IGNORE printf(" [");
117
		help_args ( str, 0 ) ;
147
		help_args(str, 0);
118
		IGNORE printf ( " ]" ) ;
148
		IGNORE printf(" ]");
119
		str = skip_text ( str ) ;
149
		str = skip_text(str);
120
		break ;
150
		break;
121
	    }
151
	    }
122
 
152
 
123
	    case '@' : {
153
	    case '@': {
124
		/* Conditional arguments */
154
		/* Conditional arguments */
125
		str += 2 ;
155
		str += 2;
126
		help_args ( str, 0 ) ;
156
		help_args(str, 0);
127
		str = skip_text ( str ) ;
157
		str = skip_text(str);
128
		break ;
158
		break;
129
	    }
159
	    }
130
 
160
 
131
	    case '!' : {
161
	    case '!': {
132
		/* Token applications */
162
		/* Token applications */
133
		if ( func_help ) {
163
		if (func_help) {
134
		    IGNORE printf ( " identifier ( arg, ..., arg )" ) ;
164
		    IGNORE printf(" identifier ( arg, ..., arg )");
135
		} else {
165
		} else {
136
		    IGNORE printf ( " ( identifier arg ... arg )" ) ;
166
		    IGNORE printf(" ( identifier arg ... arg )");
137
		}
167
		}
138
		break ;
168
		break;
139
	    }
169
	    }
140
 
170
 
141
	    case 'F' : {
171
	    case 'F': {
142
		is_fatal = 0 ;
172
		is_fatal = 0;
143
		input_error ( "Foreign sorts not supported" ) ;
173
		input_error("Foreign sorts not supported");
144
		break ;
174
		break;
145
	    }
175
	    }
146
 
176
 
147
	    default : {
177
	    default : {
148
		sortname s = find_sort ( c ) ;
178
		sortname s = find_sort(c);
149
		IGNORE printf ( " %s", sort_name ( s ) ) ;
179
		IGNORE printf(" %s", sort_name(s));
150
		break ;
180
		break;
151
	    }
181
	    }
152
	}
182
	}
153
	if ( c != 'j' ) started = 1 ;
183
	if (c != 'j')started = 1;
154
	str++ ;
184
	str++;
155
    }
185
    }
156
    return ;
186
    return;
157
}
187
}
158
 
188
 
159
 
189
 
160
/*
190
/*
161
    OUTPUT HELP INFORMATION
191
    OUTPUT HELP INFORMATION
162
 
192
 
163
    The help information on the construct p is output.
193
    The help information on the construct p is output.
164
*/
194
*/
165
 
195
 
166
static void output_help
196
static void
167
    PROTO_N ( ( p ) )
-
 
168
    PROTO_T ( construct *p )
197
output_help(construct *p)
169
{
198
{
170
    char *args = get_char_info ( p ) ;
199
    char *args = get_char_info(p);
171
    IGNORE printf ( ( func_help ? "%s" : "( %s" ), p->name ) ;
200
    IGNORE printf((func_help ? "%s" : "( %s"), p->name);
172
    if ( args ) {
201
    if (args) {
173
	boolean num = 0 ;
202
	boolean num = 0;
174
	if ( ( p->sortnum == SORT_nat && p->encoding == ENC_make_nat ) ||
203
	if ((p->sortnum == SORT_nat && p->encoding == ENC_make_nat) ||
175
	     ( p->sortnum == SORT_signed_nat &&
204
	    (p->sortnum == SORT_signed_nat &&
176
	       p->encoding == ENC_make_signed_nat ) ) {
205
	       p->encoding == ENC_make_signed_nat)) {
177
	    num = 1 ;
206
	    num = 1;
178
	}
207
	}
179
	if ( func_help ) IGNORE printf ( " (" ) ;
208
	if (func_help)IGNORE printf(" (");
180
	help_args ( args, num ) ;
209
	help_args(args, num);
181
	if ( func_help ) IGNORE printf ( " )" ) ;
210
	if (func_help)IGNORE printf(" )");
182
    }
211
    }
183
    if ( !func_help ) IGNORE printf ( " )" ) ;
212
    if (!func_help)IGNORE printf(" )");
184
    IGNORE printf ( " -> %s\n", sort_name ( p->sortnum ) ) ;
213
    IGNORE printf(" -> %s\n", sort_name(p->sortnum));
185
    return ;
214
    return;
186
}
215
}
187
 
216
 
188
 
217
 
189
/*
218
/*
190
    PRINT HELP ON A TDF CONSTRUCT
219
    PRINT HELP ON A TDF CONSTRUCT
191
 
220
 
192
    The help information on the construct named nm is output.
221
    The help information on the construct named nm is output.
193
*/
222
*/
194
 
223
 
195
void help
224
void
196
    PROTO_N ( ( nm ) )
-
 
197
    PROTO_T ( char *nm )
225
help(char *nm)
198
{
226
{
199
    sortname s ;
227
    sortname s;
200
    construct *p ;
228
    construct *p;
201
    static int sorted = 0 ;
229
    static int sorted = 0;
202
    func_help = func_input ;
230
    func_help = func_input;
203
 
231
 
204
    /* Check for "help all" */
232
    /* Check for "help all" */
205
    if ( streq ( nm, "all" ) ) {
233
    if (streq(nm, "all")) {
206
	for ( s = 0 ; s < SORT_no ; s++ ) {
234
	for (s = 0; s < SORT_no; s++) {
207
	    if ( s != SORT_sortname ) {
235
	    if (s != SORT_sortname) {
208
		sort_table ( cons_hash_tables, s ) ;
236
		sort_table(cons_hash_tables, s);
209
		sorted = 1 ;
237
		sorted = 1;
210
		p = cons_hash_tables [ hash_size * s ] ;
238
		p = cons_hash_tables[hash_size * s];
211
		if ( p ) {
239
		if (p) {
212
		    for ( ; p ; p = p->next ) output_help ( p ) ;
240
		    for (; p; p = p->next)output_help(p);
213
		    IGNORE printf ( "\n" ) ;
241
		    IGNORE printf("\n");
214
		}
242
		}
215
	    }
243
	    }
216
	}
244
	}
217
	return ;
245
	return;
218
    }
246
    }
219
 
247
 
220
    /* Check for "help construct" */
248
    /* Check for "help construct" */
221
    for ( s = 0 ; s < SORT_no ; s++ ) {
249
    for (s = 0; s < SORT_no; s++) {
222
	if ( s != SORT_sortname ) {
250
	if (s != SORT_sortname) {
223
	    p = search_cons_hash ( nm, s ) ;
251
	    p = search_cons_hash(nm, s);
224
	    if ( p ) {
252
	    if (p) {
225
		output_help ( p ) ;
253
		output_help(p);
226
		return ;
254
		return;
227
	    }
255
	    }
228
	    if ( sorted ) {
256
	    if (sorted) {
229
		p = cons_hash_tables [ hash_size * s ] ;
257
		p = cons_hash_tables[hash_size * s];
230
		for ( ; p ; p = p->next ) {
258
		for (; p; p = p->next) {
231
		    if ( streq ( nm, p->name ) ) {
259
		    if (streq(nm, p->name)) {
232
			output_help ( p ) ;
260
			output_help(p);
233
			return ;
261
			return;
234
		    }
262
		    }
235
		}
263
		}
236
	    }
264
	    }
237
	}
265
	}
238
    }
266
    }
239
 
267
 
240
    /* Check for "help sort" */
268
    /* Check for "help sort" */
241
    if ( streq ( nm, "alignment_sort" ) ) nm = "alignment" ;
269
    if (streq(nm, "alignment_sort"))nm = "alignment";
242
    p = search_cons_hash ( nm, SORT_sortname ) ;
270
    p = search_cons_hash(nm, SORT_sortname);
243
    if ( p ) {
271
    if (p) {
244
	s = ( sortname ) p->encoding ;
272
	s = (sortname)p->encoding;
245
	sort_table ( cons_hash_tables, s ) ;
273
	sort_table(cons_hash_tables, s);
246
	sorted = 1 ;
274
	sorted = 1;
247
	p = cons_hash_tables [ hash_size * s ] ;
275
	p = cons_hash_tables[hash_size * s];
248
	for ( ; p ; p = p->next ) output_help ( p ) ;
276
	for (; p; p = p->next)output_help(p);
249
	return ;
277
	return;
250
    }
278
    }
251
 
279
 
252
    /* Unknown construct */
280
    /* Unknown construct */
253
    is_fatal = 0 ;
281
    is_fatal = 0;
254
    input_error ( "Unknown construct, %s", nm ) ;
282
    input_error("Unknown construct, %s", nm);
255
    return ;
283
    return;
256
}
284
}