source: git/src/imgtest.c @ 226342b

Last change on this file since 226342b was 4c83f84, checked in by Olly Betts <olly@…>, 7 months ago

Don't check HAVE_CONFIG_H in most cases

This check is only useful for img.c, which is intended to be usable
outside of Survex (and had fallbacks for functions which may not be
available which will get used if built in a non-autotools project).
For all the other source files it's just useless boilerplate.

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