-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathjnxutil.c
More file actions
151 lines (138 loc) · 3.76 KB
/
Copy pathjnxutil.c
File metadata and controls
151 lines (138 loc) · 3.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/******************************************************************************
jnxutil - Garmin jnx file manipulation utility.
-------------------
begin : 0:04 october,15 2019
copyright : (C)2019 by Plasteev Vladislav
email : apr2504@yandex.ru
*******************************************************************************/
/******************************************************************************
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*******************************************************************************/
#include "common.h"
int work_mode;
uint print_tiles_table, print_raw_values, new_value_number;
char tiles_dir[1024];
char *jnx_file_name;
char *new_value = "";
extern void check_jnx_file(void);
extern void read_jnx_file(void);
extern void read_tiles_table(void);
#ifdef WITH_GDAL
extern void export_tiles(void);
#endif
extern void edit_jnx_file(void);
void make_config(int argc, char **argv)
{
int option;
work_mode = -1;
print_tiles_table = 0;
print_raw_values = 0;
if (argc < 2)
{
USAGE;
exit(-1);
}
while ((option = getopt(argc, argv, ":Vh?ritev:n:d:")) != -1)
{
switch (option)
{
case 'V':
VERSION;
exit(1);
break;
case ':':
fprintf(stderr, "%s: option '-%c' needs argument\n", PROG_NAME, optopt);
exit(1);
break;
case 'v':
new_value = strdup(optarg);
break;
case 'i':
work_mode = INFO;
break;
case 'n':
work_mode = EDIT;
new_value_number = atoi(optarg);
break;
case 't':
print_tiles_table = 1;
break;
case 'r':
print_raw_values = 1;
break;
#ifdef WITH_GDAL
case 'e':
work_mode = TILES;
break;
case 'd':
ZERO_CHAR_L(tiles_dir, 1024);
strcpy(tiles_dir, optarg);
break;
#endif
case 'h':
case '?':
default :
USAGE; // macros defined in common.h
exit(1);
break;
} // switch
} // while
if (optind < argc) jnx_file_name = argv[optind];
if (jnx_file_name == NULL) jnx_file_name = "";
if ((strlen(jnx_file_name)) == 0)
{
fprintf(stderr, "%s: proper jnx filename should be specified\n", PROG_NAME);
exit(1);
}
#ifdef WITH_GDAL
if ((work_mode == TILES) & ((strlen(tiles_dir)) == 0))
{
fprintf(stderr, "%s: option '-e' needs output tiles dir ('-d' option)\n", PROG_NAME);
exit(1);
}
#endif
if ((work_mode == EDIT) & ((strlen(new_value)) == 0))
{
fprintf(stderr, "%s: option '-n' needs new value ('-v' option)\n", PROG_NAME);
exit(1);
}
if ((work_mode == -1) & (print_tiles_table == 0) & (print_raw_values == 0)) work_mode = INFO;
}
int main(int argc, char **argv)
{
make_config(argc, argv);
open_jnx_file();
check_jnx_file();
read_jnx_file();
read_tiles_table();
if (print_raw_values) elements_print();
switch (work_mode)
{
case INFO:
printout();
break;
#ifdef WITH_GDAL
case TILES:
export_tiles();
break;
#endif
case EDIT:
edit_jnx_file();
break;
}
free_struct_mem();
close_jnx_file();
exit(0);
}