source: git/src/imgtest.c @ 04078a7

faster-cavernloglog-selectwalls-datawalls-data-hanging-as-warningwarn-only-for-hanging-survey
Last change on this file since 04078a7 was b28bf56, checked in by Olly Betts <olly@…>, 4 years ago

Add regression test for preceding img fix

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/* imgtest.c */
2/* Test img in unhosted mode */
3/* Copyright (C) 2014,2020 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
26#include "img.h"
27
28int
29main(int argc, char **argv)
30{
31    char *fnm;
32    char *survey;
33    img *pimg;
34    unsigned long c_stations = 0;
35    unsigned long c_legs = 0;
36
37    if (argc < 2 || argc > 3) {
38        fprintf(stderr, "Syntax: %s 3DFILE [SURVEY]\n", argv[0]);
39        return 1;
40    }
41
42    fnm = argv[1];
43    survey = argv[2];
44
45    if (survey) {
46        pimg = img_open_survey(fnm, survey);
47    } else {
48        pimg = img_open(fnm);
49    }
50    if (!pimg) {
51        fprintf(stderr, "%s: Failed to open '%s' (error code %d)\n",
52                argv[0], fnm, (int)img_error());
53        return 1;
54    }
55
56    printf("Title: \"%s\"\n", pimg->title);
57    printf("Date: \"%s\"\n", pimg->datestamp);
58    printf("Format-Version: %d\n", pimg->version);
59    printf("Extended-Elevation: %s\n",
60           pimg->is_extended_elevation ? "yes" : "no");
61    while (1) {
62        img_point pt;
63        int code = img_read_item(pimg, &pt);
64        if (code == img_STOP) break;
65        switch (code) {
66            case img_LINE:
67                c_legs++;
68                break;
69            case img_LABEL:
70                c_stations++;
71                break;
72            case img_BAD:
73                img_close(pimg);
74                fprintf(stderr, "%s: img_read_item failed (error code %d)\n",
75                        argv[0], (int)img_error());
76                return 1;
77        }
78    }
79
80    printf("Stations: %lu\nLegs: %lu\n", c_stations, c_legs);
81
82    img_close(pimg);
83
84    return 0;
85}
Note: See TracBrowser for help on using the repository browser.