I have a program like this :
./server
Which has this usage :
Usage :
-p Port to use (4242 by default)
-x Map width (20)
-y Map height (20)
-n Team name (name_team1 name_team2)
-c Players per team
-t Delay
I was able to parse all the options with this code :
int parse_cmd(int argc, char **argv, t_args *a)
{
char ch;
if (argv[1] && argv[1][0] != '-')
usage();
while ((ch = getopt(argc, argv, "p:x:y:n:c:t:")) != -1)
{
if (ch == 'p')
a->port = atoi(optarg);
else if (ch == 'x')
a->x = atoi(optarg);
else if (ch == 'y')
a->y = atoi(optarg);
else if (ch == 'n')
a->teams = name_teams(optarg);
else if (ch == 'c')
a->size = atoi(optarg);
else if (ch == 't')
a->delay = atoi(optarg);
else
usage();
}
if (check_values(a) == FALSE)
return (FALSE);
return (TRUE);
}
But the thing is, for the -n
option, I have to get the teams names like this :
./server -n team1 team2 team2
I just can't change the way it is.
Obviously I can do :
./server -n "team1 team2 team3"
And parse the teams, but it's for my firm and they don't want to put quotes around the team names, don't ask me why...
Any help in how can I get all the team names without using the quotes in shell?