source: git/src/dump3d.c @ 6a6cb97

RELEASE/1.0
Last change on this file since 6a6cb97 was 6a6cb97, checked in by Olly Betts <olly@…>, 14 years ago

src/img.c,src/img.h: Update to the version from 1.1.13 so that we
can read version 6 .3d files written by newer 1.1.x releases.
src/dump3d.c,src/extend.c,src/netskel.c: Set img_output_version to 3
before writing out a .3d file for compatibility with older 1.0.x
releases. We don't use any of the newer features, so there's no
benefit to using a newer format version.

git-svn-id: file:///home/survex-svn/survex/branches/1.0@3444 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100644
File size: 3.4 KB
Line 
1/* dump3d.c */
2/* Show raw contents of .3d file in text form */
3/* Copyright (C) 2001,2002,2010 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   img_output_version = 3;
75   pimg = img_open_write("dump3d.3d", "dump3d", fTrue);
76   if (!pimg) fatalerror(img_error(), "dump3d.3d");
77   img_write_item(pimg, img_MOVE, 0, NULL, 0, 0, 0);
78   img_write_item(pimg, img_LINE, 0, "161.lostworld.upstream",
79                  36920.120000, 82672.840000, 1528.820000);
80   img_write_item(pimg, img_LINE, 0, "161.keinzimmer",
81                  36918.480000, 82663.360000, 1527.670000);
82   img_write_item(pimg, img_LINE, 0, "161.lostworld.upstream",
83                  36959.760000, 82679.880000, 1537.900000);
84   img_close(pimg);
85#endif
86
87   pimg = img_open_survey(fnm, survey);
88   if (!pimg) fatalerror(img_error(), fnm);
89
90   printf("TITLE \"%s\"\n", pimg->title);
91   printf("DATE \"%s\"\n", pimg->datestamp);
92   printf("VERSION %d\n", pimg->version);
93   printf("--\n");
94
95   code = img_BAD;
96   do {
97      if (code == img_STOP) {
98         printf("<<< REWIND <<<\n");
99         fRewind = fFalse;
100         if (!img_rewind(pimg)) fatalerror(img_error(), fnm);
101      }
102
103      do {
104         code = img_read_item(pimg, &pt);
105         switch (code) {
106          case img_MOVE:
107            printf("MOVE %f %f %f\n", pt.x, pt.y, pt.z);
108            break;
109          case img_LINE:
110            printf("LINE %f %f %f [%s]\n", pt.x, pt.y, pt.z, pimg->label);
111            break;
112          case img_LABEL:
113            printf("NODE %f %f %f [%s]\n", pt.x, pt.y, pt.z, pimg->label);
114            break;
115          case img_BAD:
116            img_close(pimg);
117            fatalerror(img_error(), fnm);
118         }
119      } while (code != img_STOP);
120   } while (fRewind);
121
122   img_close(pimg);
123
124   return 0;
125}
Note: See TracBrowser for help on using the repository browser.