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/tnc/help.c – Rev 2

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
/*
2
    		 Crown Copyright (c) 1997
3
 
4
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
12
 
13
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
15
 
16
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
19
 
20
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
22
        these conditions;
23
 
24
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
27
        it may be put.
28
*/
29
 
30
 
31
#include "config.h"
32
#include "types.h"
33
#include "read_types.h"
34
#include "analyser.h"
35
#include "node.h"
36
#include "table.h"
37
#include "tdf.h"
38
#include "utility.h"
39
 
40
 
41
/*
42
    FLAG
43
 
44
    Should help information be printed in functional form?
45
*/
46
 
47
boolean func_help = 0 ;
48
 
49
 
50
/*
51
    PRINT A LIST OF ARGUMENTS
52
 
53
    This routine prints the arguments corresponding to the argument
54
    string str.  The flag num is true to indicate an actual TDF
55
    integer, rather than the identifier for a tag, token etc.
56
*/
57
 
58
static void help_args
59
    PROTO_N ( ( str, num ) )
60
    PROTO_T ( char *str X boolean num )
61
{
62
    char c ;
63
    boolean started = 0 ;
64
    while ( c = *str, c != 0 && c != ']' ) {
65
	if ( func_help && started ) IGNORE putchar ( ',' ) ;
66
	switch ( c ) {
67
 
68
	    case '[' :
69
	    case '{' :
70
	    case '}' :
71
	    case '&' :
72
	    case '^' :
73
	    case '|' : {
74
		/* Ignore these cases */
75
		break ;
76
	    }
77
 
78
	    case 'i' : {
79
		/* Numbers or identifiers */
80
		if ( num ) {
81
		    IGNORE printf ( " number" ) ;
82
		} else {
83
		    IGNORE printf ( " identifier" ) ;
84
		}
85
		break ;
86
	    }
87
 
88
	    case 'j' : {
89
		/* Ignore bits */
90
		break ;
91
	    }
92
 
93
	    case '$' : {
94
		/* Strings */
95
		IGNORE printf ( " tdfstring" ) ;
96
		break ;
97
	    }
98
 
99
	    case '*' : {
100
		/* Repeated arguments */
101
		str += 2 ;
102
		help_args ( str, 0 ) ;
103
		if ( func_help ) {
104
		    IGNORE printf ( ", ...," ) ;
105
		} else {
106
		    IGNORE printf ( " ..." ) ;
107
		}
108
		help_args ( str, 0 ) ;
109
		str = skip_text ( str ) ;
110
		break ;
111
	    }
112
 
113
	    case '?' : {
114
		/* Optional arguments */
115
		str += 2 ;
116
		IGNORE printf ( " [" ) ;
117
		help_args ( str, 0 ) ;
118
		IGNORE printf ( " ]" ) ;
119
		str = skip_text ( str ) ;
120
		break ;
121
	    }
122
 
123
	    case '@' : {
124
		/* Conditional arguments */
125
		str += 2 ;
126
		help_args ( str, 0 ) ;
127
		str = skip_text ( str ) ;
128
		break ;
129
	    }
130
 
131
	    case '!' : {
132
		/* Token applications */
133
		if ( func_help ) {
134
		    IGNORE printf ( " identifier ( arg, ..., arg )" ) ;
135
		} else {
136
		    IGNORE printf ( " ( identifier arg ... arg )" ) ;
137
		}
138
		break ;
139
	    }
140
 
141
	    case 'F' : {
142
		is_fatal = 0 ;
143
		input_error ( "Foreign sorts not supported" ) ;
144
		break ;
145
	    }
146
 
147
	    default : {
148
		sortname s = find_sort ( c ) ;
149
		IGNORE printf ( " %s", sort_name ( s ) ) ;
150
		break ;
151
	    }
152
	}
153
	if ( c != 'j' ) started = 1 ;
154
	str++ ;
155
    }
156
    return ;
157
}
158
 
159
 
160
/*
161
    OUTPUT HELP INFORMATION
162
 
163
    The help information on the construct p is output.
164
*/
165
 
166
static void output_help
167
    PROTO_N ( ( p ) )
168
    PROTO_T ( construct *p )
169
{
170
    char *args = get_char_info ( p ) ;
171
    IGNORE printf ( ( func_help ? "%s" : "( %s" ), p->name ) ;
172
    if ( args ) {
173
	boolean num = 0 ;
174
	if ( ( p->sortnum == SORT_nat && p->encoding == ENC_make_nat ) ||
175
	     ( p->sortnum == SORT_signed_nat &&
176
	       p->encoding == ENC_make_signed_nat ) ) {
177
	    num = 1 ;
178
	}
179
	if ( func_help ) IGNORE printf ( " (" ) ;
180
	help_args ( args, num ) ;
181
	if ( func_help ) IGNORE printf ( " )" ) ;
182
    }
183
    if ( !func_help ) IGNORE printf ( " )" ) ;
184
    IGNORE printf ( " -> %s\n", sort_name ( p->sortnum ) ) ;
185
    return ;
186
}
187
 
188
 
189
/*
190
    PRINT HELP ON A TDF CONSTRUCT
191
 
192
    The help information on the construct named nm is output.
193
*/
194
 
195
void help
196
    PROTO_N ( ( nm ) )
197
    PROTO_T ( char *nm )
198
{
199
    sortname s ;
200
    construct *p ;
201
    static int sorted = 0 ;
202
    func_help = func_input ;
203
 
204
    /* Check for "help all" */
205
    if ( streq ( nm, "all" ) ) {
206
	for ( s = 0 ; s < SORT_no ; s++ ) {
207
	    if ( s != SORT_sortname ) {
208
		sort_table ( cons_hash_tables, s ) ;
209
		sorted = 1 ;
210
		p = cons_hash_tables [ hash_size * s ] ;
211
		if ( p ) {
212
		    for ( ; p ; p = p->next ) output_help ( p ) ;
213
		    IGNORE printf ( "\n" ) ;
214
		}
215
	    }
216
	}
217
	return ;
218
    }
219
 
220
    /* Check for "help construct" */
221
    for ( s = 0 ; s < SORT_no ; s++ ) {
222
	if ( s != SORT_sortname ) {
223
	    p = search_cons_hash ( nm, s ) ;
224
	    if ( p ) {
225
		output_help ( p ) ;
226
		return ;
227
	    }
228
	    if ( sorted ) {
229
		p = cons_hash_tables [ hash_size * s ] ;
230
		for ( ; p ; p = p->next ) {
231
		    if ( streq ( nm, p->name ) ) {
232
			output_help ( p ) ;
233
			return ;
234
		    }
235
		}
236
	    }
237
	}
238
    }
239
 
240
    /* Check for "help sort" */
241
    if ( streq ( nm, "alignment_sort" ) ) nm = "alignment" ;
242
    p = search_cons_hash ( nm, SORT_sortname ) ;
243
    if ( p ) {
244
	s = ( sortname ) p->encoding ;
245
	sort_table ( cons_hash_tables, s ) ;
246
	sorted = 1 ;
247
	p = cons_hash_tables [ hash_size * s ] ;
248
	for ( ; p ; p = p->next ) output_help ( p ) ;
249
	return ;
250
    }
251
 
252
    /* Unknown construct */
253
    is_fatal = 0 ;
254
    input_error ( "Unknown construct, %s", nm ) ;
255
    return ;
256
}