【发布时间】:2013-07-02 14:20:23
【问题描述】:
我有一个这样的程序:
./server
哪个有这个用法:
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
我能够用这段代码解析所有选项:
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);
}
但问题是,对于-n 选项,我必须得到这样的团队名称:
./server -n team1 team2 team2
我就是无法改变现状。
显然我可以做到:
./server -n "team1 team2 team3"
并解析团队,但这是针对我的公司的,他们不想在团队名称周围加上引号,不要问我为什么...
在不使用 shell 引号的情况下如何获取所有团队名称的任何帮助?
【问题讨论】: