source: git/src/dump3d.c @ 8dfcf6c

RELEASE/1.1RELEASE/1.2debug-cidebug-ci-sanitisersstereowalls-data
Last change on this file since 8dfcf6c was 8dfcf6c, checked in by Olly Betts <olly@…>, 18 years ago

Report unknown (to dump3d) codes returned by img.

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

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/* dump3d.c */
2/* Show raw contents of .3d file in text form */
3/* Copyright (C) 2001,2002,2006 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#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"
30#include "debug.h"
31#include "filelist.h"
32#include "img.h"
33
34static const struct option long_opts[] = {
35   /* const char *name; int has_arg (0 no_argument, 1 required_*, 2 optional_*); int *flag; int val; */
36   {"survey", required_argument, 0, 's'},
37   {"rewind", no_argument, 0, 'r'},
38   {"help", no_argument, 0, HLP_HELP},
39   {"version", no_argument, 0, HLP_VERSION},
40   {0, 0, 0, 0}
41};
42
43#define short_opts "rs:"
44
45static struct help_msg help[] = {
46/*                              <-- */
47   {HLP_ENCODELONG(0),          "only load the sub-survey with this prefix"},
48   {HLP_ENCODELONG(1),          "rewind file and read it a second time"},
49   {0, 0}
50};
51
52int
53main(int argc, char **argv)
54{
55   char *fnm;
56   img *pimg;
57   img_point pt;
58   int code;
59   const char *survey = NULL;
60   bool fRewind = fFalse;
61
62   msg_init(argv);
63
64   cmdline_init(argc, argv, short_opts, long_opts, NULL, help, 1, 1);
65   while (1) {
66      int opt = cmdline_getopt();
67      if (opt == EOF) break;
68      if (opt == 's') survey = optarg;
69      if (opt == 'r') fRewind = fTrue;
70   }
71   fnm = argv[optind];
72
73#if 0
74   pimg = img_open_write("dump3d.3d", "dump3d", fTrue);
75   if (!pimg) fatalerror(img_error(), "dump3d.3d");
76   img_write_item(pimg, img_MOVE, 0, NULL, 0, 0, 0);
77   img_write_item(pimg, img_LINE, 0, "161.lostworld.upstream",
78                  36920.120000, 82672.840000, 1528.820000);
79   img_write_item(pimg, img_LINE, 0, "161.keinzimmer",
80                  36918.480000, 82663.360000, 1527.670000);
81   img_write_item(pimg, img_LINE, 0, "161.lostworld.upstream",
82                  36959.760000, 82679.880000, 1537.900000);
83   img_close(pimg);
84#endif
85
86   pimg = img_open_survey(fnm, survey);
87   if (!pimg) fatalerror(img_error(), fnm);
88
89   printf("TITLE \"%s\"\n", pimg->title);
90   printf("DATE \"%s\"\n", pimg->datestamp);
91   printf("VERSION %d\n", pimg->version);
92   printf("--\n");
93
94   code = img_BAD;
95   do {
96      if (code == img_STOP) {
97         printf("<<< REWIND <<<\n");
98         fRewind = fFalse;
99         if (!img_rewind(pimg)) fatalerror(img_error(), fnm);
100      }
101
102      do {
103         code = img_read_item(pimg, &pt);
104         switch (code) {
105          case img_MOVE:
106            printf("MOVE %f %f %f\n", pt.x, pt.y, pt.z);
107            break;
108          case img_LINE:
109            printf("LINE %f %f %f [%s]", pt.x, pt.y, pt.z, pimg->label);
110            if (pimg->flags & img_FLAG_SURFACE) printf(" SURFACE");
111            if (pimg->flags & img_FLAG_DUPLICATE) printf(" DUPLICATE");
112            if (pimg->flags & img_FLAG_SPLAY) printf(" SPLAY");
113            printf("\n");
114            break;
115          case img_LABEL:
116            printf("NODE %f %f %f [%s]", pt.x, pt.y, pt.z, pimg->label);
117            if (pimg->flags & img_SFLAG_SURFACE) printf(" SURFACE");
118            if (pimg->flags & img_SFLAG_UNDERGROUND) printf(" UNDERGROUND");
119            if (pimg->flags & img_SFLAG_ENTRANCE) printf(" ENTRANCE");
120            if (pimg->flags & img_SFLAG_EXPORTED) printf(" EXPORTED");
121            if (pimg->flags & img_SFLAG_FIXED) printf(" FIXED");
122            printf("\n");
123            break;
124          case img_XSECT:
125            printf("XSECT %f %f %f %f [%s]\n",
126                   pimg->l, pimg->r, pimg->u, pimg->d, pimg->label);
127            break;
128          case img_XSECT_END:
129            printf("XSECT_END\n");
130            break;
131          case img_BAD:
132            img_close(pimg);
133            fatalerror(img_error(), fnm);
134          default:
135            printf("CODE_0x%02x\n", code);
136         }
137      } while (code != img_STOP);
138   } while (fRewind);
139
140   img_close(pimg);
141
142   return 0;
143}
Note: See TracBrowser for help on using the repository browser.