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 |
#define calculus_IO_ROUTINES
|
|
|
62 |
#include "config.h"
|
|
|
63 |
#include "calculus.h"
|
|
|
64 |
#include "common.h"
|
|
|
65 |
#include "error.h"
|
|
|
66 |
#include "pretty.h"
|
|
|
67 |
|
|
|
68 |
|
|
|
69 |
/*
|
7 |
7u83 |
70 |
* AUTOMATICALLY GENERATED PRETTY PRINTING ROUTINES
|
|
|
71 |
*
|
|
|
72 |
* The main pretty printing routines are automatically generated. The
|
|
|
73 |
* various macros are used to customise these routines.
|
|
|
74 |
*/
|
2 |
7u83 |
75 |
|
7 |
7u83 |
76 |
#define OUTPUT_int(A, B) fprintf_v((A), "%d",(B))
|
|
|
77 |
#define OUTPUT_number(A, B) fprintf_v((A), "%lu",(B))
|
|
|
78 |
#define OUTPUT_string(A, B) fprintf_v((A), "\"%s\"",(B))
|
2 |
7u83 |
79 |
|
|
|
80 |
#ifndef DEBUG
|
|
|
81 |
#define BAD_PRINT_OP 0
|
7 |
7u83 |
82 |
#define PRINT_alg(A, B, C, D) ASSERT(BAD_PRINT_OP)
|
|
|
83 |
#define PRINT_list_ptr_en(A, B, C, D) ASSERT(BAD_PRINT_OP)
|
|
|
84 |
#define PRINT_list_ptr_ident(A, B, C, D) ASSERT(BAD_PRINT_OP)
|
|
|
85 |
#define PRINT_list_ptr_prim(A, B, C, D) ASSERT(BAD_PRINT_OP)
|
|
|
86 |
#define PRINT_list_ptr_str(A, B, C, D) ASSERT(BAD_PRINT_OP)
|
|
|
87 |
#define PRINT_list_ptr_un(A, B, C, D) ASSERT(BAD_PRINT_OP)
|
|
|
88 |
#define PRINT_ptr_int(A, B, C, D) ASSERT(BAD_PRINT_OP)
|
|
|
89 |
#define PRINT_ptr_number(A, B, C, D) ASSERT(BAD_PRINT_OP)
|
|
|
90 |
#define PRINT_ptr_ptr_cid(A, B, C, D) ASSERT(BAD_PRINT_OP)
|
|
|
91 |
#define PRINT_ptr_ptr_type(A, B, C, D) ASSERT(BAD_PRINT_OP)
|
|
|
92 |
#define PRINT_ptr_string(A, B, C, D) ASSERT(BAD_PRINT_OP)
|
2 |
7u83 |
93 |
#endif
|
|
|
94 |
|
|
|
95 |
#include "print_def.h"
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
/*
|
7 |
7u83 |
99 |
* PRETTY PRINT AN ALGEBRA
|
|
|
100 |
*
|
|
|
101 |
* This routine pretty prints the entire algebra type list into the
|
|
|
102 |
* file named nm.
|
|
|
103 |
*/
|
2 |
7u83 |
104 |
|
7 |
7u83 |
105 |
void
|
|
|
106 |
pretty_file(char *nm)
|
2 |
7u83 |
107 |
{
|
7 |
7u83 |
108 |
int old_indent_step;
|
|
|
109 |
int old_ptr_depth;
|
|
|
110 |
int old_list_expand;
|
2 |
7u83 |
111 |
|
|
|
112 |
/* Open file */
|
7 |
7u83 |
113 |
FILE *f;
|
|
|
114 |
if (streq(nm, ".")) {
|
|
|
115 |
f = stdout;
|
2 |
7u83 |
116 |
} else {
|
7 |
7u83 |
117 |
f = fopen(nm, "w");
|
|
|
118 |
if (f == NULL) {
|
|
|
119 |
error(ERROR_SERIOUS, "Can't open output file, '%s'", nm);
|
|
|
120 |
return;
|
2 |
7u83 |
121 |
}
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
/* Save values */
|
7 |
7u83 |
125 |
old_indent_step = print_indent_step;
|
|
|
126 |
old_ptr_depth = print_ptr_depth;
|
|
|
127 |
old_list_expand = print_list_expand;
|
|
|
128 |
print_indent_step = 2;
|
|
|
129 |
print_ptr_depth = 10000;
|
|
|
130 |
print_list_expand = 1;
|
2 |
7u83 |
131 |
|
|
|
132 |
/* Print the algebra */
|
7 |
7u83 |
133 |
PRINT_string(f, algebra->name, "name", 0);
|
|
|
134 |
PRINT_int(f, algebra->major_no, "major_no", 0);
|
|
|
135 |
PRINT_int(f, algebra->minor_no, "minor_no", 0);
|
|
|
136 |
fputc_v('\n', f);
|
|
|
137 |
PRINT_list_ptr_type(f, algebra->types, "types", 0);
|
2 |
7u83 |
138 |
|
|
|
139 |
/* Restore values */
|
7 |
7u83 |
140 |
clear_calculus_alias();
|
|
|
141 |
print_indent_step = old_indent_step;
|
|
|
142 |
print_ptr_depth = old_ptr_depth;
|
|
|
143 |
print_list_expand = old_list_expand;
|
2 |
7u83 |
144 |
|
|
|
145 |
/* Close file */
|
7 |
7u83 |
146 |
if (f != stdout)fclose_v(f);
|
|
|
147 |
return;
|
2 |
7u83 |
148 |
}
|