mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-03 02:13:35 +02:00
main(): Use getopts for parameter parsing
This commit is contained in:
parent
346b1f05a7
commit
f9f5becd16
1 changed files with 18 additions and 2 deletions
20
main.cc
20
main.cc
|
@ -52,8 +52,24 @@ clear(void)
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
class map map(argc < 2 ? 40 : atoi(argv[1]), argc < 3 ? 20 : atoi(argv[2]));
|
int w = 40, h = 20;
|
||||||
int herbs = argc < 4 ? map.w * map.h / world::herb_rate : atoi(argv[3]);
|
int herbs_opt = -1;
|
||||||
|
|
||||||
|
int opt;
|
||||||
|
while ((opt = getopt(argc, argv, "h:x:y:")) != -1) {
|
||||||
|
switch (opt) {
|
||||||
|
case 'h': herbs_opt = atoi(optarg); break;
|
||||||
|
case 'x': w = atoi(optarg); break;
|
||||||
|
case 'y': h = atoi(optarg); break;
|
||||||
|
default: /* '?' */
|
||||||
|
fprintf(stderr, "Usage: %s [-h HERBS] [-x WIDTH] [-y HEIGHT]\n",
|
||||||
|
argv[0]);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class map map(w, h);
|
||||||
|
int herbs = herbs_opt < 0 ? map.w * map.h / world::herb_rate : herbs_opt;
|
||||||
|
|
||||||
#ifdef RAWIO
|
#ifdef RAWIO
|
||||||
if(rawio_cfg(&map)==-1)
|
if(rawio_cfg(&map)==-1)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue