source: git/src/dump3d.c @ 27bd06b

RELEASE/1.0RELEASE/1.1RELEASE/1.2debug-cidebug-ci-sanitisersfaster-cavernloglog-selectstereostereo-2025walls-datawalls-data-hanging-as-warningwarn-only-for-hanging-survey
Last change on this file since 27bd06b was e7b9e00, checked in by Olly Betts <olly@…>, 23 years ago

Added --rewind option to call img_rewind and reread the contents.

git-svn-id: file:///home/survex-svn/survex/trunk@1814 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100644
File size: 3.4 KB
RevLine 
[02da880]1/* dump3d.c */
2/* Show raw contents of .3d file in text form */
[984f49e]3/* Copyright (C) 2001,2002 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
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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'},
[e7b9e00]37   {"rewind", no_argument, 0, 'r'},
[02da880]38   {"help", no_argument, 0, HLP_HELP},
39   {"version", no_argument, 0, HLP_VERSION},
40   {0, 0, 0, 0}
41};
42
[e7b9e00]43#define short_opts "rs:"
[02da880]44
45static struct help_msg help[] = {
46/*                              <-- */
[e4138b5]47   {HLP_ENCODELONG(0),          "only load the sub-survey with this prefix"},
[e7b9e00]48   {HLP_ENCODELONG(1),          "rewind file and read it a second time"},
[02da880]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;
[e7b9e00]60   bool fRewind = fFalse;
[02da880]61
[bdfe97f]62   msg_init(argv);
[02da880]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;
[e7b9e00]69      if (opt == 'r') fRewind = fTrue;
[02da880]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
[a2ad284]86   pimg = img_open_survey(fnm, survey);
[02da880]87   if (!pimg) fatalerror(img_error(), fnm);
[e7b9e00]88
[984f49e]89   printf("TITLE \"%s\"\n", pimg->title);
90   printf("DATE \"%s\"\n", pimg->datestamp);
[5757725]91   printf("VERSION %d\n", pimg->version);
[984f49e]92   printf("--\n");
[02da880]93
[e7b9e00]94   code = img_BAD;
[02da880]95   do {
[e7b9e00]96      if (code == img_STOP) {
97         printf("<<< REWIND <<<\n");
98         fRewind = fFalse;
99         if (!img_rewind(pimg)) fatalerror(img_error(), fnm);
[02da880]100      }
[e7b9e00]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]\n", pt.x, pt.y, pt.z, pimg->label);
110            break;
111          case img_LABEL:
112            printf("NODE %f %f %f [%s]\n", pt.x, pt.y, pt.z, pimg->label);
113            break;
114          case img_BAD:
115            img_close(pimg);
116            fatalerror(img_error(), fnm);
117         }
118      } while (code != img_STOP);
119   } while (fRewind);
[421b7d2]120
[02da880]121   img_close(pimg);
122
123   return 0;
124}
Note: See TracBrowser for help on using the repository browser.