[02da880] | 1 | /* dump3d.c */ |
---|
| 2 | /* Show raw contents of .3d file in text form */ |
---|
[6f402d7] | 3 | /* Copyright (C) 2001,2002,2006,2011,2012,2013,2014,2015 Olly Betts |
---|
[02da880] | 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 |
---|
[914e980] | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
[02da880] | 18 | */ |
---|
| 19 | |
---|
| 20 | #ifdef HAVE_CONFIG_H |
---|
| 21 | # include <config.h> |
---|
| 22 | #endif |
---|
| 23 | |
---|
| 24 | #include <stdio.h> |
---|
| 25 | #include <stdlib.h> |
---|
| 26 | #include <string.h> |
---|
| 27 | #include <math.h> |
---|
| 28 | |
---|
| 29 | #include "cmdline.h" |
---|
[798a6bf] | 30 | #include "date.h" |
---|
[02da880] | 31 | #include "debug.h" |
---|
| 32 | #include "filelist.h" |
---|
[a405bc1] | 33 | #include "img_hosted.h" |
---|
[02da880] | 34 | |
---|
| 35 | static const struct option long_opts[] = { |
---|
| 36 | /* const char *name; int has_arg (0 no_argument, 1 required_*, 2 optional_*); int *flag; int val; */ |
---|
| 37 | {"survey", required_argument, 0, 's'}, |
---|
[e7b9e00] | 38 | {"rewind", no_argument, 0, 'r'}, |
---|
[798a6bf] | 39 | {"show-dates", no_argument, 0, 'd'}, |
---|
[02da880] | 40 | {"help", no_argument, 0, HLP_HELP}, |
---|
| 41 | {"version", no_argument, 0, HLP_VERSION}, |
---|
| 42 | {0, 0, 0, 0} |
---|
| 43 | }; |
---|
| 44 | |
---|
[798a6bf] | 45 | #define short_opts "rds:" |
---|
[02da880] | 46 | |
---|
| 47 | static struct help_msg help[] = { |
---|
| 48 | /* <-- */ |
---|
[fbc1d32] | 49 | {HLP_ENCODELONG(0), /*only load the sub-survey with this prefix*/199, 0}, |
---|
[736f7df] | 50 | /* TRANSLATORS: --help output for dump3d --rewind option */ |
---|
[fbc1d32] | 51 | {HLP_ENCODELONG(1), /*rewind file and read it a second time*/204, 0}, |
---|
[81dc8f3] | 52 | {HLP_ENCODELONG(2), /*show survey date information (if present)*/396, 0}, |
---|
[fbc1d32] | 53 | {0, 0, 0} |
---|
[02da880] | 54 | }; |
---|
| 55 | |
---|
| 56 | int |
---|
| 57 | main(int argc, char **argv) |
---|
| 58 | { |
---|
| 59 | char *fnm; |
---|
| 60 | img *pimg; |
---|
| 61 | img_point pt; |
---|
| 62 | int code; |
---|
| 63 | const char *survey = NULL; |
---|
[e7b9e00] | 64 | bool fRewind = fFalse; |
---|
[798a6bf] | 65 | bool show_dates = fFalse; |
---|
[02da880] | 66 | |
---|
[bdfe97f] | 67 | msg_init(argv); |
---|
[02da880] | 68 | |
---|
| 69 | cmdline_init(argc, argv, short_opts, long_opts, NULL, help, 1, 1); |
---|
| 70 | while (1) { |
---|
| 71 | int opt = cmdline_getopt(); |
---|
| 72 | if (opt == EOF) break; |
---|
| 73 | if (opt == 's') survey = optarg; |
---|
[e7b9e00] | 74 | if (opt == 'r') fRewind = fTrue; |
---|
[798a6bf] | 75 | if (opt == 'd') show_dates = fTrue; |
---|
[02da880] | 76 | } |
---|
| 77 | fnm = argv[optind]; |
---|
| 78 | |
---|
| 79 | #if 0 |
---|
[ce9057c] | 80 | pimg = img_open_write("dump3d.3d", "dump3d", 0); |
---|
[a405bc1] | 81 | if (!pimg) fatalerror(img_error2msg(img_error()), "dump3d.3d"); |
---|
[02da880] | 82 | img_write_item(pimg, img_MOVE, 0, NULL, 0, 0, 0); |
---|
| 83 | img_write_item(pimg, img_LINE, 0, "161.lostworld.upstream", |
---|
| 84 | 36920.120000, 82672.840000, 1528.820000); |
---|
| 85 | img_write_item(pimg, img_LINE, 0, "161.keinzimmer", |
---|
| 86 | 36918.480000, 82663.360000, 1527.670000); |
---|
| 87 | img_write_item(pimg, img_LINE, 0, "161.lostworld.upstream", |
---|
| 88 | 36959.760000, 82679.880000, 1537.900000); |
---|
| 89 | img_close(pimg); |
---|
| 90 | #endif |
---|
| 91 | |
---|
[a2ad284] | 92 | pimg = img_open_survey(fnm, survey); |
---|
[a405bc1] | 93 | if (!pimg) fatalerror(img_error2msg(img_error()), fnm); |
---|
[e7b9e00] | 94 | |
---|
[984f49e] | 95 | printf("TITLE \"%s\"\n", pimg->title); |
---|
| 96 | printf("DATE \"%s\"\n", pimg->datestamp); |
---|
[4f70ebc] | 97 | printf("DATE_NUMERIC %ld\n", pimg->datestamp_numeric); |
---|
[48a7381] | 98 | if (pimg->cs) |
---|
| 99 | printf("CS %s\n", pimg->cs); |
---|
[5757725] | 100 | printf("VERSION %d\n", pimg->version); |
---|
[88c1ccb] | 101 | if (pimg->is_extended_elevation) |
---|
| 102 | printf("EXTENDED ELEVATION\n"); |
---|
[6f402d7] | 103 | printf("SEPARATOR '%c'\n", pimg->separator); |
---|
[984f49e] | 104 | printf("--\n"); |
---|
[02da880] | 105 | |
---|
[e7b9e00] | 106 | code = img_BAD; |
---|
[02da880] | 107 | do { |
---|
[e7b9e00] | 108 | if (code == img_STOP) { |
---|
| 109 | printf("<<< REWIND <<<\n"); |
---|
| 110 | fRewind = fFalse; |
---|
[a405bc1] | 111 | if (!img_rewind(pimg)) fatalerror(img_error2msg(img_error()), fnm); |
---|
[02da880] | 112 | } |
---|
[e7b9e00] | 113 | |
---|
| 114 | do { |
---|
| 115 | code = img_read_item(pimg, &pt); |
---|
| 116 | switch (code) { |
---|
| 117 | case img_MOVE: |
---|
[f346a33] | 118 | printf("MOVE %.2f %.2f %.2f\n", pt.x, pt.y, pt.z); |
---|
[e7b9e00] | 119 | break; |
---|
| 120 | case img_LINE: |
---|
[f346a33] | 121 | printf("LINE %.2f %.2f %.2f [%s]", pt.x, pt.y, pt.z, pimg->label); |
---|
[567445a] | 122 | switch (pimg->style) { |
---|
| 123 | case img_STYLE_UNKNOWN: |
---|
| 124 | break; |
---|
| 125 | case img_STYLE_NORMAL: |
---|
| 126 | printf(" STYLE=NORMAL"); |
---|
| 127 | break; |
---|
| 128 | case img_STYLE_DIVING: |
---|
| 129 | printf(" STYLE=DIVING"); |
---|
| 130 | break; |
---|
| 131 | case img_STYLE_CARTESIAN: |
---|
| 132 | printf(" STYLE=CARTESIAN"); |
---|
| 133 | break; |
---|
| 134 | case img_STYLE_CYLPOLAR: |
---|
| 135 | printf(" STYLE=CYLPOLAR"); |
---|
| 136 | break; |
---|
| 137 | case img_STYLE_NOSURVEY: |
---|
| 138 | printf(" STYLE=NOSURVEY"); |
---|
| 139 | break; |
---|
| 140 | } |
---|
[914e980] | 141 | if (pimg->flags & img_FLAG_SURFACE) printf(" SURFACE"); |
---|
| 142 | if (pimg->flags & img_FLAG_DUPLICATE) printf(" DUPLICATE"); |
---|
| 143 | if (pimg->flags & img_FLAG_SPLAY) printf(" SPLAY"); |
---|
[798a6bf] | 144 | if (show_dates && pimg->days1 != -1) { |
---|
| 145 | int y, m, d; |
---|
| 146 | ymd_from_days_since_1900(pimg->days1, &y, &m, &d); |
---|
| 147 | printf(" %04d.%02d.%02d", y, m, d); |
---|
| 148 | if (pimg->days1 != pimg->days2) { |
---|
| 149 | ymd_from_days_since_1900(pimg->days2, &y, &m, &d); |
---|
| 150 | printf("-%04d.%02d.%02d", y, m, d); |
---|
| 151 | } |
---|
| 152 | } |
---|
[914e980] | 153 | printf("\n"); |
---|
[e7b9e00] | 154 | break; |
---|
| 155 | case img_LABEL: |
---|
[f346a33] | 156 | printf("NODE %.2f %.2f %.2f [%s]", pt.x, pt.y, pt.z, pimg->label); |
---|
[914e980] | 157 | if (pimg->flags & img_SFLAG_SURFACE) printf(" SURFACE"); |
---|
| 158 | if (pimg->flags & img_SFLAG_UNDERGROUND) printf(" UNDERGROUND"); |
---|
| 159 | if (pimg->flags & img_SFLAG_ENTRANCE) printf(" ENTRANCE"); |
---|
| 160 | if (pimg->flags & img_SFLAG_EXPORTED) printf(" EXPORTED"); |
---|
| 161 | if (pimg->flags & img_SFLAG_FIXED) printf(" FIXED"); |
---|
[a2c33ae] | 162 | if (pimg->flags & img_SFLAG_ANON) printf(" ANON"); |
---|
[914e980] | 163 | printf("\n"); |
---|
[e7b9e00] | 164 | break; |
---|
[01a88e5] | 165 | case img_XSECT: |
---|
[a7f78d4] | 166 | printf("XSECT %.2f %.2f %.2f %.2f [%s]", |
---|
[01a88e5] | 167 | pimg->l, pimg->r, pimg->u, pimg->d, pimg->label); |
---|
[a7f78d4] | 168 | if (show_dates && pimg->days1 != -1) { |
---|
| 169 | int y, m, d; |
---|
| 170 | ymd_from_days_since_1900(pimg->days1, &y, &m, &d); |
---|
| 171 | printf(" %04d.%02d.%02d", y, m, d); |
---|
| 172 | if (pimg->days1 != pimg->days2) { |
---|
| 173 | ymd_from_days_since_1900(pimg->days2, &y, &m, &d); |
---|
| 174 | printf("-%04d.%02d.%02d", y, m, d); |
---|
| 175 | } |
---|
| 176 | } |
---|
| 177 | printf("\n"); |
---|
[01a88e5] | 178 | break; |
---|
| 179 | case img_XSECT_END: |
---|
| 180 | printf("XSECT_END\n"); |
---|
| 181 | break; |
---|
[68961ee] | 182 | case img_ERROR_INFO: |
---|
| 183 | printf("ERROR_INFO #legs %d, len %.2fm, E %.2f H %.2f V %.2f\n", |
---|
| 184 | pimg->n_legs, pimg->length, pimg->E, pimg->H, pimg->V); |
---|
| 185 | break; |
---|
[e7b9e00] | 186 | case img_BAD: |
---|
| 187 | img_close(pimg); |
---|
[a405bc1] | 188 | fatalerror(img_error2msg(img_error()), fnm); |
---|
[8f365d5] | 189 | case img_STOP: |
---|
| 190 | printf("STOP\n"); |
---|
| 191 | break; |
---|
[8dfcf6c] | 192 | default: |
---|
| 193 | printf("CODE_0x%02x\n", code); |
---|
[e7b9e00] | 194 | } |
---|
| 195 | } while (code != img_STOP); |
---|
| 196 | } while (fRewind); |
---|
[421b7d2] | 197 | |
---|
[02da880] | 198 | img_close(pimg); |
---|
| 199 | |
---|
| 200 | return 0; |
---|
| 201 | } |
---|