source: git/src/listpos.c

walls-data-hanging-as-warning
Last change on this file was 9a92e86, checked in by Olly Betts <olly@…>, 2 days ago

Hack to only warn about hanging surveys

  • Property mode set to 100644
File size: 5.2 KB
Line 
1/* listpos.c
2 * SURVEX Cave surveying software: stuff to do with stn position output
3 * Copyright (C) 1991-2002,2011,2012,2013,2014 Olly Betts
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 */
19
20#include <config.h>
21
22#define PRINT_STN_POS_LIST 1
23#define NODESTAT 1
24
25#include <limits.h>
26
27#include "cavern.h"
28#include "datain.h"
29#include "debug.h"
30#include "filename.h"
31#include "message.h"
32#include "filelist.h"
33#include "netbits.h"
34#include "listpos.h"
35#include "out.h"
36
37/* Traverse prefix tree depth first starting at from, and
38 * calling function fn at each node */
39static void
40traverse_prefix_tree(prefix *from, void (*fn)(prefix *))
41{
42   prefix *p;
43
44   fn(from);
45
46   p = from->down;
47   if (!p) return;
48
49   while (1) {
50      fn(p);
51      if (p->down) {
52         p = p->down;
53      } else {
54         if (!p->right) {
55            do {
56               p = p->up;
57               if (p == from) return; /* got back to start */
58            } while (!p->right);
59         }
60         p = p->right;
61      }
62   }
63}
64
65static void
66check_node(prefix *p)
67{
68   if (!p->pos) {
69      if (!TSTBIT(p->sflags, SFLAGS_SURVEY)) {
70         /* Could do away with the SFLAGS_SURVEY check and check
71          * p->min_export instead of p->max_export I think ... */
72         if (TSTBIT(p->sflags, SFLAGS_ENTRANCE) || p->max_export) {
73             /* p is a station which was referred to in "*entrance" and/or
74              * "*export" but not elsewhere (otherwise it'd have a position).
75              * p could also be a survey (SFLAGS_SURVEY) or be mentioned as
76              * a station, but only in a line of data which was rejected
77              * because of an error.
78              */
79             warning_in_file(p->filename, p->line,
80                     /*Station “%s” referred to by *entrance or *export but never used*/190,
81                     sprint_prefix(p));
82         }
83      }
84   } else {
85      /* Do we need to worry about export violations in hanging surveys? */
86      if (fExportUsed) {
87#if 0
88         printf("L min %d max %d pfx %s\n",
89                p->min_export, p->max_export, sprint_prefix(p));
90#endif
91         if ((p->min_export > 1 && p->min_export != USHRT_MAX) ||
92             (p->min_export == 0 && p->max_export)) {
93            char *s;
94            prefix *where = p->up;
95            int msgno;
96            SVX_ASSERT(where);
97            s = osstrdup(sprint_prefix(where));
98            /* Report better when station called 2.1 for example */
99            while (!where->filename && where->up) where = where->up;
100
101            if (TSTBIT(where->sflags, SFLAGS_PREFIX_ENTERED)) {
102               msgno = /*Station “%s” not exported from survey “%s”*/26;
103            } else {
104                /* TRANSLATORS: This error occurs if there's an attempt to
105                 * export a station from a survey which doesn't actually exist.
106                 *
107                 * Here "survey" is a "cave map" rather than list of questions - it should be
108                 * translated to the terminology that cavers using the language would use.
109                 */
110               msgno = /*Reference to station “%s” from non-existent survey “%s”*/286;
111            }
112            compile_diagnostic_pfx(DIAG_ERR, where, msgno, sprint_prefix(p), s);
113            osfree(s);
114         }
115      }
116
117      if (TSTBIT(p->sflags, SFLAGS_SUSPECTTYPO)) {
118         /* TRANSLATORS: Here "station" is a survey station, not a train station. */
119         warning_in_file(p->filename, p->line,
120                 /*Station “%s” referred to just once, with an explicit survey name - typo?*/70,
121                 sprint_prefix(p));
122      }
123   }
124}
125
126#if NODESTAT
127static int *cOrder;
128static int icOrderMac;
129
130static void
131node_stat(prefix *p)
132{
133   if (p->pos && pfx_fixed(p)) {
134      int order;
135      SVX_ASSERT(pfx_fixed(p));
136
137      order = p->shape;
138
139      if (order >= icOrderMac) {
140         int c = order * 2;
141         cOrder = osrealloc(cOrder, c * ossizeof(int));
142         while (icOrderMac < c) cOrder[icOrderMac++] = 0;
143      }
144      cOrder[order]++;
145   }
146
147   check_node(p);
148}
149
150static void
151node_stats(prefix *from)
152{
153   prefix * p;
154   icOrderMac = 8; /* Start value */
155   cOrder = osmalloc(icOrderMac * ossizeof(int));
156   memset(cOrder, 0, icOrderMac * ossizeof(int));
157   traverse_prefix_tree(from, node_stat);
158   for (p = anon_list; p; p = p->right) {
159      node_stat(p);
160   }
161}
162#endif
163
164extern void
165print_node_stats(void)
166{
167#if NODESTAT
168   int c;
169   int max_c = 9999; /* Always allow space for 4 digits. */
170   int width;
171   node_stats(root);
172   for (c = 0; c < icOrderMac; c++) {
173      if (cOrder[c] > max_c) {
174         max_c = cOrder[c];
175      }
176   }
177   width = 1 + (int)log10((double)max_c);
178   for (c = 0; c < icOrderMac; c++) {
179      if (cOrder[c] > 0) {
180         printf("%*d %d-%s.\n", width, cOrder[c], c,
181                msg(cOrder[c] == 1 ?
182                    /* TRANSLATORS: node/nodes as in:  "Survey has 1 2-node and 2 3-nodes." */
183                    /*node*/176 :
184                    /* TRANSLATORS: node/nodes as in:  "Survey has 1 2-node and 2 3-nodes." */
185                    /*nodes*/177));
186      }
187   }
188#endif
189}
190
191extern void
192check_node_stats(void)
193{
194   traverse_prefix_tree(root, check_node);
195}
Note: See TracBrowser for help on using the repository browser.