Subversion Repositories tendra.SVN

Rev

Rev 5 | Details | Compare with Previous | 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
#include "config.h"
62
#include "release.h"
63
#include "types.h"
64
#include "ascii.h"
65
#include "basic.h"
66
#include "file.h"
67
#include "capsule.h"
68
#include "pretty.h"
69
#include "sort.h"
70
#include "tdf.h"
71
#include "tree.h"
72
#include "unit.h"
73
#include "utility.h"
74
 
75
 
76
/*
77
    CURRENT VERSION
78
*/
79
 
80
#define version_string		"Version: 1.5"
81
 
82
 
83
/*
84
    MAIN ROUTINE
85
*/
86
 
6 7u83 87
int
88
main(int argc, char **argv)
2 7u83 89
{
6 7u83 90
    char c;
91
    int input, output;
92
    int a, b, stage = 1;
2 7u83 93
 
94
    /* Read the arguments */
6 7u83 95
    for (a = 1; a < argc; a++) {
96
	if (argv[a][0] == '-') {
97
	    b = 1;
98
	    if (argv[a][1] == 'n') {
99
		maxcol = 0;
100
		while (c = argv[a][++b], is_digit(c)) {
101
		    maxcol = 10 * maxcol + digit(c);
2 7u83 102
		}
103
	    } else {
6 7u83 104
		while (c = argv[a][b++], c != 0) {
105
		    switch (c) {
106
			case 'd': dflag = 0; break;
107
			case 'g': diagnostics = 1; break;
108
			case 'h': helpflag = 0; break;
2 7u83 109
			case 'i' : /* Compatibility */ break ;
6 7u83 110
			case 'p': progress = 1; break;
111
			case 'q': quickflag = 1; break;
112
			case 'r': recover = 1; break;
113
			case 'x': versions = 0; break;
114
			case 'A': {
115
			    diagnostics = 1;
116
			    show_usage = 1;
117
			    versions = 1;
118
			    break;
2 7u83 119
			}
6 7u83 120
			case 'D': dump = 1; break;
121
			case 'E': show_stuff = 1; break;
122
			case 'S': skip_pass = 0; break;
123
			case 'T': show_skip = 1; break;
124
			case 'U': show_usage = 1; break;
125
			case 'V': dumb_mode = 1; break;
126
			case 'W': warn_undeclared = 1; break;
2 7u83 127
 
6 7u83 128
			case 'v': {
2 7u83 129
			    /* Version number */
6 7u83 130
			    IGNORE fprintf(stderr, "%s: %s",
131
					     progname, version_string);
132
			    IGNORE fprintf(stderr, " (TDF %d.%d)",
133
					     version_major, version_minor);
134
			    IGNORE fprintf(stderr, " (release %s)\n",
135
					     RELEASE);
136
			    break;
2 7u83 137
			}
138
		    }
139
		}
140
	    }
141
	} else {
142
	    /* Handle files */
6 7u83 143
	    switch (stage) {
144
		case 1 : input = a; stage = 2; break;
145
		case 2 : output = a; stage = 3; break;
146
		default : stage = 4; break;
2 7u83 147
	    }
148
	}
149
    }
150
 
151
    /* Open the files */
6 7u83 152
    switch (stage) {
153
	case 1: {
154
	    fatal_error("Not enough arguments");
155
	    break;
2 7u83 156
	}
6 7u83 157
	case 2: {
158
	    SET(input);
159
	    open_files(argv[input],(char *)null);
160
	    break;
2 7u83 161
	}
6 7u83 162
	case 3: {
163
	    SET(input);
164
	    SET(output);
165
	    open_files(argv[input], argv[output]);
166
	    break;
2 7u83 167
	}
168
	default : {
6 7u83 169
	    fatal_error("Too many arguments");
170
	    break;
2 7u83 171
	}
172
    }
173
 
174
    /* Perform binary dump if required */
6 7u83 175
    if (dump) {
176
	long f;
177
	int bits = 0, n = 1;
178
	while (f = fetch(1), !read_error) {
179
	    if (n == 1)IGNORE fprintf(pp_file, "%d :\t", bits / 8);
180
	    IGNORE fputc((f ? '1' : '0'), pp_file);
181
	    if (n == 64) {
182
		IGNORE fputc('\n', pp_file);
183
		n = 1;
2 7u83 184
	    } else {
6 7u83 185
		if (n % 8 == 0)IGNORE fputc(' ', pp_file);
186
		n++;
2 7u83 187
	    }
6 7u83 188
	    bits++;
2 7u83 189
	}
6 7u83 190
	if (n != 1)IGNORE fputc('\n', pp_file);
191
	exit(0);
2 7u83 192
    }
193
 
194
    /* Call the main routines */
6 7u83 195
    if (diagnostics || show_usage) do_foreign_sorts = 1;
196
    init_foreign_sorts();
197
    initialize_tree();
198
    de_capsule();
199
    pretty_tree();
200
    return(exit_status);
2 7u83 201
}