@@ -75,6 +75,31 @@ void display_rate(struct timeval start, struct timeval end, int num)
7575 fflush (NULL );
7676}
7777
78+ int min_max_opt (char * opt_arg , char * opt_type_name , int minimum , int maximum )
79+ {
80+ int opt = atoi (opt_arg );
81+ float opt_float ;
82+
83+ if (minimum != -1 && opt < minimum ) {
84+ fprintf (stderr , "Invalid %s, must be >= %i (%s was provided)\n" , opt_type_name , minimum , opt_arg );
85+ exit (1 );
86+ }
87+
88+ if (maximum != -1 && opt > maximum ) {
89+ fprintf (stderr , "Invalid %s, must be <= %i (%s was provided)\n" , opt_type_name , maximum , opt_arg );
90+ exit (1 );
91+ }
92+
93+ if (sscanf (opt_arg , "%f" , & opt_float ) != 0 ) {
94+ if ((float ) opt != opt_float ) {
95+ fprintf (stderr , "Invalid %s, must be an integer (%s was provided)\n" , opt_type_name , opt_arg );
96+ exit (1 );
97+ }
98+ }
99+
100+ return opt ;
101+ }
102+
78103int main (int argc , char * * argv )
79104{
80105 char * spath = strdup (RENDERD_SOCKET );
@@ -141,53 +166,35 @@ int main(int argc, char **argv)
141166 break ;
142167
143168 case 'l' : /* -l, --max-load */
144- maxLoad = atoi (optarg );
169+ maxLoad = min_max_opt (optarg , "maximum load" , 0 , -1 );
145170 break ;
146171
147172 case 'n' : /* -n, --num-threads */
148- numThreads = atoi (optarg );
149-
150- if (numThreads <= 0 ) {
151- fprintf (stderr , "Invalid number of threads, must be at least 1\n" );
152- return 1 ;
153- }
154-
173+ numThreads = min_max_opt (optarg , "number of threads" , 1 , -1 );
155174 break ;
156175
157176 case 'x' : /* -x, --min-x */
158- minX = atoi (optarg );
177+ minX = min_max_opt (optarg , "minimum X tile coordinate" , 0 , -1 );
159178 break ;
160179
161180 case 'X' : /* -X, --max-x */
162- maxX = atoi (optarg );
181+ maxX = min_max_opt (optarg , "maximum X tile coordinate" , 0 , -1 );
163182 break ;
164183
165184 case 'y' : /* -y, --min-y */
166- minY = atoi (optarg );
185+ minY = min_max_opt (optarg , "minimum Y tile coordinate" , 0 , -1 );
167186 break ;
168187
169188 case 'Y' : /* -Y, --max-y */
170- maxY = atoi (optarg );
189+ maxY = min_max_opt (optarg , "maximum Y tile coordinate" , 0 , -1 );
171190 break ;
172191
173192 case 'z' : /* -z, --min-zoom */
174- minZoom = atoi (optarg );
175-
176- if (minZoom < 0 || minZoom > MAX_ZOOM ) {
177- fprintf (stderr , "Invalid minimum zoom selected, must be between 0 and %d\n" , MAX_ZOOM );
178- return 1 ;
179- }
180-
193+ minZoom = min_max_opt (optarg , "minimum zoom" , 0 , MAX_ZOOM );
181194 break ;
182195
183196 case 'Z' : /* -Z, --max-zoom */
184- maxZoom = atoi (optarg );
185-
186- if (maxZoom < 0 || maxZoom > MAX_ZOOM ) {
187- fprintf (stderr , "Invalid maximum zoom selected, must be between 0 and %d\n" , MAX_ZOOM );
188- return 1 ;
189- }
190-
197+ maxZoom = min_max_opt (optarg , "maximum zoom" , 0 , MAX_ZOOM );
191198 break ;
192199
193200 case 'f' : /* -f, --force */
@@ -211,6 +218,7 @@ int main(int argc, char **argv)
211218 fprintf (stderr , " -z, --min-zoom=ZOOM filter input to only render tiles greater or equal to this zoom level (default is 0)\n" );
212219 fprintf (stderr , "\n" );
213220 fprintf (stderr , "If you are using --all, you can restrict the tile range by adding these options:\n" );
221+ fprintf (stderr , " (please note that tile coordinates must be positive integers and are not latitude and longitude values)\n" );
214222 fprintf (stderr , " -X, --max-x=X maximum X tile coordinate\n" );
215223 fprintf (stderr , " -x, --min-x=X minimum X tile coordinate\n" );
216224 fprintf (stderr , " -Y, --max-y=Y maximum Y tile coordinate\n" );
0 commit comments