[ci] GHA fixes
[survex.git] / src / imgtest.c
blobe8b884ad4c1b230125d15e6f466b9dc2f9f86614
1 /* imgtest.c */
2 /* Test img in unhosted mode */
3 /* Copyright (C) 2014,2020 Olly Betts
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.
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.
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
20 #ifdef HAVE_CONFIG_H
21 # include <config.h>
22 #endif
24 #include <stdio.h>
26 #include "img.h"
28 int
29 main(int argc, char **argv)
31 char *fnm;
32 char *survey;
33 img *pimg;
34 unsigned long c_stations = 0;
35 unsigned long c_legs = 0;
37 if (argc < 2 || argc > 3) {
38 fprintf(stderr, "Syntax: %s 3DFILE [SURVEY]\n", argv[0]);
39 return 1;
42 fnm = argv[1];
43 survey = argv[2];
45 if (survey) {
46 pimg = img_open_survey(fnm, survey);
47 } else {
48 pimg = img_open(fnm);
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;
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;
80 printf("Stations: %lu\nLegs: %lu\n", c_stations, c_legs);
82 img_close(pimg);
84 return 0;