File: consist.c

package info (click to toggle)
clara 20031214-4
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,184 kB
  • ctags: 1,833
  • sloc: ansic: 28,836; perl: 1,522; makefile: 121; sed: 9
file content (303 lines) | stat: -rw-r--r-- 5,413 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/*
  Copyright (C) 1999-2002 Ricardo Ueda Karpischek

  This is free software; you can redistribute it and/or modify
  it under the terms of the version 2 of the GNU General Public
  License as published by the Free Software Foundation.

  This software is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this software; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
  USA.
*/

/*

consist.c: Consistency tests for all data structures.

*/

#include <stdio.h>
#include "common.h"

/*

Consist closure c.

*/
int cl_cons(int c)
{
    cldesc *m;
    int i,f;

    /* invalid closure index */
    if ((c < 0) || (topcl < c)) {
        show_hint(2,"closure %d does not exist",c);
        return(1);
    }

    /* consist closure parameters */
    m = cl + c;
    if ((m->l < 0) || (m->r >= XRES) || (m->t < 0) || (m->b >= YRES) ||
        (m->nbp < 0) || (m->nbp > (m->r-m->l+1)*(m->b-m->t+1)) ||
        (m->seed[0] < m->l) || (m->seed[0] > m->r) ||
        (m->seed[1] < m->t) || (m->seed[1] > m->b)) {

        show_hint(2,"closure %d inconsistent",c);
        return(1);
    }

    /* consist indexes of symbols */
    for (i=f=0; m->sup[i]>=0; ++i) {
        if (tops < m->sup[i])
            f = 1;
    }
    if (f != 0) {
        show_hint(2,"closure %d points to inexistent symbol",c);
        return(1);
    }

    return(0);
}

/*

Consist symbol c.

*/
int s_cons(int c)
{
    sdesc *s;
    int i;

    s = mc + c;

    if (s->ncl <= 0) {
        show_hint(2,"invalid number of closures on symbol %d",c);
        return(1);
    }

    else if (s->cl==NULL) {
        show_hint(2,"absent list of closures on symbol %d",c);
        return(1);
    }

    else {
        for (i=0; i<s->ncl; ++i)
            if ((s->cl[i]<0) || (s->cl[i]>topcl)) {
                show_hint(2,"invalid closures on symbol %d",c);
                return(1);
            }
    }

    if ((s->l<0) || (s->l>=XRES) ||
        (s->r<0) || (s->l>=XRES) ||
        (s->t<0) || (s->t>=YRES) ||
        (s->b<0) || (s->b>=YRES) ||
        (s->l>s->r) || (s->t>s->b) ||
        (s->nbp > (s->r-s->l+1)*(s->b-s->t+1))) {

        show_hint(2,"symbol %d has invalid geometry\n",c);
        return(1);
    }

    if ((s->f & C_AS) != s->f) {
        show_hint(2,"symbol %d has invalid flags\n",c);
        return(1);
    }

    /* TO BE COMPLETED */

    return(0);
}

/*

Run all consistencies.

*/
int cons(int reset)
{
    static int st=0,i=0;
    int r=0;

    if (reset) {
        st = 0;
        i = 0;
        return(1);
    }

    /* consist closures */
    if (st == 0) {
        if (i > topcl) {
            st = 1;
            i = 0;
            r = 0;
        }
        else {
            if (i == 0)
                show_hint(1,"checking closures");
            r = cl_cons(i++);
        }
    }

    /* consist symbols */
    else if (st == 1) {
        if (i > tops) {
            st = 2;
            i = 0;
            r = 0;
        }
        else {
            if (i == 0)
                show_hint(1,"checking symbols");
            r = s_cons(i++);
        }
    }

    else if (st == 2) {
        show_hint(1,"tests finished successfully");
        return(0);
    }

    /* fatal */
    if (r) {
        return(2);
    }

    return(1);
}

/*

Consist page geometry

*/
void consist_pg(void)
{
    float md;

    /* maximum acceptable width or height, in millimeters */
    md = ((float) FS * 25.4) / DENSITY;

    /* letter width and height */
    if (LW > md)
        LW = md;
    if (LW < 1)
        LW = 1;
    if (LH > md)
        LH = md;
    if (LH < 1)
        LH = 1;

    /* dot diameter */
    if (DD > md)
        DD = md;
    if (DD < 1)
        DD = 1;

    /* vertical separation between text lines */
    if (LS > 3*md)
        LS = 3*md;
    if (LS < 3)
        LS = 3;

    /* text columns */
    if (TC > 2)
        TC = 2;
    if (TC < 1)
        TC = 1;

    /* separation line */
    SL = (SL != 0);

    /* margins */
    if (LM < 1)
        LM = 1;
    if (RM < 1)
        RM = 1;
    if (TM < 1)
        TM = 1;
    if (BM < 1)
        BM = 1;
}

/*

Consist density

*/
void consist_density(void)
{
    if (DENSITY <= 0)
        DENSITY = 600;
    if (DENSITY > 1200)
        DENSITY = 1200;
}

/*

Consist magic numbers

*/
void consist_magic(void)
{
    if (m_mwd < 1)
        m_mwd = 1;
    if (m_mwd > 5000)
        m_mwd = 5000;
    if (m_msd < 1)
        m_msd = 1;
    if (m_msd > 500)
        m_msd = 500;
    if (m_mae < 0)
        m_mae = 0;
    if (m_mae > 500)
        m_mae = 500;
    if (m_ds < 10)
        m_ds = 10;
    if (m_ds > 2000)
        m_ds = 2000;
    if (m_as < 10)
        m_as = 10;
    if (m_as > 2000)
        m_as = 2000;
    if (m_xh < 10)
        m_xh = 10;
    if (m_xh > 2000)
        m_xh = 2000;
    if (m_fs < 1)
        m_fs = 1;
    if (m_fs > 100)
        m_fs = 100;
}

/*

Consist preprocessing variables.

*/
void consist_pp(void)
{
    if ((pp_avoid_links < 0.0) || (1.0 < pp_avoid_links))
        pp_avoid_links = 0.0;
}

#ifdef TEST

/*

Run all internal tests.

*/
void internal_tests(void)
{
    test_clusterize();
}

#endif