[2b6eca8] | 1 | /* listpos.c |
---|
[d1b1380] | 2 | * SURVEX Cave surveying software: stuff to do with stn position output |
---|
[736f7df] | 3 | * Copyright (C) 1991-2002,2011,2012,2013,2014 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 */ |
---|
| 41 | static void |
---|
| 42 | traverse_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 | |
---|
[a420b49] | 67 | static void |
---|
[335f37a] | 68 | check_node(prefix *p) |
---|
[a420b49] | 69 | { |
---|
[7d86d87] | 70 | if (!p->pos) { |
---|
[cfcfd28] | 71 | if (!TSTBIT(p->sflags, SFLAGS_SURVEY)) { |
---|
| 72 | /* Could do away with the SFLAGS_SURVEY check and check |
---|
| 73 | * p->min_export instead of p->max_export I think ... */ |
---|
| 74 | if (TSTBIT(p->sflags, SFLAGS_ENTRANCE) || p->max_export) { |
---|
| 75 | /* p is a station which was referred to in "*entrance" and/or |
---|
| 76 | * "*export" but not elsewhere (otherwise it'd have a position). |
---|
| 77 | * p could also be a survey (SFLAGS_SURVEY) or be mentioned as |
---|
| 78 | * a station, but only in a line of data which was rejected |
---|
| 79 | * because of an error. |
---|
| 80 | */ |
---|
[0d38f0e] | 81 | warning_in_file(p->filename, p->line, |
---|
[0804fbe] | 82 | /*Station “%s” referred to by *entrance or *export but never used*/190, |
---|
[cfcfd28] | 83 | sprint_prefix(p)); |
---|
| 84 | } |
---|
[7d86d87] | 85 | } |
---|
| 86 | } else { |
---|
[335f37a] | 87 | /* Do we need to worry about export violations in hanging surveys? */ |
---|
[d1878c51] | 88 | if (fExportUsed) { |
---|
[dd5b1a8] | 89 | #if 0 |
---|
| 90 | printf("L min %d max %d pfx %s\n", |
---|
| 91 | p->min_export, p->max_export, sprint_prefix(p)); |
---|
| 92 | #endif |
---|
[c00c74a9] | 93 | if ((p->min_export > 1 && p->min_export != USHRT_MAX) || |
---|
| 94 | (p->min_export == 0 && p->max_export)) { |
---|
[dd5b1a8] | 95 | char *s; |
---|
[016068a] | 96 | prefix *where = p->up; |
---|
[93e3492] | 97 | int msgno; |
---|
[4c07c51] | 98 | SVX_ASSERT(where); |
---|
[016068a] | 99 | s = osstrdup(sprint_prefix(where)); |
---|
| 100 | /* Report better when station called 2.1 for example */ |
---|
| 101 | while (!where->filename && where->up) where = where->up; |
---|
| 102 | |
---|
[cd971de] | 103 | if (TSTBIT(where->sflags, SFLAGS_PREFIX_ENTERED)) { |
---|
[93e3492] | 104 | msgno = /*Station “%s” not exported from survey “%s”*/26; |
---|
[cd971de] | 105 | } else { |
---|
[736f7df] | 106 | /* TRANSLATORS: This error occurs if there's an attempt to |
---|
| 107 | * export a station from a survey which doesn't actually exist. |
---|
[0b8c321] | 108 | * |
---|
| 109 | * Here "survey" is a "cave map" rather than list of questions - it should be |
---|
| 110 | * translated to the terminology that cavers using the language would use. |
---|
[736f7df] | 111 | */ |
---|
[93e3492] | 112 | msgno = /*Reference to station “%s” from non-existent survey “%s”*/286; |
---|
[cd971de] | 113 | } |
---|
[93e3492] | 114 | compile_error_pfx(where, msgno, sprint_prefix(p), s); |
---|
[dd5b1a8] | 115 | osfree(s); |
---|
[d1878c51] | 116 | } |
---|
[932f7e9] | 117 | } |
---|
[335f37a] | 118 | |
---|
| 119 | if (TSTBIT(p->sflags, SFLAGS_SUSPECTTYPO)) { |
---|
[736f7df] | 120 | /* TRANSLATORS: Here "station" is a survey station, not a train station. */ |
---|
[335f37a] | 121 | warning_in_file(p->filename, p->line, |
---|
[ec3d624] | 122 | /*Station “%s” referred to just once, with an explicit survey name - typo?*/70, |
---|
[335f37a] | 123 | sprint_prefix(p)); |
---|
| 124 | } |
---|
[d1b1380] | 125 | } |
---|
| 126 | } |
---|
| 127 | |
---|
[335f37a] | 128 | #if NODESTAT |
---|
| 129 | static int *cOrder; |
---|
| 130 | static int icOrderMac; |
---|
| 131 | |
---|
| 132 | static void |
---|
| 133 | node_stat(prefix *p) |
---|
| 134 | { |
---|
| 135 | if (p->pos) { |
---|
| 136 | int order; |
---|
| 137 | SVX_ASSERT(pfx_fixed(p)); |
---|
| 138 | |
---|
| 139 | order = p->shape; |
---|
| 140 | |
---|
| 141 | if (order >= icOrderMac) { |
---|
| 142 | int c = order * 2; |
---|
| 143 | cOrder = osrealloc(cOrder, c * ossizeof(int)); |
---|
| 144 | while (icOrderMac < c) cOrder[icOrderMac++] = 0; |
---|
| 145 | } |
---|
| 146 | cOrder[order]++; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | check_node(p); |
---|
| 150 | } |
---|
| 151 | |
---|
[9f5d1675] | 152 | static void |
---|
[a420b49] | 153 | node_stats(prefix *from) |
---|
| 154 | { |
---|
[a2c33ae] | 155 | prefix * p; |
---|
[a420b49] | 156 | icOrderMac = 8; /* Start value */ |
---|
| 157 | cOrder = osmalloc(icOrderMac * ossizeof(int)); |
---|
| 158 | memset(cOrder, 0, icOrderMac * ossizeof(int)); |
---|
| 159 | traverse_prefix_tree(from, node_stat); |
---|
[a2c33ae] | 160 | for (p = anon_list; p; p = p->right) { |
---|
| 161 | node_stat(p); |
---|
| 162 | } |
---|
[d1b1380] | 163 | } |
---|
| 164 | #endif |
---|
| 165 | |
---|
[a420b49] | 166 | extern void |
---|
[2b6eca8] | 167 | print_node_stats(void) |
---|
[a420b49] | 168 | { |
---|
[d1b1380] | 169 | #if NODESTAT |
---|
[a420b49] | 170 | int c; |
---|
[187e72b] | 171 | int max_c = 9999; /* Always allow space for 4 digits. */ |
---|
[449dca9] | 172 | int width; |
---|
[a420b49] | 173 | node_stats(root); |
---|
[449dca9] | 174 | for (c = 0; c < icOrderMac; c++) { |
---|
[187e72b] | 175 | if (cOrder[c] > max_c) { |
---|
| 176 | max_c = cOrder[c]; |
---|
[449dca9] | 177 | } |
---|
| 178 | } |
---|
[187e72b] | 179 | width = 1 + (int)log10((double)max_c); |
---|
[a420b49] | 180 | for (c = 0; c < icOrderMac; c++) { |
---|
[c7c70fe] | 181 | if (cOrder[c] > 0) { |
---|
[449dca9] | 182 | printf("%*d %d-%s.\n", width, cOrder[c], c, |
---|
[736f7df] | 183 | msg(cOrder[c] == 1 ? |
---|
| 184 | /* TRANSLATORS: node/nodes as in: "Survey has 1 2-node and 2 3-nodes." */ |
---|
| 185 | /*node*/176 : |
---|
| 186 | /* TRANSLATORS: node/nodes as in: "Survey has 1 2-node and 2 3-nodes." */ |
---|
| 187 | /*nodes*/177)); |
---|
[a420b49] | 188 | } |
---|
| 189 | } |
---|
[d1b1380] | 190 | #endif |
---|
| 191 | } |
---|
[335f37a] | 192 | |
---|
| 193 | extern void |
---|
| 194 | check_node_stats(void) |
---|
| 195 | { |
---|
| 196 | traverse_prefix_tree(root, check_node); |
---|
| 197 | } |
---|