source: git/src/listpos.c @ ecbc6c18

RELEASE/1.1RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-datawalls-data-hanging-as-warning
Last change on this file since ecbc6c18 was ecbc6c18, checked in by Olly Betts <olly@…>, 14 years ago

src/: Update FSF address in licence notices.

git-svn-id: file:///home/survex-svn/survex/branches/survex-1_1@3417 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100644
File size: 4.2 KB
RevLine 
[2b6eca8]1/* listpos.c
[d1b1380]2 * SURVEX Cave surveying software: stuff to do with stn position output
[b14f44f]3 * Copyright (C) 1991-2002 Olly Betts
[846746e]4 *
[89231c4]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.
[846746e]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
[89231c4]12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 * GNU General Public License for more details.
[846746e]14 *
[89231c4]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
[ecbc6c18]17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
[d1b1380]18 */
19
[a420b49]20#ifdef HAVE_CONFIG_H
21# include <config.h>
22#endif
[d1b1380]23
24#define PRINT_STN_POS_LIST 1
25#define NODESTAT 1
26
[c00c74a9]27#include <limits.h>
28
[a420b49]29#include "cavern.h"
[e05bdb8]30#include "datain.h"
[dd5b1a8]31#include "debug.h"
[c082b69]32#include "filename.h"
33#include "message.h"
[d1b1380]34#include "filelist.h"
35#include "netbits.h"
36#include "listpos.h"
37#include "out.h"
38
[a420b49]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;
[d1b1380]45
[a420b49]46   fn(from);
[d1b1380]47
[a420b49]48   p = from->down;
49   if (!p) return;
[cb3d1e2]50
[a420b49]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      }
[d1b1380]64   }
65}
66
67#if NODESTAT
[a420b49]68static int *cOrder;
69static int icOrderMac;
70
71static void
72node_stat(prefix *p)
73{
[7d86d87]74   if (!p->pos) {
[cfcfd28]75      if (!TSTBIT(p->sflags, SFLAGS_SURVEY)) {
76         /* Could do away with the SFLAGS_SURVEY check and check
77          * p->min_export instead of p->max_export I think ... */
78         if (TSTBIT(p->sflags, SFLAGS_ENTRANCE) || p->max_export) {
79             /* p is a station which was referred to in "*entrance" and/or
80              * "*export" but not elsewhere (otherwise it'd have a position).
81              * p could also be a survey (SFLAGS_SURVEY) or be mentioned as
82              * a station, but only in a line of data which was rejected
83              * because of an error.
84              */
85             warning(/*Station `%s' referred to by *entrance or *export but never used*/190,
86                     sprint_prefix(p));
87         }
[7d86d87]88      }
89   } else {
[c7c70fe]90      int order;
[4c07c51]91      SVX_ASSERT(pfx_fixed(p));
[c7c70fe]92
93      order = p->shape;
[eb04711]94
[a420b49]95      if (order >= icOrderMac) {
96         int c = order * 2;
97         cOrder = osrealloc(cOrder, c * ossizeof(int));
98         while (icOrderMac < c) cOrder[icOrderMac++] = 0;
99      }
100      cOrder[order]++;
[c7c70fe]101
[95c3272]102      if (TSTBIT(p->sflags, SFLAGS_SUSPECTTYPO)) {
[d227ee5]103         warning(/*Station `%s' referred to just once, with an explicit prefix - typo?*/70,
[647407d]104                 sprint_prefix(p));
105      }
[c7c70fe]106
[05ae103]107      /* Don't need to worry about export violations in hanging surveys -
[c7c70fe]108       * if there are hanging surveys then we give up in articulate()
109       * and never get here... */
[d1878c51]110      if (fExportUsed) {
[dd5b1a8]111#if 0
112         printf("L min %d max %d pfx %s\n",
113                p->min_export, p->max_export, sprint_prefix(p));
114#endif
[c00c74a9]115         if ((p->min_export > 1 && p->min_export != USHRT_MAX) ||
116             (p->min_export == 0 && p->max_export)) {
[dd5b1a8]117            char *s;
[016068a]118            const char *filename_store = file.filename;
119            unsigned int line_store = file.line;
120            prefix *where = p->up;
[4c07c51]121            SVX_ASSERT(where);
[016068a]122            s = osstrdup(sprint_prefix(where));
123            /* Report better when station called 2.1 for example */
124            while (!where->filename && where->up) where = where->up;
125
126            file.filename = where->filename;
127            file.line = where->line;
128            compile_error(/*Station `%s' not exported from survey `%s'*/26,
129                          sprint_prefix(p), s);
130            file.filename = filename_store;
131            file.line = line_store;
[dd5b1a8]132            osfree(s);
[d1878c51]133         }
[932f7e9]134      }
[d1b1380]135   }
136}
137
[9f5d1675]138static void
[a420b49]139node_stats(prefix *from)
140{
141   icOrderMac = 8; /* Start value */
142   cOrder = osmalloc(icOrderMac * ossizeof(int));
143   memset(cOrder, 0, icOrderMac * ossizeof(int));
144   traverse_prefix_tree(from, node_stat);
[d1b1380]145}
146#endif
147
[a420b49]148extern void
[2b6eca8]149print_node_stats(void)
[a420b49]150{
[d1b1380]151#if NODESTAT
[a420b49]152   int c;
153   node_stats(root);
154   for (c = 0; c < icOrderMac; c++) {
[c7c70fe]155      if (cOrder[c] > 0) {
[2b6eca8]156         printf("%4d %d-%s.\n", cOrder[c], c,
157                msg(cOrder[c] == 1 ? /*node*/176 : /*nodes*/177));
[a420b49]158      }
159   }
[d1b1380]160#endif
161}
Note: See TracBrowser for help on using the repository browser.