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