source: git/src/listpos.c @ eb5b48df

RELEASE/1.0RELEASE/1.1RELEASE/1.2debug-cidebug-ci-sanitisersfaster-cavernlogstereowalls-datawalls-data-hanging-as-warning
Last change on this file since eb5b48df was c00c74a9, checked in by Olly Betts <olly@…>, 22 years ago

Added "*infer export on" to infer *export commands for any stations
encountered while it is active.

Fixed handling of "*infer unknown on".

git-svn-id: file:///home/survex-svn/survex/trunk@1923 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/* listpos.c
2 * SURVEX Cave surveying software: stuff to do with stn position output
3 * Copyright (C) 1991-2002 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 */
19
20#ifdef HAVE_CONFIG_H
21# include <config.h>
22#endif
23
24#define PRINT_STN_POS_LIST 1
25#define NODESTAT 1
26
27#include <limits.h>
28
29#include "cavern.h"
30#include "datain.h"
31#include "debug.h"
32#include "filename.h"
33#include "message.h"
34#include "filelist.h"
35#include "netbits.h"
36#include "listpos.h"
37#include "out.h"
38
39/* Traverse prefix tree depth first starting at from, and
40 * calling function fn at each node */
41static void
42traverse_prefix_tree(prefix *from, void (*fn)(prefix *))
43{
44   prefix *p;
45
46   fn(from);
47
48   p = from->down;
49   if (!p) return;
50
51   while (1) {
52      fn(p);
53      if (p->down) {
54         p = p->down;
55      } else {
56         if (!p->right) {
57            do {
58               p = p->up;
59               if (p == from) return; /* got back to start */
60            } while (!p->right);
61         }
62         p = p->right;
63      }
64   }
65}
66
67#if NODESTAT
68static int *cOrder;
69static int icOrderMac;
70
71static void
72node_stat(prefix *p)
73{
74   if (!p->pos) {
75      if (TSTBIT(p->sflags, SFLAGS_ENTRANCE) || p->max_export) {
76          /* p was referred to in "*entrance" and/or "*export"
77           * but not elsewhere (otherwise it would have a position).
78           * p could also be a survey (SFLAGS_SURVEY) or be mentioned as
79           * a station, but only in a line of data which was rejected because
80           * of an error.
81           */
82          warning(/*Station `%s' referred to by *entrance or *export but never used*/190,
83                  sprint_prefix(p));
84      }
85   } else {
86      int order;
87      ASSERT(pfx_fixed(p));
88
89      order = p->shape;
90
91      if (order >= icOrderMac) {
92         int c = order * 2;
93         cOrder = osrealloc(cOrder, c * ossizeof(int));
94         while (icOrderMac < c) cOrder[icOrderMac++] = 0;
95      }
96      cOrder[order]++;
97
98      if (TSTBIT(p->sflags, SFLAGS_SUSPECTTYPO)) {
99         warning(/*Station `%s' referred to just once, with an explicit prefix - typo?*/70,
100                 sprint_prefix(p));
101      }
102
103      /* Don't need to worry about export violations in hanging surveys -
104       * if there are hanging surveys then we give up in articulate()
105       * and never get here... */
106      if (fExportUsed) {
107#if 0
108         printf("L min %d max %d pfx %s\n",
109                p->min_export, p->max_export, sprint_prefix(p));
110#endif
111         if ((p->min_export > 1 && p->min_export != USHRT_MAX) ||
112             (p->min_export == 0 && p->max_export)) {
113            char *s;
114            const char *filename_store = file.filename;
115            unsigned int line_store = file.line;
116            prefix *where = p->up;
117            ASSERT(where);
118            s = osstrdup(sprint_prefix(where));
119            /* Report better when station called 2.1 for example */
120            while (!where->filename && where->up) where = where->up;
121
122            file.filename = where->filename;
123            file.line = where->line;
124            compile_error(/*Station `%s' not exported from survey `%s'*/26,
125                          sprint_prefix(p), s);
126            file.filename = filename_store;
127            file.line = line_store;
128            osfree(s);
129         }
130      }
131   }
132}
133
134static void
135node_stats(prefix *from)
136{
137   icOrderMac = 8; /* Start value */
138   cOrder = osmalloc(icOrderMac * ossizeof(int));
139   memset(cOrder, 0, icOrderMac * ossizeof(int));
140   traverse_prefix_tree(from, node_stat);
141}
142#endif
143
144extern void
145print_node_stats(void)
146{
147#if NODESTAT
148   int c;
149   node_stats(root);
150   for (c = 0; c < icOrderMac; c++) {
151      if (cOrder[c] > 0) {
152         printf("%4d %d-%s.\n", cOrder[c], c,
153                msg(cOrder[c] == 1 ? /*node*/176 : /*nodes*/177));
154      }
155   }
156#endif
157}
Note: See TracBrowser for help on using the repository browser.